Skip to content

refactor(pty): extract ActivityMonitor subsystems into standalone classes#3396

Merged
gregpriday merged 5 commits intodevelopfrom
feature/issue-3375-activitymonitor-implements
Mar 16, 2026
Merged

refactor(pty): extract ActivityMonitor subsystems into standalone classes#3396
gregpriday merged 5 commits intodevelopfrom
feature/issue-3375-activitymonitor-implements

Conversation

@gregpriday
Copy link
Copy Markdown
Collaborator

Summary

ActivityMonitor was 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 in electron/services/pty/.

The main ActivityMonitor class is retained as the orchestrator and state machine. It delegates to the extracted subsystems rather than re-implementing their logic.

Resolves #3375

Changes

  • Extracted BootDetector, CompletionDetector, CompletionTimer, HighOutputDetector, InputTracker, LineRewriteDetector, OutputVolumeDetector, PatternBuffer, PromptDetector, and WorkingSignalDebouncer into electron/services/pty/
  • ActivityMonitor refactored to instantiate and delegate to these subsystems; class is materially smaller
  • Unit test suites added for all ten extracted subsystems (electron/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 of ActivityMonitor is preserved through delegation — no detection heuristics were changed, only where they live.

- 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
@gregpriday
Copy link
Copy Markdown
Collaborator Author

Review status: Ready

@gregpriday gregpriday merged commit a918fdc into develop Mar 16, 2026
4 checks passed
@gregpriday gregpriday deleted the feature/issue-3375-activitymonitor-implements branch March 17, 2026 05:08
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.

ActivityMonitor implements eight detection subsystems in a single class

1 participant