Data Types
All shared TypeScript types are defined in src/types/index.ts. This document explains each type in plain language, including what the values mean and how they are used in practice.
Primitive Union Types
Section titled “Primitive Union Types”CardType
Section titled “CardType”type CardType = 'Pokemon' | 'Trainer' | 'Energy';The three card categories in the Pokemon TCG. Used to group cards in the deck list and to infer the role during import.
CardRole
Section titled “CardRole”type CardRole = 'attacker' | 'supporter' | 'item' | 'stadium' | 'energy' | 'tech';A more granular classification than CardType. The role is inferred during deck import by src/lib/deckImport.ts — it is never entered manually. Rules:
Pokemoncards are'attacker'by default, or'tech'if the name matches a known tech-Pokemon list (Budew, Fezandipiti, Pecharunt, etc.)Trainercards are classified as'supporter','item', or'stadium'based on name heuristicsEnergycards are always'energy'
EventType
Section titled “EventType”type EventType = 'LC' | 'LCup' | 'Regional' | 'Worlds' | 'Online';The type of event where a match was played. LC = League Challenge, LCup = League Cup. Not the match format — see BestOf below; EventType only feeds BestOf’s default (Regional/Worlds → Bo3, else Bo1) in the log form, it is never used to infer the format for an already-logged match.
BestOf (@pokekon/shared)
Section titled “BestOf (@pokekon/shared)”const BEST_OF_VALUES = ['BO1', 'BO3'] as const;type BestOf = (typeof BEST_OF_VALUES)[number];Whether a logged match was single-game (Bo1) or best-of-three (Bo3). Lives on OpponentLog.bestOf as BestOf | undefined — undefined means “format unknown” (a log written before this field existed), never a silently-assumed default. Used to convert a Bo3 win rate back to its Bo1 equivalent (bo1ToBo3WinRate/bo3ToBo1WinRate, closed-form inverse of P_Bo3 = 3p² − 2p³) so a mixed Bo1/Bo3 personal record can be compared to the Bo1-only meta baseline (bo1EquivalentWinRate).
MatchResult
Section titled “MatchResult”type MatchResult = 'W' | 'L' | 'T';Win, Loss, or Tie. Semantic change: meta snapshots, the matchup matrix and ArchetypeStats.winRate now weight a tie as a third of a win (tournamentWinRatePct = (wins + ties/3) / (wins + losses + ties), @pokekon/shared) — the official tournament scoring — instead of excluding ties entirely. A handful of other, deliberately unchanged personal-analytics views (deckAnalytics.ts’s WinRateBlock, deckPerformanceStats.ts, useRecommendations.ts) still use the older “decided games only” semantic; that inconsistency is out of scope here (Spec 4).
Database Entity Types
Section titled “Database Entity Types”These are the types that map directly to IndexedDB tables.
interface Card { id?: number; name: string; set: string; number: string; type: CardType; subtype: string;}A card definition. The id is optional because it is assigned by Dexie on insert. The set field holds the set code (e.g., "TWM") and number holds the collector number (e.g., "189"). In practice, the cards table is rarely queried directly — card data is denormalized into deckCards.
interface Deck { id?: number; archetype: string; archetypeName: string; variant: string; createdAt: string;}One row per deck the user manages. The distinction between archetype and archetypeName:
archetypeis the Limitless slug (lowercase, hyphen-separated, e.g."n-zoroark"). This is used when matching against Limitless API tournament data.archetypeNameis the display name (e.g.,"N's Zoroark"). This is what the user sees in the UI.variantdescribes the specific build within an archetype (e.g.,"Fezandipiti Build"). Multiple deck rows can share the samearchetypeandarchetypeNamebut have differentvariantlabels.
DeckCard
Section titled “DeckCard”interface DeckCard { id?: number; deckId?: number; cardId: number; name: string; count: number; type: CardType; role: CardRole;}One row per distinct card in a deck. count is how many copies are in the list (1–4). The cardId is a foreign key to the cards table, but in practice it is often 0 when the card was imported from a text list without a matching card entry.
DeckSnapshot
Section titled “DeckSnapshot”interface DeckSnapshot { id?: number; deckId?: number; label: string; cards: string; totalCards: number; createdAt: string;}A frozen copy of a deck’s card list at a specific point in time. The cards field is JSON.stringify(DeckCard[]) — the full array serialized as a string. Use parseDeckSnapshot(snap) from queries.ts to get it back as an array. The label is a free-text user description, typically describing what changed in that version (e.g., "Added Fezandipiti, -1 Judge").
OpponentLog
Section titled “OpponentLog”interface OpponentLog { id?: number; deckId?: number; archetype: string; eventType: EventType; bestOf?: BestOf; eventDate: string; result: MatchResult; notes: string; round?: number; deckSnapshotId?: number; battleLog?: string; analysis?: string;}One row per match played. This is the primary personal-data table. Key fields:
archetype: The opponent’s deck archetype. This is entered manually and must match the names used inmetaSnapshotsfor win-rate correlation to work.bestOf: Bo1 or Bo3 (seeBestOfabove). Required on new logs;undefinedon logs written before this field existed (“format unknown” — shown as a badge, excluded from the Bo1-equivalent comparison but still counted inwinRate).deckSnapshotId: Optional. When set, it links this match to the deck version that was played. This is what powers the “version comparison” recommendations.battleLog: The raw text copied from TCG Live’s battle protocol (in German). Optional — only present when the user pastes it in.analysis:JSON.stringify(BattleAnalysis)— the result of the server-side LLM analyzing the battle log. Only present after the user triggers analysis.
Wire-only addition, not part of this type (plan personal-data-role-rework.md
§0.6/§3.7): apps/web/src/lib/api.ts’s LogWriteBody is Omit<OpponentLog, 'id'> & { playerName?: string }. playerName is never persisted on opponent_logs
— it only pins “me” for the server-side battle-log parse
(apps/api/src/lib/matchLogPipeline.ts), closing a gap where the web client
accepted-but-never-sent the field the server already validated.
UserPreferences (Spec 7 §5.1)
Section titled “UserPreferences (Spec 7 §5.1)”interface UserPreferences { activeArchetypeId: string | null; // Limitless slug; null → onboarding activeDeckIdByArchetype: Record<string, number>; // last active deck per archetype slug}Server table user_preferences (database.md), exposed as
GET/PATCH /api/preferences (response shape = this type, PreferencesResponse in
apps/api/src/routes/preferences.ts). The PATCH body is partial:
{ activeArchetypeId?: string | null; activeDeck?: { archetypeId: string; deckId: number | null } }
— at least one field, unknown keys rejected, deckId: null forgets that archetype’s entry.
Deck Performance Types
Section titled “Deck Performance Types”These types represent aggregated statistics computed from battle logs in src/lib/deckPerformanceStats.ts.
CardPerformance
Section titled “CardPerformance”interface CardPerformance { card: string; totalPlays: number; gamesPlayed: number; totalGames: number; playRate: number; winsWithCard: number; lossesWithCard: number; winRate: number; avgPlaysPerGame: number;}Performance stats for a single card across all analyzed battle logs. Definitions:
playRate:gamesPlayed / totalGames * 100— what percentage of games this card was played at allwinRate:winsWithCard / (winsWithCard + lossesWithCard) * 100— win rate in games where the card was played (0 when no decisive games)avgPlaysPerGame:totalPlays / gamesPlayed— how often the card is played per game it appears in
Cards played in fewer than 2 games are excluded from the output.
DeckPerformanceStats
Section titled “DeckPerformanceStats”interface DeckPerformanceStats { totalGamesAnalyzed: number; overallWinRate: number; avgGameLength: number; avgGameLengthWins: number; avgGameLengthLosses: number; avgTurn1Actions: number; lowActivityTurnRate: number; cardPerformance: CardPerformance[]; prizeEfficiency: { avgPrizesOpponentTookInWins: number; avgPrizesYouTookInLosses: number; lossGamesCount: number; winGamesCount: number; };}The top-level aggregation result. The prizeEfficiency object measures how close games are:
avgPrizesOpponentTookInWins: How many prizes the opponent took before you won. Lower = more dominant wins.avgPrizesYouTookInLosses: How many prizes you took before losing. Higher = you were close to winning even in losses.lowActivityTurnRate: Percentage of your turns where you played 1 or fewer cards. A high value (>35%) is a “brick rate” signal.
Battle Log Analysis Types
Section titled “Battle Log Analysis Types”These types represent the structured output from the server-side LLM battle-log analysis. They are defined in @pokekon/shared (shared by the API’s analysis route and the web client).
BattleAnalysisPlay
Section titled “BattleAnalysisPlay”interface BattleAnalysisPlay { turn: number; observation: string; evidence: string; suggestion?: string; impact: 'high' | 'medium' | 'low';}One notable play or mistake, with the turn it occurred and a mandatory verbatim quote from the battle log as evidence. The evidence requirement is an anti-hallucination measure: any item whose evidence cannot be found in the raw log is discarded after parsing.
BattleAnalysisCardNote
Section titled “BattleAnalysisCardNote”interface BattleAnalysisCardNote { card: string; observation: string; evidence: string; deckSuggestion?: 'add' | 'remove' | 'increase' | 'decrease' | null; deckSuggestionReason?: string;}An observation about a specific card’s performance during the game. The optional deckSuggestion and deckSuggestionReason fields carry card-level deck change recommendations from the AI.
BattleAnalysis
Section titled “BattleAnalysis”interface BattleAnalysis { playerName: string; opponentName: string; summary: string; keyMoments: BattleAnalysisPlay[]; playMistakes: BattleAnalysisPlay[]; cardNotes: BattleAnalysisCardNote[]; deckSuggestions: { action: 'add' | 'remove' | 'increase' | 'decrease'; card: string; reasoning: string; evidence: string; }[]; analyzedAt: string;}The complete analysis of one match. Stored in opponentLogs.analysis as a JSON string. All four arrays (keyMoments, playMistakes, cardNotes, deckSuggestions) are validated after Claude returns the response — items whose evidence field cannot be found in the raw log are silently removed.
Battle-Log Prefill Types (@pokekon/shared)
Section titled “Battle-Log Prefill Types (@pokekon/shared)”Introduced by the battle-log-first “Match loggen” flow (plan
personal-data-role-rework.md §3.1–§3.5, packages/shared/src/battleLogPrefill.ts).
Pure, client-side computation — none of this is persisted; it only pre-fills the
AddLogModal form fields from a pasted battle log.
ArchetypeSignature
Section titled “ArchetypeSignature”interface ArchetypeSignature { slug: string; name: string; logNames: string[];}One archetype’s recognition signature: card-name fragments as they appear in a
German PTCG-Live log. Supplied by the caller (apps/web/src/constants/archetypes.ts’s
archetypeSignatures()) so this module stays free of UI constants.
ArchetypeCandidate
Section titled “ArchetypeCandidate”interface ArchetypeCandidate { slug: string; name: string; matched: string[]; coverage: number;}One archetype’s match result against a set of opponent card names. coverage is
matched.length / signature.logNames.length (0–1, unrounded) — a coverage
ratio, not a fabricated percent confidence: the parser itself exposes no
confidence signal at all.
OpponentArchetypeGuess
Section titled “OpponentArchetypeGuess”interface OpponentArchetypeGuess { candidates: ArchetypeCandidate[]; // sorted by coverage desc, then name asc; max 3 best: ArchetypeCandidate | null; // non-null exactly when confidence === 'unique' confidence: 'unique' | 'ambiguous' | 'none';}unique = exactly one candidate reaches coverage 1 with no tie at the top → safe
to pre-select. ambiguous = at least one candidate, but not uniquely so → offer,
never pick. none = nothing matched at all.
BattleLogPrefill
Section titled “BattleLogPrefill”interface BattleLogPrefill { parsed: ParsedBattleLog; playerPinned: boolean; detectedPlayers: [string, string]; opponentCards: string[]; archetype: OpponentArchetypeGuess; result: 'W' | 'L' | null; // never 'T' — German logs carry no draw marker}The full prefill result for one pasted log, assembled by
prefillFromBattleLog(log, playerName, signatures). playerPinned is true only
when playerName exactly matched one of the two names the parser detected — when
false, the UI must ask “Welcher Spieler bist du?” before using result or
archetype (an unpinned split could mean the “opponent” card evidence is actually
the local player’s own deck).
Meta Data Types
Section titled “Meta Data Types”MetaSnapshot
Section titled “MetaSnapshot”interface MetaSnapshot { id?: number; archetype: string; frequencyPct: number; winRatePct: number | null; wins: number; losses: number; ties: number; playerCount: number; period: string; sourceNote: string;}One archetype’s stats for one week. The period field uses the ISO week format YYYY-Www (e.g., "2026-W15"). The sourceNote is auto-generated during sync and describes which tournaments and how many players were included. winRatePct is the tie-weighted tournament win rate (see MatchResult above) — null only when the archetype had zero games in the period, not merely zero decisive games.
WilsonInterval (Spec 3 — packages/shared/src/wilsonInterval.ts)
Section titled “WilsonInterval (Spec 3 — packages/shared/src/wilsonInterval.ts)”interface WilsonInterval { pct: number; // tie-weighted point estimate in percent, unrounded lowPct: number; // lower bound, clamped to [0, 100] highPct: number; // upper bound, clamped to [0, 100] widthPct: number; // highPct - lowPct n: number; // wins + losses + ties significant: boolean; // true when the interval excludes 50 %}The 95 % Wilson score interval (score-test inversion — not the Wald/normal approximation, which collapses to zero width at p̂ ∈ {0, 1}) for a tie-weighted wins/losses/ties record. null when n === 0. Ties are a deliberately conservative approximation: the score used is wins + ties/3 (the same tie-weighted value as tournamentWinRate), evaluated with the standard binomial Wilson formula, which slightly overstates the true trinomial variance — the interval comes out a few percent too wide, never too narrow. zForConfidence is table-backed (80/90/95/98/99 % — no numeric approximation) and throws for any other level. combineIndependentIntervals propagates a share-weighted sum of independent Wilson intervals via Var(Σ wᵢXᵢ) = Σ wᵢ²Var(Xᵢ), reading each term’s asymmetric standard error back from its own bounds; a term whose bounds equal its point estimate (e.g. the definitional 50 % mirror) contributes zero variance. matchupCellInterval resolves one MatchupCell’s interval by precedence: explicit lowPct/highPct on the cell, then raw wins/losses/ties (only if they sum to at least one game — an all-zero placeholder record falls through), then a reconstruction from total/winRate. This is the only place the Wilson formula is implemented in the repo; nothing else re-derives it.
Independence caveat: real matchup cells in one row share players/tournaments (mild correlation) and the sharePct weights are themselves estimates treated as exact here — both effects make the combined band tend to be too narrow, not too wide, partially offsetting the ties approximation above. Accepted for now (plan confidence-aware-matchups.md §6 risk 3); not a correctness bug, a documented approximation.
MatchupCell / WeightedMatchup / FieldScore (Spec 3 — packages/shared/src/fieldWinRate.ts)
Section titled “MatchupCell / WeightedMatchup / FieldScore (Spec 3 — packages/shared/src/fieldWinRate.ts)”interface MatchupCell { deck1: string; deck2: string; total: number; winRate: number; wins?: number; losses?: number; ties?: number; // raw record (preferred) lowPct?: number; highPct?: number; // precomputed bounds (win over raw record)}
interface WeightedMatchup { archetypeId: string; archetypeName: string; sharePct: number; winRatePct: number; games: number; weightPct: number; lowPct: number; highPct: number; significant: boolean;}
interface FieldScore { archetypeId: string; archetypeName: string; sharePct: number; fieldWinRatePct: number | null; fieldWinRateLowPct: number | null; fieldWinRateHighPct: number | null; coveragePct: number; mirrorSharePct: number; rank: number; threats: WeightedMatchup[]; freeWins: WeightedMatchup[];}computeFieldScores(shares, matchups, opts?) computes the meta-weighted field win rate for every archetype. Spec 3 change: the previous hard MIN_MATCHUP_GAMES (10) sample-size cutoff is gone — a cell is skipped only when it is missing or has total <= 0 (no data at all); a 1-game cell now counts fully, with its uncertainty expressed as fieldWinRateLowPct/fieldWinRateHighPct (full error propagation via combineIndependentIntervals, weight = opponent sharePct) instead of vanishing. The point estimate is still the raw cell.winRate — no shrinkage toward the Wilson centre (a deliberate choice: shrinking would decouple the displayed matrix number from the field-score input for the same cell; candidate for a later spec). opts.minGamesPerPair was removed (no in-repo caller used it); opts.confidence was added instead. threats/freeWins now sort by significance first, then by weightPct — a non-significant matchup no longer disappears, it just sorts behind significant ones at the same weight.
coveragePct changed meaning: it used to mean “share of the field covered by a cell with ≥10 games”, it now means “share of the field with any matchup data at all”. This number typically goes up under the new contract and no longer implies the score is reliable — that question moved into the band. LOW_COVERAGE_PCT (40, in FieldScorePanel.tsx) is unchanged and still shown alongside the band, not replaced by it — coverage and confidence are two separate questions.
RecentTournament
Section titled “RecentTournament”interface RecentTournament { id: string; name: string; date: string; players: number; topArchetypes: { name: string; count: number; winRate: number }[];}A single tournament entry fetched from Limitless. This is not persisted to IndexedDB — it is fetched on demand and stored only in Zustand’s recentTournaments array. topArchetypes contains up to 5 archetypes sorted by player count.
View / Derived Types
Section titled “View / Derived Types”These types are computed from raw data and are never written to the database.
ArchetypeStats
Section titled “ArchetypeStats”interface ArchetypeStats { archetype: string; encounters: number; wins: number; losses: number; ties: number; winRate: number; frequencyPct: number; metaWinRate: number; bo1EquivalentWinRate: number | null; bo1Games: number; bo3Games: number; unknownFormatGames: number;}Per-archetype summary combining personal match history and meta data. Computed by getArchetypeStats() in queries.ts. The frequencyPct and metaWinRate come from the latest metaSnapshots; everything else comes from opponentLogs. Sorted by frequencyPct descending, then by encounters descending.
winRate: tie-weighted across all logs (tournamentWinRatePct),0when there are no logs at all.bo1EquivalentWinRate/bo1Games/bo3Games/unknownFormatGames: the Bo1-comparable personal win rate (bo1EquivalentWinRatefrom@pokekon/shared) — Bo3 logs converted back viabo3ToBo1WinRate, logs with unknownbestOfcounted but excluded from the rate itself.nullonly when there are zero Bo1/Bo3-tagged logs (i.e. every log for this archetype has an unknown format, or there are no logs at all).
MetaTrendPoint
Section titled “MetaTrendPoint”interface MetaTrendPoint { period: string; archetype: string; frequencyPct: number;}One data point for a trend chart. Used when plotting how an archetype’s meta share has changed across multiple weeks.
DeckRecommendation
Section titled “DeckRecommendation”interface DeckRecommendation { id: string; priority: 'high' | 'medium' | 'low'; category: 'add' | 'remove' | 'ratio' | 'tech' | 'version'; suggestion: string; reasoning: string; dataPoints: number;}One recommendation from the useRecommendations hook. The id is a stable string like "tech-Dragapult ex" or "version-overall-decline". The category classifies the type of change recommended. dataPoints is the number of game logs that back the recommendation — used for sorting (more data = shown first within same priority).
DeckVariantStats
Section titled “DeckVariantStats”interface DeckVariantStats { deckId: number; deck: Deck; games: number; wins: number; losses: number; ties: number; winRate: number; metaScore: number; recentForm: MatchResult[]; matchupBreakdown: { archetype: string; wins: number; losses: number; ties: number; winRate: number; metaFreq: number; }[];}Per-deck performance stats used in the DeckAnalyticsPanel to compare multiple variants of the same archetype. The metaScore is a frequency-weighted win rate: Σ(metaFreq × WR) / Σ(metaFreq), computed only over matchups with at least 2 decisive games and a known meta frequency. recentForm is the last 10 match results, newest first.
Card Performance Delta Types (Spec 5 — packages/shared/src/cardPerformance.ts)
Section titled “Card Performance Delta Types (Spec 5 — packages/shared/src/cardPerformance.ts)”These types represent precomputed card performance analysis, bridging tournament placement data and card recommendations.
CardPerformanceDelta
Section titled “CardPerformanceDelta”interface CardPerformanceDelta { listsWith: number; listsWithout: number; superiorityPct: number; // Mann-Whitney θ × 100, 1 decimal deltaPp: number; // superiorityPct - 50, the headline delta in pp lowPct: number; // Wilson band lower bound, 1 decimal highPct: number; // Wilson band upper bound, 1 decimal widthPct: number; // highPct - lowPct significant: boolean; // true when band excludes 50 effectiveN: number; // 3*n1*n2/(n1+n2+1), 2 decimals meanPercentileWithPct: number; // descriptive only, 1 decimal meanPercentileWithoutPct: number; // descriptive only, 1 decimal}The performance delta for one card within one archetype. Method (plan §3.0):
- Computes Mann-Whitney probability of superiority θ between two groups (lists with card vs. without)
- θ is itself a proportion in [0,1], so Wilson score intervals are legitimately applicable to it
effectiveN = 3·n1·n2/(n1+n2+1)is the effective sample size that makes a Wilson interval on θ-hat reproduce the exact Mann-Whitney null variance- The band always uses 95% confidence (Spec 3 precedent)
significantis true when the unrounded bounds exclude 50% — not a cutoff, a binary expression of “does the band contain the null?”
Three critical approximations (also in code comments and in docs/features.md §17):
- Ties assumption: The formula assumes no ties (identical percentiles). In practice, ties make the true variance smaller than predicted, so the band is too wide, never too narrow — conservative.
- Null-point calibration: The n_eff bridge makes the interval exact at θ = 0.5 (the decision boundary). Away from the null, it becomes a conservative approximation with credible coverage but not exact matching.
- Correlation, not causation: Lists are not randomly assigned to include/exclude cards. The delta measures association (lists with X ranked better), not causal effect (X makes lists better). No UI text ever claims causation.
CardSignalTier
Section titled “CardSignalTier”type CardSignalTier = | 'insufficient' // No prognosis: empty group or band too wide | 'confirmed' // Popular AND significantly positive | 'hiddenGem' // Rare AND significantly positive | 'popularityParadox' // Popular BUT negative or not significant | 'discouraged' // Significantly negative | 'neutral'; // Measurable but no strong signalClassification of a card’s signal tier, determined by classifyCardSignal(inclusionPct, delta, opts) — the single place in the codebase that decides which case the UI is looking at. Classification rules (order matters — first match wins):
delta === nullORdelta.widthPct > maxBandPp(default 40) →'insufficient'delta.significant && delta.deltaPp > 0 && inclusionPct >= 55→'confirmed'delta.significant && delta.deltaPp > 0→'hiddenGem'inclusionPct >= 55 && (delta.deltaPp <= 0 || !delta.significant)→'popularityParadox'(the core of Spec 5’s fifth AC: “popular but not helping”)delta.significant && delta.deltaPp < 0→'discouraged'- Else →
'neutral'
Rule 1 has precedence over Rule 4 so a staple with only 3 usable lists doesn’t falsely become “popularity paradox”; instead it honestly reports insufficient data.
ArchetypeCardStat
Section titled “ArchetypeCardStat”interface ArchetypeCardStat { cardName: string; cardType: 'pokemon' | 'trainer' | 'energy'; listsAnalyzed: number; listsWith: number; inclusionPct: number; // listsWith / listsAnalyzed × 100, 1 decimal avgCount: number; // Mean copies among including lists, 1 decimal delta: CardPerformanceDelta | null; tier: CardSignalTier;}One card’s complete stats within one archetype (for one time window). The inclusionPct is from the server’s own tournament database (online-Bo1 scope only) — it is purely informational and does not drive the 55%/20% thresholds used in suggestedAdds/suggestedRemoves (those stay on the Limitless-based client fetch). This design separates two data sources explicitly so they never confuse.
ListPerformanceEntry
Section titled “ListPerformanceEntry”interface ListPerformanceEntry { counts: Record<string, number>; // by normalizeCardName() key displayNames: Record<string, string>; cardTypes: Record<string, CardType>; percentile: number; // in [0,1], from placementPercentile()}One published tournament list, reduced to what the analysis needs. The counts are summed across printings (two editions of the same card = one inclusion with summed count) — a deliberate correction to deckComparison.ts’s per-entry counting (plan §0.3 / §6 risk 5). The displayNames and cardTypes map each normalised key to its first-seen display form and type, deterministic and consistent.
ListPerformanceEntry to ArchetypeCardStat (the computation)
Section titled “ListPerformanceEntry to ArchetypeCardStat (the computation)”computeArchetypeCardStats(lists, opts?) is the pure, I/O-free aggregation function that produces a list of ArchetypeCardStat from a list of tournament lists:
- Deduplicate and normalise: across all lists, collect every distinct card by
normalizeCardName()key, tracking display names and types. - Split and compute delta: for each card, partition the lists into
with(list includes the card) andwithout, computeplacementPercentile()for each, thencardPerformanceDelta(). - Classify tier: apply
classifyCardSignal()to the delta andinclusionPct. - Sort and return: by
inclusionPctdescending, thencardNameasc (stable and testable).
Game-Theoretic Meta Layer Types (Spec 6)
Section titled “Game-Theoretic Meta Layer Types (Spec 6)”The Nash equilibrium analysis rests on a constant-sum payoff matrix and several pure-function types from @pokekon/shared/nashEquilibrium.ts.
PayoffMatrix
Section titled “PayoffMatrix”interface PayoffMatrix { archetypeIds: string[]; /** p[i][j] = probability that i beats j, in [0,1]. Guaranteed: * p[i][j] + p[j][i] === 1 and p[i][i] === 0.5. */ p: number[][]; /** Sample size behind the unordered pair {i,j}; 0 when imputed. Symmetric. */ games: number[][]; /** true where the cell carries NO data and was imputed as 0.5. Symmetric, * false on the diagonal (the mirror is definitional, not imputed). */ imputed: boolean[][]; /** Share of the n*(n-1) off-diagonal cells that were imputed, 1 decimal. */ imputedCellSharePct: number; /** Per archetype: opponent-share-weighted coverage of its own row (excludes * mirror). DELIBERATELY NOT the same as FieldScore.coveragePct — see * fieldWinRate.ts:58-64 vs here. */ rowCoveragePct: number[];}The payload passed to the LP solver. Built from matchup cells via buildPayoffMatrix(), which applies symmetrization p_sym(i,j) = (1 + p_ij − p_ji) / 2 to restore constant-sum-ness — this is equivalent to the “half-tie” convention and is identical to the formula used by the reference paper. Mirror cells (i === j) are always 0.5 with games = 0 and imputed = false (the mirror is definitional, not imputed).
Critical assumption (documented in code and features.md §18): The original tournament-weighted win rates use “tie = ⅓ of a win”, which makes p_ij + p_ji = 1 − t/(3n) < 1 — not a constant-sum game. The symmetrization is mandatory for the minimax theorem and LP solution to apply. Persisting this matrix would be wrong; instead, we symmetrize on read and pass it to the solver.
LpResult
Section titled “LpResult”interface LpResult { status: 'optimal' | 'unbounded' | 'iterationLimit'; objective: number; // Objective value at the optimum; 0 when not 'optimal' x: number[]; // Primal solution, length n; all zeros when not 'optimal' iterations: number; // Pivots performed (exposed for cost visibility)}Result of the Phase-II simplex solver solveStandardFormLp(c, A, b). The status values:
'optimal': Standard solution found;objectiveandxare valid.'unbounded': The LP is unbounded (rare; means the payoff matrix is broken and not constant-sum).'iterationLimit': Hit the pivot limit before finding an optimum (safety valve for malformed input).
NashEquilibrium
Section titled “NashEquilibrium”interface NashEquilibrium { archetypeIds: string[]; weightsPct: number[]; // Equilibrium weights, summing to 100 payoffsPct: number[]; // (P x*)_i × 100 — payoff of playing i against x* valuePct: number; // Game value × 100; MUST be 50 for constant-sum input support: string[]; // archetypeIds with weight > SUPPORT_EPSILON_PCT (1e-6) excludedCertain: string[]; // Payoff strictly below value; in NO equilibrium (proven) equalizerCount: number; // #{i : |payoff_i - value| <= PAYOFF_EPSILON_PP} — heuristic fragility hint iterations: number; status: 'optimal' | 'failed';}Solution of solveSymmetricZeroSumNash(matrix), the symmetric zero-sum game equilibrium. Key fields:
valuePct: Must be 50 for a correct constant-sum matrix (self-check persisted to production). Deviation signals the input was not symmetric or constant-sum.excludedCertain: These archetypes have payoff strictly below the game value. By the theorem (plan §3.0c), they are in the support of no equilibrium — this is a provable exclusion, not a heuristic. The converse does NOT hold: equal payoff does not prove inclusion, because equilibria can be non-unique.equalizerCount: Archetypes whose payoff equals the value (withinPAYOFF_EPSILON_PP). When this count exceedssupport.length, the exact composition is non-unique — a sign to show robustness numbers instead of claiming a definitive mix.
ArchetypeRobustness
Section titled “ArchetypeRobustness”interface ArchetypeRobustness { archetypeId: string; exclusionRatePct: number; // % of resamples with weight ≈ zero (numerically) meanWeightPct: number; // Mean weight across resamples weightP05Pct: number; // 5th percentile of weight weightP95Pct: number; // 95th percentile of weight certainExclusionRatePct: number; // % of resamples where payoff < value (≤ exclusionRatePct)}Per-archetype robustness over Monte-Carlo resamples. The certainExclusionRatePct is the strong claim: “in X% of scenarios, this archetype’s payoff against the equilibrium was strictly below the value, so it is excluded from every equilibrium in those scenarios.”
Documentation of the Jeffreys-Beta resampling choice (plan §3.0d): Each unordered matchup pair is sampled once from its Jeffreys posterior Beta(s + 0.5, n − s + 0.5), where s = w + t/2 (half-tie score) and n = w + l + t. This distribution is the Bayesian dual of the Wilson interval; at thin sample sizes it differs from uniform sampling in the Wilson band (more conservative at the tails), so reported percentages are not identical to “resampling uniformly in the Wilson interval” — this distinction matters for reproducibility and is load-bearing in test fixtures.
RobustnessResult
Section titled “RobustnessResult”interface RobustnessResult { resamples: number; seed: number; perArchetype: ArchetypeRobustness[]; exactSupportRatePct: number; // % of resamples reproducing the point estimate's support set failedResamples: number; // LP did not return 'optimal'; reported, never silently dropped}Aggregate robustness data from equilibriumRobustness(matrix, pointEstimate, opts). The exactSupportRatePct is the percentage of the 2000 resamples in which re-solving the equilibrium yielded the exact same set of non-zero-weight archetypes as the point estimate. Low values (e.g., 2.1% in the reference paper) indicate the composition is fragile and should be shown with a warning.
ReplicatorStep
Section titled “ReplicatorStep”interface ReplicatorStep { archetypeIds: string[]; fitnessPct: number[]; // f_i(x) × 100 meanFitnessPct: number; // Σ x_i f_i; exactly 50 for constant-sum matrix growthPct: number[]; // (f_i / phi − 1) × 100 = relative growth rate projectedSharePct: number[]; // x_i' × 100 (renormalised for next step)}One discrete step of the replicator dynamic x_i' = x_i · f_i / φ, where φ = Σ_i x_i f_i = 0.5 exactly for constant-sum games (a self-check). Used to show the theoretical “what if the meta shifts according to replicator dynamics” trajectory.
FitnessDirection
Section titled “FitnessDirection”type FitnessDirection = 'rising' | 'falling' | 'stable' | 'unknown';Week-over-week trend of an archetype’s fitness against the field, computed by fitnessTrend(). Directions:
'rising': Fitness increased by >stableBandPp(default 1 pp) from the prior week'falling': Fitness decreased by >stableBandPp'stable': Absolute delta ≤stableBandPp'unknown': No prior week available (cold start with <2 complete weeks)
The delta is always computed on the same payoff matrix against two separate complete ISO weeks; this isolates meta shifts from sampling noise per week.
FitnessTrend
Section titled “FitnessTrend”interface FitnessTrend { archetypeId: string; fitnessPct: number; // Current week's fitness previousFitnessPct: number | null; // Prior week's fitness (null on cold start) fitnessDeltaPp: number | null; // Week-over-week change in pp (null on cold start) observedShareDeltaPp: number | null; // Observed share change (descriptive, not used for direction) direction: FitnessDirection;}Per-archetype week-over-week trend. The observedShareDeltaPp is purely descriptive and never affects the computed direction — theory can diverge from observation (fitness says it should grow, but it shrank), and that divergence is meaningful to show.
Key assumption (documented in code and features.md §18): The two complete weeks are derived from meta_snapshots, excluding the current ISO week (which is continuously re-synced and thus a partial aggregate). This is the only honest way to compare: finished data against finished data.
Result is [] if the input is empty or all lists have invalid percentiles. A list with all cards means delta === null (same group for with/without), and the tier becomes 'insufficient' — this is honest: you can’t claim a card helps or hurts if it appears in every list.
Deck Synthesis Types (Spec 8 — @pokekon/shared/src/deckSynthesis.ts)
Section titled “Deck Synthesis Types (Spec 8 — @pokekon/shared/src/deckSynthesis.ts)”Structured LLM synthesis over aggregated facts (Field-Score, matchups, card deltas, equilibrium signals). Unlike battle-log analysis which grounds in verbatim quotes, synthesis grounds in structure + direction: each claim references a fact by id and declares direction matching the fact’s derived direction.
SynthesisFact
Section titled “SynthesisFact”interface SynthesisFact { id: string; // 'field.winRate' | 'matchup.<archetypeId>' | 'card.<cardKey>' | ... kind: SynthesisFactKind; // 'fieldScore' | 'coverage' | 'matchup' | 'cardDelta' | ... label: string; // Display name (archetype, card name, etc.), sanitized value: number; // The metric unit: 'pct' | 'pp' | 'games' | 'copies'; neutralValue: number; // Threshold (50 for matchups, 0 for deltas, 100 for coverage) lowPct: number | null; // Confidence band lower; null = no band highPct: number | null; // Confidence band upper; null = no band direction: FactDirection; // 'positive' | 'negative' | 'neutral' (derived from band or point) significant: boolean; // true if band excludes neutralValue usableForRecommendation: boolean; // false for context-only facts (never recommendation base) entityNames: string[]; // Allowed literal digit fragments (e.g., card names with numbers) inUserDeck?: boolean; // For cardDelta: is this card in the user's deck? userCount?: number; // For cardDelta: how many copies in the user's deck?}One fact the LLM may discuss. The direction is derived (never guessed by the model) from value, neutralValue, and the confidence band via deriveFactDirection() — if the band exists and excludes neutralValue, that determines direction; otherwise the point estimate determines it (within a NEUTRAL_EPSILON tolerance). The usableForRecommendation field controls the Spec 3/5 evidence bar: only facts meeting the confidence threshold may be claimed as recommendations.
SynthesisClaim
Section titled “SynthesisClaim”interface SynthesisClaim { factId: string; // Must match a SynthesisFact.id exactly kind: 'observation' | 'recommendation'; direction: 'positive' | 'negative' | 'neutral'; // Model's reading; must match fact.direction text: string; // Prose without numbers; placeholders: {value} {low} {high} {label}}One claim from the model. Validation checks:
factIdexists in the facts list (structural grounding)directionmatchesfact.direction(directional grounding, core of Spec 8 decision 3)textcontains only allowed placeholders and no unapproved digits (no hallucinated numbers)kind === 'recommendation'may only appear onusableForRecommendation === truefacts (evidence bar)
ValidatedSynthesis
Section titled “ValidatedSynthesis”interface ValidatedSynthesis { accepted: SynthesisClaim[]; // Surviving claims, model order preserved rejected: RejectedClaim[]; // Claims and their rejection reasons}
interface RejectedClaim { claim: SynthesisClaim; reason: ClaimRejectionReason; // 'malformed' | 'unknownFact' | 'directionMismatch' | ...}Output of validateSynthesis(claims, facts). Never throws — unusable input yields { accepted: [], rejected: [] }. Rejection reasons are prioritised (see CLAIM_REJECTION_REASONS in code for order); first violation wins.
DeckSynthesis
Section titled “DeckSynthesis”interface DeckSynthesis { deckId: number; archetypeId: string; archetypeName: string; windowDays: number; language: SynthesisLanguage; // 'de' | 'en' promptVersion: number; sections: SynthesisSectionBlock[]; // Headline, Strengths, Risks, List Levers, Context claims: SynthesisClaim[]; // Surviving claims for "based on" disclosure facts: SynthesisFact[]; // Snapshot; UI renders THESE numbers, never live context: SynthesisContext; // Deck/archetype/variant/window metadata droppedCount: number; // Model claims rejected by validation gate source: 'llm' | 'demo-seed'; provider: string | null; // 'github-models'; null for demo-seed model: string | null; // 'openai/gpt-4.1'; null for demo-seed inputHash: string; // Hash of facts; cache key generatedAt: string; // ISO timestamp}
interface SynthesisSectionBlock { section: SynthesisSection; // 'headline' | 'strengths' | 'risks' | 'listLevers' | 'context' sentences: string[]; // Rendered, placeholder-substituted claims (max 3 per section)}The complete synthesis result, ready to display. Sections contain rendered claims only (placeholders filled with numbers). Empty sections are omitted. The facts snapshot is persisted so the UI renders those numbers even if the live data changes; the claims array is preserved for transparency (“what claims survived validation?”).
SynthesisContext
Section titled “SynthesisContext”interface SynthesisContext { deckId: number; archetypeId: string; archetypeName: string; variant: string; windowDays: number; language: SynthesisLanguage; cardStatsComputedAt: string | null; // When the card delta data was computed equilibriumComputedAt: string | null; // When equilibrium data was computed matchupImportedAt: string | null; // When matchup data was last synced}Contextual metadata (deck and data source timestamps). Used for sourcing footnotes (“based on data from {timestamp}”).
SynthesisLanguage
Section titled “SynthesisLanguage”type SynthesisLanguage = 'de' | 'en';The output language for synthesis. Separate from the API’s locale system; a user can request synthesis in either language regardless of their UI language.
Decklist Clustering Types (Spec 10 Slice A — @pokekon/shared/src/decklistClustering.ts)
Section titled “Decklist Clustering Types (Spec 10 Slice A — @pokekon/shared/src/decklistClustering.ts)”Two published tournament decklists that differ by only a tech swap or an energy count are the
same list for ranking purposes — without merging them, they count as two independent, weaker
data points instead of one stronger one. Pure functions, no I/O (same shape as
fieldWinRate.ts). Composed with Slice B (ranking) in buildArchetypeSynthesisFactSet
(apps/api/src/lib/archetypeSynthesisFacts.ts, archetype recommendation) and in the
per-tournament best-list route (GET /api/analysis/tournament/:tid/archetype/:aid).
DecklistOverlap
Section titled “DecklistOverlap”interface DecklistOverlap { identicalCards: number; // sum, per distinct card, of min(count in A, count in B) overlapRatio: number; // identicalCards / max(totalCardsA, totalCardsB)}Returned by computeDecklistOverlap(a, b). Card identity uses normalizeCardName()
(cardPerformance.ts) as the join key — same normalisation already used to match tournament
decklists against the user’s own deck elsewhere in the codebase.
ClusterableStanding / DecklistCluster
Section titled “ClusterableStanding / DecklistCluster”interface ClusterableStanding { id: number; decklist: TournamentDecklist; wins: number; losses: number; ties: number; placing: number | null; totalPlayers: number | null; // for placementPercentile() in Slice B matchResults: StandingMatchResult[]; // this standing's own game-by-game log, Slice D}
interface DecklistCluster { representative: TournamentDecklist; // medoid of the cluster (Spec 1 §3.2) memberStandingIds: number[]; totalWins: number; totalLosses: number; totalTies: number; placements: { placing: number; totalPlayers: number }[]; // only members with BOTH values matchResults: StandingMatchResult[]; // concatenated across every member, Slice D}clusterDecklists(standings, opts?) first sorts its input into a canonical order (Spec 1
§3.1, specs/archetype-list-foundation.md): best placementPercentile(placing, totalPlayers)
first (standings without a usable placement last), then wins − losses desc, then id asc.
The result therefore never depends on the order the caller (or PostgreSQL) returns rows in; the
input array is not mutated. It then greedily merges each standing into the first existing
cluster whose seed (founding member) overlaps it by at least opts.minOverlapRatio (default
DEFAULT_MIN_OVERLAP_RATIO = 55/60 ≈ 91.7 %), or starts a new cluster. A cluster with a single
member is kept as its own cluster, never forced into another — protects rare-but-strong lists
(“Nadel im Heuhaufen”) from being diluted away by clustering. This is a greedy heuristic
(O(n·clusters), not an exhaustive pairwise partition) — acceptable because clusters only need
to be “close enough to pool as one data point”, not perfectly optimal. matchResults (Spec 10
Slice D) is carried through/concatenated the same way totalWins etc. are accumulated — raw,
un-aggregated per-game records; clusterFieldScore.ts (below) is what turns them into a
per-opponent breakdown.
Representative = medoid (Spec 1 §3.2). Membership is always checked against the cluster’s
founding member (the seed, first in canonical order), never against the current
representative, so the partition is exactly the greedy one. After the pass, representative is
set to the medoid: the member list with the largest summed identicalCards to all other
members, i.e. the most typical list rather than whichever one happened to come first. Ties go to
the higher placementPercentile (missing last), then the smaller standing id. seed and the
member lists are module-internal and never part of DecklistCluster or any API response. Cost:
greedy pass O(n·clusters) plus O(m²) overlap comparisons per cluster of m members, with each
member’s card-count map built once.
RankedCluster
Section titled “RankedCluster”interface RankedCluster extends DecklistCluster { winRateLowerBoundPct: number; // PRIMARY ranking signal winRateInterval: WilsonInterval | null; // null only when the cluster has 0 recorded games avgPlacementPercentile: number | null; // SECONDARY/display signal, never a multiplier rank: number; // 1-based, descending winRateLowerBoundPct (+ tie-breaks) fieldScore?: FieldScore | null; // Slice D, only set when re-ranked against a localField}rankClusters(clusters) (@pokekon/shared/src/clusterRanking.ts) turns Slice A’s clusters into
a ranked list. Sorts by the Wilson-score lower bound of the tie-weighted win rate
(wilsonInterval(), one implementation in the repo — reused verbatim, not re-derived) rather
than the raw rate: this is what stops a lucky 3-game 100 %-sample from outranking a proven
40-game 65 %-sample, without excluding the small sample from the output altogether. Mean
placementPercentile() across the cluster’s member standings is carried as a secondary,
display-only signal — it can show “this list won the event” even when the win-rate sample is
too thin to rank it highly, but it never multiplies into the primary rank (that would let a
single lucky top-8 with few games dominate, exactly the bias Spec 10 asks to avoid). Ties on the
lower bound are broken deterministically (Spec 1 §3.3): higher avgPlacementPercentile first
(null last), then more member standings, then the smallest member standing id, so the ranking
never depends on input order.
rankClusters() itself never touches fieldScore — that field is filled in by a separate
re-ranking step (clusterFieldScore.ts, below), only for scope: 'local' with a chosen field.
Field-weighted cluster scoring (Spec 10 Slice D — @pokekon/shared/src/clusterFieldScore.ts)
Section titled “Field-weighted cluster scoring (Spec 10 Slice D — @pokekon/shared/src/clusterFieldScore.ts)”Turns a Wilson-ranked cluster list into a ranking against a specific chosen local field
instead of “every opponent weighted equally” — the real field-reweighting Slice C’s MVP
deliberately deferred (ArchetypeSynthesisScope’s doc comment, deckSynthesis.ts).
function computeClusterFieldScores( clusters: RankedCluster[], field: ArchetypeShare[],): Map<number, FieldScore>; // keyed by cluster.rank (pre-reorder); empty map when field is []
function reorderClustersByFieldScore( clusters: RankedCluster[], fieldScores: Map<number, FieldScore>,): RankedCluster[]; // pure — never mutates the input; re-ranks 1..n; fieldScores.size === 0 -> input unchangedcomputeClusterFieldScores reuses computeFieldScores (fieldWinRate.ts, Spec 3) rather than
re-deriving the weighted-sum-of-Wilson-intervals math: each cluster’s matchResults are turned
into one MatchupCell per opponent archetype actually played (tournamentWinRatePct for the raw
record), a synthetic zero-share subject (archetypeId: "__cluster_<rank>__") is injected into
the shares list per cluster so it can run through computeFieldScores as its own subject
without ever counting towards field’s totalShare/coveragePct, and the resulting FieldScore
rows for the real field entries are discarded (not consumed) — no correctness impact, just
unused output. A cluster with zero matchResults vs field still gets a FieldScore object back
(every input share gets one) but with fieldWinRatePct/fieldWinRateLowPct: null — check
fieldWinRateLowPct for actual coverage, not a null-check on the FieldScore object itself.
reorderClustersByFieldScore sorts descending by fieldWinRateLowPct (same “lower bound
protects against a small sample” principle as winRateLowerBoundPct, just now against the chosen
field instead of every opponent equally weighted); clusters with no coverage (fieldWinRateLowPct: null, or genuinely absent from fieldScores) sink to the end, ordered among themselves by their
original Wilson rank — never dropped, just not artificially boosted. Sets .fieldScore on every
cluster and reassigns .rank, 1-based, in the new order.
apps/api/src/lib/archetypeSynthesisFacts.ts wires both functions in: for scope: 'local' with a
non-empty localField request field, clusters are first ranked exactly as before (Wilson lower
bound, scope-agnostic) and then re-ranked by their field-weighted score against localField
before facts are derived from them. scope: 'global', or scope: 'local' without a localField,
skip this step entirely — same ranking as before this feature, no behaviour change for existing
callers.
Archetype-level synthesis (Spec 10 Slice C — @pokekon/shared/src/deckSynthesis.ts)
Section titled “Archetype-level synthesis (Spec 10 Slice C — @pokekon/shared/src/deckSynthesis.ts)”Everything above (SynthesisFact, validateSynthesis, the anti-hallucination discipline) was
built deck-scoped (Spec 8): SynthesisContext.deckId is non-optional, and factsFromCardStats’
actionability rule is deck-relative (“in the deck” / “not in the deck”). Slice C adds a
parallel, archetype-scoped envelope rather than forcing a fake deckId through the
existing one — a ranked decklist cluster set has no single owning deck.
interface ArchetypeSynthesisContext { archetypeId: string; archetypeName: string; windowDays: number; language: SynthesisLanguage; scope: ArchetypeSynthesisScope; // against the global meta, or the user's local-meta field}factsFromClusterRanking(clusters, opts?) turns Slice B’s RankedCluster[] into facts: one
clusterWinRate fact per cluster (skipped when the cluster has 0 recorded games — nothing to
write about), plus a clusterPlacement fact when the cluster has placement data. The label is
derived from the representative decklist’s key Pokémon (there is no separate “list name” at
this layer). assembleArchetypeSynthesis(validated, facts, context, meta) mirrors
assembleSynthesis exactly for the claims→sections grouping (both now call a shared private
buildSynthesisSections helper, extracted so the two envelopes cannot silently diverge) but
returns an ArchetypeSynthesis envelope instead of DeckSynthesis.
buildArchetypeSynthesisPrompts(facts, context) is the archetype-level counterpart to
buildSynthesisPrompts — deliberately not sharing code with it for the actual prompt text:
this is safety-critical anti-hallucination wording (CLAUDE.md Golden Rule 6), so the two prompt
builders stay independent rather than risk one’s change silently altering the other’s tested,
in-prod behaviour. Same six mandatory rules, same JSON schema, same
{value}/{low}/{high}/{label} placeholder discipline as the deck-level version; only the
framing differs (“Archetyp: X, Bezug: die globale Meta / deine lokale Meta” instead of
“Deck: X (variant)”), since there is no single deck at this level.
Wired into GET/POST /api/analysis/archetype/:archetypeId (apps/api/src/routes/analysis.ts,
mirrors the deck routes exactly — same BYOK/rate-limit/cache-short-circuit pattern), backed by the
archetype_synthesis table (docs/database.md). AnalysisProvider gained a parallel
synthesizeArchetype() method (apps/api/src/ai/provider.ts) rather than reusing synthesize()
with a fake deck context — see docs/features.md for the route-level description, including the
documented scope limitation.
Personal-prior blending (Spec 10 Slice E — @pokekon/shared/src/personalPriorBlend.ts)
Section titled “Personal-prior blending (Spec 10 Slice E — @pokekon/shared/src/personalPriorBlend.ts)”Adjusts a cluster’s global win rate (Slice B) toward the user’s own track record — but only once
there is enough of it to mean something. A standalone, composable pure function, same shape as
fieldWinRate.ts, now wired into the backend (see below); the web UI toggle (“Mein Spielstil”)
is a separate, later slice.
interface PersonalPriorBlend { blendedPct: number; // the number to actually show usedPersonalData: boolean; // false => blendedPct === clusterWinRatePct, unchanged ownWeight: number; // 0 when unused; otherwise in (0, maxOwnWeight] ownWinRatePct: number | null; // tie-weighted; null only with 0 personal games}blendWithPersonalPrior(clusterWinRatePct, { wins, losses, ties }, opts?): below
DEFAULT_MIN_OWN_GAMES (5 — the same “not enough data” threshold MyMatchupsTable already uses
for encounters < 5), personal data is ignored entirely and blendedPct passes the cluster rate
through unchanged. Above that, ownWeight = min(encounters / (encounters + globalSampleEquivalent), maxOwnWeight) (defaults 20 and 0.7 respectively, both tunable and not yet validated against real
usage data — spec “Offene Fragen”) grows with the personal sample size but is capped: a personal
record, however large, only ever reflects the opponents one pilot happened to face, not the whole
field, so the global number always keeps some influence. Uses the tie-weighted win rate
(tournamentWinRatePct, one implementation in the repo, reused verbatim) for the personal record,
consistent with every other win-rate figure in the app.
Deliberate scope note: the input is a generic { wins, losses, ties } record
(PersonalRecord), not the web app’s ArchetypeStats type — packages/shared cannot depend on
an apps/web-only type.
Resolved (Konrad decision, 2026-09-23): the caller (backend route, see below) passes the
opponent-facing ArchetypeStats record — “how well do I do playing AGAINST this archetype”,
the same record MyMatchupsTable already shows — not a “my results piloting this archetype”
record, which does not exist as a data source yet. Different reference frames (cluster win rate =
performance of this list’s pilots against the field; the blended personalPrior fact = MY
performance against this archetype as an opponent), accepted as a known, documented compromise
rather than blocking on a new data source.
personalPrior fact + backend wiring (Spec 10 Slice E)
Section titled “personalPrior fact + backend wiring (Spec 10 Slice E)”factsFromPersonalPriorBlend(archetypeName, blend) (@pokekon/shared/src/deckSynthesis.ts) turns
a PersonalPriorBlend into at most one personalPrior-kind SynthesisFact — none when
blend.usedPersonalData is false (a below-threshold personal record contributes nothing, it never
silently replaces the global clusterWinRate/clusterPlacement facts). The fact is bandless
(lowPct/highPct: null, significant: false, usableForRecommendation: false, same convention
as clusterPlacement) with neutralValue: 50, value: blend.blendedPct.
Wired into buildArchetypeSynthesisFactSet (apps/api/src/lib/archetypeSynthesisFacts.ts): when
scope === 'local' and the caller passes both usePersonalPrior: true and a personalRecord,
the Wilson-conservative winRateLowerBoundPct of the cluster shown first (after local-field
re-ranking, if any — Spec 1 §3.4) (not the raw mean, consistent
with Slice B) is blended via blendWithPersonalPrior and the resulting fact is appended. For
scope === 'global', usePersonalPrior/personalRecord are silently ignored — no validation
error, simply no effect (deliberately simple, not over-engineered).
GET/POST /api/analysis/archetype/:archetypeId (apps/api/src/routes/analysis.ts,
apps/api/src/validation.ts) both accept usePersonalPrior + a personal win/loss/tie record
(personalWins/personalLosses/personalTies query params on GET, a nested personalRecord
object on POST). GET needs these too, not just POST: currentInputHash is computed from the same
facts a POST would use, so GET must be given the identical personalisation inputs to avoid
wrongly reporting stale: true right after the user generated a personalised synthesis via POST.
The apps/web UI toggle that reads ArchetypeStats from the store and sends personalRecord is
a separate, later slice (not part of this backend wiring).