Initial Commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
# OpenSpec Change: enterprise-gaming-api-plugin-matchmaking
|
||||
|
||||
- **Change ID**: enterprise-gaming-api-plugin-matchmaking
|
||||
- **Package**: `@suaveplan/api-plugin-matchmaking`
|
||||
- **Category**: gaming/server
|
||||
- **Target path**: `gaming/server/api-plugin-matchmaking`
|
||||
- **Status**: PROPOSED
|
||||
- **Date**: 2026-04-24
|
||||
- **Reference spec**: `/mnt/s/web/suaveplan/enterprise/api-plugin-matchmaking.md`
|
||||
|
||||
---
|
||||
|
||||
## Summary
|
||||
|
||||
Deliver `@suaveplan/api-plugin-matchmaking` on the genesis branch from scratch at enterprise quality. The package wraps a `MatchmakingQueue` in a Hono HTTP plugin. The queue accepts skill-rated players, sorts by rating, and builds balanced teams using alternating-rank assignment with a configurable skill gap that widens over wait time. HTTP routes expose enqueue, dequeue, status, and queue stats. Genesis adds Zod player schemas, structured errors, OTel queue-depth gauge, injectable clock, and 100% coverage.
|
||||
|
||||
---
|
||||
|
||||
## Current-state audit (genesis)
|
||||
|
||||
Package does not exist on genesis yet — fresh build.
|
||||
|
||||
---
|
||||
|
||||
## Available workspace deps on genesis
|
||||
|
||||
| Package | Role |
|
||||
|---|---|
|
||||
| `@suaveplan/error` (`workspace:^`) | `MatchmakingError`; `MM.*` codes |
|
||||
| `@suaveplan/types` (`workspace:^`) | `Clock` |
|
||||
| `@suaveplan/events` (`workspace:^`) | `mm:enqueued`, `mm:match_found`, `mm:dequeued` events |
|
||||
| `zod` (`catalog:forms`) | `QueuedPlayer`, `MatchResult` schemas |
|
||||
| `@opentelemetry/api` (`catalog:observability`) | Queue depth gauge, match counter |
|
||||
|
||||
---
|
||||
|
||||
## HTTP Routes
|
||||
|
||||
| Method | Path | Description |
|
||||
|---|---|---|
|
||||
| `POST` | `/queue` | Enqueue player |
|
||||
| `DELETE` | `/queue/:playerId` | Dequeue player |
|
||||
| `GET` | `/queue/:playerId/status` | Queue position |
|
||||
| `POST` | `/queue/tick` | Advance matchmaking (server-side tick) |
|
||||
| `GET` | `/queue/stats` | Queue depth, avg wait time |
|
||||
|
||||
---
|
||||
|
||||
## Core logic
|
||||
|
||||
```ts
|
||||
interface QueuedPlayer {
|
||||
playerId: string
|
||||
displayName: string
|
||||
skillRating: number
|
||||
gameMode: string
|
||||
enqueuedAt: number
|
||||
}
|
||||
|
||||
interface MatchResult {
|
||||
matchId: string
|
||||
team1: QueuedPlayer[]
|
||||
team2: QueuedPlayer[]
|
||||
avgSkillGap: number
|
||||
createdAt: number
|
||||
}
|
||||
|
||||
function createMatchmakingQueue(options: MatchmakingOptions): MatchmakingQueue
|
||||
|
||||
interface MatchmakingOptions {
|
||||
teamSize?: number // players per team, default 5
|
||||
baseSkillGap?: number // initial acceptable gap, default 200
|
||||
expandGapPerSecond?: number // gap expansion rate, default 10/sec
|
||||
clock?: Clock
|
||||
}
|
||||
|
||||
interface MatchmakingQueue {
|
||||
enqueue(player: QueuedPlayer): void
|
||||
dequeue(playerId: string): void
|
||||
findMatches(now: number): MatchResult[]
|
||||
getStatus(playerId: string): QueueStatus | undefined
|
||||
getStats(): QueueStats
|
||||
}
|
||||
```
|
||||
|
||||
### Error codes
|
||||
|
||||
```ts
|
||||
type MatchmakingErrorCode =
|
||||
| 'MM_PLAYER_NOT_FOUND'
|
||||
| 'MM_ALREADY_QUEUED'
|
||||
| 'MM_INVALID_GAME_MODE'
|
||||
| 'MM_QUEUE_FULL'
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## File layout
|
||||
|
||||
```text
|
||||
gaming/server/api-plugin-matchmaking/
|
||||
package.json
|
||||
tsconfig.json
|
||||
vitest.config.ts
|
||||
src/
|
||||
index.ts
|
||||
error-codes.ts
|
||||
types/common.ts
|
||||
types/common.md
|
||||
core/
|
||||
matchmaking-queue/
|
||||
matchmaking-queue.ts
|
||||
matchmaking-queue.md
|
||||
matchmaking-queue.types.ts
|
||||
matchmaking-queue.test.ts
|
||||
index.ts
|
||||
routes/
|
||||
queue.ts
|
||||
queue.md
|
||||
plugin.ts
|
||||
plugin.md
|
||||
tests/
|
||||
integration.test.ts
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Impact
|
||||
|
||||
**Downstream**: `@suaveplan/api-plugin-game-server` creates sessions for matched groups. Prerequisites: `@suaveplan/error`, `@suaveplan/types`, `@suaveplan/events`.
|
||||
@@ -0,0 +1,42 @@
|
||||
# Tasks: enterprise-gaming-api-plugin-matchmaking
|
||||
|
||||
## 0. Pre-flight (non-negotiable)
|
||||
|
||||
- [ ] 0.1 Confirm clean working tree (`git status` reports nothing) and no in-flight worktrees with uncommitted work (`git worktree list` then `git status` in each)
|
||||
- [ ] 0.2 If any worktrees exist under `.claude/worktrees/`, account for each one: still-active agent, work-pending-merge, or stale-and-prune. Stale worktrees MUST be removed (`git worktree remove`) before opening a new one — code that has been lost twice on main is the failure mode this guards against.
|
||||
- [ ] 0.3 Confirm the package set in `MANIFEST.md` matches `find packages -maxdepth 3 -name package.json` count. Drift here means a prior change archived without regenerating the manifest.
|
||||
|
||||
## Phase 1 — Scaffold
|
||||
|
||||
- [ ] Create `gaming/server/api-plugin-matchmaking/` (`@suaveplan/api-plugin-matchmaking`, `0.1.0`, `sideEffects: false`)
|
||||
- [ ] `tsconfig.json`, `vitest.config.ts`
|
||||
|
||||
## Phase 2 — Error codes + types
|
||||
|
||||
- [ ] `src/error-codes.ts` + `src/types/common.ts` + `common.md`
|
||||
|
||||
## Phase 3 — Matchmaking queue
|
||||
|
||||
- [ ] `src/core/matchmaking-queue/matchmaking-queue.ts` — sorted enqueue, time-expanding gap, team builder, events, OTel
|
||||
- [ ] Tests (balanced teams, expanding gap, already-queued guard)
|
||||
- [ ] Docs
|
||||
|
||||
## Phase 4 — Queue routes
|
||||
|
||||
- [ ] `src/routes/queue.ts` — enqueue/dequeue/status/tick/stats
|
||||
- [ ] `src/routes/queue.md`
|
||||
|
||||
## Phase 5 — Plugin factory
|
||||
|
||||
- [ ] `src/plugin.ts` — `matchmakingPlugin()` factory
|
||||
- [ ] `src/plugin.md`
|
||||
|
||||
## Phase 6 — Integration tests
|
||||
|
||||
- [ ] `tests/integration.test.ts` — enqueue players → POST /queue/tick → verify match_found
|
||||
|
||||
## Phase 7 — Pre-publish gate
|
||||
|
||||
- [ ] `bunx turbo lint typecheck test --filter=@suaveplan/api-plugin-matchmaking` green
|
||||
- [ ] 100% coverage
|
||||
- [ ] Publish: `bun scripts/publish.ts --package @suaveplan/api-plugin-matchmaking`
|
||||
Reference in New Issue
Block a user