Skip to content

[WIP] AutoShell Refactoring#2117

Draft
TalZaccai wants to merge 37 commits intomainfrom
talzacc/autoshell_refactor
Draft

[WIP] AutoShell Refactoring#2117
TalZaccai wants to merge 37 commits intomainfrom
talzacc/autoshell_refactor

Conversation

@TalZaccai
Copy link
Copy Markdown
Contributor

@TalZaccai TalZaccai commented Apr 1, 2026

Structural refactoring of autoShell to make the codebase testable, maintainable, and extensible. All 78 commands continue to work identically — verified by a command-by-command audit against origin/main.


Phase 1: Core Architecture

  • Extract 10 OS abstraction interfaces (IAudioService, IRegistryService, ISystemParametersService, IProcessService, IWindowService, INetworkService, IBrightnessService, IDisplayService, IVirtualDesktopService, IDebuggerService)
  • Extract 17 command handler classes by domain (AudioCommandHandler, WindowCommandHandler, NetworkCommandHandler, 9 settings sub-handlers, etc.)
  • Replace 78-case execLine switch with CommandDispatcher + dictionary lookup
  • Extract shared app data into IAppRegistry service (replaces static fields)
  • Migrate all scenario-specific logic from AutoShell.cs into handlers (~1604 → ~80 lines)
  • Move all P/Invoke declarations into their respective domain handlers/services
  • Move all COM interop (Virtual Desktop, Audio, Network) into respective services
  • Move interop files to Services/Interop/ (CoreAudioInterop.cs, UIAutomation.cs)
  • Move IAppRegistry + WindowsAppRegistry to project root
  • Delete AutoShell_Win32.cs, AutoShell_Settings.cs, AutoShell_Themes.cs — all logic now in handlers/services
  • Delete legacy packages.config and App.config
  • Add centralized error handling (try/catch in dispatcher)
  • Handle quit directly in dispatcher (not in handlers)

