Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

Implements a plugin architecture allowing MSAgent-AI to monitor applications/games and trigger AI responses based on process/window events.

Architecture

Core Components:

  • IAppHook interface - Contract for custom hooks
  • AppHookBase - Shared functionality (lifecycle, logging, disposal)
  • AppHookManager - Registration, lifecycle, event forwarding

Event Flow:

Hook (process/window monitor) → AppHookManager → MainForm → Ollama AI → Agent speech

Built-in Hooks

ProcessMonitorHook: Detects app start/stop via periodic process enumeration

  • Configurable prompts per event type
  • Adjustable poll interval (default: 2s)

WindowMonitorHook: Tracks active window title changes via Win32 API

  • Monitors foreground window for target process
  • Poll interval (default: 1s)

Configuration

JSON-based hook definitions in AppSettings:

{
  "EnableAppHooks": true,
  "AppHooks": [
    {
      "HookType": "ProcessMonitor",
      "TargetApp": "notepad",
      "Enabled": true,
      "Parameters": {
        "StartPrompt": "User opened Notepad. Encourage their writing!",
        "StopPrompt": "User closed Notepad. Ask if they saved.",
        "PollInterval": "2000"
      }
    }
  ]
}

Event System

AppHookEventArgs supports:

  • AI prompts vs. direct speech
  • Optional animations
  • Priority levels
  • Context metadata
  • Interrupt flags

10 event types: ApplicationStarted, ApplicationStopped, WindowTitleChanged, Achievement, Error, Custom, etc.

Integration

MainForm changes:

  • InitializeAppHooks() - Parses config, instantiates hooks
  • OnHookTriggered() - Routes events to AI/speech systems
  • Helper methods for parameter extraction
  • Lifecycle management in Dispose()

Thread-safe UI marshalling via InvokeRequired pattern.

Extensibility

Developers create custom hooks by:

  1. Implementing IAppHook or extending AppHookBase
  2. Override OnStart() / OnStop() for monitoring logic
  3. Call TriggerEvent() to send events

Example template in examples/TextFileMonitorHook.cs demonstrates file monitoring pattern.

Documentation

  • APPHOOKS.md (843 lines) - API reference, best practices, examples
  • APPHOOKS-QUICKSTART.md (360 lines) - User setup guide, common configs
  • examples/ - Hook implementations and JSON configs

Files Modified

New:

  • src/AppHook/ - Core infrastructure (5 files)
  • Documentation (3 files)
  • Examples (2 files)

Changed:

  • AppSettings.cs - AppHookConfig class
  • MainForm.cs - Hook integration (~150 lines)
  • README.md - Feature documentation
Original prompt

Create a feature that will allow the program to hook into a chosen application or game, if the game/application is compatible then it will send prompts to the AI to allow for dynamic reactions. Create extensive documentation for this feature as well, to allow developers to create custom scripts for games/applications to make them compatible.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 24, 2026 06:51
Co-authored-by: ExtCan <60326708+ExtCan@users.noreply.github.com>
Co-authored-by: ExtCan <60326708+ExtCan@users.noreply.github.com>
Co-authored-by: ExtCan <60326708+ExtCan@users.noreply.github.com>
Co-authored-by: ExtCan <60326708+ExtCan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add feature for AI integration with applications and games Add extensible application hook system for dynamic AI reactions Jan 24, 2026
Copilot AI requested a review from ExtCan January 24, 2026 06:59
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