Skip to content

feat: 3 additional events, session_started, user_message, client_connected#61

Merged
mohak34 merged 1 commit into
mohak34:mainfrom
grota:additional_events
Apr 8, 2026
Merged

feat: 3 additional events, session_started, user_message, client_connected#61
mohak34 merged 1 commit into
mohak34:mainfrom
grota:additional_events

Conversation

@grota

@grota grota commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds three new configurable event types and improves subagent detection performance by introducing in-memory session tracking.

New events

Event type Trigger Default
session_started A new top-level (non-subagent) session is opened (session.created) sound only
user_message The user submits a message in a top-level session (message.updated, role=user) sound only
client_connected The OpenCode plugin finishes initializing and is ready sound only

All three default to sound enabled, notification disabled to avoid notification spam for high-frequency or low-urgency events. Users can override each individually in opencode-notifier.json.

Note on client_connected

There is no SDK event that reliably signals client connection from a plugin's perspective. The implementation fires the event via a short setTimeout after plugin startup, which is the closest available approximation. Config is read at fire-time (not schedule-time) so user overrides are respected, and the timeout only runs after the desktop-client guard has already passed.

In-memory subagent tracking

Previously, every session.idle event required an API call (client.session.get) to determine whether the session was a subagent (by checking parentID). This PR introduces a module-level subagentSessionIds: Set<string> populated from session.created, session.updated, and session.deleted events.

  • Fast path: if a session ID is already known to be a subagent, processSessionIdle returns immediately without any API call.
  • Fallback: sessions not yet seen in the Set still go through the API call, and if confirmed as a subagent, are added to the Set for future events.
  • The Set is pruned during the existing 5-minute cleanup interval alongside the other per-session maps.

Configuration

The three new events are fully configurable like all existing events:

{
  "events": {
    "session_started": { "sound": true, "notification": false, "command": true },
    "user_message": { "sound": false, "notification": false, "command": false },
    "client_connected": { "sound": true, "notification": true, "command": false }
  },
  "messages": {
    "session_started": "Session started: {sessionTitle}",
    "user_message": "User sent a message: {sessionTitle}",
    "client_connected": "OpenCode connected"
  },
  "sounds": {
    "session_started": "/path/to/custom.wav",
    "user_message": null,
    "client_connected": null
  },
  "volumes": {
    "session_started": 0.5,
    "user_message": 0.3,
    "client_connected": 1.0
  }
}

Changes

  • src/config.ts: Added session_started, user_message, and client_connected to EventType, NotifierConfig, DEFAULT_CONFIG, and loadConfig().
  • src/index.ts:
    • Added subagentSessionIds: Set<string> for in-memory subagent tracking.
    • Handle session.created: register subagent IDs; fire session_started for top-level sessions.
    • Handle session.updated / session.deleted: keep the subagent Set accurate.
    • Handle message.updated: fire user_message when role === "user" for non-subagent sessions.
    • Fire client_connected via setTimeout after plugin initialization (inside the desktop-client guard).
    • Updated processSessionIdle to use the fast path before falling back to the API.

Tests

All 43 tests pass. No new test failures introduced.

@grota grota force-pushed the additional_events branch from be47706 to ceb7814 Compare April 5, 2026 08:56
@mohak34 mohak34 merged commit d29c661 into mohak34:main Apr 8, 2026
@grota grota deleted the additional_events branch April 9, 2026 06:45
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