Files
faceclaw/app/app.ts
T
Chris LeeandClaude Opus 5 22c851a6b9 Health: on-device store, derivations and a glasses glance for ring data
The companion half of the ring protocol, offered less as finished UI than as
an executable answer to "what does this ring data actually mean" -- the part
that took two sessions to work out and that a future contributor would
otherwise have to redo.

- app/health/: wire->domain conversion, an append-only on-device store with
  deduping ingest, rollups, a per-day step-bucket ledger, sleep stage mapping
  (0=wake 1=REM 2=light 3=deep, verified against 34 real nights), and chart
  derivations.
- app/apps/health/: a glasses glance page over that store.
- tools/health-preview.cjs: renders the real chart code headlessly, so layout
  can be checked without an emulator.
- 26 new tests, all passing.

Three clock frames meet in this data and mixing them up causes real bugs, so
they are documented at each site. The ring's clock is deliberately set to
now + 4h (matching what a real Even write carries), so every timestamp it
reports is in that shifted frame and must be corrected on read. Sleep is the
exception: it needs -8h, twice the correction, confirmed against a known
night. Why the ring wants these quantities is unexplained -- the code says so
rather than inventing a tidy mechanism, because the tidy story was tried and
measurement falsified it.

Collection runs on a wall-clock-aligned tick at :01 and :31. Aligned because
the ring's step buckets close on 10-minute boundaries, and because an elapsed
timer drifts off the boundary it is meant to track; offset by a minute because
firing exactly on the boundary risks catching a bucket before it is finalised.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-17 20:14:09 -07:00

47 lines
2.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
In NativeScript, the app.ts file is the entry point to your application.
You can use this file to perform app-level initialization, but the primary
purpose of the file is to pass control to the app’s first module.
*/
import { Application } from '@nativescript/core'
import { registerShareIntentHandler } from './native/share-intents'
import { installNativeUserAgent } from './util/http'
import { registerPhoneRotation } from './native/phone-rotation'
installNativeUserAgent()
registerShareIntentHandler()
registerPhoneRotation()
import { resyncSystemAppearance } from './native/system-appearance'
import { startLiveHealthSync, startAlignedRingPull } from './health/health-live'
installNativeUserAgent()
registerShareIntentHandler()
// Ring health records live only in the communicator's memory until something
// stores them. Both health surfaces store on open, but a pull that lands while
// they are closed would be lost if the process restarted first, so this keeps
// them reaching disk regardless. No-op when there is nothing new.
startLiveHealthSync()
// Collect from the ring on a wall-clock cadence (:01 and :31). Without this
// nothing drives a pull on a timer at all - only onRingReady() on reconnect -
// so a ring that stays connected is never read.
startAlignedRingPull()
// Live system dark/light switches while the app is running were confirmed
// (Chris, both directions, 2026-09-02) to leave the Ghost companion's Terminal
// and Doc panes white-on-white and Rich View visually dark-locked -- while a
// COLD launch in either theme renders correctly. That proves the app.css
// .ns-dark rules themselves are right and the LIVE-UPDATE signal is the gap,
// not any one pane's styling -- see system-appearance.ts for the actual fix
// and why it resyncs from two triggers instead of trusting the framework's
// own automatic recolor alone.
Application.on(Application.systemAppearanceChangedEvent, resyncSystemAppearance)
Application.on(Application.resumeEvent, resyncSystemAppearance)
Application.run({ moduleName: 'app-root' })
// Don't place any code after the application has been started