refactor: move event system to reducer, remove engine package #32

Merged
mvhutz merged 7 commits from refactor/move-events-to-reducer into main 2026-01-17 00:27:37 +00:00
Owner

Description

This PR completes the MVC-inspired refactoring by moving the event system from the engine into the reducer.
The engine package is now removed entirely, as the reducer handles both reduction logic and lifecycle events.

  • Add pkg/reducer/events.go with StartEvent, StepEvent, and StopEvent.
  • Extend Reducer interface to embed Emitter[Event] and add Expression() method.
  • Update NormalOrderReducer to embed BaseEmitter and emit lifecycle events during reduction.
  • Update all plugins to attach to Reducer instead of Engine.
  • Remove internal/engine package entirely.
  • Add Off() method to BaseEmitter to complete the Emitter interface.
  • Fix Emitter.On signature to use generic type E instead of string.

Decisions

  • The Reducer interface now combines reduction logic with event emission, making it the single orchestration point.
  • Plugins attach directly to the reducer, simplifying the architecture.
  • The Expression() method on Reducer provides access to current state for plugins.

Benefits

  • Simpler architecture with one fewer abstraction layer.
  • Plugins are now mode-agnostic - they work with any Reducer implementation.
  • Cleaner separation: reducers handle reduction, plugins observe via events.
  • Easier to add new evaluation modes - just implement Reducer with embedded emitter.

Checklist

  • Code follows conventional commit format.
  • Branch follows naming convention (<type>/<description>).
  • Tests pass (if applicable).
  • Documentation updated (if applicable).
## Description This PR completes the MVC-inspired refactoring by moving the event system from the engine into the reducer. The engine package is now removed entirely, as the reducer handles both reduction logic and lifecycle events. - Add `pkg/reducer/events.go` with `StartEvent`, `StepEvent`, and `StopEvent`. - Extend `Reducer` interface to embed `Emitter[Event]` and add `Expression()` method. - Update `NormalOrderReducer` to embed `BaseEmitter` and emit lifecycle events during reduction. - Update all plugins to attach to `Reducer` instead of `Engine`. - Remove `internal/engine` package entirely. - Add `Off()` method to `BaseEmitter` to complete the `Emitter` interface. - Fix `Emitter.On` signature to use generic type `E` instead of `string`. ### Decisions - The `Reducer` interface now combines reduction logic with event emission, making it the single orchestration point. - Plugins attach directly to the reducer, simplifying the architecture. - The `Expression()` method on `Reducer` provides access to current state for plugins. ## Benefits - Simpler architecture with one fewer abstraction layer. - Plugins are now mode-agnostic - they work with any `Reducer` implementation. - Cleaner separation: reducers handle reduction, plugins observe via events. - Easier to add new evaluation modes - just implement `Reducer` with embedded emitter. ## Checklist - [x] Code follows conventional commit format. - [x] Branch follows naming convention (`<type>/<description>`). - [x] Tests pass (if applicable). - [ ] Documentation updated (if applicable).
mvhutz added 1 commit 2026-01-16 23:51:05 +00:00
Move the event emitter and lifecycle events from the engine into the reducer,
making the reducer the single point of orchestration for reduction.
This eliminates the engine package entirely.

- Add events.go to pkg/reducer with Start, Step, and Stop events.
- Extend Reducer interface to embed Emitter and add Expression() method.
- Update NormalOrderReducer to embed BaseEmitter and emit lifecycle events.
- Update all plugins to attach to Reducer instead of Engine.
- Remove internal/engine package.
- Add Off() method to BaseEmitter to complete Emitter interface.
- Fix Emitter.On signature to use generic type E instead of string.
mvhutz added 1 commit 2026-01-16 23:56:05 +00:00
Update call sites to match the new Reducer interface where the expression
is passed to the constructor and Reduce() takes no arguments.
mvhutz added 1 commit 2026-01-16 23:58:11 +00:00
mvhutz added 1 commit 2026-01-17 00:02:30 +00:00
The tea CLI does not have a pr edit command.
Updated documentation to use tea comment instead.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
mvhutz added 1 commit 2026-01-17 00:03:17 +00:00
mvhutz added 1 commit 2026-01-17 00:09:26 +00:00
mvhutz added 1 commit 2026-01-17 00:27:16 +00:00
mvhutz merged commit 1974ad582f into main 2026-01-17 00:27:37 +00:00
mvhutz deleted branch refactor/move-events-to-reducer 2026-01-17 00:27:37 +00:00
Sign in to join this conversation.