Skip to content

feat: complete TypeScript migration with cross-platform focus detection#12

Merged
MasuRii merged 18 commits intomasterfrom
feature/typescript-migration
Feb 19, 2026
Merged

feat: complete TypeScript migration with cross-platform focus detection#12
MasuRii merged 18 commits intomasterfrom
feature/typescript-migration

Conversation

@MasuRii
Copy link
Owner

@MasuRii MasuRii commented Feb 19, 2026

Summary

Complete TypeScript migration of the entire codebase with full type safety, cross-platform focus detection (Windows, macOS, Linux), improved notification reliability, and comprehensive test coverage. All 9 utility modules, the main plugin entry point, and 22 test files have been converted from JavaScript to TypeScript.

Changes

TypeScript Migration

  • Add TypeScript configuration (tsconfig.json, tsconfig.build.json) and build setup
  • Define typed interfaces for config, TTS engines, notifications, events, Linux platform, OpenCode SDK, and test helpers (9 type definition files)
  • Convert all 9 utility modules (config, tts, ai-messages, webhook, desktop-notify, focus-detect, linux, sound-theme, per-project-sound) to TypeScript with full type annotations
  • Convert main plugin entry point (index.jssrc/index.ts) with typed plugin hooks and session event handlers
  • Convert all test files (unit, integration, e2e) and test setup to TypeScript
  • Remove all legacy JavaScript source files

Cross-Platform Focus Detection

  • Add Windows focus detection using PowerShell with Win32 API interop (GetForegroundWindow, GetWindowText, IsIconic, IsWindowVisible)
  • Add Linux focus detection supporting X11 (xdotool/xprop) and Wayland compositors (Sway, GNOME, KDE)
  • Detect minimized and hidden windows properly on both macOS and Windows
  • Change suppressWhenFocused default to false (opt-in) for safer defaults
  • Remove IDE entries from terminal process lists to reduce false positives

Notification Reliability

  • Prevent sub-agent completions from triggering duplicate notifications
  • Add 30-second TTL session cache to reduce redundant API calls during repeated events
  • Add fallback notification flow when session API fails (degraded but functional alerts)

Documentation & Config

  • Synchronize comments between example.config.jsonc and config.ts
  • Update focus detection documentation to reflect cross-platform support
  • Fix Edge TTS description to document dual approach (Python CLI recommended + npm fallback)
  • Add missing enableContextAwareAI field to example config

Files Changed

File Type Impact
tsconfig.json, tsconfig.build.json Added TypeScript project configuration
package.json Modified TypeScript devDependencies, build scripts, dist/ output
.gitignore Modified Added dist/ and tsbuildinfo patterns
src/types/*.ts (9 files) Added Type definitions for entire plugin architecture
src/index.ts Added Typed main entry point (replaces index.js)
src/util/*.ts (9 files) Added Typed utility modules (replaces util/*.js)
util/*.js (9 files) Deleted Legacy JavaScript modules removed
tests/**/*.test.ts (22 files) Renamed/Added All tests converted to TypeScript
tests/setup.ts Added Typed test setup (replaces tests/setup.js)
tests/unit/linux-focus-detect.test.ts Added Linux-specific focus detection tests
tests/unit/sub-session-filtering.test.ts Added Sub-session filtering and caching tests
tests/unit/config-update.test.ts Added Config update logic tests (45 tests)
example.config.jsonc Modified Synchronized descriptions, added missing fields
README.md Modified Updated platform compatibility documentation

Testing

  • Manual testing: Manually tested for 2+ days in real usage with no regressions
  • Automated tests: 672 tests pass across unit, integration, and e2e suites
  • Line coverage: 88.99%
  • New test suites added:
    • Focus detection tests (Windows + macOS mocks): comprehensive visibility and minimized window scenarios
    • Linux focus detection tests: X11 and Wayland compositor coverage
    • Sub-session filtering tests: 31 tests covering detection, fail-safe, debounce, and caching
    • Config update tests: 45 tests covering value preservation, comment sync, and roundtrip stability