Phase 2: Code Quality

  • Add XML doc comments to all interface methods + <inheritdoc/> on implementations
  • Clean up unused using directives across all files
  • Add explicit private modifiers (satisfying .editorconfig rules)
  • Unify all command names to PascalCase (C# handlers + TS schemas + connector)
  • Run dotnet format for code style consistency
  • Fix all build warnings (CA1806, SYSLIB1054) — target zero warnings
  • Modernize collections: HashtableDictionary<string,string> with OrdinalIgnoreCase, SortedListDictionary
  • Fix Dictionary indexer regression (TryGetValue for null-return contract)
  • Add ILogger abstraction with Error, Warning, Info, Debug levels
  • Replace Console.WriteLine/Debug.WriteLine with proper logger calls
  • Restore all important original comments (API semantics, design rationale, TODOs)

Phase 3: Testing

  • Create autoShell.Tests xUnit project with Moq
  • Unit tests for all 17 handler classes with mocked services (153 tests)
  • CommandDispatcher tests — verify correct handler routing for each action
  • HandlerRegistration reflection tests — enforce every command has at least one unit test
  • WindowsAppRegistry tests — real class, null returns, case insensitivity (9 tests)
  • CommandDispatcherIntegration tests — full wiring with mock services (11 tests)
  • E2E stdin/stdout tests — query commands, protocol edge cases, command-line mode (15 tests)
  • Add dotnet test to CI

The PascalCase rename missed the .agr (agent grammar) files, causing
agc compilation failures in CI. Updated all actionName values in 5 .agr
files to match their PascalCase counterparts in the TypeScript schemas.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
TalZaccai and others added 2 commits April 1, 2026 11:58
Phase 2 unit test project with three test classes:
- CommandDispatcherTests: quit detection, routing, error isolation, empty/unknown commands
- AudioCommandHandlerTests: volume set/restore, mute on/off, invalid input handling
- HandlerRegistrationTests: all 77 commands registered, no duplicates, PascalCase enforced

Uses xUnit + Moq for mocking IAudioService and other internal interfaces.
Added InternalsVisibleTo for test project and DynamicProxyGenAssembly2.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Runs dotnet test for autoShell.Tests after the MSBuild build step,
in both Debug and Release configurations.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@TalZaccai TalZaccai force-pushed the talzacc/autoshell_refactor branch from fba483e to b450c9d Compare April 1, 2026 20:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the autoShell Windows desktop agent to a handler/service-based architecture with a centralized command dispatcher, while aligning the TS action schemas/connector to PascalCase command names and adding a comprehensive .NET test suite + CI test execution.

Changes:

  • Updated desktop TS .agr grammars + action schema types and connector.ts routing to use PascalCase actionNames (matching the refactored .NET command keys).
  • Introduced a new .NET command pipeline (CommandDispatcher + domain command handlers) and OS-abstraction service interfaces with Windows implementations.
  • Added autoShell.Tests (xUnit + Moq) including integration/E2E protocol tests, and wired dotnet test into CI.

Reviewed changes

Copilot reviewed 84 out of 84 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
ts/packages/agents/desktop/src/windows/systemSchema.agr Renames network/gaming/system action names to PascalCase in the grammar mappings.
ts/packages/agents/desktop/src/windows/systemActionsSchema.ts Updates actionName string literal types for system actions to PascalCase.
ts/packages/agents/desktop/src/windows/powerSchema.agr Updates power-mode command mappings to PascalCase action names.
ts/packages/agents/desktop/src/windows/powerActionsSchema.ts Updates SetPowerModePluggedIn action type to PascalCase actionName.
ts/packages/agents/desktop/src/windows/inputSchema.agr Updates mouse-related action names and extends cursor-trail utterances.
ts/packages/agents/desktop/src/windows/inputActionsSchema.ts Updates actionName string literals (e.g., SetPrimaryMouseButton, MousePointerCustomization).
ts/packages/agents/desktop/src/windows/displaySchema.agr Updates Night Light color temperature action name to PascalCase.
ts/packages/agents/desktop/src/windows/displayActionsSchema.ts Updates AdjustColorTemperature action type to PascalCase actionName.
ts/packages/agents/desktop/src/desktopSchema.agr Updates core desktop command mappings (launch/close/window mgmt, volume, wifi, desktops, etc.) to PascalCase action names.
ts/packages/agents/desktop/src/connector.ts Updates action routing switch cases + protocol keys (e.g., ListAppNames) to PascalCase command keys.
ts/packages/agents/desktop/src/actionsSchema.ts Updates the top-level Desktop action schema types to PascalCase actionName literals and examples.
dotnet/autoShell/WindowsAppRegistry.cs Adds IAppRegistry implementation for friendly-name → path/AppUserModelId metadata + AppsFolder enumeration.
dotnet/autoShell/Services/WindowsWindowService.cs Adds Win32/PInvoke-backed IWindowService implementation (maximize/minimize/raise/tile/find).
dotnet/autoShell/Services/WindowsSystemParametersService.cs Adds ISystemParametersService implementation wrapping SystemParametersInfo + mouse button swap.
dotnet/autoShell/Services/WindowsRegistryService.cs Adds IRegistryService implementation for HKCU/HKLM value set/get and WM_SETTINGCHANGE broadcast.
dotnet/autoShell/Services/WindowsProcessService.cs Adds IProcessService implementation for process start and lookup.
dotnet/autoShell/Services/WindowsDisplayService.cs Adds IDisplayService implementation (resolution list/set; text-size via UIAutomation).
dotnet/autoShell/Services/WindowsDebuggerService.cs Adds IDebuggerService implementation using Debugger.Launch().
dotnet/autoShell/Services/WindowsBrightnessService.cs Adds IBrightnessService implementation using registry + WMI.
dotnet/autoShell/Services/WindowsAudioService.cs Adds IAudioService implementation using CoreAudio COM interop.
dotnet/autoShell/Services/IWindowService.cs Introduces window-management abstraction interface.
dotnet/autoShell/Services/IVirtualDesktopService.cs Introduces virtual desktop abstraction interface.
dotnet/autoShell/Services/ISystemParametersService.cs Introduces system-parameters abstraction interface.
dotnet/autoShell/Services/IRegistryService.cs Introduces registry abstraction interface.
dotnet/autoShell/Services/IProcessService.cs Introduces process abstraction interface.
dotnet/autoShell/Services/Interop/UIAutomation.cs Moves UIAutomation interop under Services/Interop and routes logging through ILogger.
dotnet/autoShell/Services/Interop/CoreAudioInterop.cs Adds CoreAudio COM interop definitions under Services/Interop.
dotnet/autoShell/Services/INetworkService.cs Introduces network abstraction interface (wifi, airplane mode, bluetooth).
dotnet/autoShell/Services/IDisplayService.cs Introduces display abstraction interface.
dotnet/autoShell/Services/IDebuggerService.cs Introduces debugger abstraction interface.
dotnet/autoShell/Services/IBrightnessService.cs Introduces brightness abstraction interface.
dotnet/autoShell/Services/IAudioService.cs Introduces audio abstraction interface.
dotnet/autoShell/packages.config Removes legacy NuGet packages.config usage.
dotnet/autoShell/Logging/ILogger.cs Adds logging abstraction used across services/handlers.
dotnet/autoShell/Logging/ConsoleLogger.cs Adds console-backed logger implementation.
dotnet/autoShell/IAppRegistry.cs Introduces shared application registry abstraction.
dotnet/autoShell/Handlers/WindowCommandHandler.cs Adds handler for Maximize/Minimize/SwitchTo/Tile.
dotnet/autoShell/Handlers/VirtualDesktopCommandHandler.cs Adds handler for desktop creation/move/pin/switch commands.
dotnet/autoShell/Handlers/ThemeCommandHandler.cs Adds handler for theme apply/list/mode/wallpaper logic.
dotnet/autoShell/Handlers/SystemCommandHandler.cs Adds handler for debug + notification center commands.
dotnet/autoShell/Handlers/Settings/TaskbarSettingsHandler.cs Adds taskbar settings handler backed by registry edits + settings change notify.
dotnet/autoShell/Handlers/Settings/SystemSettingsHandler.cs Adds system settings handler (DST, game mode, quiet hours, display-related settings URIs).
dotnet/autoShell/Handlers/Settings/PrivacySettingsHandler.cs Adds privacy settings handler (camera/location/microphone consent store).
dotnet/autoShell/Handlers/Settings/PowerSettingsHandler.cs Adds power settings handler (battery threshold + settings URIs).
dotnet/autoShell/Handlers/Settings/PersonalizationSettingsHandler.cs Adds personalization settings handler (title bar color, transparency, theme mode).
dotnet/autoShell/Handlers/Settings/MouseSettingsHandler.cs Adds mouse/touchpad settings handler (cursor speed, trails, wheel lines, swap buttons, etc.).
dotnet/autoShell/Handlers/Settings/FileExplorerSettingsHandler.cs Adds File Explorer settings handler (extensions, hidden/system files).
dotnet/autoShell/Handlers/Settings/DisplaySettingsHandler.cs Adds display settings handler (brightness, night light, scaling, blue light registry, rotation lock).
dotnet/autoShell/Handlers/Settings/AccessibilitySettingsHandler.cs Adds accessibility settings handler (filter keys, sticky keys, narrator/magnifier, mono audio).
dotnet/autoShell/Handlers/NetworkCommandHandler.cs Adds network command handler for wifi/airplane/bluetooth/metered connections.
dotnet/autoShell/Handlers/ICommandHandler.cs Defines common handler contract and supported command list.
dotnet/autoShell/Handlers/DisplayCommandHandler.cs Adds handler for listing resolutions and setting resolution/text size.
dotnet/autoShell/Handlers/AudioCommandHandler.cs Adds handler for mute/volume/restore behavior.
dotnet/autoShell/Handlers/AppCommandHandler.cs Adds handler for launch/close/list-app-names and app registry resolution.
dotnet/autoShell/CoreAudioInterop.cs Removes old CoreAudio interop file (moved under Services/Interop).
dotnet/autoShell/CommandDispatcher.cs Adds central dispatcher that registers handlers and routes JSON keys via dictionary lookup with error isolation.
dotnet/autoShell/autoShell.sln Adds test project and expands solution configurations.
dotnet/autoShell/autoShell.csproj Updates project metadata for net8 WindowsDesktop build, warning suppressions, and InternalsVisibleTo for tests/mocking.
dotnet/autoShell/AutoShell_Themes.cs Removes legacy theme logic file (migrated into ThemeCommandHandler).
dotnet/autoShell/App.config Removes legacy App.config for old .NET Framework runtime config.
dotnet/autoShell.Tests/WindowsAppRegistryTests.cs Adds unit tests for WindowsAppRegistry behaviors and contracts.
dotnet/autoShell.Tests/WindowCommandHandlerTests.cs Adds tests validating window command routing and service calls.
dotnet/autoShell.Tests/VirtualDesktopCommandHandlerTests.cs Adds tests validating virtual desktop command behavior and edge cases.
dotnet/autoShell.Tests/ThemeCommandHandlerTests.cs Adds tests validating theme mode/wallpaper behaviors and safe handling.
dotnet/autoShell.Tests/SystemCommandHandlerTests.cs Adds tests for Debug and Action Center behavior.
dotnet/autoShell.Tests/NetworkCommandHandlerTests.cs Adds tests for wifi/bluetooth/airplane/metered routing.
dotnet/autoShell.Tests/HandlerRegistrationTests.cs Adds reflection-based enforcement that commands are uniquely owned and have test coverage.
dotnet/autoShell.Tests/EndToEndTests.cs Adds stdin/stdout protocol E2E tests for query commands, quit, malformed input, and command-line mode.
dotnet/autoShell.Tests/DisplayCommandHandlerTests.cs Adds tests for resolution parsing and display command routing.
dotnet/autoShell.Tests/CommandDispatcherTests.cs Adds tests for dispatcher routing, quit semantics, and exception isolation.
dotnet/autoShell.Tests/CommandDispatcherIntegrationTests.cs Adds integration tests for full Create() wiring with mock services.
dotnet/autoShell.Tests/AutoShellProcess.cs Adds helper to run autoShell.exe as a child process for E2E tests.
dotnet/autoShell.Tests/autoShell.Tests.csproj Introduces the xUnit test project targeting net8.0-windows with Moq + test SDK deps.
dotnet/autoShell.Tests/AudioCommandHandlerTests.cs Adds tests for volume/mute/restore behavior.
dotnet/autoShell.Tests/AppCommandHandlerTests.cs Adds tests for launch/close/list and various launch fallbacks.
dotnet/.editorconfig Updates qualification/naming/analyzer severities to fit refactoring conventions.
.github/workflows/build-dotnet.yml Adds dotnet test step for the new autoShell.Tests project in CI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@TalZaccai TalZaccai temporarily deployed to development-fork April 3, 2026 20:36 — with GitHub Actions Inactive
@TalZaccai TalZaccai temporarily deployed to development-fork April 3, 2026 20:36 — with GitHub Actions Inactive
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.

2 participants