Commit graph

32 commits

Author SHA1 Message Date
Jason Monk
d2595ed091
Fix #406 final wave: ui.md drift fixes + relay.md endpoint pointer (#413)
ui.md (chunk C) — replace fictional CertStatus interface with real
OnboardingState (only two steps: Registering, ProvisioningCerts), drop
the "Connection Confirmed" screen and "Integration Settings
(integration-owned)" wireframe (neither exist in code), update the
Integration Enabled URL example to the per-integration-hostname format
(https://<integration-secret>.<subdomain>.rousecontext.com/mcp), redraw
the navigation flow to show the post-#389/#392 path
(Welcome → NotificationPreferences → onboarding?autostart=true → Home),
rename DeviceCodeApprovalViewModel to AuthorizationApprovalViewModel
and add rows for OnboardingViewModel, NotificationPreferencesViewModel,
and the four per-integration setup VMs, expand the screen catalog with
the missing screens (NotificationSetup/OutreachSetup/UsageSetup,
AllClients, AuditDetail). Add a top-of-doc note explaining the
Screen / Content / Destination split so readers know production
renders *Content via *Destination, with *Screen reserved for previews
and screenshot tests.

relay.md (chunk B) — fix mux frame numbering (DATA=0x00, OPEN=0x01,
CLOSE=0x02, ERROR=0x03) and add PING=0x04 / PONG=0x05 with the 8-byte
nonce on stream id 0; replace the wrong single-round /register and
single-body /renew Path A snippets with a high-level endpoint table
that defers to docs/design/relay-api.md for the canonical request /
response shapes; drop /wake/:subdomain (no such endpoint — FCM wakeup
is internal to passthrough on cache miss).

Refs #406. android-app.md "Still needs design" section reviewed; the
sole remaining item (third-party provider discovery) is genuinely
undesigned and a non-v1 future feature, so it stays.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-25 18:49:10 -04:00
Jason Monk
2482559e00
Update tunnel-client + health-connect-expansion docs; delete superseded proposal docs (#406) (#412)
Apply audit findings from #406:

- docs/design/tunnel-client.md (chunk B, 7 findings): drop the KMP
  framing (module is JVM-only); update TunnelClient to current
  surface (connect(url), sendFcmToken, healthCheck); replace
  TunnelError taxonomy with the actual sealed Exception subclasses;
  rewrite MuxStream block (id: UInt, incoming: Flow<ByteArray>, send,
  close); move reconnect ownership description to :work; rewrite
  onboarding section as 3-hop flow with cert provisioning chained in
  (#389); refresh CertificateStore section to cover per-integration
  secrets, fingerprint bootstrap markers, and the deprecated PEM-key
  hooks (#200).

- docs/design/health-connect-expansion.md (chunk C, 4 findings): flip
  status to Implemented; replace the 12-entry record-type snippet
  with a category table summarizing the shipped registry; rename
  cycle category to reproductive and add mindfulness; update module
  path from :health to :integrations and describe the
  category-grouped query files (ActivityQueries.kt etc.) that
  shipped instead of per-type RecordTypeHandlers.

- docs/design/per-integration-hostnames.md: deleted. Status was
  proposed but the feature shipped with a different schema; the
  shipped behavior is now in docs/design/relay-api.md and
  docs/design/overall.md (post-#409, #410 rewrites).

- docs/design/secret-prefix-bot-rejection.md: deleted. Superseded by
  the per-integration-hostnames work which generalized it; same
  shipped behavior is covered by relay-api.md + overall.md.

- docs/design/overall.md: redirect the surviving inbound link from
  secret-prefix-bot-rejection.md to relay-api.md.

- docs/audit.md: collapse the per-integration-hostnames + secret-prefix
  entries to "deleted (superseded)" and update the punch list.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-25 18:13:09 -04:00
Jason Monk
ddddcc39eb
Update docs/design/overall.md to match shipped system (#406 chunk D) (#409)
Doc maintenance only — no code change. Removes the 363-line embedded
test-case inventory that had drifted off the implementation, and fixes
the prose drift items called out in the chunk D audit on #406:

- Onboarding flow rewritten as the post-#389 three-hop sequence:
  /request-subdomain -> /register -> /register/certs (CSR generated
  after subdomain assignment so its SAN matches), citing
  OnboardingFlow.execute() and docs/ux-decisions.md (2026-04-24).
- Firestore data model gains the three load-bearing fields on
  devices/ (secret_prefix legacy, valid_secrets, integration_secrets)
  and the subdomain_reservations/ collection.
- Auth-method table adds the /register/certs row and corrects the
  /renew rows to show that both paths are body-driven and signature
  is over CSR DER (not firebase_token).
- Ghost "Wake pre-flight" subsection removed — /wake is not a public
  endpoint; FCM wake is internal to passthrough on SNI-cache miss.
- Subdomain Format reframed around the post-#92 single-word pool with
  adjective-noun as overflow.
- Module Structure replaces the stale KMP framing (no commonMain ships)
  with the actual 11-module layout from settings.gradle.kts.
- Integration Model and OAuth/MCP examples reframed around per-
  integration hostnames as the routing key, with /.well-known/...,
  /device/authorize, /token, /mcp at the root of each per-integration
  host (not URL path segments).
- FCM payload format adds the type:"renew" example used by the
  maintenance loop's expiry nudge.
- Test inventory replaced with a one-paragraph pointer to the test
  source roots in each module — per-feature coverage notes belong
  with the feature, not in this design doc.

Refs #406.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-25 17:54:12 -04:00
Jason Monk
40a5ebd4b0
Rewrite docs/design/android-app.md to match shipped behavior (#408)
The doc had drifted materially from the codebase (chunk C of #406 audit).
Module map listed a non-existent :health module and missed :core:bridge
and :core:testfixtures; the McpIntegration interface sketch invented a
registerNavigation() that has never shipped; the route table didn't
match Routes.kt; and the onboarding sequence predated the #389/#392
chained cert-provisioning flow.

Restructured around an architecture overview, a single source-of-truth
module table (verified against each build.gradle.kts), the actual
McpIntegration interface from api/, the canonical Routes catalog with
the autostart re-entry trick from #392, and the three-hop onboarding
sequence (request-subdomain → register → register/certs).

Refs #406.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-25 17:43:22 -04:00
Jason Monk
0b5e755c22
Fix #406 (chunk B, relay-api.md): rewrite to match shipped relay API (#410)
The relay-api.md document had drifted significantly from the implementation.
This rewrite addresses every chunk B finding for relay-api.md (#406):

* Removed the fictitious POST /wake/:subdomain endpoint section (item 1).
  Wake-up is internal to the passthrough resolver; documented as the
  "Internal FCM wakeup" subsection pointing at resolve_device_stream.
* Rewrote /register as the two-round flow it actually is (item 2): round 1
  assigns subdomain + per-integration secrets; round 2 takes the CSR.
* Added the missing /register/certs section (item 3) including the
  proof-of-possession signature semantics (#201).
* Added the missing /request-subdomain section (item 4) including the
  per-UID rate limiter, idempotent-retry behaviour, and pool tiers.
* Added the missing /rotate-secret section (item 5): mTLS-only,
  replace-by-request-set semantics, empty-list legitimacy (#202, #285).
* Added an "Admin / Test-Mode Endpoints" appendix (item 6) listing
  /test/kill-ws, /test/fcm-wake, /test/open-stream,
  /test/emit-stream-error, /test/wait-session-registered, /test/stats,
  with the test-mode feature + loopback-only guarantees.
* Split signature semantics by endpoint (item 7): /register
  re-registration signs the firebase_token bytes; /register/certs PoP
  and /renew sign the CSR DER bytes. Added a dedicated table.
* Renumbered the mux frame types (item 8): DATA=0x00, OPEN=0x01,
  CLOSE=0x02, ERROR=0x03, plus PING=0x04 and PONG=0x05 with their
  u64-BE nonce payload semantics (#179).
* Replaced the ERROR code table (item 9) with the actual codes
  STREAM_REFUSED=1, STREAM_RESET=2, PROTOCOL_ERROR=3, INTERNAL_ERROR=4
  encoded as u32 BE (4 bytes), not u8.
* Expanded the devices/{subdomain} schema (item 10) with secret_prefix
  (deprecated), valid_secrets, and integration_secrets.
* Added the subdomain_reservations/{subdomain} collection (item 11).
* Swept ACME rate-limit text (item 12) so GTS is the primary CA in
  prose, not just in passing references.

Also restructured the endpoint catalog into a summary table at the top
plus a per-endpoint section, since the previous numbering scheme
fought the new contents.

Documentation only; no code changes.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-25 17:26:38 -04:00
Jason Monk
a97caf0941
Fix #391: Update design docs to reflect GTS as primary CA (#398)
Production rousecontext.com has been on Google Trust Services since #213
(relay default when no [acme] section is configured). The three design
docs still described Let's Encrypt as primary and cited LE-specific
limits (50/registered-domain/week, ISRG roots). This updates:

- docs/design/relay.md: CA Selection now names GTS with the
  dv.acme-v02.api.pki.goog directory and the EAB requirement; CAA
  example flipped to pki.goog; rate-limit section now covers both
  CAs; mTLS trust anchors corrected (relay's own private device CA
  loaded from tls.ca_cert_path, not public CA roots embedded in
  the binary — this was wrong on two counts).
- docs/design/overall.md: Primary CA header flipped to GTS, with
  LE framed as a supported option for self-hosters; CAA example
  updated.
- docs/design/relay-api.md: mTLS auth description, server_cert
  field description, and rate-limit tables no longer claim LE.
- docs/self-hosting.md: troubleshooting note about quotas broadened
  to cover both CAs (kept the LE example intact per the issue).

Docs-only; no code or config change.

Co-authored-by: Claude Opus 4 (1M context) <noreply@anthropic.com>
2026-04-24 22:41:23 -04:00
Jason Monk
4c442a8f48 Fix #170: align /renew request/response shapes between client and relay
The Android RelayApiClient and the relay's POST /renew endpoint had drifted
apart on both request and response shapes: the client was sending
{ csrPem, authMethod, currentCertPem } while the relay required
{ csr, subdomain, firebase_token, signature }, and the client expected
{ certificatePem } in the response while the relay returned
{ server_cert, client_cert, relay_ca_cert }. Neither side had integration
coverage on the renew path, so /renew returned 422 unconditionally in
production and cert renewal was quietly broken until devices approached
expiry.

This change keeps the relay's response shape (it already matched
/register/certs) and aligns the client to the relay side, plus a small
relay-side simplification so both auth paths are body-driven:

Request (both paths):
  { csr, subdomain, signature, firebase_token? }

Path A ("mTLS-equivalent", cert still valid): omit firebase_token.
Path B (cert expired): include firebase_token.
The relay verifies the signature against the public key it registered
earlier, and additionally verifies firebase_token (+ UID match) on Path B.

Response (matches /register/certs):
  { server_cert, client_cert, relay_ca_cert }

Wire-contract tests pin both sides:
- relay/tests/api_renew_test.rs gains a Path A signature-only success case
  and a bad-signature-on-Path-A case; pre-existing tests were adjusted
  for the new "signature always required" rule.
- core/tunnel CertRenewalTest gains serializer tests that assert the
  snake_case field names on both the request and the response, so a
  future rename on either side fails loudly here first.

CertRenewalFlow now routes the signature through a CsrSigner (parallel to
the existing FirebaseRenewalCredentialsProvider) so both paths sign over
the freshly-generated CSR DER rather than accepting a pre-computed value,
and stores all three cert bundle fields (mirroring CertProvisioningFlow).
RenewalAuthProvider in :work gains a signCsr hook to match.

docs/design/relay-api.md is updated to the new shape; the old stale
"Path A uses TLS client cert" language no longer reflects reality and
would have slowly misled future work.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 19:41:25 -04:00
Jason Monk
d9bf8c4ab7 Fix #79: Remove stale NotificationModel references from docs
Follow-up to #78 cleanup. The code for NotificationModel was deleted
but implementation-specific references remained in other docs:

- docs/design/overall.md: rename section heading from
  "NotificationModel + audit" to "notification behavior + audit"
- docs/test-coverage-audit.md: drop NotificationModelTest row and
  update file count from 7 to 6
- docs/notifications/index.html: remove "/ NotificationModel.kt"
  from source references (hand-written HTML, not generated)

Historical planning references in docs/workflow.md describing the
original T-7 plan are left intact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 13:02:21 -04:00
Jason Monk
5caae171ea Fix #78: Remove unused NotificationSettings, NotificationModel, and NotificationModelTest
The notifications-package NotificationModel state machine was never wired into
production code — only its own unit test referenced it. Its companion
NotificationSettings data class is exclusively used by NotificationModel (the
real per-user notification settings live in :api as a separate type). Delete
all three files.

Also prune design-doc claims in android-app.md that described the deleted
state machine as the implementation; leave high-level notification architecture
intact.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:59:49 -04:00
Jason Monk
5bd58cb678 Add design doc for per-integration hostnames
Each integration gets its own hostname with the format
{adjective}-{integration}.{subdomain}.rousecontext.com/mcp
so Claude can't confuse integrations that share a host.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 17:23:24 -04:00
Jason Monk
b9f4403e56 Update README and add secret prefix bot rejection design doc
Rewrite README to lead with the project vision and current status.
Add design doc for secret URL prefix scheme that prevents bots from
waking devices without knowing a rotatable secret.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-08 10:59:23 -04:00
Jason Monk
4d03fc34f6 Add design specs for new integrations and overnight execution plan
New integration designs:
- Notifications: active + Room-backed history, actions, search
- Outreach: launch apps, links, clipboard, notifications, optional DND
- Usage: UsageStatsManager queries for app usage patterns
- Health Connect: generic query interface replacing hardcoded tools

Also: launcher icon (adaptive vector, navy bg + amber sun foreground),
updated backlog (28 items), overnight execution plan.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-06 17:03:37 -04:00
Jason Monk
c1eccc116e Remove relay_host/relay_port from FCM payloads, add FCM base URL override
Device now gets its relay URL from BuildConfig at compile time, so
FCM payloads no longer need to carry relay_host or relay_port. Updated
all design docs to reflect the simplified payloads.

Added RealFcmClient to relay/src/fcm.rs with a configurable base_url
so the device test framework can point the relay at a fake FCM server
via the FCM_BASE_URL env var.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-05 15:46:05 -04:00
Jason Monk
91d81e8373 Add security monitoring design: self-cert verification, CT log monitoring, CAA records
Two complementary mechanisms for user-verifiable trust:
- Self-cert verification: app connects to its own subdomain and checks the
  TLS leaf cert fingerprint against what it provisioned (handles renewal
  window with dual-fingerprint acceptance)
- CT log monitoring via crt.sh: detects any cert issued for the subdomain
  that the app didn't issue, defeating targeted MITM attacks
- CAA record requirement documented for production DNS zone
- Trust status UI component for Settings screen (verified/warning/alert)
- 9 new test scenarios (45-53) covering both monitoring mechanisms

Changes across 4 design docs:
- overall.md: new Security Monitoring section + test scenarios, renumbered
  all subsequent scenarios (old 45-265 → 54-274)
- tunnel-client.md: CertificateStore additions, implementation details for
  both self-check and CT monitoring, WorkManager scheduling
- android-app.md: trust status UI spec, alert behavior, new preferences
- relay.md: CAA record configuration for rousecontext.com DNS zone

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 19:41:45 -04:00
Jason Monk
6a52536271 Add comprehensive relay API specification
778-line API reference covering:
- All 5 REST endpoints with full JSON schemas, auth requirements,
  error responses, rate limiting, and examples
- Mux WebSocket binary framing protocol: exact byte layout, message
  types (DATA/OPEN/CLOSE/ERROR), stream lifecycle, edge cases
- FCM message formats (wake + renew)
- Common error envelope with error code table
- Firestore document schemas with indexes
- Signature verification algorithm
- Rate limiting summary

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:34:38 -04:00
Jason Monk
232f1e4f0d Add missing relay test scenarios, fix numbering to 265 total
Added 25 relay-specific tests that were missing from coverage review:
- Subdomain generation (63-66): two-word format, DNS-safe, collision retry
- Graceful shutdown (67-71): SIGTERM drain, CLOSE all streams, stats logged
- /status endpoint (72-76): correct counts for all metrics
- Daily maintenance job (77-83): cert nudge with dedup, pending queue, reclamation
- Config loading (84-87): TOML parsing, env vars, missing config errors

Renumbered all scenarios sequentially 1-265 with no gaps or duplicates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:21:28 -04:00
Jason Monk
0f792bd171 Add UI test scenarios: navigation flows, screen states, integration manage
240 total test scenarios (was 189). New UI coverage:
- Navigation flows (15): first launch, first/second integration setup,
  re-enable, pending/active taps, device code from notification,
  audit deep-link, subdomain rotation
- Bottom nav (3): tab switching, state preservation
- Dashboard states (12): all CertStatus variants, empty/populated,
  connection status, recent activity
- Add picker (4): Available/Disabled/Unavailable rendering
- Integration manage (6): Active/Pending variants, revoke, disable,
  settings navigation
- Settings (5): idle timeout, battery, notifications, rotation
- Audit history (6): rendering, filters, deep-link, clear, empty

All UI tests designed as Compose host-side JVM tests with fake ViewModels.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:12:11 -04:00
Jason Monk
cf0a98429d Move authorized clients into per-integration manage screen
- Removed global Authorized Clients screen and bottom nav tab
- Bottom nav is now 3 tabs: Home, Audit, Settings
- New Integration Manage screen (app-owned, /integration/{id}/manage):
  URL, recent activity, authorized clients, disable, settings link
- Integration Settings screen (integration-owned) reached via Settings
  button on Manage screen
- Dashboard taps Active/Pending → Integration Manage
- Updated navigation flow, ViewModel table, wireframes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 16:11:23 -04:00
Jason Monk
cc329064e9 Fix duplicate test numbering and missing AuditListener Koin binding
- Renumbered test scenarios 103-189 (was 99-185 with duplicates at 99-102)
- 189 total test scenarios, sequential with no gaps or duplicates
- Added missing AuditListener Koin binding (RoomAuditListener) in app doc

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:55:57 -04:00
Jason Monk
a357ade13b Fix consistency issues from per-integration auth changes
- Renumbered duplicate test IDs (69-70 appeared twice)
- Updated mcp-core OAuth test paths to use integration prefixes
  (/health/device/authorize, /health/token, etc.)
- Added test for cross-integration token rejection (91)
- Rewrote tests 168-173: removed stale isEnabled() references,
  now test IntegrationStateStore + ProviderRegistry + permission banners
- Fixed stale OnboardingFlow references in ui.md → onboardingRoute
- Authorized Clients screen now grouped by integration with per-integration
  revoke (matches per-integration TokenStore API)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:52:14 -04:00
Jason Monk
f4f501caf5 Per-integration auth, IntegrationStateStore, and gap analysis fixes
Major changes from final gap analysis:
- OAuth is now per-integration: each path has its own OAuth endpoints,
  device codes, and tokens. /health token can't access /notifications.
- TokenStore scoped by integrationId (validateToken, createToken, etc.)
- IntegrationStateStore: user-toggled enable/disable decoupled from
  platform permission checks. Backed by Preferences DataStore.
- NotificationSettingsProvider interface replaces static NotificationSettings
  in NotificationModel — settings changes take effect immediately
- DeviceInfo subdomain injected as StateFlow<String?> via Koin
- McpIntegration interface: added description field, removed isEnabled()
  (enabled state managed by IntegrationStateStore)
- Integration dashboard states derived: Available/Disabled/Pending/Active
  from IntegrationStateStore + TokenStore.hasTokens()
- CertStatus expanded with Onboarding sub-states (GENERATING_KEYS,
  REGISTERING, ISSUING_CERT)
- Device code approval shows integration name ("wants to access Health Connect")
- OAuth metadata per-integration (issuer = subdomain + path)
- Koin graph updated with new bindings

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:36:54 -04:00
Jason Monk
bac3d10647 Refactor integration UI: own screens via Nav3 route registration
McpIntegration no longer injects Composables (OnboardingFlow, SettingsContent).
Instead, integrations register their own routes via registerNavigation() with
an app-provided prefix for uniqueness. Each integration owns its screens
entirely — the app just navigates to integration/{id}/setup or
integration/{id}/settings.

Updated Nav3 route table, Health Connect integration description, and UI
wireframes to reflect integration-owned detail/settings screens.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 15:12:23 -04:00
Jason Monk
86b873d31f Update UI design: integration detail screen, device code navigation rules
- Added Integration Detail screen (Active integrations: URL, recent
  activity, settings, disable button)
- Clarified device code navigation: auto-navigate ONLY from Integration
  Enabled screen, all other contexts use notification
- Multiple simultaneous auth requests: each posts notification, first-come
  first-served approval
- Pending integration tap: routes to Setting Up or Integration Enabled
  depending on cert state
- Added IntegrationDetailViewModel to ViewModel table

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 14:58:08 -04:00
Jason Monk
762b24dd6d Add UI design doc: wireframes, navigation flow, ViewModels, integration states
Complete UI specification:
- 12 screens with ASCII wireframes (Welcome, Dashboard, Add Picker,
  Integration Setup flow (4 screens), Device Code Approval, Connection
  Confirmed, Audit History, Authorized Clients, Settings)
- Integration states: Available, Disabled, Pending, Active with transitions
- Cert status banners: None, Valid, Renewing, Expired, RateLimited
- Navigation flow map with all transitions
- ViewModel table with observables and key state
- Testing strategy: ViewModel unit tests, screenshot/preview tests,
  integration setup flow tests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 14:44:24 -04:00
Jason Monk
4d1aacfde4 Add app module test scenarios: notifications, work, health, app wiring
185 total test scenarios (was 137). New coverage:
- :notifications (15): NotificationModel state machine, all setting
  combinations, audit persistence/queries/retention
- :work (15): foreground service lifecycle, wakelock per TunnelState,
  idle timeout behavior, WorkManager cert renewal, FCM dispatch
- :api + :health (6): McpIntegration contract, availability/enabled
  checks, permission revocation, onboarding flow completion/cancel
- :app (12): navigation, integration enable/disable → ProviderRegistry,
  device code approval/denial, client revocation, subdomain rotation,
  battery optimization UX, notification permission gating

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 14:05:40 -04:00
Jason Monk
f6c6e12167 Rewrite app design doc with full module architecture
Complete restructure into focused modules:
- :core:tunnel, :core:mcp — KMP protocol layers
- :api — McpIntegration contract (onboarding UI, settings UI, MCP binding)
- :health — Health Connect implementation of :api
- :notifications — NotificationModel state machine, audit persistence, channels
- :work — foreground service, WorkManager, FCM receiver, wakelock management
- :app — Compose shell, Koin graph, navigation, provider registration

Includes: dependency graph, Koin wiring, Compose navigation routes,
McpIntegration interface, integration state machine, settings schema.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 13:43:03 -04:00
Jason Monk
337771cb20 Add comprehensive test scenarios for mcp-core, tunnel, and cross-module
137 test scenarios total (was 60). New coverage:
- Cross-module: tunnel→mcp-core full stack, tunnel↔relay mux protocol,
  cert flow through app→CertificateStore→tunnel→relay
- mcp-core: Streamable HTTP, MCP tool/resource calls, OAuth device code
  flow, auth middleware, ProviderRegistry dynamic behavior, per-stream
  HTTP server lifecycle
- Tunnel: mux frame parser/outbound, TLS server accept, CertificateStore
  integration, state machine transitions, FCM dispatch, cert renewal
  execution, onboarding execution
- App scenarios deferred pending architecture discussion

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 13:27:19 -04:00
Jason Monk
505184326b Fix McpSession wiring in app doc to match ProviderRegistry design
App doc showed creating a new McpSession per stream with a static list.
Updated to match overall.md: McpSession is a shared singleton taking
ProviderRegistry and TokenStore, with run() called per stream.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 13:19:42 -04:00
Jason Monk
ac7955cee9 Resolve third design review: McpSession interface, stream IDs, rate limits
Pass 3 findings (8 items):
- McpSession reworked: takes ProviderRegistry (live, dynamic) and TokenStore
  interfaces instead of static provider list. No reconstruction on config change.
- Mux stream IDs: u32 per-connection (routing only), tunnel generates UUID
  per stream for audit trail (MuxStream.sessionId)
- /wake rate limited: 6/min per subdomain, prevents battery-drain DoS
- Cert renewal threshold aligned to 14 days (was 30 in tunnel doc)
- OAuth metadata: full RFC 8414 response specified
- Post-renewal cert validation: device verifies CN/SAN matches subdomain
- /register always runs ACME (relay never has private key, can't reuse certs)
- 60 integration test scenarios (was 57)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 13:17:47 -04:00
Jason Monk
4c6c31dc00 Resolve second design review: TLS layers, HTTP protocol, routing, deployment
Addresses 8 gaps from second review pass:
- mcp-core HTTP server: Streamable HTTP (MCP spec) over Ktor, per-stream
  instances, auth middleware checks Bearer on non-OAuth routes
- Inner TLS: tunnel terminates using device cert via CertificateStore
  interface (defined in tunnel, implemented by app)
- Port 443 SNI routing: relay.rousecontext.com → terminate TLS + serve
  HTTP (REST + WebSocket); *.rousecontext.com → passthrough
- Relay TLS: optional client cert at TLS level, enforced per-route
  (/ws requires cert, /register doesn't, /renew accepts either)
- Relay cert: manually provisioned via certbot, deployed from GitHub
  Secrets (VPS is stateless)
- Daily maintenance job: cert expiry nudge (7-day, with renewal_nudge_sent
  tracking), pending cert queue, subdomain reclamation
- FCM types: "wake" (high priority) and "renew" (normal priority)
- 57 integration test scenarios (was 52)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:58:28 -04:00
Jason Monk
851e4dee58 Resolve design review gaps: auth details, rate limits, notifications, rotation
Addresses findings from thorough design review across all docs:
- Crypto: ECDSA P-256, SHA256withECDSA, Base64 DER for keys/signatures
- OAuth: device code TTL 10min, polling 5s, opaque tokens (no expiry)
- Cert renewal: two-stage (14 days proactive, 7 days relay-pushed warning)
- Expired certs rejected for mux — must renew via /renew endpoint first
- ACME: Let's Encrypt primary (50/week), rate limit handling with pending
  queue, admin alerts, and device notification
- Subdomain rotation: once per 30 days, old invalidated, tokens revoked
- Max 8 concurrent streams per device (configurable)
- TunnelClient interface: added errors SharedFlow, TunnelError sealed class,
  unified TunnelState enum with ACTIVE state
- FCM payload format specified (data-only, type/relay_host/relay_port)
- Disabled integration returns 404 + app notification
- 52 integration test scenarios covering all flows
- Cross-references between docs for mux wire format

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 12:04:00 -04:00
Jason Monk
015430e85c Add comprehensive design docs for all system components
Four design documents covering the full architecture:
- overall.md: end-to-end flows, identity model, Firestore schema, integration
  model (per-provider URLs), OAuth device code auth, 38 integration test
  scenarios, KMP module structure, subdomain format (two-word memorable)
- relay.md: Rust relay internals — mux framing protocol, SNI parsing, API
  endpoints (/register, /renew, /wake), ACME via ZeroSSL/Cloudflare,
  FCM REST integration, config/shutdown/monitoring
- tunnel-client.md: KMP tunnel module — mux WebSocket client, stream demux,
  FCM receiver, Keystore/CSR/cert management, TunnelClient interface
- android-app.md: Compose UI, integration management, device code auth UI,
  testable notification model, wakelock/battery strategy, audit logging,
  onboarding flow with notification permission gating

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 11:34:59 -04:00