Reviewer Checklist

  • TypeScript types are accurate and comprehensive
  • Cross-platform focus detection logic handles edge cases properly
  • Session cache TTL (30s) and invalidation strategy are appropriate
  • Fallback notification behavior is acceptable when session API fails
  • suppressWhenFocused default change to false is a safe default
  • No regressions in existing functionality
  • Documentation accurately reflects current behavior

Related Issues

Add tsconfig.json and tsconfig.build.json for project-references build.
Update package.json with TypeScript devDependencies, build scripts,
dist/ output paths, and bumped version to 1.3.3.
Update .gitignore with dist/ and tsbuildinfo patterns.
Define typed interfaces for config, TTS engines, notifications,
events, Linux platform support, OpenCode SDK, and test helpers.
Add ambient declarations for msedge-tts and detect-terminal modules.
Migrate all util/ modules to src/util/ with full type annotations:
config, tts, ai-messages, webhook, desktop-notify, focus-detect,
linux, sound-theme, and per-project-sound.
Migrate index.js to src/index.ts with typed plugin hooks, session
event handlers, and notification orchestration logic.
Remove legacy index.js from project root.
Migrate test setup and all unit, integration, and e2e test files
from .js to .ts with typed mocks, fixtures, and assertions.
Update bunfig.toml preload path to tests/setup.ts.
Delete all original util/*.js modules now superseded by their
typed equivalents in src/util/.
Add proper error handling for session.get() API failures so that
network errors no longer accidentally let sub-session events through.
Clear debounce entries when returning early for sub-sessions or API
errors to keep the debounce map accurate.

Introduce a 30-second TTL session cache (sessionCache Map) to reduce
redundant API calls during repeated idle/error events. Cache is
invalidated on session.created and expired entries are cleaned up
periodically.

Add debug logging across all decision branches for improved
observability.

Closes #11
Cover sub-session detection, API error fail-safe behavior, debounce cleanup on early returns, and session cache hit/miss/invalidation logic across both session.idle and session.error handlers (31 tests).
Add cross-platform focus detection using PowerShell with Win32 API interop on Windows and xdotool/xprop (X11) plus Sway/GNOME/KDE compositor queries on Wayland for Linux. Includes executeCommand abstraction for testable shell execution, platform-specific terminal name lists, and a comprehensive Linux-specific test suite.
Add visibility checks to cross-platform focus detection scripts:
- macOS: check app visibility and filter out miniaturized windows
- Windows: add IsIconic and IsWindowVisible DLL imports and checks

Focus detection now returns empty when the foreground window is
minimized or hidden, preventing false positive focus matches.
Replace early-return behavior on session lookup failure with a
degraded notification flow that still alerts the user:

- Add usedIdleSessionFallback and usedErrorSessionFallback flags
- Send shorter desktop messages when session context is unavailable
- Pass empty AI context in fallback mode to avoid stale data
- Fix indentation inconsistency in idle/error notification blocks
… terminal lists

- Change suppressWhenFocused default from true to false (opt-in)
- Remove VS Code variants and JetBrains IDEs from KNOWN_TERMINALS_MACOS
- Add comprehensive focus detection mock tests for Windows and macOS
- Update sub-session filtering tests to match fail-safe skip behavior
- Align platform support tests with current detection capabilities
- Document focus detection as cross-platform (Windows, macOS, Linux)
- Update platform compatibility table with full support checkmarks
- Add focus detection configuration details to example config
- Update platform-specific notes for macOS focus detection
Update focus detection section to reflect cross-platform support status (Windows, macOS, and Linux). Fix Edge TTS description to document dual approach: Python CLI recommended with msedge-tts npm fallback.
…documentation

Synchronize Edge TTS description with config.ts (Python CLI + npm fallback). Add missing enableContextAwareAI field. Add extensive inline comments covering desktop notifications, AI endpoints, sound themes, webhooks, permission batching, and per-project sound settings.
Add 45 tests covering config value preservation, comment updates without value loss, focus detection field defaults and persistence, deepMerge edge cases, findNewFields detection, and full roundtrip regeneration stability.
@MasuRii MasuRii self-assigned this Feb 19, 2026
@MasuRii MasuRii added the enhancement New feature or request label Feb 19, 2026
@MasuRii MasuRii merged commit 6582fc0 into master Feb 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sub-agents trigger sounds

1 participant