2
0
Fork 0

feat: add bell notifications #31

Merged
aleksei merged 14 commits from feat/bell-notifications into main 2026-11-04 12:01:12 +00:00
Owner

Adds tmux bell detection without attaching clients to every window, a bell icon in the session list, and Web Push notifications for the installed PWA.

Design: adr/notifications.md.

What changed

  • Window.bell is read from #{window_bell_flag} in the existing list-windows call. No control mode, no pipe-pane, no per-window PTY, no tmux hooks.
  • A non-viewed window follows one unread state: the first bell after the flag clears notifies; later bells wait for the window to be selected. Opening the window clears the flag.
  • The window open in the portal is different: tmux does not flag the client's current window, so the terminal PTY reader scans its byte stream for BEL and sends a push for every bell in that window. This covers a chat that keeps ringing without attaching to any other window. A bell in a window viewed by another tmux client is not reported.
  • A server-side watcher (2 s, only while push subscriptions exist) sends Web Push on the false -> true transition for the inventory. The first read is a baseline, so a restart does not replay old flags.
  • VAPID keys live in the optional push block. When the block is present and the key is missing or a placeholder, the first start generates a P-256 key pair, writes it back to config.json with mode 0600, and logs only that it did so. mux_portal vapid-keys remains for manual generation. The private key is redacted in Debug and never logged.
  • push.subject is required and must be a real contact URI. A missing or empty subject is a startup error. Apple rejects a localhost subject.
  • Push subscriptions are persisted in push-subscriptions.json with mode 0600, in $STATE_DIRECTORY (StateDirectory=mux-portal) or next to the config without systemd. They survive a portal restart, so the client does not have to re-register. A state file for a different VAPID key is ignored; the authenticated page still re-registers idempotently as a safety net.
  • web-push is used with default features off; ECE still needs OpenSSL, so the HTTP client is reqwest with native-tls and the build/host need libssl.
  • GET /api/tree carries bell. New routes: GET /api/push, POST/DELETE /api/push/subscribe, POST /api/push/test.
  • The PWA keeps generateSW and imports push-handler.js via workbox.importScripts; it handles push, notificationclick and pushsubscriptionchange, with every URL resolved against the service worker scope.
  • The Settings card has permission state, Enable/Disable/Send test, iOS instructions, and a per-browser "Notify while the app is in the foreground" switch stored in IndexedDB.
  • Foreground suppression is conservative. The page writes a visibility record on visibilitychange, pagehide, pageshow, freeze and resume, and refreshes it every five seconds while visible. A push is suppressed only when that record is fresh (under fifteen seconds) and the worker also sees a focused, visible client. A backgrounded or closed app still gets notifications when iOS reports a stale WindowClient.
  • The Settings card shows the last push decision, worker version, page foreground value and client count, and refreshes while the page is visible.
  • The systemd unit sets StateDirectory=mux-portal for the state file and ReadWritePaths=/etc/mux-portal for the first-start config rewrite. No startup check for monitor-bell; the Settings card and docs state the requirement.

Verification

  • cargo test --workspace — unit, API, tmux integration, terminal WebSocket, push, watcher, config generation, state persistence and BEL scan tests pass.
  • cargo clippy --workspace --all-targets -- -D warnings — clean.
  • npm run typecheck and npm run build — clean; push-handler.js is imported by sw.js.
  • Host checks: the watcher delivered real bells to Apple (delivered=1); the active-window PTY path was confirmed on the chat window with bg3; a direct push returned 201, POST /api/push/test returned 204; the subject change fixed the Apple 401/403.
  • Deployed on the host from c0308db; service active with push=true; temporary debug logging removed; clean backup under /var/backups/mux-portal-20261104-114939-clean-final.
