Find a file
Jason Monk 567e9ee9a7
Fix #426: Test-methodology gap that let #417 ship (#428)
Two gates to prevent reintroduction of the malformed-JSON bug class
that shipped in #417 (Outreach error helpers used a """{...}""" template
with raw exception text, producing unparseable bodies).

(A) Harness-level JSON parse assertion. Introduces shared
`McpToolTestHarness` (in `integrations/src/test/.../testing/`) that
wraps the duplicated mockk(Server) + addTool capture pattern previously
copy-pasted across `OutreachMcpProviderTest`, `UsageMcpProviderTest`,
`NotificationMcpToolExecutionTest`, and `NotificationMcpProviderToolsTest`.
Every `callTool(...)` invocation runs the result body through
`Json.parseToJsonElement`; parse failures throw with the offending tool
name and body content. Per-call `expectJsonBody = false` opt-out for
tools whose contract is plain text (currently only one test uses it,
referencing #427 which tracks the underlying core MCP DSL gap the
harness surfaced).

Regression test `McpToolTestHarnessTest` constructs fake tools that
return non-JSON bodies and asserts the harness throws with the tool
name + body in the message, plus a passing-case to lock down the
expectJsonBody opt-out.

(B) CI grep check. New `scripts/check-no-manual-json.sh` greps
`*/src/main/*.kt` for `"""\{` and fails the build on hits unless the
line carries a `// allow-manual-json: <reason>` marker, or matches the
explicit `AuditDetailScreen.kt` allowlist (Compose preview fixtures).
Wired into `.github/workflows/android-ci.yml` next to the existing
`check-zombie-screens.sh` step. Verified manually that the script
fires on a synthetic `"""{"x":"$bar"}"""` and clears once the marker
is added.

