Migrate to event-driven orchestration architecture#1
Merged
Conversation
Migrated from imperative orchestration loop to fully event-driven
architecture using Atmos events, reducers, before hooks, and listeners.
Key changes:
- Created orchestration.go (346 lines) with event-driven flow:
* Reducers: Build state only (no side effects)
* Before hooks: Do work (Claude calls, context gathering, enrichment)
* Listeners: Chain events (event-driven flow)
- Created execution.go (175 lines) with reusable business logic:
* ExecuteTask, BuildTaskContext, StoreTaskResult
* ClaudeCaller interface with DefaultClaudeCaller implementation
- Simplified cmd/hearth/run.go from 425 → 92 lines (78% reduction)
* Removed imperative task loop
* Single entry point: h.Process(&ExecuteTasksRequested{})
- Added orchestration events to events.go:
* ExecuteTasksRequested, NextTaskSelected, TaskExecuted
* SummaryRequested, SummaryGenerated
- Fixed parent auto-completion:
* Replaced reducer mutation with event-driven approach
* onTaskCompletedParent emits TaskCompleted for parents
- Added logging directly in orchestration hooks
* beforeNextTaskSelected: logs task selection
* beforeTaskExecuted: logs Claude calls
* onTaskCompletedParent: logs task completion
- Deleted obsolete cmd/hearth/run_test.go (278 lines)
* Logic now tested in hearth_test.go and orchestration_test.go
All 10 tests passing. Event-driven architecture complete.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
Major refactoring to improve code organization and test coverage: ## File Organization - Split orchestration.go into architectural layers: - hooks.go: Before hooks (where work happens) - listeners.go: Event chaining - reducers.go: State updates (added orchestration reducers) - Moved HearthState and Task types to state.go - Deleted orchestration.go (setup moved to hearth.go) - Deleted persistence.go (merged into hearth.go) - Created test_utils.go for shared test helpers ## API Cleanup - Merged NewHearth and NewHearthWithPersistence into single constructor - Empty workspaceDir = in-memory (for tests) - Non-empty workspaceDir = persistence + services - Removed complete command (not needed with autonomous orchestration) - Removed DependsOn field from TaskCreated event and Task struct - Removed --depends-on flag from add command ## Service Registration - Moved service registration into NewHearth constructor - Services now registered during engine construction (not after) - Removed RegisterServices method ## Decoupling - Decoupled execution.go from Hearth dependency - ExecuteTask and BuildTaskContext now pure functions - Functions take taskID and tasks map instead of Hearth instance ## Testing - Rewrote TestHearthJourney to test autonomous orchestration - Exercises full event-driven flow (79% code coverage) - Tests depth-first scheduling, parent auto-completion, summary generation - Revealed and fixed orchestration bug in onSummaryGenerated - Created MockClaudeCaller for testing without real API calls - Fixed all persistence tests (were hanging due to Claude API calls) - TestEventPersistence - TestEventPersistence_ComplexHierarchy - TestEventPersistence_EmptyWorkspace - TestEventPersistence_EventMerging - All tests passing, golangci-lint clean 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Migrated Hearth from imperative orchestration loop to fully event-driven architecture using Atmos events, reducers, before hooks, and listeners.
Key Changes
New Files:
orchestration.go(346 lines) - Event-driven orchestration logicexecution.go(175 lines) - Reusable business logicorchestration_test.go- Test event-driven orchestrationSimplified:
cmd/hearth/run.go: 425 → 92 lines (78% reduction)h.Process(&ExecuteTasksRequested{})Enhanced:
events.go: Added orchestration eventsreducers.go: Removed mutation logic (now event-driven)Removed:
cmd/hearth/run_test.go(278 lines) - Logic now tested in core testsArchitecture Benefits
✅ Clear separation of concerns (reducers/hooks/listeners)
✅ Fully auditable event log
✅ Highly testable (10 tests passing)
✅ No state mutations in reducers
✅ Event-driven parent auto-completion
Test Plan
Known Issues
🤖 Generated with Claude Code