No description
Find a file
Joey Yakimowich-Payne 747d0fb728
feat(engine): wire trigger primitives + absorb-damage into runtime pipelines
T3 follow-up addressing 4 of the 6 e2e fixmes (T29). Ships the engine
wiring that was deferred in T3's original scope per the implementation
retrospective.

New triggers.ts exports four dispatchers + an HP snapshot helper:
- fireOnTurnStartHooks(engine, whoseTurn): walks every piece of the
  given color, runs each OnTurnStartHooks entry as a primitive list.
- fireOnCaptureHooks(engine, attackerId): runs OnCaptureHooks for the
  attacker piece. attackerId is captured in onBeforeMove (engine.moveLog
  isn't yet populated when onAfterMove fires, so we can't read from it).
- fireOnDamagedHooks(engine, preMoveHp): compares post-move Hp facts
  against a pre-move snapshot; pieces whose Hp dropped (or whose Hp
  fact was retracted = died) get their OnDamagedHooks fired.
- fireConditionalHooks(engine): re-evaluates every ConditionalHook's
  condition against current piece state; runs the matching then/else
  branch.
- snapshotHp(session): freezes Hp facts at the supplied phase for the
  on-damaged dispatcher to compare against.

Conditions supported: attr-lt, attr-gt, attr-eq, always, never (matches
the ConditionSpec union from T14).

Each dispatcher recurses through nested primitives via the same
PRIMITIVE_REGISTRY lookup the descriptor applier uses, with the runtime
depth cap (8) as a backstop. Trigger evaluation has no parent
descriptor — synthesised __trigger__ ref fills the contract.

Integration in apply.ts (__modifier-profile-integration__ preset):

- onBeforeMove: snapshots Hp + the attacker pieceId (when isCapture).
  Both stored in WeakMaps keyed by engine so concurrent engines
  (server-authoritative + client-predicted) keep independent state.
- onDamage: NEW absorb-damage-with-attribute branch BEFORE the existing
  DamageResistance branch. When AbsorbDamageAttr+AbsorbDamageRate are
  set on the target, incoming damage spends the attribute first;
  full absorption short-circuits with consume:true died:false.
  Partial absorbs fall through (same documented limitation as
  partial DamageResistance).
- onAfterMove: now runs computeAuraFacts (T28, unchanged) + four
  trigger dispatchers in order:
    fireOnDamagedHooks → fireOnCaptureHooks → fireConditionalHooks
    → fireOnTurnStartHooks (for the next-mover's color)

7 vitest scenarios in triggers.test.ts cover each dispatcher
including the absorb-damage shield (3 charges → 0 → fall through).
2026-04-19 21:38:01 -06:00
.github/workflows chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
.sisyphus chore(sisyphus): mark T3 Wave 4 (UI) complete 2026-04-19 20:23:21 -06:00
docs docs(adr): T4 scripted modifiers forward-design 2026-04-19 21:09:52 -06:00
packages feat(engine): wire trigger primitives + absorb-damage into runtime pipelines 2026-04-19 21:38:01 -06:00
scripts feat(rete): add replay engine + state-hash determinism verifier (P3.3) 2026-04-16 15:25:13 -06:00
.gitignore chore: ignore .org.chromium.Chromium.* runtime files 2026-04-19 10:20:42 -06:00
eslint.config.js feat(engine): damage-resistance modifier descriptor 2026-04-18 22:22:31 -06:00
lefthook.yml chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
LICENSE chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
package.json feat(rete): add replay engine + state-hash determinism verifier (P3.3) 2026-04-16 15:25:13 -06:00
playwright.config.ts fix(rete): inject clock into EventLog; use tsc for DTS; fix cycle.test.ts private access; add Playwright worker limit 2026-04-16 18:25:49 -06:00
README.md chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
tsconfig.base.json chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
tsconfig.json chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00
vitest.workspace.ts chore(root): scaffold monorepo — Phase 0 complete 2026-04-16 13:32:21 -06:00

@paratype

A Doorenbos-style Rete II rules engine for TypeScript games, with an authoritative WebSocket chess demo.

Packages

Docs

Getting Started

bun install && bun run check