From b7de91a65284ff88080b66956d987042c0761b82 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sat, 31 Oct 2026 21:55:07 -0400 Subject: [PATCH 1/2] feat(mobile): Settings, Personas and Playbooks are an Owner's Mobile Settings now follows web's rule (People and access AC27 to AC29): someone who owns no connected server sees only the pages about the device itself, any other Settings page, Archive included, shows a notice in its place, and Settings, Archive, Personas and Playbooks list only the servers the person owns. A thread's Playbook progress is shown to anyone who reads the thread, as on web. The ownership atoms move into client-runtime so web and mobile share them. Co-Authored-By: Claude Opus 5.5 --- FORK.md | 7 +- apps/mobile/src/Stack.tsx | 4 +- .../archive/ArchivedThreadsRouteScreen.tsx | 5 +- .../features/settings/SettingsRouteScreen.tsx | 7 +- .../settings/components/SettingsScreen.tsx | 9 +- .../settings/settings-environment-filter.tsx | 4 +- .../j5/agents/AgentLibrarySettingsScreen.tsx | 23 ++-- .../j5/playbooks/PlaybookComposerControl.tsx | 6 +- .../PlaybookLibrarySettingsScreen.tsx | 7 +- apps/mobile/src/j5/sharing/guestAccess.ts | 39 ++++--- .../src/j5/sharing/ownerOnlySettingsRoute.tsx | 23 ++++ .../j5/sharing/settingsAccess.logic.test.ts | 32 ++++++ .../src/j5/sharing/settingsAccess.logic.ts | 37 +++++++ apps/mobile/src/j5/sharing/settingsAccess.tsx | 64 +++++++++++ apps/mobile/src/j5/upstreamSeams.test.ts | 30 ++++++ .../src/j5/agents/AgentLibrarySettings.tsx | 3 +- apps/web/src/j5/sharing/access.ts | 69 ++---------- .../j5/sharing/settingsAccess.logic.test.ts | 45 +------- .../src/j5/sharing/settingsAccess.logic.ts | 32 ------ apps/web/src/j5/sharing/settingsAccess.tsx | 2 +- .../client-runtime/src/j5/sharing.test.ts | 40 +++++++ packages/client-runtime/src/j5/sharing.ts | 101 ++++++++++++++++++ 22 files changed, 403 insertions(+), 186 deletions(-) create mode 100644 apps/mobile/src/j5/sharing/ownerOnlySettingsRoute.tsx create mode 100644 apps/mobile/src/j5/sharing/settingsAccess.logic.test.ts create mode 100644 apps/mobile/src/j5/sharing/settingsAccess.logic.ts create mode 100644 apps/mobile/src/j5/sharing/settingsAccess.tsx diff --git a/FORK.md b/FORK.md index 1721c461ebd11..a05938dc020e4 100644 --- a/FORK.md +++ b/FORK.md @@ -440,7 +440,7 @@ migrations after upstream migrations. 69. A connection whose person's scope is narrower than the server is narrowed to it ([#532](https://github.com/Jacksondr5/j5code/issues/532), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-09, 2026-10-11 and 2026-10-17 decisions). Upstream's permissions are per connection and cover the whole server. J5 reads, for each session, whose device it is (J5-owned `apps/server/src/j5/sharing/PersonAccess.ts`, `sessionReach`): a person's, by the binding case 70 records as the session is issued; the first owner's, by the subjects of the startup link, the desktop app, T3 Connect (`cloud-connect`, which upstream mints only for the cloud account the server is linked to) and the development credential; a service's (`peer:*`, `machine:*`, `mcp-client`, `cli-issued-session`); or a device no one has claimed. A service session and a person who holds Collaborator or Owner at server scope are wide and get upstream's own answers, the same objects. Everyone else is narrowed: a person at a project or a thread at either level, a Viewer at server scope, and an unclaimed device. A narrowed session is refused everything but an allow-list, every listed request is checked against the level the person holds at the scope it names, and the answers that name the host are reduced. All of it is J5-owned code under `apps/server/src/j5/sharing/`, reached from two upstream server files. In `apps/server/src/server.ts`, `layerAuth` is upstream's `EnvironmentAuth.layer` wrapped in `gateEnvironmentAuth` (`AccessGate.ts`): a narrowed session keeps its permissions only on the routes `accessHttpRule` allows (`/ws`, a reachable thread's loads, a preview tab's stream, downloads and uploads for a thread the person holds Collaborator on, and J5's artifact read for a reachable project), so every other route's own permission check refuses it. In `apps/server/src/ws.ts`, the per-connection `RpcAuthorization.layer(session.scopes, …)`, with upstream's feature-use recorder as its second argument, is wrapped in `layerRpcAuthorization`, which refuses a narrowed session every request not in `ACCESS_RPC_RULES` and checks each listed one: at a thread or project the payload names, at the level given (`thread`, `project`); for a person who holds Collaborator anywhere, whatever folder it names (`collaborator`: files, terminals' folders, git, previews' profiles, the host's devices; a terminal or an agent reaches every folder anyway, Jackson 2026-10-17), and the server's Playbook library, read only (AC20); for anyone (`anyone`: what a client reports of itself); for a person with a level at server scope (`server`: the Fleet page, Personas, the providers' skills, every Playbook run, read only); or answered narrowly by its handler (`narrowed`). Upstream's own permission check runs after J5's on every request, so what a level's permissions lack (settings, providers, access, relay management, environment maintenance) is refused by upstream. A request still running is ended when the person's reach changes so that it no longer meets its rule (`PersonAccess.subscribeChanges`). Whether a session is wide is read once, when the socket opens; a change that would alter it renews the session (case 70). `layerWsRpc` reads `connectionView(currentSession)` (`GuestView.ts`) once, and nine handlers pass their answer through it: `server.getConfig` (`Effect.map(j5View.config)`), `subscribeServerConfig` (`.pipe(j5View.configStream)`), `subscribeServerLifecycle` (`.pipe(j5View.lifecycleStream)`), `orchestration.subscribeShell` (`j5View.shellStream` around upstream's `subscribeOrchestrationV2Shell`), and `scheduledTasks.list` and `scheduledTasks.subscribe` (`j5View.scheduledTasks`, `j5View.scheduledTasksStream`), which list a narrowed person only the tasks bound to a thread they reach or, for a task bound to no thread, its project's, and give a Viewer no webhook address. Every narrowed session's thread shell, thread-detail stream and thread projection leave out `opens`, the last Cmd+K queries that picked the thread, which are the owner's searches, and upstream's `guestShare` (`subscribeThread` passes its stream through `.pipe(j5View.threadStream)` and `getThreadProjection` ends with `j5View.threadProjection`); `orchestration.searchThreads`, upstream's Cmd+K message search, is listed as `narrowed` and runs inside `j5View.searchThreads(input, (request, narrowed) => …)`, which hands upstream's `search` the threads the person reaches (`PersonAccess.reachableThreads`, the same parent rule as `threadLevel`; every thread for a level at server scope) and drops `olderSettledBefore`, `projectIds` and `environmentLabel`, since a narrowed sidebar has no older-settled cut and those rows are read from every settled thread ([#696](https://github.com/Jacksondr5/j5code/issues/696), Jackson 2026-10-31). The search is held to those threads in upstream's query, not filtered after it: `apps/server/src/orchestration-v2/ThreadSearch.ts` gains a server-only `threadIds` on `search`'s input and `SearchRequest`, one condition in `messageHitsQuery`'s `eligible` CTE, before the hit limit, and a `withoutOpens` input that ranks with no `opens`, so the owner's picks and open counts don't order a narrowed person's results. Upstream's global floor of the newest 10,000 index hits (and the scan's newest 20,000 messages without the index) still applies before the condition, as it does to the owner's hidden threads (Captain's ruling, 2026-10-31). A narrowed Collaborator's `thread.visit` is admitted with `opened` and `searchQuery` removed (`CommandAdmission.ts`, no upstream edit), so it moves the read marker and leaves `opens`; a Viewer's visit stays refused, unseen, since upstream's client sends it with `reportFailure: false`. Of the RPCs upstream added at that advance, `projects.listIgnoredFiles` and `device.easAccount` are listed as `collaborator`, like `projects.listEntries`, and `pullRequests.filterOptions` and `pullRequests.changeBreakdown` are not listed, as no `pullRequests.*` method is. The configuration is reduced for a Viewer and an unclaimed device (AC24) and given whole to a narrowed Collaborator, who can open a terminal on the host; the lifecycle welcome is reduced and the sidebar filtered for every narrowed session, and a Viewer's projects and threads carry placeholder folders where a Collaborator's carry the real ones. `apps/server/src/orchestration-v2/http.ts` is upstream's file: the HTTP sidebar snapshot (`GET /api/orchestration/shell`) is refused to a narrowed session, and upstream's client then reads the sidebar from the socket's feed (`packages/client-runtime/src/state/shell.ts` falls back when the HTTP load fails), so the feed is the one filtered path. A Viewer may ask `assets.createUrl` for an attachment or a tool's image only when `PersonAccess.messageAssetLevel` finds it in a thread they reach: in a message's attachments, or in a turn item's output, where a page a tool published is named; a Collaborator may ask for any asset. A favicon reaches a narrowed person through J5 and never by a host path (Jackson's 2026-10-12 decision; `GuestProjectIcons.ts`, no upstream edit): a reduced project carries `guestIconPath(projectId)` as its `faviconPath`, `ACCESS_RPC_RULES` reads the project id from a `project-favicon` request's `path`, checks `PersonAccess.projectInFeed`, and answers in place of upstream's handler with a link to `GET /api/j5/sharing/project-icon//`, signed with J5's own key, which serves the file through upstream's exported `issueAssetUrl`, `resolveAsset` and `assetFileResponse`. Both allow-lists refuse by default, so a route or request upstream adds is closed to a narrowed session until J5 lists it; `ACCESS_RPC_RULES` is keyed by the RPC group's method names, so a method upstream renames or removes fails to compile. Upstream's `ws.test.ts` gives `layerWsRpc` J5's sixth argument and mocks `PersonAccess` (a service session) and `SharedConversation`, so its sockets get upstream's own answers. The reduced configuration is built field by field (`reduceServerConfig`, `reduceProvider`), so a field upstream adds is left out for a Viewer until J5 lists it. The client half adds three J5 RPC groups and one call in each chat view: `J5AccessRpcGroup`, `J5PeopleRpcGroup` and `J5SharedConversationRpcGroup` (J5-owned `packages/contracts/src/j5/access.ts`, `people.ts` and `sharedConversation.ts`) are merged in `packages/contracts/src/rpc.ts`, and their streams (`j5.access.subscribeThreadLevel`, `j5.people.subscribeScopeChanges`, `j5.sharedConversation.subscribeThreadAuthorsChanges`) join `EnvironmentSubscriptionRpcTag` in `packages/client-runtime/src/rpc/client.ts` (one line each, the shape of cases 45 and 64); `packages/client-runtime/package.json` exports `./j5/sharing`. In `apps/server/src/ws.ts`, case 58's `layerJ5WsRpc(...)` call passes the connection's `session`, so the handlers answer for the session the socket was opened with. Upstream's web chat view (`apps/web/src/components/ChatView.tsx`) and mobile thread screen (`apps/mobile/src/features/threads/ThreadRouteScreen.tsx`) each call J5-owned `useCanOperateThread(environmentId, threadId)` from their app's `j5/sharing/access.ts` (web) or `j5/sharing/guestAccess.ts` (mobile) where they computed `canOperateThread` (one import and one call), and upstream's thread action menu (`apps/web/src/hooks/useThreadActionMenu.ts`) calls `readCanOperateThread(threadRef)` from `apps/web/src/j5/sharing/threadOperability.ts`. On a pin advance: keep the wrapping calls where the answers are produced; if upstream adds another place that sends a `ServerConfig`, a lifecycle event, a shell item or a list of scheduled tasks, a narrowed session cannot reach it until it is listed, and it must pass through `GuestView` when it is; if upstream changes how the shell feed resumes or what its items are, reread `GuestView.ts`; if upstream reshapes `messageHitsQuery`'s `eligible` CTE or ranks message hits by another per-thread record than `opens`, carry `threadIds` and `withoutOpens` with it, and if `searchThreadsWithOlderSettledRows` starts returning rows for something other than `olderSettledBefore`, drop that input for a narrowed connection too; if upstream's client stops falling back to the feed when the HTTP sidebar snapshot is refused, a narrowed person's sidebar stays empty; if upstream adds an asset kind or changes where attachments are named (`orchestration_v2_projection_messages` `$.attachments[].id`, or a turn item's payload), reread `messageAssetLevel`; if upstream reshapes its permissions, reread case 70's level mapping; if upstream changes how its client keys a favicon request or the three asset functions, reread `GuestProjectIcons.ts`, whose test runs upstream's real resolution. 70. Every device belongs to a person, holds its level's permissions, and renews when the level changes ([#535](https://github.com/Jacksondr5/j5code/issues/535), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-11 approval on [#531](https://github.com/Jacksondr5/j5code/issues/531) of one small edit inside upstream's pairing code, and his 2026-10-17 rulings). A level's permissions are listed in one place, J5-owned `packages/contracts/src/j5/levels.ts` (`LEVEL_PERMISSIONS`), and a device holds its person's highest level's set cut to the ceiling it was paired with (`devicePermissions`). Whose device a session is, and that ceiling, are recorded in J5's own table `j5_a2a_person_session` (J5 migrations 34 and 39) as upstream issues the session, without changing upstream's tables. The person a pairing credential is for is recorded in `j5_a2a_pairing_intent` (migration 39), found again by a hash of the credential because upstream's pairing code holds the credential when it issues a session. `apps/server/src/auth/EnvironmentAuth.ts` carries the edit, at seven sites: one import; two lines in `make` (`const j5TiedToPerson = yield* makePairingSessionIssuer` and `const j5ApprovesMcpClient = yield* makeMcpApprovalCheck`, each read with `Effect.serviceOption`, so upstream's own tests build the layer without them); one pipe step, `j5TiedToPerson(grant, credential)`, on each of the two `sessions.issue` calls that issue a session from a pairing grant (`createBrowserSession` and `exchangeBootstrapCredentialForAccessToken`); and one check in `consumeMcpApprovalCode`, so only a code an Owner's level backs approves an MCP client (`PairingIntents.approvesMcpClient`: not a J5 link's credential, subject `j5:link`, and not one whose intent names someone who is not an Owner); and the message a browser session from another origin is refused with is a named export, `FOREIGN_ORIGIN_DIAGNOSTIC`, so J5's renewal refuses what upstream refuses. Lowering or removing an Owner voids every MCP approval checked before it, however soon after the check it lands, and ends the MCP clients that Owner approved: J5-owned `McpApproval.layerGatedMcpOAuth` decorates upstream's `McpOAuth` (`apps/server/src/auth/McpOAuth.ts` is not edited), reads which change of Owners it is (`Access.ownersGeneration`, under the same lock as a change of level) and who approves (the person the pairing code's intent names, read before upstream spends it, or the person whose browser session approves) before upstream's `approve` checks the approval, ties both to the code in the redirect `approve` returns, and gives them to the exchange of that code; `layerGatedEnvironmentAuth` wraps `issueMcpClientSession` in `Access.issueMcpClient`, which refuses under that lock if the Owners changed since, or if no approval was given to it, and otherwise records the issued session as its approver's in J5's own table `j5_a2a_mcp_client_approver` (J5 migration 45), keyed by the session id upstream's `SessionStore.verify` reads from the token it issued. Lowering or removing that person as an Owner revokes those sessions upstream in the same transaction. Upstream's MCP sign-in issues no refresh token, so a client's session is never replaced under a new id; an MCP client approved before migration 45, or with a code that names no one (the first owner's), has no approver and is ended by hand. In `server.ts`, `McpOAuth.layer` is wrapped in `gateMcpOAuth` where `McpOAuthHttp.layer` is given it (one import and one line). For a credential with no intent the pipe step costs one read by primary key and returns upstream's own effect, and binds the session to the first owner when the credential is the startup link's, the desktop app's or T3 Connect's (`FIRST_OWNER_SUBJECTS`; if upstream mints another credential for the server's own account, add its subject there, or its device is one no one has claimed). For one with an intent it runs upstream's `sessions.issue` and the binding in one transaction (`PairingIntents.issueSession`), so the session and the record of whose it is commit together, and it issues nothing when the credential carries more than its person may hold now, when its person was removed, or when it carries the retired guest subject `j5:guest`. In `apps/server/src/server.ts`, `layerAuth` (case 69) gains one line, `Layer.provideMerge(J5PeopleLive)`, above `layerPersistence`: it gives `PersonAccess` and `PairingIntents` to upstream's `EnvironmentAuth.layer` and to J5's own services. `apps/server/src/auth/http.ts`'s `pairingCredential` handler, which Connections' "Create link" calls, records after `issuePairingCredential` that the link pairs a device for the person whose device made it, under the permissions chosen there (`recordConnectionsLinkCreator`; one import and one call, piped through `Effect.provideService` with the `SessionStore` upstream's layer reads when it is built); a link whose maker cannot be recorded is revoked before the request fails, and that includes one whose maker's session is no one's and no longer live (its person was removed while the link was made), so no such link approves an MCP client as no one. A change of level ends each of the person's sessions for renewal (`Access.ts`): the binding is marked and upstream's `SessionStore.revoke` ends the session, which closes its open sockets at once, in the transaction that changes the level. The device then renews on J5's route `POST /api/j5/session/renew` (`SessionRenewal.ts`, no upstream edit) with its old token: upstream's `SessionStore.verify` checks a token's signature before whether it was revoked and names a revoked token's session, so the route issues a session that holds the new permissions, with the old session's method, subject, client and expiry, only for a session J5 marked, once. `apps/web/src/environments/primary/auth.ts` calls `renewPrimarySession` before its sign-in gate sends a browser to pair (one import and one line), and J5-owned `SessionRenewalWatcher` reloads the page once when the primary connection drops and renewal succeeds. `apps/web/src/connection/runtime.ts` adds J5-owned `@t3tools/client-runtime/j5/session-renewal` to the connection runtime (one import and one line), which renews a saved server's bearer token when its connection is refused for authentication; `packages/client-runtime/package.json` exports it. `apps/mobile/src/connection/runtime.ts` adds the same layer to mobile's connection runtime (one import and one line), and `apps/mobile/src/App.tsx` mounts J5-owned `NameQuestionHost` (`apps/mobile/src/j5/sharing/NameQuestion.tsx`) beside upstream's `Dialog.Host` (one import and one line): it asks a device a saved server cannot place, or the first owner with no name, the name question before the device uses that server (AC5, AC6), as web's `NameDialog` does, with the rule shared in `packages/client-runtime/src/j5/sharing.ts` (`serverToAskNameFor`). DPoP sessions and a device offline past its session's life are paired again by hand; an MCP client holds no person's level, so a change of level does not touch it, except that lowering or removing an Owner ends the ones they approved. The refusal of a browser paired as one person opening a link made for another reaches the pairing page with its reason through three upstream files, each a line or a literal: `packages/contracts/src/environmentHttp.ts` (`EnvironmentAuthInvalidError`'s optional `pairingRefusal: "paired_as_someone_else"`), `apps/server/src/auth/http.ts` (`failEnvironmentAuthInvalid`'s third argument, passed by the `browserSession` handler), and `apps/web/src/environments/primary/auth.ts` (the rejected-credential error's flag). `layerGatedEnvironmentAuth` (case 69's J5-owned decorator, in `j5/sharing/AccessGate.ts`, which passes on the `use` argument upstream's `authenticateWebSocketUpgrade` takes since stable v0.1.3) wraps `createBrowserSession` to refuse that before upstream is called, so the link is not used up, and wraps `revokeSession`, `revokeClientSession`, `revokeOtherSessionsExcept` and `revokeOtherClientSessions` so that ending a device cuts it loose from its person first, and with that from any renewal. On a pin advance: if upstream adds another place that turns a pairing grant into a session, it must go through `j5TiedToPerson`, or the device is one no one has claimed; if upstream reshapes its permissions, update `LEVEL_PERMISSIONS` and the definition (`levelPermissions.test.ts` pins each level's set by upstream's names); if upstream adds a method that ends a session, wrap it in the decorator; if upstream changes `SessionStore.verify`'s order of checks or stops naming a revoked token's session, renewal stops working and must be rethought; if upstream adds a pairing path that issues a session from something other than a pairing grant, record whose its sessions are or narrow them; if upstream changes how it refuses a browser session from another origin, keep `FOREIGN_ORIGIN_DIAGNOSTIC` the message it refuses with; if upstream adds a refresh grant or any other way to renew an MCP client's session under a new id, record the new session as the old one's approver's, or lowering that Owner leaves it live; if upstream stops returning the code in `approve`'s redirect, or issues an MCP client's session other than from `exchangeCode` through `EnvironmentAuth.issueMcpClientSession`, every MCP sign-in is refused (`McpApproval.test.ts` runs upstream's own sign-in through the gate) and the tie must be rethought; if upstream provides `McpOAuth.layer` somewhere else, wrap it there too. 71. An Owner shares from the app ([#535](https://github.com/Jacksondr5/j5code/issues/535), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-12 design and approval of an appended item in the thread menu, and the 2026-10-17 design review of the one Share dialog). The Share dialog (one for a thread, a project and the server), the link step and their state are J5-owned files under `apps/web/src/j5/sharing/`. Upstream's thread action menu (`apps/web/src/hooks/useThreadActionMenu.ts`, already carrying case 69's one call) gains one import and two calls: the list upstream's `buildThreadActionMenuItems` returns is passed through `withSharingMenuItems(items, threadRef)`, and after the menu closes `if (runSharingMenuAction(clicked.value, threadRef)) return;` opens the dialog J5 asked for and keeps J5's ids away from upstream's switch. `withSharingMenuItems` inserts "Share thread…" after "Copy" (disabled on a device without `access:write`, People and access AC34). For someone who is not an Owner of the thread's server it also leaves out Archive, Delete and "Project settings" (AC14, AC27), leaves out "Mark unread" for a Viewer of the thread (the read marker is everyone's, Shared conversations AC19), and puts "Leave thread" where Archive was when they hold a level on the thread itself (AC48). The ids (`j5:share-thread`, `j5:leave-thread`) are outside upstream's `ThreadActionMenuId` union, and `runSharingMenuAction` is the type guard that takes them back out, so upstream's `components/threadActionMenu.logic.ts` is untouched. `apps/web/src/hooks/useThreadActionMenu.test.ts` carries two J5 cases at its end (the item's place, and that picking it reaches none of upstream's actions). Upstream's sidebar builds and handles the same menu itself (`apps/web/src/components/Sidebar.tsx`, the thread row's right-click): one import, the builder wrapped where the list is built, `buildWithSharingMenuItems(buildThreadActionMenuItems, threadRef)({…})`, which leaves upstream's arguments where they are, and the same `if (runSharingMenuAction(clicked.value, threadRef)) return;` after the menu closes. The dialogs are opened from places that render nothing, so `apps/web/src/routes/__root.tsx` mounts J5's `` beside upstream's `` (one import, one line), the way upstream draws its own confirm and custom-snooze dialogs; the host also draws the name question a server asks before a device uses it (AC5, AC6), renews a session ended for a change of level (case 70), tells an Owner once that links made before the move to levels stopped working, and takes someone off a thread no longer theirs. `apps/web/src/components/CommandPalette.tsx` gains one import, one hook call (`useSharingPaletteItems({ activeThread, projectRef: contextualProjectRef })`, beside where `actionItems` is declared) and `actionItems.push(...sharingPaletteItems)` before the "Project settings" entry, for "Share thread", "Share project", "Share server", "Open People" and "Change your name"; the palette searches an entry's `searchTerms` only, so each entry's title is among its terms (Jackson's 2026-10-12 approval). The web menu draws an item's icon from the table in `apps/web/src/contextMenuFallback.ts`, which gains one entry, `users` (lucide's four shapes, six lines and a comment), so that J5's item lines up with its neighbours. `j5/sharing/sharingMenu.ts` and `sharingDialogs.ts` import nothing of React or the connection runtime, because that test mocks `react`. A link always opens on the server itself; the link step's route choice mirrors helpers that are private to upstream's `apps/web/src/components/settings/ConnectionsSettings.tsx` (`selectPairingEndpoint`'s default, `endpointDefaultPreferenceKey`, `endpointShareHint`), copied into J5-owned `j5/sharing/shareLink.logic.ts` with no upstream edit; what upstream already exports (`isQrShareableEndpoint`, `selectQrEndpointOption`, `pairingUrls.ts`, `QRCodeSvg`, the saved default route in `uiStateStore`) is imported. On a pin advance: compare those helpers with upstream's and carry over any change to how a route is picked or described; if upstream moves `api.contextMenu.show(items, position)` in the hook, re-apply the two calls around it, and the same in the sidebar's thread-row menu; if the palette's `actionItems` list or the root's dialog hosts move, re-apply the append and the mount where they went; if upstream renames the "copy", "archive", "delete", "project-settings" or "mark-unread" items, "Share thread…" falls to the end of the menu or an Owner's item shows to someone who is not one, and `sharingMenu.test.ts` still passes, so check both menus in a browser. -72. Settings › People, and Settings for someone who is not an Owner ([#535](https://github.com/Jacksondr5/j5code/issues/535), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-12 design and approval of the Settings navigation and route registration, and his 2026-10-17 ruling that Settings is an Owner's). The page (`apps/web/src/j5/sharing/PeoplePage.tsx`) and everything it draws are J5-owned; `apps/web/src/routes/_chat.settings.people.tsx` is a J5-owned route file in upstream's routes folder, the shape of `_chat.settings.skills.tsx` (case 42), and `routeTree.gen.ts` regenerates with it. Upstream moved Settings under the chat layout at v0.1.3, where it opens as a large modal over the thread (pingdotgg/t3code#24847), so J5's three Settings routes (People, Personas and Skills) moved from `settings.*.tsx` to `_chat.settings.*.tsx` with it. Registering a settings section takes upstream's own tables, each one entry: in `apps/web/src/components/settings/settingsSearch.ts` the `SettingsPath` union, `SETTINGS_SECTION_LABELS`, `SETTINGS_NAV_GROUPS` (People last in the Connections group, after Sharing & access; Personas and Skills first in the Agents group), `SETTINGS_CATEGORY_SCOPES` (`"connections"`) and one search item, `people`; in `SettingsSidebarNav.tsx` the icon map (`UsersIcon`); in `SettingsScopeSentence.tsx` one line adding the path to `SETTINGS_DEVICE_ONLY_PATHS`, since the page has its own server picker, and one more adding Open-source licenses, which is the same for every server and which a non-Owner sees, so it shows no server picker. Settings is an Owner's (AC27 to AC29), by four calls into J5-owned `j5/sharing/settingsAccess.tsx`, each one import and one or two lines. `SettingsSidebarNav.tsx` builds its groups through `useSettingsNavGroups(SETTINGS_NAV_GROUPS)` in place of upstream's groups, and highlights a page that list names before upstream's detail-page parent: for someone who owns no connected server it keeps only the pages in `PAGES_FOR_EVERYONE` (Appearance, SnapShots, People and Open-source licenses) and adds Open-source licenses, which upstream reaches only from About, as a group of its own (a `SettingsPath`, `/settings/open-source-licenses`, with its label, icon and scope). `useAvailableSettingsSearchItems.ts` returns `useShownSettingsSearchItems(items)`, so search finds the same pages, in the sidebar and the command palette alike. `apps/web/src/routes/_chat.settings.tsx` (upstream's `routes/settings.tsx` until v0.1.3) wraps upstream's `SettingsScopeBoundary` and the `` in ``, which shows that person a "Coming soon" notice in place of any other page, one upstream adds later among them, so a link to one (a thread's "Manage scheduled tasks") still lands; the gate is outside the boundary because a server the person does not own leaves the boundary's scope unavailable. `SettingsScopeContext.tsx` and `SettingsScopeSentence.tsx` read their servers through `useOwnedEnvironments(useEnvironments().environments)`, and `useSettingsProjectGroups.ts` its projects through `useOwnedEnvironments(useProjects())`, so Settings lists and changes only the servers and projects the person owns, in the scope picker and the project panel alike; upstream applies a change to every listed server and greys a row unless all of them allow it. Upstream's `ProjectSettingsPanel.browser.test.tsx` mocks `useOwnedEnvironments` as owning every listed server, since ownership is not what it tests. J5's Fleet page and inbox, which name a project from any server, group every server's projects themselves (`j5/logicalProjects.ts`). A server that has not answered yet counts as owned, so an Owner's Settings does not flicker. J5's own Settings pages (Personas, Playbooks, Skills) list only owned servers the same way. The project page carries no Sharing section (AC34). On a pin advance: if upstream reshapes how a settings section is declared, re-register People in the Connections group; if upstream resolves Settings' servers anywhere besides those two files, filter it there too, or a server the person does not own greys out their Settings; if upstream renames the Appearance or SnapShots path, update `PAGES_FOR_EVERYONE` (its test pins the list); if upstream adds a settings page of its own for people or access, read D33 before keeping J5's. +72. Settings › People, and Settings for someone who is not an Owner ([#535](https://github.com/Jacksondr5/j5code/issues/535), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-12 design and approval of the Settings navigation and route registration, and his 2026-10-17 ruling that Settings is an Owner's). The page (`apps/web/src/j5/sharing/PeoplePage.tsx`) and everything it draws are J5-owned; `apps/web/src/routes/_chat.settings.people.tsx` is a J5-owned route file in upstream's routes folder, the shape of `_chat.settings.skills.tsx` (case 42), and `routeTree.gen.ts` regenerates with it. Upstream moved Settings under the chat layout at v0.1.3, where it opens as a large modal over the thread (pingdotgg/t3code#24847), so J5's three Settings routes (People, Personas and Skills) moved from `settings.*.tsx` to `_chat.settings.*.tsx` with it. Registering a settings section takes upstream's own tables, each one entry: in `apps/web/src/components/settings/settingsSearch.ts` the `SettingsPath` union, `SETTINGS_SECTION_LABELS`, `SETTINGS_NAV_GROUPS` (People last in the Connections group, after Sharing & access; Personas and Skills first in the Agents group), `SETTINGS_CATEGORY_SCOPES` (`"connections"`) and one search item, `people`; in `SettingsSidebarNav.tsx` the icon map (`UsersIcon`); in `SettingsScopeSentence.tsx` one line adding the path to `SETTINGS_DEVICE_ONLY_PATHS`, since the page has its own server picker, and one more adding Open-source licenses, which is the same for every server and which a non-Owner sees, so it shows no server picker. Settings is an Owner's (AC27 to AC29), by four calls into J5-owned `j5/sharing/settingsAccess.tsx`, each one import and one or two lines. `SettingsSidebarNav.tsx` builds its groups through `useSettingsNavGroups(SETTINGS_NAV_GROUPS)` in place of upstream's groups, and highlights a page that list names before upstream's detail-page parent: for someone who owns no connected server it keeps only the pages in `PAGES_FOR_EVERYONE` (Appearance, SnapShots, People and Open-source licenses) and adds Open-source licenses, which upstream reaches only from About, as a group of its own (a `SettingsPath`, `/settings/open-source-licenses`, with its label, icon and scope). `useAvailableSettingsSearchItems.ts` returns `useShownSettingsSearchItems(items)`, so search finds the same pages, in the sidebar and the command palette alike. `apps/web/src/routes/_chat.settings.tsx` (upstream's `routes/settings.tsx` until v0.1.3) wraps upstream's `SettingsScopeBoundary` and the `` in ``, which shows that person a "Coming soon" notice in place of any other page, one upstream adds later among them, so a link to one (a thread's "Manage scheduled tasks") still lands; the gate is outside the boundary because a server the person does not own leaves the boundary's scope unavailable. `SettingsScopeContext.tsx` and `SettingsScopeSentence.tsx` read their servers through `useOwnedEnvironments(useEnvironments().environments)`, and `useSettingsProjectGroups.ts` its projects through `useOwnedEnvironments(useProjects())`, so Settings lists and changes only the servers and projects the person owns, in the scope picker and the project panel alike; upstream applies a change to every listed server and greys a row unless all of them allow it. Upstream's `ProjectSettingsPanel.browser.test.tsx` mocks `useOwnedEnvironments` as owning every listed server, since ownership is not what it tests. J5's Fleet page and inbox, which name a project from any server, group every server's projects themselves (`j5/logicalProjects.ts`). A server that has not answered yet counts as owned, so an Owner's Settings does not flicker. J5's own Settings pages (Personas, Playbooks, Skills) list only owned servers the same way. The project page carries no Sharing section (AC34). On a pin advance: if upstream reshapes how a settings section is declared, re-register People in the Connections group; if upstream resolves Settings' servers anywhere besides those two files, filter it there too, or a server the person does not own greys out their Settings; if upstream renames the Appearance or SnapShots path, update `PAGES_FOR_EVERYONE` (its test pins the list); if upstream adds a settings page of its own for people or access, read D33 before keeping J5's. Mobile follows the same rule ([#831](https://github.com/Jacksondr5/j5code/issues/831)) through three calls into J5-owned `apps/mobile/src/j5/sharing/settingsAccess.tsx`, each one import and one or two lines: `features/settings/SettingsRouteScreen.tsx` passes the index's sections through `useShownSettingsSections`, so for someone who owns no connected server only the device's own pages are listed (`PAGES_FOR_EVERYONE` in `settingsAccess.logic.ts`, by route name: look and input, saved servers, notifications, About and what it opens) and search finds only those; `features/settings/components/SettingsScreen.tsx`, the frame of nearly every Settings page, renders its children through `useOwnerOnlySettingsPage(route.name, …)`, which puts the same "Coming soon" notice in place of any other Settings page reached by a link, the command palette or a thread's "Manage scheduled tasks"; `features/settings/settings-environment-filter.tsx` reads its servers through `useOwnedSettingsTargets`, so mobile Settings lists and changes only the servers the person owns; and `Stack.tsx` registers Archive, the one Settings page drawn without `SettingsScreen`, as `ownerOnlySettingsRoute(ArchivedThreadsRouteScreen, "Archive")` (J5-owned `j5/sharing/ownerOnlySettingsRoute.tsx`), which for that person mounts an empty `SettingsScreen` in its place, so the notice shows under Archive's header and the archive is never read. For an Owner, `features/archive/ArchivedThreadsRouteScreen.tsx` passes its saved servers through `useOwnedSettingsTargets` (upstream's list renamed `savedEnvironments`, and one line), so Archive lists, reads and acts on only the servers they own, as web's Archive does through its Settings scope. Mobile's Personas and Playbooks pages list owned servers the same way, and a thread's Playbook progress is read by anyone who reads the thread, as on web. On a pin advance: if upstream renames a mobile Settings route that is the device's own, update `PAGES_FOR_EVERYONE`; if upstream draws another Settings page without `SettingsScreen`, register it through `ownerOnlySettingsRoute` too, or it is not gated. 73. A thread says who reaches it, and the client fits what a person's level lets them do ([#535](https://github.com/Jacksondr5/j5code/issues/535), [#541](https://github.com/Jacksondr5/j5code/issues/541), [#636](https://github.com/Jacksondr5/j5code/issues/636), register D33, Jackson's 2026-10-12 design and approval of one mount or item in each of these files, and his 2026-10-13 approvals of the route files and of the two edits that quiet what could only fail). All of it is J5-owned code under `apps/web/src/j5/sharing/`, mounted once in each upstream file, and it reads what the server says the connection is (`j5.access.getConnectionAccess`, read again when people or levels change) and the level it holds over each thread (`j5.access.subscribeThreadLevel`). `apps/web/src/components/chat/ChatHeader.tsx`: one import and `` after the breadcrumb, for a server thread; it draws nothing unless more than one person reaches the thread. `apps/web/src/components/chat/ThreadDetailsPanel.tsx`: one import and `` after `ThreadRelationshipsPanel`, under the same `density === "full" && !props.draftId` condition as its neighbours; and `const readOnly = !useCanOperateThread(…)` with `&& !readOnly` on the condition that mounts upstream's `ThreadAutomationsPanel`, so a Viewer of the thread sees no Automations. `apps/web/src/components/chat/ChatComposer.tsx`: one import, one hook call after the props are read (`useViewOnlyComposerProps(environmentId, canOperateThread)`), and one spread, `{...viewOnlyComposerProps}`, after upstream's `placeholder={…}` prop, so that someone who is not an Owner and cannot write to the thread reads "You can read this thread, but not send anything to it."; the collapsed composer's fallback literal becomes `(viewOnlyComposerProps.placeholder ?? "Ask anything...")`. The chip and the section ask the server who reaches the thread (`j5.people.listScope`) and ask again when its counter moves (`j5.people.subscribeScopeChanges`). Two route files carry a person's way in. `apps/web/src/routes/pair.tsx`: the import of upstream's `PairingRouteSurface` becomes J5's `JoinLinkPairingSurface`, and the JSX tag changes with it (three lines; upstream's `components/auth/PairingRouteSurface.tsx` is not edited). J5's surface asks `POST /api/j5/links/describe` what a link opens, without spending it, only for a link that carries J5's mark, and waits up to five seconds; everything else gets upstream's surface with the props it was given, and an ordinary pairing token is sent nowhere but upstream's own exchange. The person confirms or types their name and joins on `POST /api/j5/links/join`, which answers with an upstream pairing credential the page exchanges at once. The Share dialog puts the mark, `j5share=1`, in the fragment beside upstream's `token`; upstream reads the fragment as parameters and takes only `token`. `apps/web/src/routes/_chat.index.tsx`: one import, and `` is wrapped in ``, which renders its child at once for anyone at server scope and before the server answers, and for someone who reaches less shows their one thread, a list, or that nothing is shared with them (AC30). `apps/web/src/routes/__root.tsx`: one import, one hook call beside `primaryEnvironmentAuthenticated`, `useFirstRunSetupOffered(primaryEnvironmentAuthenticated)`, and `FirstRunGate`'s `enabled` reads its answer: the wizard is offered only to an Owner of the primary server the server has a name for, by that server's answer, so the name is asked first (AC6), and upstream's gate decides again when the answer arrives; a failed or missing answer offers nothing. `apps/web/src/routes/welcome.tsx`, the wizard's own address, gains one import and two lines before its return, `const setupRefusal = useSetupWizardRefusal(localAvailable); if (setupRefusal !== null) return setupRefusal;`, which draws nothing until the primary server answers and then sends anyone the wizard is not offered to to the first screen, where the name is asked; the hosted app, with no server of its own, is left to upstream. `apps/web/src/components/Sidebar.tsx`: one import, `const isNarrowEverywhere = useIsNarrowEverywhere()` beside the primary environment's id, and `&& !isNarrowEverywhere` on the empty list's `projects.length === 0` condition, so someone who reaches no whole server reads upstream's "No threads yet" in place of an "Add project" button that could only fail. One more quiets an upstream notice a person sees fail (J5-owned `apps/web/src/j5/sharing/upstreamNotices.ts`; Jackson's standing permission on this workstream for one import and one or two lines, used 2026-10-18): `apps/web/src/components/PermissionUpdateNotice.ts` (one import and one condition) lists in `legacyPermissionEnvironmentsAtom` only the servers J5's `permissionNoticeEnvironmentIdsAtom` names, which leaves out a server that places the connection as a person or a device it will ask about, and one that has not answered yet, as J5 sets and renews those permissions from the person's level, so "Pair again" never applies. Mobile's copy of the notice gets the same condition ([#831](https://github.com/Jacksondr5/j5code/issues/831)): `apps/mobile/src/features/connection/permissionUpdateNotice.ts` (one import and one condition) reads J5-owned `apps/mobile/src/j5/sharing/upstreamNotices.ts`, and the rule, `permissionNoticeApplies`, now lives once in `packages/client-runtime/src/j5/sharing.ts` for both clients. Upstream turned the notice from a component (`PermissionUpdateNotice.tsx`) into an atom and a coordinator that starts with the app at v0.1.3 (pingdotgg/t3code#25233), so J5's hook became that atom. The second, which showed upstream's provider updates notice only to a connection holding Manage providers, retired at the 2026-10-24 advance with the notice itself: upstream deleted `ProviderUpdateLaunchNotification` (pingdotgg/t3code#23233). Upstream also replaced `PermissionUpdateNotice`'s jsdom test, where J5 mocked the hook, with a browser test J5 does not edit. On a pin advance: if upstream moves the composer's `placeholder` prop, keep the spread after it; if upstream renames `legacyPermissionEnvironmentsAtom`, filter the notice's servers where they moved; if upstream reorders the details panel, keep People after Lineage and the condition on the Automations mount; if upstream changes how a pairing address carries its token, or starts to refuse a fragment it does not know, reread `SHARE_LINK_MARK` in J5-owned `packages/contracts/src/j5/sharing.ts`; if upstream renames `PairingRouteSurface` or changes its props, J5's surface fails to compile; if upstream's index route stops rendering `IndexDraftLanding`, re-wrap whatever it renders; if upstream renames `FirstRunGate`'s `enabled`, or decides first run before `enabled` can change, someone who is not an Owner may be offered the wizard. 74. An agent's browser tab is private unless it names a profile (register D34, Jackson's 2026-10-13 decision). Upstream's `resolveOpenProfile` in `apps/server/src/preview/ServerBrowser.ts` gives a `preview_open` call without a `profileId` the person's default profile, whose stored state every agent tab on the server shares. J5 changes that one return to `INCOGNITO_BROWSER_PROFILE_ID`, which the file already imports, so the tab gets its own throwaway storage through upstream's existing incognito path. A named profile resolves as upstream's does. The description of `preview_open`'s `profileId` changes one clause to say what omitting it now means ("Omit for a private tab whose storage no other tab shares."); since stable v0.1.3 upstream keeps that field description in `packages/contracts/src/previewAutomation.ts`, and `apps/server/src/mcp/toolkits/preview/tools.ts` is upstream's file again. `ServerBrowser.test.ts` changes one test's expectations and title and adds one J5 test, an agent tab that is private when no client reported profiles. On a pin advance, keep the return and the description clause; if upstream makes agent tabs private by default, take upstream's and retire this case and D34. 75. Highlights, a client's "What's new" ([#624](https://github.com/Jacksondr5/j5code/issues/624), register D35, Jackson's 2026-10-17 decision and design). The entries, the client filter and the rule for what is new are J5-owned `packages/client-runtime/src/j5/highlights.ts`, reached through the `./j5/highlights` export this case appends to upstream-owned `packages/client-runtime/package.json`; the web button, list, art, seen record and palette entry are J5-owned files under `apps/web/src/j5/highlights/`. Four upstream files are touched. `apps/web/src/components/sidebar/SidebarChrome.tsx`: `SidebarUtilityMenu`'s `SidebarMenu` gains the class `@container/utility`, which the button's container query reads to hide itself where the row is too narrow, and `` is mounted immediately before `` (one import, one line). The button's item carries `ms-auto` and cancels the update button's own `ms-auto` with `[&+li]:ms-0`, so the two sit together at the end of the row. `apps/web/src/components/AppSidebarLayout.tsx` mounts `` after upstream's ``, the last child of its `SidebarProvider` (one import, one line; upstream dropped `MainAppLocationTracker`, beside which it sat, at v0.1.3): the palette sits outside the sidebar provider, and this helper leaves a utility page and opens a collapsed sidebar when the palette asks for the list. `apps/web/src/components/CommandPalette.tsx` gains one import and appends J5's `HIGHLIGHTS_PALETTE_ITEMS` to case 71's `actionItems.push(...)`. `apps/web/src/onboarding/firstRun.ts`: `completeOnboarding`, which every path that finishes first run calls (the wizard, the gate's silent completion for a client on an existing workspace, and hosted mode), calls `markAllHighlightsSeen()` before it writes `onboardingCompletedAt` (one import, one call). A finished client with no record is then an existing one, and the order makes that hold whenever the highlights code first reads it. On a pin advance: if upstream moves the utility row, the update button or the `SidebarProvider`'s children, re-apply the mounts where they went; if upstream adds another writer of `onboardingCompletedAt`, it needs the same call before it; if upstream's palette `actionItems` moves, re-apply the append as in case 71. @@ -726,6 +726,11 @@ explicitly marked. | `apps/mobile/src/features/threads/NewTaskDraftScreen.tsx` | A | 45, Saved-agent mentions | | `apps/mobile/src/features/threads/ThreadDetailScreen.tsx` | A | 45, 49 | | `apps/mobile/src/features/threads/ThreadRouteScreen.tsx` | A | 69, 99 | +| `apps/mobile/src/features/settings/SettingsRouteScreen.tsx` | A | 72, Role library | +| `apps/mobile/src/features/settings/components/SettingsScreen.tsx` | N | 72 | +| `apps/mobile/src/features/settings/settings-environment-filter.tsx` | N | 72 | +| `apps/mobile/src/Stack.tsx` | A | 72, Role library | +| `apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx` | N | 72 | | `apps/mobile/src/features/threads/new-task-flow-provider.tsx` | A | 45 | | `apps/mobile/src/features/threads/use-composer-command-menu.ts` | A | 45, 49 | | `apps/mobile/src/features/threads/use-composer-command-menu.test.ts` | A | 45, 49 | diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 0a02e244ac0b5..9412a9dafa237 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -41,6 +41,7 @@ import { type RenderFailureProps, } from "./components/RenderErrorBoundary"; import { ArchivedThreadsRouteScreen } from "./features/archive/ArchivedThreadsRouteScreen"; +import { ownerOnlySettingsRoute } from "./j5/sharing/ownerOnlySettingsRoute"; import { useAgentNotificationNavigation } from "./features/agent-awareness/notificationNavigation"; import { ConnectOnboardingRouteScreen } from "./features/cloud/ConnectOnboardingRouteScreen"; import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardingNavigation"; @@ -323,7 +324,8 @@ const SETTINGS_SCREENS = { }, }), SettingsArchive: createNativeStackScreen({ - screen: ArchivedThreadsRouteScreen, + // J5: Archive is an Owner's page (FORK.md case 72). + screen: ownerOnlySettingsRoute(ArchivedThreadsRouteScreen, "Archive"), linking: "settings/archive", options: { ...SETTINGS_PAGE_OPTIONS, diff --git a/apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx b/apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx index 9ad4790faab15..5f7acd69637f2 100644 --- a/apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx +++ b/apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx @@ -5,6 +5,7 @@ import { useFocusEffect } from "@react-navigation/native"; import { useCallback, useMemo, useState } from "react"; import { useSavedRemoteConnections } from "../../state/use-remote-environment-registry"; +import { useOwnedSettingsTargets } from "../../j5/sharing/settingsAccess"; import { useArchivedThreadListActions } from "../home/useThreadListActions"; import { ArchivedThreadsScreen, @@ -21,7 +22,7 @@ export function ArchivedThreadsRouteScreen() { const [searchQuery, setSearchQuery] = useState(""); const [selectedEnvironmentId, setSelectedEnvironmentId] = useState(null); const [sortOrder, setSortOrder] = useState("newest"); - const environments = useMemo>( + const savedEnvironments = useMemo>( () => Arr.sort( Object.values(savedConnectionsById).map((connection) => ({ @@ -34,6 +35,8 @@ export function ArchivedThreadsRouteScreen() { ), [savedConnectionsById], ); + // J5: Archive manages only the servers the person owns (FORK.md case 72). + const environments = useOwnedSettingsTargets(savedEnvironments); const environmentIds = useMemo( () => environments.map((environment) => environment.environmentId), [environments], diff --git a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx index 61e818d06b501..d0985db824b5b 100644 --- a/apps/mobile/src/features/settings/SettingsRouteScreen.tsx +++ b/apps/mobile/src/features/settings/SettingsRouteScreen.tsx @@ -40,6 +40,7 @@ import { } from "./components/SettingsEnvironmentFilterHeader"; import { useSettingsEnvironmentFilter } from "./settings-environment-filter"; import { filterSettingsSections } from "./settings-search"; +import { useShownSettingsSections } from "../../j5/sharing/settingsAccess"; import { NativePrimaryColumnContext } from "../../native/v5-workspace-context"; export function SettingsRouteScreen() { @@ -164,7 +165,11 @@ function SettingsList(props: { readonly connections: readonly SettingsListRow[] const overflowRows = useOverflowRows(); const indexSections = useSettingsIndexSections(); const sections = filterSettingsSections( - [{ rows: overflowRows }, { title: "Connections", rows: props.connections }, ...indexSections], + useShownSettingsSections([ + { rows: overflowRows }, + { title: "Connections", rows: props.connections }, + ...indexSections, + ]), query, ); diff --git a/apps/mobile/src/features/settings/components/SettingsScreen.tsx b/apps/mobile/src/features/settings/components/SettingsScreen.tsx index 74a749ed24d49..8cbb37cc31066 100644 --- a/apps/mobile/src/features/settings/components/SettingsScreen.tsx +++ b/apps/mobile/src/features/settings/components/SettingsScreen.tsx @@ -9,6 +9,7 @@ import { useWorkspaceTabs } from "../../workspace/WorkspaceTabsContext"; import { useWorkspaceSurface } from "../../workspace/useWorkspaceSurface"; import { useDeviceType } from "../../../native/native-layout-metrics"; import { useCompactWorkspaceTabs } from "../../workspace/useSystemWorkspaceTabBar"; +import { useOwnerOnlySettingsPage } from "../../../j5/sharing/settingsAccess"; import { ScreenScrollViewBottomInset, ScreenScrollViewSurface, @@ -30,6 +31,8 @@ export function SettingsScreen( const deviceType = useDeviceType(); const compactTabs = useCompactWorkspaceTabs(); const cover = deviceType === "duo-folded"; + // J5: an Owner's page shows a notice to someone who owns no server (FORK.md case 72). + const children = useOwnerOnlySettingsPage(route.name, props.children); // Android opens Settings as a workspace tab; its root page has nothing to go back to. const workspaceRoot = props.workspaceRoot || @@ -52,11 +55,7 @@ export function SettingsScreen( /> - {props.formSheet ? ( - props.children - ) : ( - {props.children} - )} + {props.formSheet ? children : {children}} diff --git a/apps/mobile/src/features/settings/settings-environment-filter.tsx b/apps/mobile/src/features/settings/settings-environment-filter.tsx index eddfea1795044..1cc9d55b3465d 100644 --- a/apps/mobile/src/features/settings/settings-environment-filter.tsx +++ b/apps/mobile/src/features/settings/settings-environment-filter.tsx @@ -16,6 +16,7 @@ import { useEnvironments, type EnvironmentPresentation } from "../../state/envir import { useProjects } from "../../state/entities"; import { useMobileProjectGroupingSettings } from "../../state/project-grouping"; import { toggleSettingsEnvironment } from "./settings-environment-filter.logic"; +import { useOwnedSettingsTargets } from "../../j5/sharing/settingsAccess"; export type SettingsTarget = EnvironmentPresentation & { readonly serverConfig: NonNullable; @@ -120,7 +121,8 @@ export function useSettingsEnvironmentFilter() { const groupingSettings = useMobileProjectGroupingSettings(); const groupingMode = groupingSettings.sidebarProjectGroupingMode; const projectGroups = settingsProjectGroups(projects, groupingMode); - const availableTargets = connectedSettingsTargets(environments); + // J5: Settings manages only the servers the person owns (FORK.md case 72). + const availableTargets = useOwnedSettingsTargets(connectedSettingsTargets(environments)); const selectedTargets = useMemo( () => availableTargets.filter( diff --git a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx index 2cd21338e65a2..d2463f695c286 100644 --- a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx @@ -1,8 +1,5 @@ -import { - GUEST_LIBRARY_UNAVAILABLE, - useGuestEnvironmentIds, - useIsGuestEverywhere, -} from "../sharing/guestAccess"; +import { LIBRARY_FOR_OWNERS } from "@t3tools/client-runtime/j5/sharing"; +import { useOwnedEnvironmentIds, useOwnerSomewhere } from "../sharing/guestAccess"; import { AgentLibraryToast, type AgentLibraryNotification } from "./AgentLibraryToast"; import { AgentImportConflictModal } from "./AgentImportConflictModal"; import { AgentCreateModal } from "./AgentCreateModal"; @@ -49,24 +46,24 @@ import { SettingsSection } from "../../features/settings/components/SettingsSect import { PlaybookLibrarySettingsSection } from "../playbooks/PlaybookLibrarySettingsScreen"; export function AgentLibrarySettingsScreen() { - // A guest is not offered a server's Personas or Playbooks (Shared server AC24). - return useIsGuestEverywhere() ? ( + // Personas and Playbooks are managed by a server's Owners (People and access AC27). + return useOwnerSomewhere() === false ? ( - + ) : ( - + ); } -function MemberAgentLibrarySettingsScreen() { +function OwnerAgentLibrarySettingsScreen() { const navigation = useNavigation(); const insets = useSafeAreaInsets(); const { connectedEnvironments: connected } = useRemoteConnectionStatus(); - const guestEnvironmentIds = useGuestEnvironmentIds(); + const ownedEnvironmentIds = useOwnedEnvironmentIds(); const connectedEnvironments = useMemo( - () => connected.filter((environment) => !guestEnvironmentIds.has(environment.environmentId)), - [connected, guestEnvironmentIds], + () => connected.filter((environment) => ownedEnvironmentIds.has(environment.environmentId)), + [connected, ownedEnvironmentIds], ); const [selectedEnvironmentId, setSelectedEnvironmentId] = useState(null); const effectiveEnvironmentId = connectedEnvironments.some( diff --git a/apps/mobile/src/j5/playbooks/PlaybookComposerControl.tsx b/apps/mobile/src/j5/playbooks/PlaybookComposerControl.tsx index c5bf808c612cf..227684ce67702 100644 --- a/apps/mobile/src/j5/playbooks/PlaybookComposerControl.tsx +++ b/apps/mobile/src/j5/playbooks/PlaybookComposerControl.tsx @@ -19,7 +19,6 @@ import { useEnvironmentQuery } from "../../state/query"; import { useRemoteEnvironmentRuntime } from "../../state/use-remote-environment-registry"; import { j5Environment } from "../state"; import { usePlaybookRefresh } from "./usePlaybookRefresh"; -import { useGuestEnvironmentIds } from "../sharing/guestAccess"; export function PlaybookComposerControl(props: { environmentId: EnvironmentId; @@ -28,10 +27,9 @@ export function PlaybookComposerControl(props: { const focused = useIsFocused(); const runtime = useRemoteEnvironmentRuntime(props.environmentId); const thread = useThreadShell(scopeThreadRef(props.environmentId, props.threadId)); - // A guest is shown none of a server's Playbooks (Shared server AC24), so none is read. - const guest = useGuestEnvironmentIds().has(props.environmentId); + // A thread's Playbook runs are part of the thread, so anyone who reads it reads them. const serverConfig = useEnvironmentServerConfig(props.environmentId); - const supported = !guest && j5LedgerSupported(serverConfig) !== false; + const supported = j5LedgerSupported(serverConfig) !== false; const query = useEnvironmentQuery( supported ? j5Environment.playbooks({ diff --git a/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx b/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx index 924177dfa4d9f..7e52fb87d0620 100644 --- a/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx @@ -14,7 +14,7 @@ import { useEnvironmentQuery } from "../../state/query"; import { useAtomCommand } from "../../state/use-atom-command"; import { useRemoteConnectionStatus } from "../../state/use-remote-environment-registry"; import { AgentFolderPickerModal } from "../agents/AgentFolderPickerModal"; -import { useGuestEnvironmentIds } from "../sharing/guestAccess"; +import { useOwnedEnvironmentIds } from "../sharing/guestAccess"; import { j5Environment } from "../state"; import { PlaybookConversationModal } from "./PlaybookConversationModal"; @@ -24,8 +24,9 @@ export function PlaybookLibrarySettingsSection({ environmentId: EnvironmentId | null; }) { const { connectedEnvironments } = useRemoteConnectionStatus(); - const guests = useGuestEnvironmentIds(); - const environments = connectedEnvironments.filter((entry) => !guests.has(entry.environmentId)); + // Playbooks are managed on the servers the person owns (People and access AC27). + const owned = useOwnedEnvironmentIds(); + const environments = connectedEnvironments.filter((entry) => owned.has(entry.environmentId)); const environment = environments.find((entry) => entry.environmentId === environmentId); return environment ? ( { - const ids = new Set(); - for (const id of get(environmentCatalog.catalogValueAtom).entries.keys()) { - if (get(j5Sharing.isNarrow(id))) ids.add(id); - } - return ids as ReadonlySet; +const ownership = createSharingOwnershipAtoms({ + catalogValueAtom: environmentCatalog.catalogValueAtom, + sharing: j5Sharing, }); /** - * The servers whose Personas and Playbooks are not this person's to see or use (Shared server - * AC24). J5's own pages leave these servers out, and say so when there is no other server. + * The connected servers this person owns, which are the ones Settings, Personas and Playbooks + * manage (People and access AC27). One that has not answered yet is counted, so an Owner's page + * does not flicker. */ -export function useGuestEnvironmentIds(): ReadonlySet { - return useAtomValue(guestEnvironmentIdsAtom); +export function useOwnedEnvironmentIds(): ReadonlySet { + return useAtomValue(ownership.ownedEnvironmentIds); } -/** What J5's Personas and Playbooks pages say when every connected server is a guest one. */ -export const GUEST_LIBRARY_UNAVAILABLE = - "Personas and Playbooks are not available on a server you are a guest on."; +/** Whether the person owns a connected server, or `"loading"`; see `ownerSomewhereState`. */ +export function useOwnerSomewhere(): boolean | "loading" { + return useAtomValue(ownership.ownerSomewhere); +} -/** Whether there is at least one server and this person is a guest on all of them. */ -export function useIsGuestEverywhere(): boolean { - const guests = useAtomValue(guestEnvironmentIdsAtom); - const total = useAtomValue(environmentCatalog.catalogValueAtom).entries.size; - return total > 0 && guests.size === total; +/** Whether the person can write to anything on a connected server, so has an agent to ask. */ +export function useWritesSomewhere(): boolean { + return useAtomValue(ownership.writesSomewhere); } diff --git a/apps/mobile/src/j5/sharing/ownerOnlySettingsRoute.tsx b/apps/mobile/src/j5/sharing/ownerOnlySettingsRoute.tsx new file mode 100644 index 0000000000000..3eb4b164796bb --- /dev/null +++ b/apps/mobile/src/j5/sharing/ownerOnlySettingsRoute.tsx @@ -0,0 +1,23 @@ +import { useRoute } from "@react-navigation/native"; +import type { ComponentType } from "react"; + +import { SettingsScreen } from "../../features/settings/components/SettingsScreen"; +import { useOwnerSomewhere } from "./guestAccess"; +import { settingsPageShown } from "./settingsAccess.logic"; + +/** + * A Settings route whose page is drawn without upstream's `SettingsScreen` (Archive): for someone + * who owns no connected server it draws an empty `SettingsScreen`, whose gate puts the notice + * under the page's own header, and the page itself, with its reads, is never mounted. + */ +export function ownerOnlySettingsRoute(Screen: ComponentType, title: string): ComponentType { + function OwnerOnlySettingsRoute() { + const routeName = useRoute().name; + return settingsPageShown(routeName, useOwnerSomewhere()) ? ( + + ) : ( + {null} + ); + } + return OwnerOnlySettingsRoute; +} diff --git a/apps/mobile/src/j5/sharing/settingsAccess.logic.test.ts b/apps/mobile/src/j5/sharing/settingsAccess.logic.test.ts new file mode 100644 index 0000000000000..2a0b83be3d3c0 --- /dev/null +++ b/apps/mobile/src/j5/sharing/settingsAccess.logic.test.ts @@ -0,0 +1,32 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { settingsPageShown } from "./settingsAccess.logic"; + +describe("which Settings pages someone who owns no connected server sees", () => { + it("shows the pages about the device itself", () => { + for (const page of [ + "Settings", + "SettingsAppearance", + "SettingsEnvironments", + "SettingsAbout", + ]) { + expect(settingsPageShown(page, false), page).toBe(true); + } + }); + + it("withholds a server's pages, and any Settings page not listed as the device's", () => { + for (const page of ["SettingsProviderAccounts", "SettingsScheduledTasks", "SettingsAgents"]) { + expect(settingsPageShown(page, false), page).toBe(false); + } + expect(settingsPageShown("SettingsSomethingNew", false)).toBe(false); + }); + + it("withholds nothing from an Owner, or while the servers are still answering", () => { + expect(settingsPageShown("SettingsProviderAccounts", true)).toBe(true); + expect(settingsPageShown("SettingsProviderAccounts", "loading")).toBe(true); + }); + + it("leaves screens outside Settings alone", () => { + expect(settingsPageShown("Thread", false)).toBe(true); + }); +}); diff --git a/apps/mobile/src/j5/sharing/settingsAccess.logic.ts b/apps/mobile/src/j5/sharing/settingsAccess.logic.ts new file mode 100644 index 0000000000000..6a0b82b897ea8 --- /dev/null +++ b/apps/mobile/src/j5/sharing/settingsAccess.logic.ts @@ -0,0 +1,37 @@ +/** + * Mobile's Settings pages about the device itself, shown to everyone (People and access AC28): + * its look and input, its saved servers and notifications, and About. Every other Settings page + * is an Owner's, so a page upstream adds later is shown to Owners only until someone decides + * otherwise, as on web. + */ +const PAGES_FOR_EVERYONE: ReadonlySet = new Set([ + "Settings", + "SettingsOrganization", + "SettingsProjectGrouping", + "SettingsAppearance", + "SettingsFollowUp", + "SettingsNavigation", + "SettingsKeyboard", + "SettingsMicrophone", + "SettingsNotifications", + "SettingsEnvironments", + "SettingsEnvironmentDetail", + "SettingsEnvironmentNew", + "SettingsAuth", + "SettingsWaitlist", + "SettingsAbout", + "SettingsClientStorage", + "SettingsDiagnostics", + "SettingsOpenSourceLicenses", + "SettingsOpenSourceLicense", + "SettingsLegal", +]); + +/** + * Whether a screen is shown, by its route name. Only an answer withholds one: while servers are + * still answering, an Owner's page stays, and the server refuses what is not theirs to read. + */ +export const settingsPageShown = (routeName: string, ownerSomewhere: boolean | "loading") => + ownerSomewhere !== false || + !routeName.startsWith("Settings") || + PAGES_FOR_EVERYONE.has(routeName); diff --git a/apps/mobile/src/j5/sharing/settingsAccess.tsx b/apps/mobile/src/j5/sharing/settingsAccess.tsx new file mode 100644 index 0000000000000..2f4bc1dc84f14 --- /dev/null +++ b/apps/mobile/src/j5/sharing/settingsAccess.tsx @@ -0,0 +1,64 @@ +import { useAtomValue } from "@effect/atom-react"; +import { ownerOnlySettingsNotice } from "@t3tools/client-runtime/j5/sharing"; +import type { EnvironmentId } from "@t3tools/contracts"; +import { type ReactNode, useMemo } from "react"; + +import { EmptyState } from "../../components/ui/EmptyState"; +import { environmentPresentations } from "../../state/presentation"; +import { useOwnedEnvironmentIds, useOwnerSomewhere, useWritesSomewhere } from "./guestAccess"; +import { settingsPageShown } from "./settingsAccess.logic"; + +/** + * Settings' index as this person sees it: a row that opens a page they are not shown is left out, + * and so is a group left empty. Rows that open nothing, such as the account row, stay. + */ +export function useShownSettingsSections< + Section extends { readonly rows: ReadonlyArray<{ readonly target?: string }> }, +>(sections: ReadonlyArray
): ReadonlyArray
{ + const ownerSomewhere = useOwnerSomewhere(); + if (ownerSomewhere !== false) return sections; + return sections + .map((section) => ({ + ...section, + rows: section.rows.filter( + (row) => row.target === undefined || settingsPageShown(row.target, ownerSomewhere), + ), + })) + .filter((section) => section.rows.length > 0); +} + +/** + * A Settings page's content, or, for someone who owns no connected server and reaches an Owner's + * page by a link, the command palette or its address, a notice in its place (AC29). + */ +export function useOwnerOnlySettingsPage(routeName: string, children: ReactNode): ReactNode { + const ownerSomewhere = useOwnerSomewhere(); + if (settingsPageShown(routeName, ownerSomewhere)) return children; + return ; +} + +function OwnerOnlySettingsNotice() { + const presentations = useAtomValue(environmentPresentations.presentationsAtom); + // With one saved server the notice names it; with several, it can't tell which one is meant. + const only = presentations.size === 1 ? [...presentations.values()][0] : undefined; + const notice = ownerOnlySettingsNotice({ + serverName: only?.entry.target.label ?? null, + writesSomewhere: useWritesSomewhere(), + }); + return ; +} + +/** + * The servers Settings manages: only those the person owns (AC27). Upstream applies a change to + * every selected server and disables a row unless all of them allow it, so a server the person + * does not own would grey out an Owner's Settings for the servers that are theirs. + */ +export function useOwnedSettingsTargets( + targets: ReadonlyArray, +): ReadonlyArray { + const owned = useOwnedEnvironmentIds(); + return useMemo( + () => targets.filter((target) => owned.has(target.environmentId)), + [targets, owned], + ); +} diff --git a/apps/mobile/src/j5/upstreamSeams.test.ts b/apps/mobile/src/j5/upstreamSeams.test.ts index 9bef335b92275..138b38a59b350 100644 --- a/apps/mobile/src/j5/upstreamSeams.test.ts +++ b/apps/mobile/src/j5/upstreamSeams.test.ts @@ -214,6 +214,36 @@ const SEAMS: ReadonlyArray = [ "onArtifactLinkMenuAction(href, actionId, artifactLinkContext)", ], }, + { + file: "features/settings/SettingsRouteScreen.tsx", + record: "case 72: Settings for someone who is not an Owner", + from: "../../j5/sharing/settingsAccess", + reaches: ["useShownSettingsSections(["], + }, + { + file: "features/settings/components/SettingsScreen.tsx", + record: "case 72: Settings for someone who is not an Owner", + from: "../../../j5/sharing/settingsAccess", + reaches: ["useOwnerOnlySettingsPage(route.name, props.children)"], + }, + { + file: "features/archive/ArchivedThreadsRouteScreen.tsx", + record: "case 72: Settings for someone who is not an Owner", + from: "../../j5/sharing/settingsAccess", + reaches: ["useOwnedSettingsTargets(savedEnvironments)"], + }, + { + file: "Stack.tsx", + record: "case 72: Settings for someone who is not an Owner", + from: "./j5/sharing/ownerOnlySettingsRoute", + reaches: ['ownerOnlySettingsRoute(ArchivedThreadsRouteScreen, "Archive")'], + }, + { + file: "features/settings/settings-environment-filter.tsx", + record: "case 72: Settings for someone who is not an Owner", + from: "../../j5/sharing/settingsAccess", + reaches: ["useOwnedSettingsTargets(connectedSettingsTargets(environments))"], + }, { file: "App.tsx", record: "BRANDING.md: mobile OS identity and links", diff --git a/apps/web/src/j5/agents/AgentLibrarySettings.tsx b/apps/web/src/j5/agents/AgentLibrarySettings.tsx index 044c3477783b2..23bebc5de9a52 100644 --- a/apps/web/src/j5/agents/AgentLibrarySettings.tsx +++ b/apps/web/src/j5/agents/AgentLibrarySettings.tsx @@ -40,7 +40,8 @@ import { useOpenInPreferredEditor } from "../../editorPreferences"; import { useServerConfigs } from "../../state/entities"; import { useEnvironments, usePrimaryEnvironmentId } from "../../state/environments"; import { useSettingsScopeEnvironments } from "../settingsScopeEnvironment"; -import { LIBRARY_FOR_OWNERS, useIsOwnerSomewhere, useOwnedEnvironmentIds } from "../sharing/access"; +import { LIBRARY_FOR_OWNERS } from "@t3tools/client-runtime/j5/sharing"; +import { useIsOwnerSomewhere, useOwnedEnvironmentIds } from "../sharing/access"; import { agentPersonaEnvironment } from "./agentPersonaAtoms"; import { PlaybookLibrarySettings } from "../playbooks/PlaybookLibrarySettings"; import { useEnvironmentQuery } from "../../state/query"; diff --git a/apps/web/src/j5/sharing/access.ts b/apps/web/src/j5/sharing/access.ts index 0e62c64ddb446..7c1be949434d1 100644 --- a/apps/web/src/j5/sharing/access.ts +++ b/apps/web/src/j5/sharing/access.ts @@ -1,8 +1,8 @@ import { useAtomValue } from "@effect/atom-react"; import { scopeThreadRef } from "@t3tools/client-runtime/environment"; import { + createSharingOwnershipAtoms, isOwnerAccess, - reachesServer, sharingAllowsOperate, sharingAllowsStart, threadLevelInProject, @@ -15,7 +15,7 @@ import { type ScopedThreadRef, type ThreadId, } from "@t3tools/contracts"; -import { levelReaches, type PersonLevel } from "@t3tools/contracts/j5"; +import type { PersonLevel } from "@t3tools/contracts/j5"; import * as Option from "effect/Option"; import { AsyncResult, Atom, type AtomRegistry } from "effect/reactivity"; @@ -25,7 +25,6 @@ import { appAtomRegistry } from "../../rpc/atomRegistry"; import { readThreadShell, useThreadShell } from "../../state/entities"; import { useEnvironmentScope } from "../../state/session"; import { j5Sharing } from "../state"; -import { ownerSomewhereState } from "./settingsAccess.logic"; import { provideSharingMenuAccess } from "./sharingMenu"; import { provideSharingStart } from "./startAccess"; import { provideSharingThreadOperability } from "./threadOperability"; @@ -230,23 +229,10 @@ provideSharingMenuAccess((thread) => { }; }); -const environmentIdsWhere = (label: string, test: (access: KnownConnectionAccess) => boolean) => - Atom.make((get) => { - const ids = new Set(); - for (const id of get(environmentCatalog.catalogValueAtom).entries.keys()) { - if (test(get(j5Sharing.connectionAccess(id)))) ids.add(id); - } - return ids as ReadonlySet; - }).pipe(Atom.withLabel(label)); - -// Known to reach less than the whole server: nothing is left out before a server has answered. -const narrowEnvironmentIdsAtom = environmentIdsWhere( - "j5:access:narrow-environments", - (access) => access !== null && !reachesServer(access), -); - -// Owned, or not yet answered: a server is not taken away from its Owner while it answers. -const ownedEnvironmentIdsAtom = environmentIdsWhere("j5:access:owned-environments", isOwnerAccess); +const ownership = createSharingOwnershipAtoms({ + catalogValueAtom: environmentCatalog.catalogValueAtom, + sharing: j5Sharing, +}); /** * The servers whose own pages (the Fleet page, Personas, Playbooks, skills) are not this person's @@ -254,12 +240,12 @@ const ownedEnvironmentIdsAtom = environmentIdsWhere("j5:access:owned-environment * leave these servers out, and say so when there is no other server. */ export function useNarrowEnvironmentIds(): ReadonlySet { - return useAtomValue(narrowEnvironmentIdsAtom); + return useAtomValue(ownership.narrowEnvironmentIds); } /** Whether there is at least one server and this person reaches less than the whole of each. */ export function useIsNarrowEverywhere(): boolean { - const narrow = useAtomValue(narrowEnvironmentIdsAtom); + const narrow = useAtomValue(ownership.narrowEnvironmentIds); const total = useAtomValue(environmentCatalog.catalogValueAtom).entries.size; return total > 0 && narrow.size === total; } @@ -270,47 +256,17 @@ export function useIsNarrowEverywhere(): boolean { * does not flicker; one whose answer says otherwise drops out when it arrives. */ export function useOwnedEnvironmentIds(): ReadonlySet { - return useAtomValue(ownedEnvironmentIdsAtom); + return useAtomValue(ownership.ownedEnvironmentIds); } -const ownerSomewhereAtom = Atom.make((get) => { - const catalog = get(environmentCatalog.catalogValueAtom); - return ownerSomewhereState({ - catalogReady: catalog.isReady, - // A server that cannot answer, one from before people, settles with no answer and holds - // this client to nothing, as `isOwnerAccess` does; only one still being asked is unknown. - answers: [...catalog.entries.keys()].map((environmentId) => { - const result = get(j5Sharing.connectionAccessQuery({ environmentId, input: {} })); - if (result._tag === "Initial") return null; - return isOwnerAccess(Option.getOrNull(AsyncResult.value(result))) ? "owner" : "other"; - }), - }); -}).pipe(Atom.withLabel("j5:access:owner-somewhere")); - -// Writes to something: a Collaborator's or Owner's level anywhere, or a session that is no -// person's. Before a server has answered nothing is assumed. -const writesSomewhereAtom = Atom.make((get) => { - for (const id of get(environmentCatalog.catalogValueAtom).entries.keys()) { - const access = get(j5Sharing.connectionAccess(id)); - if (access?.kind === "service") return true; - if ( - access?.kind === "person" && - access.levels.some((held) => levelReaches(held.level, "collaborator")) - ) { - return true; - } - } - return false; -}).pipe(Atom.withLabel("j5:access:writes-somewhere")); - /** Whether the person can write to anything on a connected server, so has an agent to ask. */ export function useWritesSomewhere(): boolean { - return useAtomValue(writesSomewhereAtom); + return useAtomValue(ownership.writesSomewhere); } /** Whether the person owns a connected server, or `"loading"`; see `ownerSomewhereState`. */ export function useOwnerSomewhere(): boolean | "loading" { - return useAtomValue(ownerSomewhereAtom); + return useAtomValue(ownership.ownerSomewhere); } /** @@ -323,6 +279,3 @@ export function useIsOwnerSomewhere(): boolean { /** What J5's Skills page says to someone who owns no connected server. */ export const SKILLS_FOR_OWNERS = "Skills are managed by a server's Owners."; - -/** What J5's Personas and Playbooks pages say to someone who owns no connected server. */ -export const LIBRARY_FOR_OWNERS = "Personas and Playbooks are managed by a server's Owners."; diff --git a/apps/web/src/j5/sharing/settingsAccess.logic.test.ts b/apps/web/src/j5/sharing/settingsAccess.logic.test.ts index 80e5292e7ad86..73759f75c164b 100644 --- a/apps/web/src/j5/sharing/settingsAccess.logic.test.ts +++ b/apps/web/src/j5/sharing/settingsAccess.logic.test.ts @@ -1,11 +1,6 @@ import { describe, expect, it } from "vite-plus/test"; -import { - ownerOnlySettingsNotice, - ownerSomewhereState, - settingsNavGroups, - settingsPageShown, -} from "./settingsAccess.logic"; +import { settingsNavGroups, settingsPageShown } from "./settingsAccess.logic"; const UPSTREAM = [ { heading: null, paths: ["/settings/general", "/settings/appearance", "/settings/snap-shot"] }, @@ -35,41 +30,3 @@ describe("Settings for an Owner", () => { expect(settingsPageShown({ path: "/settings/brand-new", ownerSomewhere: true })).toBe(true); }); }); - -describe("whether the person owns a connected server", () => { - it("is not known until the catalog is read and a server has answered", () => { - expect(ownerSomewhereState({ catalogReady: false, answers: [] })).toBe("loading"); - expect(ownerSomewhereState({ catalogReady: true, answers: [null] })).toBe("loading"); - expect(ownerSomewhereState({ catalogReady: true, answers: ["other", null] })).toBe("loading"); - }); - - it("is settled by one server that says so, whatever the others have answered", () => { - expect(ownerSomewhereState({ catalogReady: true, answers: [null, "owner"] })).toBe(true); - expect(ownerSomewhereState({ catalogReady: true, answers: ["other", "other"] })).toBe(false); - }); - - it("waits while the catalog lists no server yet, as it does before the client's own is added", () => { - expect(ownerSomewhereState({ catalogReady: true, answers: [] })).toBe("loading"); - }); -}); - -describe("an Owner's Settings page, reached by someone who owns no server", () => { - it("names the server and says who to ask", () => { - expect(ownerOnlySettingsNotice({ serverName: "openclaw", writesSomewhere: true })).toEqual({ - title: "Coming soon", - body: "Only an Owner of openclaw can change this here for now. Ask an Owner, or ask an agent on a thread you can write to.", - }); - }); - - it("does not send someone who writes nowhere to an agent", () => { - expect(ownerOnlySettingsNotice({ serverName: "openclaw", writesSomewhere: false }).body).toBe( - "Only an Owner of openclaw can change this here for now. Ask an Owner.", - ); - }); - - it("says this server when the server has no name to show", () => { - expect(ownerOnlySettingsNotice({ serverName: null, writesSomewhere: false }).body).toBe( - "Only an Owner of this server can change this here for now. Ask an Owner.", - ); - }); -}); diff --git a/apps/web/src/j5/sharing/settingsAccess.logic.ts b/apps/web/src/j5/sharing/settingsAccess.logic.ts index 9157ade195d32..0002c550205b4 100644 --- a/apps/web/src/j5/sharing/settingsAccess.logic.ts +++ b/apps/web/src/j5/sharing/settingsAccess.logic.ts @@ -12,21 +12,6 @@ export const PAGES_FOR_EVERYONE: ReadonlySet = new Set([ export const LICENSES_PATH = "/settings/open-source-licenses"; -/** - * Whether the person owns a connected server, or `"loading"` until a server says so or all have - * answered. An empty catalog is a client still starting (its own server is added after the first - * read). While loading, Settings lists what it lists anyone. - */ -export function ownerSomewhereState(input: { - readonly catalogReady: boolean; - /** Each server's answer; `null` for one still being asked. */ - readonly answers: ReadonlyArray<"owner" | "other" | null>; -}): boolean | "loading" { - if (!input.catalogReady || input.answers.length === 0) return "loading"; - if (input.answers.includes("owner")) return true; - return input.answers.includes(null) ? "loading" : false; -} - /** Whether Settings shows a page, by its path. */ export const settingsPageShown = (input: { readonly path: string; @@ -59,20 +44,3 @@ export function settingsNavGroups( { heading: null, paths: [licenses] }, ]; } - -/** - * What an Owner-only Settings page says, in its place, to someone who reaches it by a link or its - * address and owns no connected server. Someone who writes nowhere has no agent to ask. - */ -export function ownerOnlySettingsNotice(input: { - readonly serverName: string | null; - readonly writesSomewhere: boolean; -}): { readonly title: string; readonly body: string } { - const server = input.serverName ?? "this server"; - return { - title: "Coming soon", - body: input.writesSomewhere - ? `Only an Owner of ${server} can change this here for now. Ask an Owner, or ask an agent on a thread you can write to.` - : `Only an Owner of ${server} can change this here for now. Ask an Owner.`, - }; -} diff --git a/apps/web/src/j5/sharing/settingsAccess.tsx b/apps/web/src/j5/sharing/settingsAccess.tsx index f3e15f5f4065a..1354b0b9ece81 100644 --- a/apps/web/src/j5/sharing/settingsAccess.tsx +++ b/apps/web/src/j5/sharing/settingsAccess.tsx @@ -1,3 +1,4 @@ +import { ownerOnlySettingsNotice } from "@t3tools/client-runtime/j5/sharing"; import type { EnvironmentId } from "@t3tools/contracts"; import { useLocation } from "@tanstack/react-router"; import { type ReactNode } from "react"; @@ -10,7 +11,6 @@ import { useOwnedEnvironmentIds, useOwnerSomewhere, useWritesSomewhere } from ". import { LICENSES_PATH, PAGES_FOR_EVERYONE, - ownerOnlySettingsNotice, settingsNavGroups, settingsPageShown, type SettingsNavGroup, diff --git a/packages/client-runtime/src/j5/sharing.test.ts b/packages/client-runtime/src/j5/sharing.test.ts index c699546f07d87..c50c43e988e8a 100644 --- a/packages/client-runtime/src/j5/sharing.test.ts +++ b/packages/client-runtime/src/j5/sharing.test.ts @@ -27,6 +27,8 @@ import { EnvironmentSupervisor } from "../connection/supervisor.ts"; import type { RpcSession } from "../rpc/session.ts"; import { createSharingEnvironmentAtoms, + ownerOnlySettingsNotice, + ownerSomewhereState, projectLevelFor, permissionNoticeApplies, reachesServer, @@ -540,3 +542,41 @@ describe("upstream's notice to pair again", () => { expect(permissionNoticeApplies(AsyncResult.success({ kind: "service" as const }))).toBe(true); }); }); + +describe("whether the person owns a connected server", () => { + it("is not known until the catalog is read and a server has answered", () => { + expect(ownerSomewhereState({ catalogReady: false, answers: [] })).toBe("loading"); + expect(ownerSomewhereState({ catalogReady: true, answers: [null] })).toBe("loading"); + expect(ownerSomewhereState({ catalogReady: true, answers: ["other", null] })).toBe("loading"); + }); + + it("is settled by one server that says so, whatever the others have answered", () => { + expect(ownerSomewhereState({ catalogReady: true, answers: [null, "owner"] })).toBe(true); + expect(ownerSomewhereState({ catalogReady: true, answers: ["other", "other"] })).toBe(false); + }); + + it("waits while the catalog lists no server yet, as it does before the client's own is added", () => { + expect(ownerSomewhereState({ catalogReady: true, answers: [] })).toBe("loading"); + }); +}); + +describe("an Owner's Settings page, reached by someone who owns no server", () => { + it("names the server and says who to ask", () => { + expect(ownerOnlySettingsNotice({ serverName: "openclaw", writesSomewhere: true })).toEqual({ + title: "Coming soon", + body: "Only an Owner of openclaw can change this here for now. Ask an Owner, or ask an agent on a thread you can write to.", + }); + }); + + it("does not send someone who writes nowhere to an agent", () => { + expect(ownerOnlySettingsNotice({ serverName: "openclaw", writesSomewhere: false }).body).toBe( + "Only an Owner of openclaw can change this here for now. Ask an Owner.", + ); + }); + + it("says this server when the server has no name to show", () => { + expect(ownerOnlySettingsNotice({ serverName: null, writesSomewhere: false }).body).toBe( + "Only an Owner of this server can change this here for now. Ask an Owner.", + ); + }); +}); diff --git a/packages/client-runtime/src/j5/sharing.ts b/packages/client-runtime/src/j5/sharing.ts index 5bdbaaee91085..d016032d3b49c 100644 --- a/packages/client-runtime/src/j5/sharing.ts +++ b/packages/client-runtime/src/j5/sharing.ts @@ -364,3 +364,104 @@ export function createSharingEnvironmentAtoms( threadOperable(threadKey(environmentId, threadId)), }; } + +/** + * Whether the person owns a connected server, or `"loading"` until a server says so or all have + * answered. An empty catalog is a client still starting (its own server is added after the first + * read). While loading, Settings lists what it lists anyone. + */ +export function ownerSomewhereState(input: { + readonly catalogReady: boolean; + /** Each server's answer; `null` for one still being asked. */ + readonly answers: ReadonlyArray<"owner" | "other" | null>; +}): boolean | "loading" { + if (!input.catalogReady || input.answers.length === 0) return "loading"; + if (input.answers.includes("owner")) return true; + return input.answers.includes(null) ? "loading" : false; +} + +/** + * What an Owner-only Settings page says, in its place, to someone who reaches it by a link or its + * address and owns no connected server. Someone who writes nowhere has no agent to ask. + */ +export function ownerOnlySettingsNotice(input: { + readonly serverName: string | null; + readonly writesSomewhere: boolean; +}): { readonly title: string; readonly body: string } { + const server = input.serverName ?? "this server"; + return { + title: "Coming soon", + body: input.writesSomewhere + ? `Only an Owner of ${server} can change this here for now. Ask an Owner, or ask an agent on a thread you can write to.` + : `Only an Owner of ${server} can change this here for now. Ask an Owner.`, + }; +} + +/** What J5's Personas and Playbooks pages say to someone who owns no connected server. */ +export const LIBRARY_FOR_OWNERS = "Personas and Playbooks are managed by a server's Owners."; + +/** + * What this person is across every connected server, for the pages that list servers (People and + * access AC23, AC27): web and mobile each build one from their catalog and sharing atoms. + */ +export function createSharingOwnershipAtoms(input: { + readonly catalogValueAtom: Atom.Atom<{ + readonly isReady: boolean; + readonly entries: ReadonlyMap; + }>; + readonly sharing: Pick< + ReturnType, + "connectionAccess" | "connectionAccessQuery" + >; +}) { + const { catalogValueAtom, sharing } = input; + const environmentIdsWhere = (label: string, test: (access: KnownConnectionAccess) => boolean) => + Atom.make((get) => { + const ids = new Set(); + for (const id of get(catalogValueAtom).entries.keys()) { + if (test(get(sharing.connectionAccess(id)))) ids.add(id); + } + return ids as ReadonlySet; + }).pipe(Atom.withLabel(label)); + + return { + /** Known to reach less than the whole server: nothing is left out before a server answers. */ + narrowEnvironmentIds: environmentIdsWhere( + "j5:access:narrow-environments", + (access) => access !== null && !reachesServer(access), + ), + /** Owned, or not yet answered: a server is not taken from its Owner while it answers. */ + ownedEnvironmentIds: environmentIdsWhere("j5:access:owned-environments", isOwnerAccess), + /** Whether the person owns a connected server, or `"loading"`; see `ownerSomewhereState`. */ + ownerSomewhere: Atom.make((get) => { + const catalog = get(catalogValueAtom); + return ownerSomewhereState({ + catalogReady: catalog.isReady, + // A server that cannot answer, one from before people, settles with no answer and holds + // this client to nothing, as `isOwnerAccess` does; only one still being asked is unknown. + answers: [...catalog.entries.keys()].map((environmentId) => { + const result = get(sharing.connectionAccessQuery({ environmentId, input: {} })); + if (result._tag === "Initial") return null; + return isOwnerAccess(Option.getOrNull(AsyncResult.value(result))) ? "owner" : "other"; + }), + }); + }).pipe(Atom.withLabel("j5:access:owner-somewhere")), + /** + * Writes to something: a Collaborator's or Owner's level anywhere, or a session that is no + * person's, so has an agent to ask. Before a server has answered nothing is assumed. + */ + writesSomewhere: Atom.make((get) => { + for (const id of get(catalogValueAtom).entries.keys()) { + const access = get(sharing.connectionAccess(id)); + if (access?.kind === "service") return true; + if ( + access?.kind === "person" && + access.levels.some((held) => levelReaches(held.level, "collaborator")) + ) { + return true; + } + } + return false; + }).pipe(Atom.withLabel("j5:access:writes-somewhere")), + }; +} From f9d57515df1380a9e7f6411ae34f62fef1a672fe Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sat, 31 Oct 2026 22:08:58 -0400 Subject: [PATCH 2/2] docs(fork): one file-index row for Stack.tsx Co-Authored-By: Claude Opus 5.5 --- FORK.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/FORK.md b/FORK.md index a05938dc020e4..fd6ff58be3127 100644 --- a/FORK.md +++ b/FORK.md @@ -729,7 +729,7 @@ explicitly marked. | `apps/mobile/src/features/settings/SettingsRouteScreen.tsx` | A | 72, Role library | | `apps/mobile/src/features/settings/components/SettingsScreen.tsx` | N | 72 | | `apps/mobile/src/features/settings/settings-environment-filter.tsx` | N | 72 | -| `apps/mobile/src/Stack.tsx` | A | 72, Role library | +| `apps/mobile/src/Stack.tsx` | A | 72, 98, Role library | | `apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx` | N | 72 | | `apps/mobile/src/features/threads/new-task-flow-provider.tsx` | A | 45 | | `apps/mobile/src/features/threads/use-composer-command-menu.ts` | A | 45, 49 | @@ -907,7 +907,6 @@ explicitly marked. | `apps/server/src/provider/CodexDeveloperInstructions.test.ts` | N | 8 | | `apps/web/test/appScenarios.renders.tsx` | N | 80 | | `apps/mobile/src/features/home/useThreadListActions.ts` | N | 21 | -| `apps/mobile/src/Stack.tsx` | N | 98 | | `apps/web/test/renderScenarios.renders.tsx` | N | 80 | | `packages/shared/src/devHome.ts` | R | H | | `packages/ssh/src/tunnel.ts` | R | H, 50 |