Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

docs(apple): document the macOS and iOS glance widgets and the apple deep link

nirholas9135f22f861e
diff --git a/apple/README.md b/apple/README.md
new file mode 100644
index 000000000..a9ae75167
--- /dev/null
+++ b/apple/README.md
@@ -0,0 +1,142 @@
+# `apple/`: the Agent glance widget for macOS and iOS
+
+The three.ws agent on a Mac's Notification Centre and on an iPhone home screen,
+plus the small Mac app that feeds it. One WidgetKit extension serves both
+platforms from one set of sources; the only thing that differs is which project
+builds it.
+
+The Android counterpart is [`../solana-mobile/android-overlay/`](../solana-mobile/android-overlay/README.md)
+and the Windows 11 one is the `widgets` member of the web manifest in
+[`../vite.config.js`](../vite.config.js) driven by
+[`../public/glance-sw.js`](../public/glance-sw.js). All four render the same
+card from the same endpoint, which is the point: adding a surface here is a
+rendering job, not a data job. The card's wire format is pinned in
+[`../specs/GLANCE_CARD.md`](../specs/GLANCE_CARD.md) and the product
+documentation is [`../docs/native-widgets.md`](../docs/native-widgets.md).
+
+## Layout
+
+```
+apple/
+├── GlanceKit/ # shared sources, compiled into every target
+│ ├── GlanceConfig.swift # origin, App Group and keychain group, from Info.plist
+│ ├── GlanceCard.swift # the card, its states, its sizes and themes
+│ ├── GlanceTokenStore.swift # the widget token, in the shared keychain
+│ ├── GlanceCache.swift # the last card downloaded, in the App Group container
+│ ├── GlanceClient.swift # GET /api/glance/mine?format=png
+│ ├── GlanceLink.swift # claims threews://glance/link?token=...
+│ ├── GlanceEntry.swift # one moment in the widget's timeline
+│ ├── GlanceImage.swift # PNG to SwiftUI Image, on either platform
+│ └── GlanceCardView.swift # the widget's ink, every state drawn
+├── GlanceWidget/ # the extension target
+│ ├── GlanceProvider.swift # the TimelineProvider and its refresh policy
+│ ├── AgentGlanceWidget.swift # the widget, its families, the bundle entry point
+│ ├── Info.plist
+│ └── GlanceWidget.entitlements
+├── macos/ # the Mac host app
+│ ├── project.yml # XcodeGen spec: app + extension
+│ └── ThreeWSGlance/ # SwiftUI window, menu bar companion, link model
+└── scripts/make-macos-icon.mjs # the Mac app icon, derived from the brand mark
+```
+
+## Building the Mac app
+
+```bash
+brew install xcodegen # once
+node apple/scripts/make-macos-icon.mjs # regenerates the icon set from the brand mark
+cd apple/macos && xcodegen generate && open ThreeWSGlance.xcodeproj
+```
+
+Set a **Development Team** on both targets in Signing and Capabilities (or pass
+`DEVELOPMENT_TEAM=XXXXXXXXXX` to `xcodebuild`). Nothing else needs configuring:
+the App Group, the keychain group and the origin are derived from it.
+
+The project is generated rather than committed because a hand-maintained
+`.xcodeproj` is a merge conflict waiting to happen and `project.yml` says what
+the two targets actually are in a page anyone can read. Distribution is
+Developer ID, so the Mac app can ship before the iOS one clears review.
+
+## Building the iOS widget
+
+Nothing extra. The extension is a target in the committed Capacitor project at
+[`../ios/native/App/App.xcodeproj`](../ios/native/App), it compiles the same
+`apple/GlanceKit` and `apple/GlanceWidget` sources by relative path, and
+`npm run ios:open` opens it. `bubblewrap`-style regeneration does not apply
+here: Capacitor generates that project once and never rewrites it, which is why
+the iOS side is a committed target rather than an overlay applied at build time
+the way Android's is.
+
+The extension deploys to iOS 17 while the app deploys to iOS 16. That is
+deliberate: WidgetKit's `containerBackground` and `contentMarginsDisabled` are
+iOS 17, and a phone too old to run the extension simply never sees it in the
+widget gallery, while the app keeps working exactly as it does today.
+
+## The three build settings, and why they are not constants
+
+`GlanceKit` reads its origin and its two container identifiers back out of the
+running target's Info.plist. They cannot be hard coded because the platforms
+disagree:
+
+| Setting | iOS | macOS |
+| --- | --- | --- |
+| `GLANCE_ORIGIN` | `https://three.ws` | `https://three.ws` |
+| `GLANCE_APP_GROUP` | `group.ws.three.app` | `$(DEVELOPMENT_TEAM).group.ws.three.glance` |
+| `GLANCE_KEYCHAIN_GROUP` | `$(DEVELOPMENT_TEAM).ws.three.shared` | `$(DEVELOPMENT_TEAM).ws.three.shared` |
+
+An App Group identifier on a Mac signed with a Developer ID has to carry the
+team prefix; the same identifier on iPhone must not. Xcode expands these
+settings into both the Info.plist and the entitlements, so one file reads them
+at runtime and neither platform needs its own copy of anything.
+
+If `DEVELOPMENT_TEAM` is unset the values expand to a leading dot, which
+`GlanceConfig` treats as absent: the token goes to the target's own keychain and
+the cache to its own container, so a single-target debug run still works and
+nothing pretends to be shared that is not.
+
+## How a device gets a token
+
+The Mac never sees a password, and neither does the phone.
+
+1. The owner opens [three.ws/glance](https://three.ws/glance) signed in and
+ presses **Link this device**. The page mints a token against the session
+ (`POST /api/glance/token`, same-site only) and gets back the plaintext once.
+2. The page navigates to `links.apple`, which is
+ `threews://glance/link?token=glw_…`. Both Apple apps register that scheme, so
+ the operating system hands it to the app rather than to a browser.
+3. `GlanceLink.claim` checks the token's shape before storing anything, writes
+ it to the shared keychain, drops any cached card from a previous account, and
+ reloads every widget timeline.
+4. If nothing claimed the URL, which is what happens on a Mac whose browser is
+ signed in on a different machine, the page also shows the code and the Mac
+ app takes it pasted.
+
+On iOS the URL is claimed in
+[`SceneDelegate`](../ios/native/App/App/SceneDelegate.swift) before Capacitor
+sees it, and `ios/src/native-bridge.js` drops `/glance/link` as well, so a live
+token can never end up as a WebView navigation.
+
+The token reads exactly one endpoint and exactly one thing, the owner's own
+card. It is revoked from the same page, and a revoked token makes the widget
+draw the "link again" card the server sends rather than an error.
+
+## Verifying without a Mac
+
+`npm run check:apple-widget` ([scripts/check-apple-widget.mjs](../scripts/check-apple-widget.mjs))
+is what a Linux build machine can prove: that both projects are internally
+consistent, that every Swift source is a member of the targets that need it,
+that the plists only expand settings the projects define, and that the client
+and `api/glance/mine.js` still agree on the endpoint, the query, the six headers,
+the four states, the sizes, the scales and the token shape. It is wired into
+`npm run gate`. It is a structural check, not a build: green means the wire and
+the projects agree, not that the Swift compiles.
+
+`npm run check:macos-icon` holds the Mac icon to the brand mark the same way
+`check:ios-icons` holds the iPhone one.
+
+## What runs when
+
+| | Refresh | Offline | Tap |
+| --- | --- | --- | --- |
+| macOS and iOS | WidgetKit timeline, requested every 30 minutes, 15 after a failure | Last card from the App Group container, with the time it was fetched | `x-glance-url`: the agent's page, opened by the app on iPhone and by the browser on a Mac |
+| Android | WorkManager, battery-aware, about every 30 minutes | Same, from internal storage | Same, in the app |
+| Windows 11 | The manifest's `update: 900` | The board keeps the last payload | The route in the Adaptive Card |
diff --git a/docs/api-reference.md b/docs/api-reference.md
index dd4fd7bb0..c6f0e979c 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -7477,7 +7477,7 @@ data: {"id":"6a29...","text":"Deploy is green","importance":80,"tone":"alert"}
## Glance API
-One agent reduced to what fits in an operating-system widget slot: name, avatar, one live number (moves in the last 24 hours), and a link back. Powers the Windows 11 widget, the Android home screen widget, README badges and the `<agent-glance>` element. Spec: [specs/GLANCE_CARD.md](../specs/GLANCE_CARD.md). Guide: [glance.md](glance.md), [native-widgets.md](native-widgets.md).
+One agent reduced to what fits in an operating-system widget slot: name, avatar, one live number (moves in the last 24 hours), and a link back. Powers the Windows 11 widget, the Android home screen widget, the macOS and iOS WidgetKit widget, README badges and the `<agent-glance>` element. Spec: [specs/GLANCE_CARD.md](../specs/GLANCE_CARD.md). Guide: [glance.md](glance.md), [native-widgets.md](native-widgets.md).
### Public card
@@ -7505,7 +7505,7 @@ PATCH /api/glance/token { id, agent: uuid|null }
DELETE /api/glance/token?id=<uuid>
```
-Session cookie required; writes must be same-site. `POST` answers `201` with `{ id, prefix, label, platform, agentId, createdAt, lastUsedAt, token, links: { android } }`. `token` is shown exactly once; `links.android` is the `intent://glance/link?token=…#Intent;scheme=threews;package=ws.three.app;…;end` URL that hands it to the Android app. At most 12 live tokens per account (`409 too_many_tokens`). `GET` answers `{ tokens: [...] }` without plaintexts. `DELETE` answers `{ revoked: true, id }`, or `404` for an id that is not the caller's live token.
+Session cookie required; writes must be same-site. `POST` answers `201` with `{ id, prefix, label, platform, agentId, createdAt, lastUsedAt, token, links: { android, apple } }`. `token` is shown exactly once; `links.android` is the `intent://glance/link?token=…#Intent;scheme=threews;package=ws.three.app;…;end` URL that hands it to the Android app, and `links.apple` is the `threews://glance/link?token=…` URL the macOS and iOS apps claim natively. At most 12 live tokens per account (`409 too_many_tokens`). `GET` answers `{ tokens: [...] }` without plaintexts. `DELETE` answers `{ revoked: true, id }`, or `404` for an id that is not the caller's live token.
| Error | Status | Meaning |
| --- | --- | --- |
diff --git a/docs/glance.md b/docs/glance.md
index feb08d02d..1758f50e2 100644
--- a/docs/glance.md
+++ b/docs/glance.md
@@ -93,7 +93,7 @@ Every state is a `200` with a designed card, never a `401`: a widget that render
### `POST | GET | PATCH | DELETE /api/glance/token`
-The widget tokens. Session and same-site only. `POST { label?, platform?, agent? }` mints one and answers the plaintext exactly once, plus `links.android`, the `intent://` URL that hands it to the Android app. `GET` lists the caller's live tokens (prefix, label, platform, last seen), `PATCH { id, agent }` repoints one, `DELETE ?id=` revokes one. The revoke list on [/glance](https://three.ws/glance#devices) is this endpoint.
+The widget tokens. Session and same-site only. `POST { label?, platform?, agent? }` mints one and answers the plaintext exactly once, plus `links.android`, the `intent://` URL that hands it to the Android app, and `links.apple`, the `threews://glance/link` URL the Mac and iPhone apps claim. `GET` lists the caller's live tokens (prefix, label, platform, last seen), `PATCH { id, agent }` repoints one, `DELETE ?id=` revokes one. The revoke list on [/glance](https://three.ws/glance#devices) is this endpoint.
### `GET /api/glance/template`
diff --git a/docs/native-widgets.md b/docs/native-widgets.md
index e19e47244..714b4a6a0 100644
--- a/docs/native-widgets.md
+++ b/docs/native-widgets.md
@@ -68,7 +68,8 @@ with no cookie jar, so it cannot use the session. Instead `/glance` mints a **wi
(`POST /api/glance/token`), a random 32-character credential prefixed `glw_`. The server stores
only its SHA-256; the plaintext travels once, inside a `threews://glance/link?token=…` deep
link that only the `ws.three.app` package can claim, and then lives in the app's private
-storage. The token is accepted by exactly one endpoint, `GET /api/glance/mine`, and reads
+storage. The Apple apps claim the same URL through the `threews` scheme and put the token in a
+shared keychain group. The token is accepted by exactly one endpoint, `GET /api/glance/mine`, and reads
exactly one thing: the owner's card.
### For developers
@@ -87,12 +88,47 @@ refreshes every 15 minutes. Details in [glance.md](glance.md#on-the-windows-11-w
## macOS and iOS
-Planned: a shared WidgetKit extension (a `TimelineProvider` that fetches
-`/api/glance/mine?format=png` with a widget token stored in the keychain) and a small SwiftUI
-host app that signs in and mints the token. macOS ships first because it can be distributed
-outside the App Store; the iOS build is the same extension target and waits on an Apple
-Developer account. The card, the token, and the endpoint are the ones above; nothing on the
-server changes for either.
+One WidgetKit extension serves both, in small, medium and large. It fetches the same
+`/api/glance/mine?format=png` with the same kind of widget token, kept in the keychain and
+shared with its host app.
+
+### On a Mac
+
+1. Install **three.ws Glance**, the small menu bar app that holds the token. It is a Developer
+ ID build, so it does not go through the App Store.
+2. Open [three.ws/glance](https://three.ws/glance) signed in, press **Link this device**, and
+ let the app claim the link. If the browser is signed in on a different machine, copy the
+ code the page shows and paste it into the app instead.
+3. Click the date in the menu bar to open Notification Centre, scroll to **Edit Widgets**, find
+ **three.ws Glance**, and drag **Agent glance** out.
+
+The menu bar item shows the same card, and carries **Open my agent**, **Refresh now** and
+**Unlink this Mac**.
+
+### On an iPhone or iPad
+
+Requires the three.ws iOS app on iOS 17 or later ([ios-app.md](ios-app.md)). Link it exactly
+the same way from [three.ws/glance](https://three.ws/glance), then long-press the home screen,
+tap **Edit**, tap **Add Widget**, and pick **three.ws**.
+
+### What it does
+
+The system refreshes it on its own timeline; the widget asks for about every half hour, and 15
+minutes after a refresh that failed. With no network it draws the last card it downloaded with
+"From 14:02 (offline)" under it, never a spinner and never a broken image. It follows the
+reader's appearance: each refresh fetches the card in both themes, so a Mac in light mode gets
+a light card. Tapping it opens the agent, on the phone in the app and on a Mac in the browser.
+
+The states are the ones in the Android table above, and they come from the same server. The two
+extra ones are local: a device with no token yet says "Add your agent", and a device that has a
+token but has not finished its first download says "Fetching your agent".
+
+### For developers
+
+The sources are in [apple/](../apple/README.md): `apple/GlanceKit/` is shared, the extension is
+`apple/GlanceWidget/`, the Mac app is generated from `apple/macos/project.yml` with XcodeGen,
+and the iOS extension is a target in the committed Capacitor project. `npm run check:apple-widget`
+verifies both projects and the wire contract without a Mac.
## The endpoints
@@ -100,7 +136,7 @@ server changes for either.
| --- | --- |
| `GET /api/glance/mine?format=png&size=small\|medium\|large&theme=dark\|light&scale=1\|2\|3` | The card bitmap for the caller (widget token as `Authorization: Bearer`, or the session cookie). Always `200`; the state is in `x-glance-state` and the tap target in `x-glance-url`. |
| `GET /api/glance/mine` | The same as JSON: `{ signedIn, state, card, notice, agents, … }`. |
-| `POST /api/glance/token` | Mint a widget token (session, same-site). Returns the plaintext once plus `links.android`. |
+| `POST /api/glance/token` | Mint a widget token (session, same-site). Returns the plaintext once plus `links.android` and `links.apple`. |
| `GET /api/glance/token` | List the caller's live tokens. |
| `PATCH /api/glance/token` | Repoint a token at another owned agent. |
| `DELETE /api/glance/token?id=…` | Revoke a token. |
diff --git a/ios/README.md b/ios/README.md
index 34590bcf1..ef246c7d6 100644
--- a/ios/README.md
+++ b/ios/README.md
@@ -31,6 +31,25 @@ ios/
└── docs/ # SUBMISSION.md, REVIEW-RISK.md, ASSETS.md, CARPLAY.md
```
+The project carries a second target, **GlanceWidgetExtension** (`ws.three.app.glance`),
+which is the Agent glance home screen widget. Its sources are not in this
+directory: they live in [`../apple/`](../apple/README.md) and are compiled by
+both this project and the Mac app, byte for byte, so the two platforms cannot
+drift. It deploys to iOS 17 while the app stays on iOS 16, so an older phone
+simply never sees the widget in the gallery.
+
+## The home screen widget
+
+Long press the home screen, **Edit**, **Add Widget**, **three.ws**, and the
+agent's card is there in small, medium or large. It authenticates with a widget
+token the owner mints on [three.ws/glance](https://three.ws/glance), which
+arrives as `threews://glance/link?token=…` and is claimed in
+[`SceneDelegate`](native/App/App/SceneDelegate.swift) before Capacitor sees it,
+so a live credential never reaches the WebView. Everything about it, including
+how to build and verify it without a Mac, is in
+[`../apple/README.md`](../apple/README.md) and
+[`../docs/native-widgets.md`](../docs/native-widgets.md).
+
## CarPlay
The app carries a second scene for **three.ws Drive**, the agent in the car. Apple's
diff --git a/specs/GLANCE_CARD.md b/specs/GLANCE_CARD.md
index e3c868357..bed8d94a4 100644
--- a/specs/GLANCE_CARD.md
+++ b/specs/GLANCE_CARD.md
@@ -123,6 +123,15 @@ The PNG answer is always status `200` and carries the same facts in headers, so
| `x-glance-updated` | `updatedAt` |
| `x-glance-width`, `x-glance-height` | bitmap pixels |
+`POST /api/glance/token` answers the plaintext once, along with the hand-off URL for each native shell. These are part of the contract rather than an implementation detail: a shipped app claims a fixed scheme and cannot be redeployed in step with the server.
+
+| Link | Value | Claimed by |
+| --- | --- | --- |
+| `links.android` | `intent://glance/link?token=<token>#Intent;scheme=threews;package=ws.three.app;S.browser_fallback_url=<install page>;end` | the `ws.three.app` package |
+| `links.apple` | `threews://glance/link?token=<token>` | the iOS app (`ws.three.app`) and the macOS app (`ws.three.glance`) |
+
+A consumer MUST validate the token against `glw_` plus 32 URL-safe characters before storing it: the scheme is an entry point any application can call.
+
## Versioning
New optional fields are additive and do not bump `version`. Removing a field, changing a type, or changing the meaning of `metric` requires v2 served alongside v1; the `version` field is what lets a widget pinned a year ago keep rendering.