Documents the convention in new `docs/agent-quickstart.md`.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-26 17:31:31 -04:00
.claude Refine ux-changes rule: doc updates describing shipped behavior are not UX changes (#407) 2026-04-25 17:43:19 -04:00
.github Fix #426: Test-methodology gap that let #417 ship (#428) 2026-04-26 17:31:31 -04:00
.signing Fix #205: move release keystore passwords to env/.properties file 2026-04-17 14:36:01 -04:00
api Fix #347: Client-subject notification copy + deep-link taps + Manage action (#362) 2026-04-22 03:11:08 -04:00
app Fix #419: Apply awaitReady pattern to securityAlertCheck + OutreachIntegration + DeviceRegistrationStatus (#421) 2026-04-26 14:18:17 -04:00
config/detekt Fix #353: Baseline existing detekt violations and make CI gate hard (#361) 2026-04-22 02:07:34 -04:00
core Fix #420: Complete CompletableDeferreds on all termination paths in WS/MCP/tunnel layers (#422) 2026-04-26 14:57:53 -04:00
deploy Fix systemd unit: ReadWritePaths for device CA, positional config arg 2026-04-06 13:34:40 -04:00
device-tests Fix #323: Remove personal machine identifiers from public repo (#326) 2026-04-20 12:24:01 -04:00
docs Fix #426: Test-methodology gap that let #417 ship (#428) 2026-04-26 17:31:31 -04:00
e2e Fix #394: ColdStartEndToEndTest uses cmd activity stop-app (#396) 2026-04-24 12:58:33 -04:00
gradle Fix #262: Swap in BouncyCastle JSSE for SNI emission under Robolectric (#281) 2026-04-19 11:01:39 -04:00
integrations Fix #426: Test-methodology gap that let #417 ship (#428) 2026-04-26 17:31:31 -04:00
notifications Fix #370: Unify Recent Activity rendering; audit default to 7 days; drop session-window override (#371) 2026-04-22 17:15:25 -04:00
relay Fix #423: Clear FCM-wake throttle entry when WS session registers (#424) 2026-04-26 15:54:57 -04:00
scripts Fix #426: Test-methodology gap that let #417 ship (#428) 2026-04-26 17:31:31 -04:00
work Fix #414: Await IntegrationProviderRegistry first emission before checking enabledPaths() (#416) 2026-04-26 11:38:58 -04:00
.editorconfig Add Compose screens with mock data, Roborazzi screenshot tests, and HTML dashboard 2026-04-04 16:50:39 -04:00
.gitignore Fix #205: move release keystore passwords to env/.properties file 2026-04-17 14:36:01 -04:00
BLOCKERS.md Configure mTLS client cert for relay WebSocket connection 2026-04-05 19:58:55 -04:00
build.gradle.kts Fix #353: Baseline existing detekt violations and make CI gate hard (#361) 2026-04-22 02:07:34 -04:00
gradle.properties Initial project scaffold: multi-module Android/Kotlin Gradle project 2026-04-03 19:38:30 -04:00
gradlew Initial project scaffold: multi-module Android/Kotlin Gradle project 2026-04-03 19:38:30 -04:00
gradlew.bat Initial project scaffold: multi-module Android/Kotlin Gradle project 2026-04-03 19:38:30 -04:00
last_session Merge T-1 interfaces: TunnelState, TunnelError, CertificateStore, TunnelClient (KMP) 2026-04-05 07:25:50 -04:00
LICENSE Initial commit 2026-04-03 19:35:18 -04:00
README.md Update README and security docs to match shipped behavior (#406 chunk A) (#411) 2026-04-25 18:38:12 -04:00
settings.gradle.kts Fix #250: App-wired integration test scaffold (Robolectric + real Koin + TestRelayFixture) (#258) 2026-04-18 20:14:48 -04:00

Rouse Context

Your phone has context that AI doesn't — your health data, your notifications, your app usage. Rouse Context makes that context available to AI assistants on demand, without ever syncing your data to the cloud.

It's an Android app that turns your phone into an MCP server. AI clients like Claude connect to a URL, your phone wakes up, and a direct encrypted session is established. The AI asks for what it needs, your phone responds, and then it goes back to sleep. Your data never leaves your device except through that live session.

Status: Active development. The core e2e flow works — Claude can connect, wake the phone, authorize via OAuth, and call MCP tools. Health Connect, Notifications, Outreach, and Usage Stats integrations are implemented. See docs/design/ for detailed design documents.

How It Works

AI Client ──TLS──> Relay (SNI passthrough) ──mux WebSocket (mTLS)──> Your Phone
  1. You enable an integration (e.g. Health Connect) and get a URL like https://brave-health.abc123.rousecontext.com/mcp (the integration is identified by the hostname prefix; the path is always /mcp)
  2. Add that URL to Claude, Cursor, or any MCP client
  3. When the client connects, the relay wakes your phone via FCM push
  4. Your phone connects back through a mTLS WebSocket, and the relay splices the two TLS streams together
  5. The AI client talks directly to your phone over end-to-end encrypted TLS — the relay never sees the plaintext

Sessions are ephemeral. The phone goes back to sleep when the client disconnects.

Integrations

Integration What it exposes
Health Connect Step count, heart rate, sleep, HRV, workout history
Notifications Active and historical device notifications
Outreach Send messages, make calls, toggle DND
Usage Stats App usage patterns and screen time

Each integration is independently enabled and gets its own MCP endpoint with OAuth authorization (PKCE).

Architecture

Android App

Module Purpose
:app Compose UI, Koin DI, navigation, theming
:core:tunnel Mux protocol, WebSocket client, TLS accept, CertificateStore
:core:mcp MCP session routing, HTTP server, OAuth (device code + auth code + PKCE), token management
:core:bridge Bridges tunnel mux streams to MCP sessions via TLS
:api McpIntegration interface, IntegrationStateStore
:integrations MCP providers: Health Connect, outreach (calls/SMS/DND), usage stats, notification capture
:notifications Cross-cutting notification infrastructure, audit persistence (Room)
:work Foreground service, FCM receiver, WorkManager
:core:testfixtures Shared fixtures for integration-tier tests that boot the real relay binary

Relay Server (relay/)

Rust binary on a small VPS. Handles:

  • TLS passthrough — routes AI client connections to devices via SNI, never terminates inner TLS
  • Mux WebSocket — multiplexes multiple client sessions over one device connection
  • FCM wakeup — sends push notifications to wake sleeping devices
  • ACME certs — issues per-device TLS certs via Google Trust Services DNS-01 (Cloudflare API); Let's Encrypt also supported
  • Bot protection — secret URL prefix validated before waking device, plus FCM throttle and IP rate limiting

Security

  • End-to-end encrypted — TLS terminates on your phone. The relay does SNI passthrough only.
  • No cloud sync — data is read from on-device sources and served live. Nothing stored remotely.
  • Per-device ACME certs — per-device certs via Google Trust Services (DNS-01), private key in Android Keystore (hardware-backed).
  • mTLS device auth — relay authenticates the device by client certificate before allowing connections.
  • Secret URL prefix — each device URL includes a rotatable per-integration secret (brave-health.abc123.rousecontext.com, where brave-health is {adjective}-{integrationId}). Bots that discover the device subdomain can't wake it without the secret.
  • OAuth per-client — each AI client must be authorized via on-device approval before accessing tools.
  • Audit trail — every tool invocation is logged locally with arguments, response, and duration.

Building

Android

./gradlew assembleDebug

Requires Android SDK (compileSdk 36, targetSdk 35, minSdk 24). Build requires JDK 21 (JAVA_HOME=/usr/lib/jvm/java-21-openjdk).

Coverage report

./gradlew koverHtmlReport

Aggregates line + branch coverage across every module's unit tests and the :core:tunnel:integrationTest tier (real relay subprocess). HTML lands in build/reports/kover/html/index.html. CI publishes the same report as a test-coverage artifact plus a per-module summary on each PR.

Relay

cd relay
cargo build --release

End-to-end tests

The e2e tests drive a real device over adb via a (typically LAN-local) host running adb. The adb.host system property is required and defaults to empty — the :e2e:e2eTest task fails fast if unset. Device serial is optional and only needed if multiple devices are connected to that host.

./gradlew :e2e:e2eTest \
    -Dadb.host=<your-dev-host> \
    -Dadb.serial=<your-device-serial>

The :device-tests module has a separate runner that builds an APK pointed at a locally-running relay. It also requires a LAN IP reachable from the device:

./gradlew :device-tests:test -Dlan.ip=<your-lan-ip>

Without lan.ip, the device-tests skip cleanly via JUnit assumptions.

Status

Active development. The core flow works end-to-end: Claude can connect, wake the phone, authorize via OAuth, and call MCP tools. See docs/design/ for detailed design documents.

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.