refactor(#74) P4: wire engine/stub/db through the ABILITIES registry

Behavior-preserving rewire: every per-ability code path now iterates the
ordered ABILITIES registry instead of hand-enumerating the eight fields.

- engine.ts: buildSystemPrompt (schema lines + constraint bullets),
  buildUserPrompt (payload keys at their historical positions),
  validateTurnResult (per-field validate), applyTurnResult (ordered apply
  block), isMeaningful, and the runTurn "unclear" fallback all drive off
  ABILITIES. The eight moved ability bodies (~1,249 lines) are deleted;
  the names the engine and its tests import are re-exported from
  ./abilities.
- abilities/types.ts: Ability.stub is a zero-arg method (the stub has no
  GameState/AbilityCtx to pass; it needs none) — all eight implementations
  were already arg-less.
- stub.ts: deterministicTurn fills the eight ability fields from the
  registry (each contributes its inert default), between the core fields
  and markers — JSON output stays byte-identical (verified against
  origin/master).
- db.ts: the legacy-row migration for ability-owned GameState fields
  (wars/trades/embargoes/industry) iterates the registry's stateFields,
  only-if-undefined, instead of a hardcoded field list.

No client changes, no new deps, no shared/ runtime deps. typecheck + lint
+ 511 unit tests green; stub JSON byte-identical to origin/master.

Fixes #74
This commit is contained in:
2026-10-16 07:23:11 +00:00
parent 2d17c743f6
commit 15a1642eec
4 changed files with 129 additions and 1612 deletions
+3 -2
View File
@@ -158,9 +158,10 @@ export interface Ability<K extends AbilityField = AbilityField> {
/**
* The deterministic stub's value for this field. Every ability returns
* `default()` (the stub never exercises an ability, so e2e is unaffected) —
* kept as a method so the stub stays a uniform registry loop.
* kept as a zero-arg method so the stub stays a uniform registry loop (the
* stub has no real `GameState` / `AbilityCtx` to hand one; it needs none).
*/
stub(state: GameState, ctx: AbilityCtx): TurnResult[K];
stub(): TurnResult[K];
/**
* The keys this ability contributes to the user prompt payload, each included