Adds tmux bell detection without attaching clients to every window, a bell icon in the session list, and Web Push notifications for the installed PWA. Design: [adr/notifications.md](adr/notifications.md). ## What changed - `Window.bell` is read from `#{window_bell_flag}` in the existing `list-windows` call. No control mode, no `pipe-pane`, no per-window PTY, no tmux hooks. - A non-viewed window follows one unread state: the first bell after the flag clears notifies; later bells wait for the window to be selected. Opening the window clears the flag. - The window open in the portal is different: tmux does not flag the client's current window, so the terminal PTY reader scans its byte stream for BEL and sends a push for every bell in that window. This covers a chat that keeps ringing without attaching to any other window. A bell in a window viewed by another tmux client is not reported. - A server-side watcher (2 s, only while push subscriptions exist) sends Web Push on the `false -> true` transition for the inventory. The first read is a baseline, so a restart does not replay old flags. - VAPID keys live in the optional `push` block. When the block is present and the key is missing or a placeholder, the first start generates a P-256 key pair, writes it back to `config.json` with mode `0600`, and logs only that it did so. `mux_portal vapid-keys` remains for manual generation. The private key is redacted in `Debug` and never logged. - `push.subject` is required and must be a real contact URI. A missing or empty subject is a startup error. Apple rejects a `localhost` subject. - Push subscriptions are persisted in `push-subscriptions.json` with mode `0600`, in `$STATE_DIRECTORY` (`StateDirectory=mux-portal`) or next to the config without systemd. They survive a portal restart, so the client does not have to re-register. A state file for a different VAPID key is ignored; the authenticated page still re-registers idempotently as a safety net. - `web-push` is used with default features off; ECE still needs OpenSSL, so the HTTP client is `reqwest` with `native-tls` and the build/host need `libssl`. - `GET /api/tree` carries `bell`. New routes: `GET /api/push`, `POST/DELETE /api/push/subscribe`, `POST /api/push/test`. - The PWA keeps `generateSW` and imports `push-handler.js` via `workbox.importScripts`; it handles `push`, `notificationclick` and `pushsubscriptionchange`, with every URL resolved against the service worker scope. - The Settings card has permission state, Enable/Disable/Send test, iOS instructions, and a per-browser "Notify while the app is in the foreground" switch stored in IndexedDB. - Foreground suppression is conservative. The page writes a visibility record on `visibilitychange`, `pagehide`, `pageshow`, `freeze` and `resume`, and refreshes it every five seconds while visible. A push is suppressed only when that record is fresh (under fifteen seconds) and the worker also sees a focused, visible client. A backgrounded or closed app still gets notifications when iOS reports a stale `WindowClient`. - The Settings card shows the last push decision, worker version, page foreground value and client count, and refreshes while the page is visible. - The systemd unit sets `StateDirectory=mux-portal` for the state file and `ReadWritePaths=/etc/mux-portal` for the first-start config rewrite. No startup check for `monitor-bell`; the Settings card and docs state the requirement. ## Verification - `cargo test --workspace` — unit, API, tmux integration, terminal WebSocket, push, watcher, config generation, state persistence and BEL scan tests pass. - `cargo clippy --workspace --all-targets -- -D warnings` — clean. - `npm run typecheck` and `npm run build` — clean; `push-handler.js` is imported by `sw.js`. - Host checks: the watcher delivered real bells to Apple (`delivered=1`); the active-window PTY path was confirmed on the chat window with `bg3`; a direct push returned `201`, `POST /api/push/test` returned `204`; the subject change fixed the Apple `401/403`. - Deployed on the host from `c0308db`; service active with `push=true`; temporary debug logging removed; clean backup under `/var/backups/mux-portal-20261104-114939-clean-final`.
aleksei changed title from WIP: feat: add bell notifications to feat: add bell notifications 2026-11-04 10:00:31 +00:00
Author
Owner

Implementation is complete and the branch is ready for review.

Checks run:

  • cargo test --workspace — pass (unit, API, tmux bell integration, terminal WebSocket, push and watcher tests)
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • npm run typecheck and npm run build — clean; push-handler.js is copied to dist/ and imported by sw.js
  • local smoke test with a real tmux socket and VAPID key: health, login, push.enabled with a public key, bell=true after printf '\\a', bell=false after select-window, and 400 for an invalid subscription

Still worth a manual device pass: desktop Chrome, an Android PWA, and an installed iOS 16.4+ PWA (closed app, foreground switch, Send test).

Note: fj pr status 31 currently fails with unknown variant '' while parsing the Forgejo response, so CI status was not checked through fj.

Implementation is complete and the branch is ready for review. Checks run: - `cargo test --workspace` — pass (unit, API, tmux bell integration, terminal WebSocket, push and watcher tests) - `cargo clippy --workspace --all-targets -- -D warnings` — clean - `npm run typecheck` and `npm run build` — clean; `push-handler.js` is copied to `dist/` and imported by `sw.js` - local smoke test with a real tmux socket and VAPID key: health, login, `push.enabled` with a public key, `bell=true` after `printf '\\a'`, `bell=false` after `select-window`, and `400` for an invalid subscription Still worth a manual device pass: desktop Chrome, an Android PWA, and an installed iOS 16.4+ PWA (closed app, foreground switch, Send test). Note: `fj pr status 31` currently fails with `unknown variant ''` while parsing the Forgejo response, so CI status was not checked through `fj`.
Author
Owner

