feat(plugins): notify.respond, answering webhooks and asset links for the Android app #43

Closed
gabrielvidal wants to merge 0 commits from android-push-bridge into main
pull from: android-push-bridge
Owner

Summary

The hub side of the native Android app (gabrielvidal/ai-agent-android, contract docs/PROTOCOL.md) is the new android-push plugin (ai-agent-plugins PR, branch android-push). This PR is the small, generic core part it needs: a bridge that lets a phone channel answer for its user, webhooks that can be a plugin's own API, and the asset-links file the app's Trusted Web Activity checks.

Merge order: this PR first, then the plugins PR (its manifest uses notify.respond, respond and methods, which the current hub refuses).

Key changes

  • backend/plugins/hubnotify.py — capability notify.respond (/proxy/tools/plugins/{pid}/hub/notify/…, the plugin's handler token only): GET pairing (who the installer is, the addresses their app can use and the install's webhook URLs), GET push/{id} (one recorded push or ask, whole), GET push/{id}/image (that push's own picture as bytes), POST answer, POST action, POST dismissed. Everything acts as the handler's user and only on their own pushes (notifications.routes.push_is_for: in the entry's to, or their conversation's audience); anything else is a 404.
  • backend/notifications/routes.py — the ask / action / dismissed routes share their work with the bridge (record_ask_answer, run_notify_action, dismiss_tags); their own behaviour is unchanged.
  • backend/users/deliver.py, backend/notifications/channels.py — clear(skip_channel=…) / clear_async(exclude=…): a swipe on one phone channel clears the person's other channels (Home Assistant, in parallel), not the one it came from.
  • backend/plugins/manifest.py, backend/plugins/proxyroutes.py — webhooks[].respond: "result" (the action's JSON is the HTTP body, or a _file of the plugin's shared / the installer's data dir as a download) and webhooks[].methods (GET). Written and fingerprinted only when set, so installed plugins keep their approval.
  • backend/core/routes.py — GET /.well-known/assetlinks.json, unauthenticated, every host.
  • Tests backend/test_notify_respond.py (30), backend/test_assetlinks.py (3); docs/plugins.md ("A phone app as a channel", capability table, runtime APIs) and a CLAUDE.md section.

Key decisions

  • Not an operator capability: guests install the plugin for themselves, so notify.respond must be approvable by them. It is safe because it is handler-only (a guest's run token gets 403) and scoped to the token's user.
  • "Their own pushes" is narrower than what the owner can see: the owner's phone channel can't answer a guest's ask he doesn't follow — his phone never got it.
  • First answer wins on the bridge (409 answered / expired); /api/ask/{id}/answer itself still overwrites, as before — not changed here.
  • The owner's webhook goes through the guest host. /proxy/tools/…/webhook/… is served on ai-agent.lab.gabvdl.xyz (tailnet) and ai-agent.gabvdl.xyz (internet); hub.gabvdl.xyz refuses every /proxy/ path at Traefik (ai-agent-owner-machines). The webhook token names the install, so the owner's already answers on the guest host: pairing gives hub: https://hub.gabvdl.xyz + hook: https://ai-agent.gabvdl.xyz/proxy/tools/plugins/android-push/webhook/app?token=…. No Traefik change needed, and the hook isn't behind the FR+DE geo-lock.
  • A push's picture for a phone with no session: push/{id}/image is not a proxy — only the image recorded on the person's own push, image/*, at most 5 MB. A picture on the hub itself is read through the file route it names (/api/host-file/raw, /api/artefact, /api/project-asset; /api/screenshot and /api/data-asset for the owner only) by calling that route's function as this person, so its check stays the check; a public address goes through the existing image_proxy.fetch; a lab address is never fetched.
  • APK hosting through the webhook (_file + methods: ["GET"]) rather than a new download route: the app repo is private and guests need the build too.
  • The GET webhook and the new routes are out of the OpenAPI schema: openapi.json, src/generated and matrix.golden.txt are unchanged (checked: no path added or removed; test_authz_matrix passes).

Changelog

  • Added: plugins can answer questions, tap a push's buttons and mark pushes read for the person they run as (notify.respond) — what the Android app's channel uses
  • Added: a plugin webhook can answer its action's own JSON or a file, and GET (respond, methods)
  • Added: /.well-known/assetlinks.json for the Android app (ANDROID_APP_FINGERPRINTS, ANDROID_APP_PACKAGE)

Test notes

  • Every backend/test_*.py module, one process each under a throwaway /data (bwrap): all pass except test_typed_plugins.py::TestStore::test_records_carry_kind, which fails the same way on main.
  • Live, on a local hub from this branch with the plugin installed (EVOX2, port 8141): a fake phone paired through the webhook with Host: ai-agent.gabvdl.xyz, a push and an ask sent through /api/notify and /api/ask reached a local HTTP sink as protocol JSON, op: answer resolved the ask (GET /api/ask/{id} → answered, a second answer → answered), op: dismissed moved the push to dismissed in the ledger, a guest's webhook couldn't touch the owner's ask, the APK came back byte-identical from the apk webhook, a push whose picture is a hub file came back byte-identical from the plugin's img webhook (a guest's token on it: 404), and /.well-known/assetlinks.json answered 200 on every host.
  • Not run: the frontend suites (no frontend change) and scripts/test.py itself (it needs the lab's image).
  • Deploy from the Homelab after merge (ai-agent-deploy), with two things only Gabriel can do:
    • set ANDROID_APP_FINGERPRINTS (the release — and debug — certificate SHA-256) in the service's env; until then the route is a 404 and the TWA shows its address bar;
    • ai-agent.lab.gabvdl.xyz is behind Authelia: its router needs a no-auth rule for Path(/.well-known/assetlinks.json) if the app is ever paired on the tailnet address (the public hub.gabvdl.xyz and the guest host need nothing).

🤖 Generated with Claude Code

## Summary The hub side of the native Android app (`gabrielvidal/ai-agent-android`, contract `docs/PROTOCOL.md`) is the new `android-push` plugin (ai-agent-plugins PR, branch `android-push`). This PR is the small, generic core part it needs: a bridge that lets a phone channel answer for its user, webhooks that can be a plugin's own API, and the asset-links file the app's Trusted Web Activity checks. **Merge order: this PR first, then the plugins PR** (its manifest uses `notify.respond`, `respond` and `methods`, which the current hub refuses). ## Key changes - `backend/plugins/hubnotify.py` — capability **`notify.respond`** (`/proxy/tools/plugins/{pid}/hub/notify/…`, the plugin's handler token only): `GET pairing` (who the installer is, the addresses their app can use and the install's webhook URLs), `GET push/{id}` (one recorded push or ask, whole), `GET push/{id}/image` (that push's own picture as bytes), `POST answer`, `POST action`, `POST dismissed`. Everything acts as the handler's user and only on their own pushes (`notifications.routes.push_is_for`: in the entry's `to`, or their conversation's audience); anything else is a 404. - `backend/notifications/routes.py` — the ask / action / dismissed routes share their work with the bridge (`record_ask_answer`, `run_notify_action`, `dismiss_tags`); their own behaviour is unchanged. - `backend/users/deliver.py`, `backend/notifications/channels.py` — `clear(skip_channel=…)` / `clear_async(exclude=…)`: a swipe on one phone channel clears the person's other channels (Home Assistant, in parallel), not the one it came from. - `backend/plugins/manifest.py`, `backend/plugins/proxyroutes.py` — `webhooks[].respond: "result"` (the action's JSON is the HTTP body, or a `_file` of the plugin's shared / the installer's data dir as a download) and `webhooks[].methods` (`GET`). Written and fingerprinted only when set, so installed plugins keep their approval. - `backend/core/routes.py` — `GET /.well-known/assetlinks.json`, unauthenticated, every host. - Tests `backend/test_notify_respond.py` (30), `backend/test_assetlinks.py` (3); `docs/plugins.md` ("A phone app as a channel", capability table, runtime APIs) and a CLAUDE.md section. ## Key decisions - **Not an operator capability**: guests install the plugin for themselves, so `notify.respond` must be approvable by them. It is safe because it is handler-only (a guest's run token gets 403) and scoped to the token's user. - **"Their own pushes" is narrower than what the owner can see**: the owner's phone channel can't answer a guest's ask he doesn't follow — his phone never got it. - **First answer wins on the bridge** (409 `answered` / `expired`); `/api/ask/{id}/answer` itself still overwrites, as before — not changed here. - **The owner's webhook goes through the guest host.** `/proxy/tools/…/webhook/…` is served on `ai-agent.lab.gabvdl.xyz` (tailnet) and `ai-agent.gabvdl.xyz` (internet); `hub.gabvdl.xyz` refuses every `/proxy/` path at Traefik (`ai-agent-owner-machines`). The webhook token names the install, so the owner's already answers on the guest host: `pairing` gives `hub: https://hub.gabvdl.xyz` + `hook: https://ai-agent.gabvdl.xyz/proxy/tools/plugins/android-push/webhook/app?token=…`. No Traefik change needed, and the hook isn't behind the FR+DE geo-lock. - **A push's picture for a phone with no session**: `push/{id}/image` is not a proxy — only the image recorded on the person's own push, `image/*`, at most 5 MB. A picture on the hub itself is read through the file route it names (`/api/host-file/raw`, `/api/artefact`, `/api/project-asset`; `/api/screenshot` and `/api/data-asset` for the owner only) by calling that route's function as this person, so its check stays the check; a public address goes through the existing `image_proxy.fetch`; a lab address is never fetched. - **APK hosting through the webhook** (`_file` + `methods: ["GET"]`) rather than a new download route: the app repo is private and guests need the build too. - The GET webhook and the new routes are out of the OpenAPI schema: `openapi.json`, `src/generated` and `matrix.golden.txt` are unchanged (checked: no path added or removed; `test_authz_matrix` passes). ## Changelog - Added: plugins can answer questions, tap a push's buttons and mark pushes read for the person they run as (`notify.respond`) — what the Android app's channel uses - Added: a plugin webhook can answer its action's own JSON or a file, and GET (`respond`, `methods`) - Added: `/.well-known/assetlinks.json` for the Android app (`ANDROID_APP_FINGERPRINTS`, `ANDROID_APP_PACKAGE`) ## Test notes - Every `backend/test_*.py` module, one process each under a throwaway `/data` (bwrap): all pass except `test_typed_plugins.py::TestStore::test_records_carry_kind`, which fails the same way on main. - Live, on a local hub from this branch with the plugin installed (EVOX2, port 8141): a fake phone paired through the webhook with `Host: ai-agent.gabvdl.xyz`, a push and an ask sent through `/api/notify` and `/api/ask` reached a local HTTP sink as protocol JSON, `op: answer` resolved the ask (`GET /api/ask/{id}` → answered, a second answer → `answered`), `op: dismissed` moved the push to dismissed in the ledger, a guest's webhook couldn't touch the owner's ask, the APK came back byte-identical from the `apk` webhook, a push whose picture is a hub file came back byte-identical from the plugin's `img` webhook (a guest's token on it: 404), and `/.well-known/assetlinks.json` answered 200 on every host. - Not run: the frontend suites (no frontend change) and `scripts/test.py` itself (it needs the lab's image). - **Deploy from the Homelab** after merge (`ai-agent-deploy`), with two things only Gabriel can do: - set `ANDROID_APP_FINGERPRINTS` (the release — and debug — certificate SHA-256) in the service's env; until then the route is a 404 and the TWA shows its address bar; - `ai-agent.lab.gabvdl.xyz` is behind Authelia: its router needs a no-auth rule for `Path(/.well-known/assetlinks.json)` if the app is ever paired on the tailnet address (the public `hub.gabvdl.xyz` and the guest host need nothing). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gabrielvidal self-assigned this 2026-11-28 20:14:13 +01:00
gabrielvidal added 3 commits 2026-11-28 20:14:13 +01:00
Unauthenticated, on every host: package xyz.gabvdl.aiagent (ANDROID_APP_PACKAGE)
and the signing certificates' SHA-256 from ANDROID_APP_FINGERPRINTS; nothing
configured answers 404.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- notify.respond (plugins/hubnotify.py, handler token only, any user may
  approve it): pairing addresses, read one push back, answer an ask, run a
  push's button, mark pushes dismissed — as the handler's user, for their own
  pushes only; an ask no longer pending answers 409, a swipe clears the
  person's other channels but the one it came from.
- webhooks[].respond: "result" answers the action's own JSON (or a file of
  the plugin's shared / data dir); webhooks[].methods lets one answer GET.
- The ask / action / dismissed routes share their work with the bridge.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gabrielvidal added 1 commit 2026-11-28 20:19:17 +01:00
GET …/hub/notify/push/{id}/image: the image recorded on the handler's user's
own push, as bytes (image/* only, at most 5 MB). A picture on the hub itself is
read through the file route it names with that route's own check; a public one
through image_proxy.fetch; a lab address is never fetched.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
Owner
Merged into `main` as 293a6a5d by the auto-ship batch https://ai-agent.lab.gabvdl.xyz/conversation/e16d945b-9f58-4a6c-9747-71e0d81d3bd4.
gabrielvidal closed this pull request 2026-11-29 15:23:53 +01:00

Pull request closed

Please reopen this pull request to perform a merge.
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gabrielvidal/ai-agent#43