refactor(pty): extract ActivityMonitor subsystems into standalone classes#3396
Merged
gregpriday merged 5 commits intodevelopfrom Mar 16, 2026
Merged
Conversation
- Add PatternBuffer, InputTracker, OutputVolumeDetector, HighOutputDetector - Add WorkingSignalDebouncer, LineRewriteDetector, PromptDetector, CompletionDetector - Add CompletionTimer, BootDetector as independently testable modules - All files in electron/services/pty/ following AgentPatternDetector pattern
- Replace inline detection logic with subsystem method calls - InputTracker handles input parsing, echo detection, pending input state - PatternBuffer, OutputVolumeDetector, HighOutputDetector manage output tracking - LineRewriteDetector, WorkingSignalDebouncer handle spinner and recovery - BootDetector, CompletionTimer, PromptDetector, CompletionDetector handle state detection - All 96 existing tests pass without modification - ActivityMonitor reduced from 1573 to ~490 lines
- Add tests for PatternBuffer, InputTracker, OutputVolumeDetector - Add tests for HighOutputDetector, WorkingSignalDebouncer, LineRewriteDetector - Add tests for PromptDetector, CompletionDetector, CompletionTimer, BootDetector - All 465 tests pass (96 existing + 121 new subsystem tests)
- Remove unused PromptDetectionResult type import from ActivityMonitor - Remove unused result variable in InputTracker test
- InputTracker: verify escape sequences don't count as typed text via follow-up Enter - CompletionTimer: add delayed re-emit test to verify timer deadline resets - LineRewriteDetector: add negative cases for isStatusLineRewrite with ordinary content
Collaborator
Author
|
Review status: Ready |
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
ActivityMonitorwas a 1,573-line class implementing eight distinct detection subsystems with no shared internal state requirements. Each subsystem (input tracking, prompt detection, completion detection, line-rewrite/spinner detection, boot detection, output volume analysis, working signal debouncing, completion timing) is now a standalone class inelectron/services/pty/.The main
ActivityMonitorclass is retained as the orchestrator and state machine. It delegates to the extracted subsystems rather than re-implementing their logic.Resolves #3375
Changes
BootDetector,CompletionDetector,CompletionTimer,HighOutputDetector,InputTracker,LineRewriteDetector,OutputVolumeDetector,PatternBuffer,PromptDetector, andWorkingSignalDebouncerintoelectron/services/pty/ActivityMonitorrefactored to instantiate and delegate to these subsystems; class is materially smallerelectron/services/pty/__tests__/)Testing
All extracted subsystems have focused unit tests covering their core detection logic. Tests run with
npm test(Vitest). The existing behaviour ofActivityMonitoris preserved through delegation — no detection heuristics were changed, only where they live.