Updated after review: subscriptions now persist in $STATE_DIRECTORY and the VAPID key is generated on the first start and written back to config.json. A portal restart no longer requires re-registration; the client re-registers idempotently only as a safety net. The systemd unit now sets StateDirectory=mux-portal and ReadWritePaths=/etc/mux-portal. All Rust/UI checks and the restart smoke test pass.

Updated after review: subscriptions now persist in $STATE_DIRECTORY and the VAPID key is generated on the first start and written back to config.json. A portal restart no longer requires re-registration; the client re-registers idempotently only as a safety net. The systemd unit now sets StateDirectory=mux-portal and ReadWritePaths=/etc/mux-portal. All Rust/UI checks and the restart smoke test pass.
Author
Owner

Deployment follow-up: Apple Web Push rejected the VAPID sub claim mailto:mux-portal@localhost (HTTP 401/403), which is the "push service rejected the request" error. The host now uses mailto:a@kosyrev.name; a direct push to the stored Apple subscription returned 201 Created, and the server POST /api/push/test path returned 204 with the same config/state. The VAPID key and subscription were unchanged.

Also fixed in 61bc389: a missing or empty push.subject is now a startup error instead of defaulting to a localhost address. The host runs the new binary; push=true, subscription persisted, no re-registration.

Deployment follow-up: Apple Web Push rejected the VAPID `sub` claim `mailto:mux-portal@localhost` (HTTP 401/403), which is the "push service rejected the request" error. The host now uses `mailto:a@kosyrev.name`; a direct push to the stored Apple subscription returned `201 Created`, and the server `POST /api/push/test` path returned `204` with the same config/state. The VAPID key and subscription were unchanged. Also fixed in `61bc389`: a missing or empty `push.subject` is now a startup error instead of defaulting to a `localhost` address. The host runs the new binary; `push=true`, subscription persisted, no re-registration.
Author
Owner

Background delivery fix is in 63bb9c1 and deployed to the host. The page writes a foreground/visibility record with a 10 s heartbeat; the service worker suppresses only when that record says foreground and is younger than 30 s. A backgrounded or closed iOS PWA now gets notifications even when the old WindowClient state looked focused. Reload/update the PWA once so the new page and service worker are active.

Background delivery fix is in `63bb9c1` and deployed to the host. The page writes a foreground/visibility record with a 10 s heartbeat; the service worker suppresses only when that record says foreground and is younger than 30 s. A backgrounded or closed iOS PWA now gets notifications even when the old `WindowClient` state looked focused. Reload/update the PWA once so the new page and service worker are active.
Author
Owner

Deployed e935b6a with diagnostics and a more conservative background rule. The host watcher sent two real debug bells and logged delivered=1 for both, so delivery from the server to Apple works. The Settings card now shows the last push decision and worker version. Please reload the PWA, press Send test to confirm worker bg2, then background the app and ring a bell in a non-current window; report the "Last push" line and the UTC time. Debug logging is temporarily enabled as RUST_LOG=mux_portal=debug; it will be removed after diagnosis.

Deployed `e935b6a` with diagnostics and a more conservative background rule. The host watcher sent two real debug bells and logged `delivered=1` for both, so delivery from the server to Apple works. The Settings card now shows the last push decision and worker version. Please reload the PWA, press Send test to confirm worker `bg2`, then background the app and ring a bell in a non-current window; report the "Last push" line and the UTC time. Debug logging is temporarily enabled as `RUST_LOG=mux_portal=debug`; it will be removed after diagnosis.
Author
Owner

Root cause of the chat case was the tmux active window: tmux does not set window_bell_flag for the window the portal client is viewing, and repeated bells in an unread non-viewed window wait for the flag to clear. c0308db adds a BEL scan over the already-open terminal PTY, so the viewed chat reports every bell; the flag watcher remains the first-unread path for non-viewed windows. Confirmed on the host; debug logging removed.

Root cause of the chat case was the tmux active window: tmux does not set `window_bell_flag` for the window the portal client is viewing, and repeated bells in an unread non-viewed window wait for the flag to clear. `c0308db` adds a BEL scan over the already-open terminal PTY, so the viewed chat reports every bell; the flag watcher remains the first-unread path for non-viewed windows. Confirmed on the host; debug logging removed.
aleksei deleted branch feat/bell-notifications 2026-11-04 12:01:12 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zoo/mux-portal!31
No description provided.