Skip to content

W-037: ecs-schedule hooks (SCH-F07, part 2)

Type: feature · Size: M · Epic: E-schedule-v0 · Target: packages/ecs-schedule · Breaking: no Depends: W-032, W-036 Refs: spec SCH-144, SCH-145, SCH-146, SCH-147, SCH-148, SCH-149, SCH-150

Goal

Add build-time hooks (beforeSystem, afterSystem, onSkip) with one reused context object per schedule and world. The schedule reads no clock; observers measure time themselves. Hooks run only for systems that are considered. The allocation check (SCH-149) is manual.

Steps

  • S1 (SCH-144, SCH-147): beforeSystem runs after the checks pass, afterSystem after a successful run, and onSkip with reason disabled or condition; no hooks for done OnStart systems or manual phases in run; files: packages/ecs-schedule/src/hooks.ts, packages/ecs-schedule/tests/hooks-calls.test.ts
  • S2 (SCH-145, SCH-150): context is { schedule, world, system, phase, dt }; one object per schedule and world, the same across hooks and calls; snapshots inside each hook match; a nested call on another world does not overwrite it; files: packages/ecs-schedule/src/hook-context.ts, packages/ecs-schedule/tests/hooks-context.test.ts
  • S3 (SCH-146, SCH-148): afterSystem is not called when the system throws; hook errors propagate unchanged; hooks cannot be changed after build; files: packages/ecs-schedule/tests/hooks-errors.test.ts
  • S4 (SCH-149 [manual]): benchmark that a run without hooks costs no more than a null check per system, and that hooks do not allocate per call; files: packages/ecs-schedule/bench/hooks.bench.ts
  • S5 (changeset): add .changeset/w-037-ecs-schedule-hooks.md (patch, @workspace/ecs-schedule)

Log

  • 2026-11-01 created from the approved spec split of W-004 (Triage)