feat: add push notifications with VAPID (#110)

* Add OAuth authentication support for MCP servers

* Improve mobile text sizing with responsive text classes

* refactor: improve virtualized text viewer with React Query infinite scroll and simplified buffering

* Add push notifications with VAPID and PWA support

* feat: add VAPID environment variables for push notifications

* Replace SquareFill with MicOff icon for stop recording buttons

* Send push notifications when app is not focused

* Fix stop generation button icons to use X instead of MicOff

* feat: enhance push notification logging and debugging

- Add structured logging throughout push notification flow
- Improve error handling with detailed diagnostics
- Add /api/notifications/debug endpoint for troubleshooting
- Enhanced test notification response with per-subscription results
- Add service worker logging and better install/activate handling

* Improve VAPID push notification configuration with validation and better defaults

- Add validation warnings for VAPID_SUBJECT format (requires mailto: prefix for iOS/Safari)
- Expose VAPID details via notifications API endpoint
- Update default VAPID_SUBJECT from mailto:admin@opencode.local to empty string
- Enhance VAPID logging with key lengths and subject info
- Improve documentation in .env.example with setup instructions

* Fix notification URL to use repo ID instead of filesystem path

* Clean up push notification logging and debug endpoints

* Add push notifications documentation
This commit is contained in:
Chris Scott authored and GitHub committed 2026-02-06 11:23:10 -05:00
1 parent 3d9e9b8322
commit ae644e851d
47 files changed
+4506 -67

No files matched your search

+63 -17
View File
@@ -33,9 +33,38 @@ Complete reference for all configuration options.
| `PASSKEY_RP_NAME` | Display name for passkey prompts | `OpenCode Manager` |
| `PASSKEY_ORIGIN` | Origin URL for WebAuthn (backend port) | `http://localhost:5003` |
!!! tip "IMPORTANT"
- `PASSKEY_ORIGIN` must use the **backend** port (5003), not the frontend port (5173)
- The origin must exactly match where the auth API is served
## Push Notifications (VAPID)
| Variable | Description | Required |
|----------|-------------|----------|
| `VAPID_PUBLIC_KEY` | VAPID public key for push notifications | Yes |
| `VAPID_PRIVATE_KEY` | VAPID private key for push notifications | Yes |
| `VAPID_SUBJECT` | Contact email for VAPID (MUST use `mailto:` format) | Yes |
### Generating VAPID Keys
Generate VAPID public/private key pair:
```bash
npx web-push generate-vapid-keys
```
Add to `.env`:
```bash
VAPID_PUBLIC_KEY=BMx-1234567890abcdefghijklmnopqrstuv...
VAPID_PRIVATE_KEY=abcd1234567890abcdef...
VAPID_SUBJECT=mailto:you@example.com
```
!!! warning "iOS/Safari Requirement"
`VAPID_SUBJECT` **MUST** use `mailto:` format for iOS/Safari push notifications to work. Apple's push service rejects `https://` subjects.
**Correct:** `VAPID_SUBJECT=mailto:you@yourdomain.com`
**Incorrect:** `VAPID_SUBJECT=https://yourdomain.com`
When configured, users can enable push notifications in Settings → Notifications to receive background alerts for agent events.
## Server
@@ -67,6 +96,11 @@ GITHUB_CLIENT_SECRET=your-client-secret
PASSKEY_RP_ID=localhost
PASSKEY_RP_NAME=OpenCode Manager
PASSKEY_ORIGIN=http://localhost:5003
# Push notifications (optional)
VAPID_PUBLIC_KEY=BMx-1234567890abcdefghijklmnopqrstuv...
VAPID_PRIVATE_KEY=abcd1234567890abcdef...
VAPID_SUBJECT=mailto:you@example.com
```
## Generating Secrets
@@ -84,10 +118,32 @@ Output example:
K7gNU3sdo+OL0wNhqoVWhr3g6s1xYv72ol/pe/Unols=
```
!!! warning "Security"
- Never commit AUTH_SECRET to version control
- Use different secrets for development and production
- Rotate secrets periodically
### VAPID Keys
Generate VAPID public/private key pair for push notifications:
```bash
npx web-push generate-vapid-keys
```
Output example:
```
=======================================
Public Key:
BMx-1234567890abcdefghijklmnopqrstuv...
Private Key:
abcd1234567890abcdef...
Subject:
mailto:you@example.com
===========================================
```
!!! warning "iOS/Safari Requirement"
`VAPID_SUBJECT` **MUST** use `mailto:` format for iOS/Safari push notifications to work.
## Environment Precedence
@@ -98,14 +154,4 @@ Variables are loaded in this order (later overrides earlier):
3. Docker Compose `environment` section
4. Docker Compose `env_file` reference
## Validating Configuration
Check your configuration:
```bash
# View current environment (inside container)
docker exec opencode-manager env | grep -E '^(AUTH|ADMIN|PASSKEY)'
# Check if secrets are set (without revealing values)
docker exec opencode-manager sh -c 'if [ -n "$AUTH_SECRET" ]; then echo "AUTH_SECRET: set"; else echo "AUTH_SECRET: NOT SET"; fi'
```
+116
View File
@@ -0,0 +1,116 @@
# Push Notifications
Send background notifications when the OpenCode Manager PWA is closed, keeping you informed of agent activity without keeping the app open.
## Overview
Push notifications allow you to receive alerts on your mobile device or desktop when:
- The **agent needs permission** to continue (file operations, tool use, etc.)
- The **agent has a question** for you (clarifications, confirmations)
- A **session encounters an error** during execution
- A **session completes successfully**
Notifications are only sent when you don't have the app open (no SSE connections), preventing duplicate alerts while you're actively monitoring a session.
## Supported Events
| Event | Description | Default |
|-------|-------------|---------|
| `permissionAsked` | Agent requests permission for an action | Enabled |
| `questionAsked` | Agent asks a clarifying question | Enabled |
| `sessionError` | Session encounters an error | Enabled |
| `sessionIdle` | Session completes successfully | Disabled |
## Browser Compatibility
Push notifications require HTTPS (except on `localhost`) and browser support:
| Browser | Support | Notes |
|---------|---------|-------|
| Chrome/Edge | ✅ Full | Works well |
| Firefox | ✅ Full | Works well |
| Safari (iOS/macOS) | ✅ Full | Requires `mailto:` VAPID subject |
| Android browser | ✅ Full | Works well |
### iOS/Safari Requirements
Apple's Push Notification Service (APNs) has strict requirements:
1. **HTTPS is required** - `localhost` testing requires Safari Dev Tools
2. **VAPID_SUBJECT must use `mailto:` format** - `https://` subjects are rejected
**Correct:** `VAPID_SUBJECT=mailto:you@yourdomain.com`
**Incorrect:** `VAPID_SUBJECT=https://yourdomain.com`
## Setup
### 1. Generate VAPID Keys
Generate VAPID public/private key pair:
```bash
npx web-push generate-vapid-keys
```
Output:
```
=======================================
Public Key:
BMx-123456... (your public key here)
Private Key:
abcd1234... (your private key here)
Subject:
mailto:your-email@example.com
=======================================
```
### 2. Configure Environment Variables
Add to your `.env` file:
```bash
VAPID_PUBLIC_KEY=BMx-123456...
VAPID_PRIVATE_KEY=abcd1234...
VAPID_SUBJECT=mailto:you@yourdomain.com
```
### 3. Subscribe Devices
1. Open OpenCode Manager in your browser
2. Go to **Settings** → **Notifications**
3. Click **Enable Push Notifications**
4. Allow browser permission when prompted
5. Your device is now subscribed
## Managing Subscriptions
### View Subscribed Devices
Navigate to **Settings** → **Notifications** to see all registered devices:
- Device name (if provided)
- Subscription date
- Last used timestamp
### Remove a Device
Click **Unsubscribe** next to a device to remove it from receiving notifications.
### Test Notifications
Go to **Settings** → **Notifications** and click **Send Test Notification** to verify your setup is working.
## Notification Preferences
Control which events trigger notifications:
**Notification Settings:**
- **Enable Push Notifications** - Master toggle (default: off)
- **Permission Requested** - Get notified when agent needs permission (default: on)
- **Question Asked** - Get notified when agent has a question (default: on)
- **Session Error** - Get notified on session errors (default: on)
- **Session Complete** - Get notified when session finishes (default: off)
+9
View File
@@ -68,3 +68,12 @@ OpenCode Manager provides a comprehensive web interface for managing OpenCode AI
[Learn more →](mobile.md)
### Push Notifications
- **Background Alerts** - Receive notifications when the app is closed
- **Agent Events** - Get alerted for permissions, questions, errors, and completions
- **Multi-Device** - Subscribe multiple devices (phone, tablet, desktop)
- **Customizable** - Control which events trigger notifications
[Learn more →](notifications.md)
+2 -1
View File
@@ -22,7 +22,7 @@ OpenCode Manager provides a web-based interface for OpenCode AI agents, allowing
- **Manage repositories** - Clone, browse, and work with multiple git repos
- **Chat with AI** - Real-time streaming chat with file mentions and slash commands
- **View diffs** - See code changes with syntax highlighting
- **Control from anywhere** - Mobile-first PWA works on any device
- **Control from anywhere** - Mobile-first PWA with push notifications
- **Configure AI** - Manage models, providers, and MCP servers
## Key Features
@@ -31,6 +31,7 @@ OpenCode Manager provides a web-based interface for OpenCode AI agents, allowing
- **Git Integration** - View diffs, manage branches, create PRs directly from the UI
- **Real-time Chat** - Stream responses with file mentions and custom slash commands
- **Mobile-First PWA** - Install as an app on any device with offline support
- **Push Notifications** - Get background alerts for agent events when app is closed
- **AI Configuration** - Configure models, providers, OAuth, and custom agents
- **MCP Servers** - Add local or remote MCP servers with pre-built templates