Commit 0b26edf
feat(agents-mobile): session sharing, access management & copy/share links (desktop parity) (#4564)
## Summary
Brings session sharing to `agents-mobile`, closing the parity gap with
the desktop `ShareEntityDialog` while using mobile-native UX paradigms.
Mobile previously only *consumed* effective permissions to gate actions;
it can now manage who has access to a session, copy the session id, and
share a browser-openable session link.
Part of the agents-mobile ↔ agents-desktop parity track (follows #4553,
#4546).
## What's included
### 1. Share session screen (`ShareSessionScreen` +
`app/session-share.tsx` modal route)
Opened from the session kebab menu's **Share** entry. Single-column
layout, top to bottom:
- **Session title + copyable id** (tap id → copy, copy→check icon swap).
- **Session link pill** — abbreviated web URL (scheme stripped,
middle-ellipsized) with a share glyph; one tap opens the **native OS
share sheet** (which includes Copy, so there is no separate in-app "Copy
link").
- **People with access** — pinned, non-removable **Owner** row derived
from `entity.created_by` (omitted when null), then one row per grantee
(avatar/initials, name/email, role pill). Desktop doesn't show the
owner; mobile adds it so the list is never confusingly empty.
- **General access** — the workspace-wide *All users* grant
(`subject_kind: principal_kind / user`) as its own section (Google-Drive
style) rather than mixed into the people list like desktop.
- **Add people** — search-first user list (synced `users` table),
excluding self/owner/existing grantees.
- **Role picker** — tapping any row opens a bottom sheet with **View /
Chat / Manage** (same permission sets and eye/message/shield glyphs as
desktop) plus a destructive **Remove access** (Alert-confirmed). Roles
commit immediately per row — no desktop-style deferred Grant/Update
button.
### 2. Copy session id
The session menu's status header now shows the id (in place of the agent
type label) with a tap-to-copy affordance; same treatment on the
long-press row sheet's id line. Mirrors the desktop `EntityHeader`
copy-id pattern (1.2s icon swap, via the new `useCopyFeedback` hook +
`expo-clipboard`).
### 3. Session web links
`sessionWebUrl(serverUrl, entityUrl)` builds
`{serverUrl}/__agent_ui/#/entity/{id}`.
## Key decisions & why
| Decision | Rationale |
|---|---|
| Grants come from REST `GET /_electric/entities/:type/:id/grants`, not
sync | The synced `entity_effective_permissions` shape is scoped to the
**current principal only** (`server-utils.ts`
`buildCurrentPrincipalEntityEffectivePermissionsWhere`), so it cannot
list other people's access. Same approach as desktop's `loadGrants()`.
Refetch-after-mutation (no optimistic grant state) because the server
owns grant ids needed for subsequent diffs. |
| Web URL targets `/__agent_ui/` directly, not the server root | The
root `302` redirect uses an absolute `location: /__agent_ui/`, which
would drop a Cloud `/t/<service-id>/v1` tenant prefix. The session id
stays **un-encoded** to match the web UI's hash splat route
(`/entity/$`). |
| Share screen reachable by **everyone** (no `manage` gate on the menu
entry) | Link sharing must work for non-managers. The grant sections
self-gate: the manage-protected endpoint returns 401/403 → the screen
shows a manage-required message (this also gracefully handles revoking
your own manage access mid-session). |
| Single share affordance (link pill → native sheet), no in-app Copy
link | The native sheet includes Copy; two buttons for the same URL was
duplicative. The pill shows the URL being shared (Meet/Zoom pattern).
In-app clipboard copy remains only for the session **id**. |
| One **Share** menu item next to Pin | Earlier iteration had Copy id /
Copy link / Share… / Share & access — collapsed after review feedback. |
| `userDisplay()`/`initials()` extracted to
`agents-server-ui/src/lib/userDisplay.ts` | Mobile deep-imports shared
lib code (existing pattern: `principals`, `sharePermissions`,
`entity-api`, `auth-fetch`); extraction avoids drift vs. duplicating.
Internal lib file only — no public API change, desktop dialog updated to
import it. |
| Inbound links **out of scope** | Universal links (https → app) need
associated-domain setup; planned follow-up. The web URL format was
chosen so those links can later deep-link into the app once a domain is
verified. |
## Architecture notes (for future sessions on this PR)
- `src/lib/entityGrants.ts` — all grant logic, pure where possible: REST
wrappers (`listEntityGrants`/`createEntityGrant`/`deleteEntityGrant`,
errors throw `GrantsRequestError` carrying `status`),
`diffGrantsForRole` (set-based create/delete diff, ignores non-share
custom permissions, handles duplicate rows), `grantIdsForRemoval`,
`buildShareAccessModel` (groups grants → all-users + per-user entries
with roles, drops current user / system principals / role-less
subjects), `setSubjectRole` / `removeSubjectAccess` orchestration.
Unit-tested with the repo's hoisted `serverFetch` mock pattern.
- `src/lib/sessionLinks.ts` — `sessionIdFromEntityUrl`, `sessionWebUrl`
(pure, unit-tested incl. Cloud prefix + malformed-URL fallback).
- Role semantics live in shared
`agents-server-ui/src/lib/sharePermissions.ts`: View=[read,fork],
Chat=[read,write,signal,fork,schedule,spawn], Manage=[manage,delete];
`roleFromGrants` / `rolePermissionsMatchGrants` reused.
- `SessionMenu` takes an optional `onShare` prop threaded from
`app/session.tsx` → `SessionScreen` (router push to
`/session-share?entityUrl=…`).
- `BottomSheetItem` always reserves a 22px icon slot — give items icons
or they look indented (why the role options carry glyphs).
- Search fields must mirror `SearchBar` metrics (fixed 36px height,
zero-padding input) or the placeholder sits off-centre on Android.
## Testing
- ✅ 22 new vitest tests (`sessionLinks.test.ts`, `entityGrants.test.ts`)
— written test-first; full mobile suite 83/83, `agents-server-ui` 88/88,
both packages typecheck clean.
- ⬜ Manual QA needed (see below).
### Manual QA checklist
- [ ] **Rebuild dev clients** — `expo-clipboard` is a new native module;
old dev binaries won't load this JS (the one build-impacting change).
- [ ] Open a copied/shared link in a browser against a **local** server
and a **Cloud** server (verifies `/__agent_ui/#/entity/{id}` resolves
under the `/t/<svc>/v1` prefix — the one assumption not verifiable
statically).
- [ ] iOS + Android: copy id from menu + long-press sheet; link pill
opens native sheet; cancel is silent.
- [ ] Manager flow: add user → change role View↔Chat↔Manage → remove →
All-users grant add/change/remove; cross-check grants in the desktop
ShareEntityDialog.
- [ ] Non-manager: share screen shows link actions + manage-required
message; no crash.
- [ ] Self-revocation: remove the All-users *Manage* grant that granted
you manage → screen degrades to access-denied state.
## Out of scope / follow-ups
- Universal links / inbound https session links opening the app (needs
associated domains + per-deployment config).
- Haptic feedback on copy (would add `expo-haptics`).
- Sharing for non-session entity types (no mobile detail surfaces exist
for them yet).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 176bec8 commit 0b26edf
17 files changed
Lines changed: 1624 additions & 45 deletions
File tree
- .changeset
- packages
- agents-mobile
- app
- src
- components
- lib
- screens
- agents-server-ui/src
- components
- lib
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
125 | 128 | | |
126 | 129 | | |
127 | 130 | | |
| |||
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| 182 | + | |
179 | 183 | | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
184 | 188 | | |
| 189 | + | |
185 | 190 | | |
186 | 191 | | |
187 | 192 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
76 | 90 | | |
77 | 91 | | |
78 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
| 13 | + | |
12 | 14 | | |
| 15 | + | |
13 | 16 | | |
14 | 17 | | |
15 | 18 | | |
| |||
102 | 105 | | |
103 | 106 | | |
104 | 107 | | |
105 | | - | |
106 | | - | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
107 | 112 | | |
108 | 113 | | |
109 | 114 | | |
| |||
116 | 121 | | |
117 | 122 | | |
118 | 123 | | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
| 135 | + | |
| 136 | + | |
129 | 137 | | |
130 | 138 | | |
131 | 139 | | |
| 140 | + | |
132 | 141 | | |
133 | 142 | | |
134 | 143 | | |
| |||
267 | 276 | | |
268 | 277 | | |
269 | 278 | | |
270 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
271 | 287 | | |
272 | | - | |
273 | | - | |
274 | | - | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
275 | 292 | | |
276 | 293 | | |
277 | | - | |
278 | | - | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
279 | 312 | | |
280 | 313 | | |
281 | 314 | | |
| |||
341 | 374 | | |
342 | 375 | | |
343 | 376 | | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
344 | 402 | | |
345 | 403 | | |
346 | 404 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
89 | 91 | | |
90 | 92 | | |
91 | 93 | | |
| 94 | + | |
92 | 95 | | |
93 | 96 | | |
94 | 97 | | |
| |||
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | | - | |
112 | | - | |
113 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
114 | 129 | | |
115 | 130 | | |
116 | 131 | | |
| |||
166 | 181 | | |
167 | 182 | | |
168 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
169 | 191 | | |
| 192 | + | |
170 | 193 | | |
171 | 194 | | |
172 | 195 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
0 commit comments