Skip to content

Refactor Bot to use TypedEventEmitter for type-safe events#89

Merged
chapel merged 1 commit intomainfrom
refactor/typed-event-emitter
Feb 3, 2026
Merged

Refactor Bot to use TypedEventEmitter for type-safe events#89
chapel merged 1 commit intomainfrom
refactor/typed-event-emitter

Conversation

@chapel
Copy link
Copy Markdown
Contributor

@chapel chapel commented Feb 3, 2026

Summary

Implemented TypedEventEmitter utility class that extends Node.js EventEmitter with compile-time type safety for event names and payloads. Refactored Bot class to use TypedEventEmitter instead of base EventEmitter.

Key changes:

  • Created packages/core/src/utils/typed-event-emitter.ts with generic TypedEventEmitter class
  • Added overload signatures for backward compatibility with generic EventEmitter interfaces
  • Updated Bot class to extend TypedEventEmitter<BotEvents>
  • Fixed BotEvents interface to match actual SessionLifecycleEvents payloads
  • Exported TypedEventEmitter from @kynetic-bot/core package

Test plan

  • All 1567 tests passing
  • Build successful with full TypeScript type checking
  • Lint checks pass
  • Type safety verified - incorrect event names/payloads caught at compile time
  • Backward compatibility maintained - Discord adapter works with typed Bot

Task: @01KGGX57

🤖 Generated with Claude Code

…ents

Implemented TypedEventEmitter utility class that extends Node.js EventEmitter
with compile-time type safety for event names and payloads. Refactored Bot class
to extend TypedEventEmitter<BotEvents> instead of base EventEmitter, providing
full type checking for all emit/on/off/once operations.

Key changes:
- Created packages/core/src/utils/typed-event-emitter.ts with generic TypedEventEmitter class
- Added overload signatures for backward compatibility with generic EventEmitter interfaces
- Updated Bot class to extend TypedEventEmitter<BotEvents>
- Fixed BotEvents interface to match actual SessionLifecycleEvents payloads
- Exported TypedEventEmitter from @kynetic-bot/core package

All 1567 tests passing. Build successful with full TypeScript type checking.

Task: @01KGGX57

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown

claude bot commented Feb 3, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@chapel
Copy link
Copy Markdown
Contributor Author

chapel commented Feb 3, 2026

PR Review Summary

Quality Gates

  • ✅ All tests passing (1567 tests)
  • ✅ CI checks passing (test, claude-review, check-unresolved-comments)
  • ✅ Type safety implementation verified
  • ✅ Backward compatibility maintained

Changes Overview

This PR refactors the Bot class to use a new TypedEventEmitter utility that provides compile-time type safety for event names and payloads:

  1. New TypedEventEmitter utility (packages/core/src/utils/typed-event-emitter.ts)

    • Extends Node.js EventEmitter with typed emit/on/off/once methods
    • Provides compile-time type checking for event names and handler signatures
    • Includes backward compatibility overloads for generic EventEmitter interfaces
  2. Bot class refactored (packages/bot/src/bot.ts)

    • Now extends TypedEventEmitter<BotEvents> instead of base EventEmitter
    • BotEvents interface updated to accurately reflect actual emitted events
    • Session lifecycle event payloads corrected to match SessionLifecycleManager
  3. All existing tests pass - No behavior changes, pure refactoring for type safety

Spec Alignment

This is a technical refactoring task with no associated spec (spec_ref: null). The changes are internal improvements that don't affect observable behavior. The refactoring:

  • Adds compile-time type safety without changing runtime behavior
  • Maintains backward compatibility with existing event listeners
  • Corrects event interface to match actual implementation

Verdict

Ready to merge - All quality gates pass, implementation is sound, tests verify correctness.

@chapel chapel merged commit e6a9151 into main Feb 3, 2026
3 checks passed
@chapel chapel deleted the refactor/typed-event-emitter branch February 3, 2026 10:18
chapel added a commit that referenced this pull request Feb 3, 2026
…edEventEmitter for compile-time type safety on event names and payloads. Created new TypedEventEmitter utility that extends Node.js EventEmitter with typed emit/on/off/once methods. Updated BotEvents interface to accurately reflect actual emitted events from SessionLifecycleManager. Maintained backward compatibility with overload signatures for generic EventEmitter interfaces. All 1567 tests passing, all CI checks passed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant