From 3508bb18f6bd7298c4d07abe9845449f069d434c Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:14:38 -0500 Subject: [PATCH 1/2] feat(mobile): one sheet per persona holds its details and actions A Personas row had a tap that opened the editor or the details sheet and a separate menu with another Details item. Now a tap opens one sheet for every persona, with its details and its actions: Edit, Duplicate, Export, Copy to each other environment, and Remove or Restore. The row keeps its switch and shows one marker word, Removed, Blocked or the override, with the reasons and the override note in the sheet. Co-Authored-By: Claude Opus 5.5 --- .../j5/agents/AgentLibrarySettingsScreen.tsx | 236 +++++++++--------- ...AgentDetailsModal.tsx => PersonaSheet.tsx} | 36 ++- .../src/j5/agents/personaDetails.test.ts | 11 + apps/mobile/src/j5/agents/personaDetails.ts | 5 +- .../src/j5/agents/personaRowActions.test.ts | 25 -- .../mobile/src/j5/agents/personaRowActions.ts | 26 -- .../mobile/src/j5/agents/personaSheet.test.ts | 40 +++ apps/mobile/src/j5/agents/personaSheet.ts | 28 +++ 8 files changed, 228 insertions(+), 179 deletions(-) rename apps/mobile/src/j5/agents/{AgentDetailsModal.tsx => PersonaSheet.tsx} (74%) delete mode 100644 apps/mobile/src/j5/agents/personaRowActions.test.ts delete mode 100644 apps/mobile/src/j5/agents/personaRowActions.ts create mode 100644 apps/mobile/src/j5/agents/personaSheet.test.ts create mode 100644 apps/mobile/src/j5/agents/personaSheet.ts diff --git a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx index 1dddfa16b40bb..51bc4211c789b 100644 --- a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx @@ -3,15 +3,12 @@ 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 { - AGENT_PERSONA_OVERRIDE_NOTE, - agentPersonaDuplicateDraft, -} from "@t3tools/client-runtime/j5/agent-personas"; -import { AgentDetailsModal } from "./AgentDetailsModal"; +import { agentPersonaDuplicateDraft } from "@t3tools/client-runtime/j5/agent-personas"; +import { PersonaSheet, type PersonaSheetActionRow } from "./PersonaSheet"; import { AgentFolderPickerModal } from "./AgentFolderPickerModal"; import { useSettingsFormNavigation } from "./SettingsFormScreen"; import { sendWhenReconnected } from "./watchEnvironmentSessions"; -import { personaRowActions } from "./personaRowActions"; +import { personaRowMarker, personaSheetActions } from "./personaSheet"; import { Menu } from "../../components/ui/Menu"; import { SymbolView } from "../../components/ui/AppSymbol"; import { @@ -327,6 +324,90 @@ function OwnerAgentLibrarySettingsScreen() { : presentAgentPersonaCatalog(catalog.data, providers ?? []); const viewedPersona = personas.find((persona) => persona.personaId === viewing); + // Every action closes the sheet first, so its toast, form or confirmation shows on the page. + const closeAnd = (run: () => void) => () => { + setViewing(null); + run(); + }; + const sheetActions: ReadonlyArray = + viewedPersona === undefined + ? [] + : personaSheetActions( + { + removed: viewedPersona.removed, + editable: viewedPersona.edit !== null && canOperate, + }, + otherEnvironments.length > 0, + ).flatMap((action): ReadonlyArray => { + const id = viewedPersona.personaId; + switch (action) { + case "edit": + return [ + { + key: action, + label: "Edit", + disabled: locked, + onPress: closeAnd(() => { + if (viewedPersona.edit && effectiveEnvironmentId) + navigation.navigate("SettingsPersonaEdit", { + environmentId: effectiveEnvironmentId, + initial: viewedPersona.edit, + }); + }), + }, + ]; + case "duplicate": + return [ + { + key: action, + label: "Duplicate as personal persona", + disabled: locked || viewedPersona.availability === "unsupported", + onPress: closeAnd(() => void duplicatePersona(id)), + }, + ]; + case "export": + return [ + { + key: action, + label: "Export YAML", + disabled: busy, + onPress: closeAnd(() => void exportPersona(id)), + }, + ]; + case "copy": + return otherEnvironments.map((environment) => ({ + key: `copy:${environment.environmentId}`, + label: `Copy to ${environment.environmentLabel}`, + disabled: busy, + onPress: closeAnd( + () => + void copyPersona(id, { + environmentId: environment.environmentId, + label: environment.environmentLabel, + }), + ), + })); + case "remove": + return [ + { + key: action, + label: "Remove", + tone: "danger" as const, + disabled: locked, + onPress: closeAnd(() => void removePersona(id)), + }, + ]; + case "restore": + return [ + { + key: action, + label: "Restore", + disabled: locked, + onPress: closeAnd(() => void restorePersona(id)), + }, + ]; + } + }); const folders = librarySources.data?.folders ?? []; const environmentLabel = connectedEnvironments.find( @@ -446,25 +527,8 @@ function OwnerAgentLibrarySettingsScreen() { borderTop={index > 0} locked={locked} busy={busy} - otherEnvironments={otherEnvironments} onToggle={(enabled) => void toggleAgent(persona.personaId, enabled)} - onEdit={ - persona.edit && effectiveEnvironmentId && canOperate - ? () => { - if (persona.edit && effectiveEnvironmentId) - navigation.navigate("SettingsPersonaEdit", { - environmentId: effectiveEnvironmentId, - initial: persona.edit, - }); - } - : null - } - onDetails={() => setViewing(persona.personaId)} - onDuplicate={() => void duplicatePersona(persona.personaId)} - onExport={() => void exportPersona(persona.personaId)} - onCopy={(target) => void copyPersona(persona.personaId, target)} - onRemove={() => void removePersona(persona.personaId)} - onRestore={() => void restorePersona(persona.personaId)} + onOpen={() => setViewing(persona.personaId)} /> )) )} @@ -549,7 +613,7 @@ function OwnerAgentLibrarySettingsScreen() { /> ) : null} {viewedPersona && effectiveEnvironmentId ? ( - setViewing(null)} /> ) : null} @@ -615,47 +680,35 @@ function InfoRow(props: { type PresentedPersona = ReturnType[number]; -/** One persona as a settings row: name and status, its switch, and the rest in a menu. */ +/** One persona as a settings row: its name, one status word, and its switch. A tap opens its sheet. */ function PersonaRow(props: { readonly persona: PresentedPersona; readonly borderTop: boolean; readonly locked: boolean; readonly busy: boolean; - readonly otherEnvironments: ReadonlyArray<{ - readonly environmentId: EnvironmentId; - readonly environmentLabel: string; - }>; readonly onToggle: (enabled: boolean) => void; - readonly onEdit: (() => void) | null; - readonly onDetails: () => void; - readonly onDuplicate: () => void; - readonly onExport: () => void; - readonly onCopy: (target: { environmentId: EnvironmentId; label: string }) => void; - readonly onRemove: () => void; - readonly onRestore: () => void; + readonly onOpen: () => void; }) { const { persona } = props; - const unavailable = !persona.removed && persona.availability !== "available"; - const actions = personaRowActions( - { removed: persona.removed, editable: props.onEdit !== null }, - props.otherEnvironments.length > 0, - ); - const onEdit = actions.includes("edit") ? props.onEdit : null; + const marker = personaRowMarker({ + removed: persona.removed, + blocked: + !persona.removed && persona.availability !== "available" && persona.blockedReasons.length > 0, + overrideLabel: persona.overridesFolder === null ? null : persona.originLabel, + }); return ( {persona.displayName} - {persona.removed ? Removed : null} - {persona.overridesFolder !== null ? ( - - {persona.originLabel}. {AGENT_PERSONA_OVERRIDE_NOTE} - - ) : null} - {unavailable && persona.blockedReasons.join("; ") ? ( - - {persona.blockedReasons.join("; ")} + {marker === null ? null : ( + + {marker.label} - ) : null} + )} {persona.removed ? null : ( )} - { - switch (action) { - case "edit": - return { id: action, title: "Edit", attributes: { disabled: props.locked } }; - case "details": - return { id: action, title: "Details" }; - case "duplicate": - return { - id: action, - title: "Duplicate as personal persona", - attributes: { disabled: props.locked || persona.availability === "unsupported" }, - }; - case "export": - return { id: action, title: "Export YAML", attributes: { disabled: props.busy } }; - case "copy": - return { - id: action, - title: "Copy to environment", - attributes: { disabled: props.busy }, - subactions: props.otherEnvironments.map((environment) => ({ - id: `copy:${environment.environmentId}`, - title: environment.environmentLabel, - })), - }; - case "remove": - return { - id: action, - title: "Remove", - attributes: { destructive: true, disabled: props.locked }, - }; - case "restore": - return { id: action, title: "Restore", attributes: { disabled: props.locked } }; - } - })} - onPressAction={({ nativeEvent }) => { - const action = nativeEvent.event; - if (action === "edit") onEdit?.(); - else if (action === "details") props.onDetails(); - else if (action === "duplicate") props.onDuplicate(); - else if (action === "export") props.onExport(); - else if (action === "remove") props.onRemove(); - else if (action === "restore") props.onRestore(); - else if (action.startsWith("copy:")) { - const target = props.otherEnvironments.find( - (environment) => `copy:${environment.environmentId}` === action, - ); - if (target) - props.onCopy({ environmentId: target.environmentId, label: target.environmentLabel }); - } - }} - > - - - - ); } diff --git a/apps/mobile/src/j5/agents/AgentDetailsModal.tsx b/apps/mobile/src/j5/agents/PersonaSheet.tsx similarity index 74% rename from apps/mobile/src/j5/agents/AgentDetailsModal.tsx rename to apps/mobile/src/j5/agents/PersonaSheet.tsx index f74a4a9b631f8..d7bca25fac89f 100644 --- a/apps/mobile/src/j5/agents/AgentDetailsModal.tsx +++ b/apps/mobile/src/j5/agents/PersonaSheet.tsx @@ -8,6 +8,7 @@ import { Modal, Pressable, ScrollView, View } from "react-native"; import { SafeAreaView } from "react-native-safe-area-context"; import { AppText as Text } from "../../components/ui/AppText"; +import { ListActionRow } from "../../components/ui/ListActionRow"; import { ListRowLayout } from "../../components/ui/ListRowLayout"; import { SettingsSection } from "../../features/settings/components/SettingsSection"; import { cn } from "../../lib/cn"; @@ -15,11 +16,23 @@ import { useAtomCommand } from "../../state/use-atom-command"; import { agentPersonaEnvironment } from "./agentPersonaAtoms"; import { personaDetailRows } from "./personaDetails"; -/** A persona the person can't edit, such as one from a folder, shown read-only. */ -export function AgentDetailsModal(props: { +export interface PersonaSheetActionRow { + readonly key: string; + readonly label: string; + readonly tone?: "danger"; + readonly disabled: boolean; + readonly onPress: () => void; +} + +/** + * Everything about one persona and what can be done with it, opened by a tap on its row. + * Actions are plain rows, not a Menu: Android's Menu can't draw over a Modal. + */ +export function PersonaSheet(props: { readonly environmentId: EnvironmentId; readonly persona: AgentPersonaCatalogRow; readonly usageLine: string | null; + readonly actions: ReadonlyArray; readonly onClose: () => void; }) { const [models, setModels] = useState< @@ -71,7 +84,7 @@ export function AgentDetailsModal(props: { Done - + {rows.map((row, index) => ( ))} + {props.actions.length === 0 ? null : ( + + {props.actions.map((action, index) => ( + 0 && "border-t border-border-subtle")} + > + + + ))} + + )} diff --git a/apps/mobile/src/j5/agents/personaDetails.test.ts b/apps/mobile/src/j5/agents/personaDetails.test.ts index 3c603fad7ef6f..cabd705da8f59 100644 --- a/apps/mobile/src/j5/agents/personaDetails.test.ts +++ b/apps/mobile/src/j5/agents/personaDetails.test.ts @@ -25,6 +25,17 @@ const rowsOf = (rows: ReturnType) => rows.map(({ label, value }) => [label, value]); describe("personaDetailRows", () => { + it("explains an override, after its source", () => { + const override = { + ...persona, + origin: { kind: "imported" }, + originLabel: "Overrides personas", + overridesFolder: "/srv/personas/luna.yaml", + } as unknown as Parameters[0]; + const labels = personaDetailRows(override, { status: "failed" }, null).map((row) => row.label); + expect(labels.slice(0, 4)).toEqual(["Status", "Source", "Override", "Access"]); + }); + it("shows a folder persona's path, access, both models and description", () => { expect( rowsOf( diff --git a/apps/mobile/src/j5/agents/personaDetails.ts b/apps/mobile/src/j5/agents/personaDetails.ts index 0d3f601d57ed3..f913aceaa2d73 100644 --- a/apps/mobile/src/j5/agents/personaDetails.ts +++ b/apps/mobile/src/j5/agents/personaDetails.ts @@ -1,4 +1,5 @@ import { + AGENT_PERSONA_OVERRIDE_NOTE, agentPersonaEntryLabel, type AgentPersonaCatalogRow, } from "@t3tools/client-runtime/j5/agent-personas"; @@ -11,7 +12,7 @@ export interface PersonaDetailRow { } /** - * What the read-only sheet shows for a persona the person can't edit. Models come from the + * What a persona's sheet shows about it. Models come from the * definition, read on open: `null` while it loads, and the catalog's resolved route if it fails. */ export function personaDetailRows( @@ -24,6 +25,7 @@ export function personaDetailRows( | "availabilityLabel" | "blockedReasons" | "route" + | "overridesFolder" >, models: | { readonly status: "loading" } @@ -45,6 +47,7 @@ export function personaDetailRows( tone: "danger" as const, })), ...(source === null ? [] : [{ label: "Source", value: source }]), + ...(persona.overridesFolder ? [{ label: "Override", value: AGENT_PERSONA_OVERRIDE_NOTE }] : []), { label: "Access", value: persona.authority }, ...(models.status === "loaded" ? (models.models ?? models.route).map((entry, index) => { diff --git a/apps/mobile/src/j5/agents/personaRowActions.test.ts b/apps/mobile/src/j5/agents/personaRowActions.test.ts deleted file mode 100644 index 74ee660ada5e3..0000000000000 --- a/apps/mobile/src/j5/agents/personaRowActions.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { describe, expect, it } from "vite-plus/test"; - -import { personaRowActions } from "./personaRowActions"; - -describe("personaRowActions", () => { - it("offers only Restore for a removed persona, even an editable one", () => { - expect(personaRowActions({ removed: true, editable: true }, true)).toEqual(["restore"]); - }); - - it("offers Edit and Details only for an editable persona, and Copy only with another environment", () => { - expect(personaRowActions({ removed: false, editable: true }, true)).toEqual([ - "edit", - "details", - "duplicate", - "export", - "copy", - "remove", - ]); - expect(personaRowActions({ removed: false, editable: false }, false)).toEqual([ - "duplicate", - "export", - "remove", - ]); - }); -}); diff --git a/apps/mobile/src/j5/agents/personaRowActions.ts b/apps/mobile/src/j5/agents/personaRowActions.ts deleted file mode 100644 index ad3c57e29f0f7..0000000000000 --- a/apps/mobile/src/j5/agents/personaRowActions.ts +++ /dev/null @@ -1,26 +0,0 @@ -export type PersonaRowAction = - | "edit" - | "details" - | "duplicate" - | "export" - | "copy" - | "remove" - | "restore"; - -/** - * What a Personas settings row offers, in menu order. A removed persona offers only Restore. - * Details is here only where a tap opens the editor; elsewhere the tap already opens the sheet. - */ -export function personaRowActions( - persona: { readonly removed: boolean; readonly editable: boolean }, - hasOtherEnvironments: boolean, -): ReadonlyArray { - if (persona.removed) return ["restore"]; - return [ - ...(persona.editable ? (["edit", "details"] as const) : []), - "duplicate", - "export", - ...(hasOtherEnvironments ? (["copy"] as const) : []), - "remove", - ]; -} diff --git a/apps/mobile/src/j5/agents/personaSheet.test.ts b/apps/mobile/src/j5/agents/personaSheet.test.ts new file mode 100644 index 0000000000000..2ae3b0160bf67 --- /dev/null +++ b/apps/mobile/src/j5/agents/personaSheet.test.ts @@ -0,0 +1,40 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { personaRowMarker, personaSheetActions } from "./personaSheet"; + +describe("personaSheetActions", () => { + it("offers only Restore for a removed persona, even an editable one", () => { + expect(personaSheetActions({ removed: true, editable: true }, true)).toEqual(["restore"]); + }); + + it("offers Edit only for an editable persona, and Copy only with another environment", () => { + expect(personaSheetActions({ removed: false, editable: true }, true)).toEqual([ + "edit", + "duplicate", + "export", + "copy", + "remove", + ]); + expect(personaSheetActions({ removed: false, editable: false }, false)).toEqual([ + "duplicate", + "export", + "remove", + ]); + }); +}); + +describe("personaRowMarker", () => { + it("names one state, removed first, then blocked, then an override", () => { + const all = { removed: true, blocked: true, overrideLabel: "Overrides personas" }; + expect(personaRowMarker(all)).toEqual({ label: "Removed", tone: "muted" }); + expect(personaRowMarker({ ...all, removed: false })).toEqual({ + label: "Blocked", + tone: "danger", + }); + expect(personaRowMarker({ ...all, removed: false, blocked: false })).toEqual({ + label: "Overrides personas", + tone: "muted", + }); + expect(personaRowMarker({ removed: false, blocked: false, overrideLabel: null })).toBeNull(); + }); +}); diff --git a/apps/mobile/src/j5/agents/personaSheet.ts b/apps/mobile/src/j5/agents/personaSheet.ts new file mode 100644 index 0000000000000..a1c7288a1a55b --- /dev/null +++ b/apps/mobile/src/j5/agents/personaSheet.ts @@ -0,0 +1,28 @@ +export type PersonaSheetAction = "edit" | "duplicate" | "export" | "copy" | "remove" | "restore"; + +/** What a persona's sheet offers, in order. A removed persona offers only Restore. */ +export function personaSheetActions( + persona: { readonly removed: boolean; readonly editable: boolean }, + hasOtherEnvironments: boolean, +): ReadonlyArray { + if (persona.removed) return ["restore"]; + return [ + ...(persona.editable ? (["edit"] as const) : []), + "duplicate", + "export", + ...(hasOtherEnvironments ? (["copy"] as const) : []), + "remove", + ]; +} + +/** The one word a Personas row shows under the name; the sheet holds the detail behind it. */ +export function personaRowMarker(persona: { + readonly removed: boolean; + readonly blocked: boolean; + readonly overrideLabel: string | null; +}): { readonly label: string; readonly tone: "muted" | "danger" } | null { + if (persona.removed) return { label: "Removed", tone: "muted" }; + if (persona.blocked) return { label: "Blocked", tone: "danger" }; + if (persona.overrideLabel !== null) return { label: persona.overrideLabel, tone: "muted" }; + return null; +} From 56b55a62ec0db80ab9aedaf2e99764306917d662 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 8 Nov 2026 23:25:25 -0500 Subject: [PATCH 2/2] fix(mobile): a persona sheet action waits for the sheet to close on iOS Export's share sheet and Copy's import-conflict modal could try to present while the pageSheet was still sliding out. The sheet now stays mounted with visible false and runs the queued action from onDismiss on iOS; Android runs it at once. The row's accessibility label includes its marker. Co-Authored-By: Claude Opus 5.5 --- .../j5/agents/AgentLibrarySettingsScreen.tsx | 33 ++++++++----------- apps/mobile/src/j5/agents/PersonaSheet.tsx | 23 ++++++++++--- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx index 51bc4211c789b..1d6d194a59902 100644 --- a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx @@ -324,11 +324,6 @@ function OwnerAgentLibrarySettingsScreen() { : presentAgentPersonaCatalog(catalog.data, providers ?? []); const viewedPersona = personas.find((persona) => persona.personaId === viewing); - // Every action closes the sheet first, so its toast, form or confirmation shows on the page. - const closeAnd = (run: () => void) => () => { - setViewing(null); - run(); - }; const sheetActions: ReadonlyArray = viewedPersona === undefined ? [] @@ -347,13 +342,13 @@ function OwnerAgentLibrarySettingsScreen() { key: action, label: "Edit", disabled: locked, - onPress: closeAnd(() => { + onPress: () => { if (viewedPersona.edit && effectiveEnvironmentId) navigation.navigate("SettingsPersonaEdit", { environmentId: effectiveEnvironmentId, initial: viewedPersona.edit, }); - }), + }, }, ]; case "duplicate": @@ -362,7 +357,7 @@ function OwnerAgentLibrarySettingsScreen() { key: action, label: "Duplicate as personal persona", disabled: locked || viewedPersona.availability === "unsupported", - onPress: closeAnd(() => void duplicatePersona(id)), + onPress: () => void duplicatePersona(id), }, ]; case "export": @@ -371,7 +366,7 @@ function OwnerAgentLibrarySettingsScreen() { key: action, label: "Export YAML", disabled: busy, - onPress: closeAnd(() => void exportPersona(id)), + onPress: () => void exportPersona(id), }, ]; case "copy": @@ -379,13 +374,11 @@ function OwnerAgentLibrarySettingsScreen() { key: `copy:${environment.environmentId}`, label: `Copy to ${environment.environmentLabel}`, disabled: busy, - onPress: closeAnd( - () => - void copyPersona(id, { - environmentId: environment.environmentId, - label: environment.environmentLabel, - }), - ), + onPress: () => + void copyPersona(id, { + environmentId: environment.environmentId, + label: environment.environmentLabel, + }), })); case "remove": return [ @@ -394,7 +387,7 @@ function OwnerAgentLibrarySettingsScreen() { label: "Remove", tone: "danger" as const, disabled: locked, - onPress: closeAnd(() => void removePersona(id)), + onPress: () => void removePersona(id), }, ]; case "restore": @@ -403,7 +396,7 @@ function OwnerAgentLibrarySettingsScreen() { key: action, label: "Restore", disabled: locked, - onPress: closeAnd(() => void restorePersona(id)), + onPress: () => void restorePersona(id), }, ]; } @@ -705,7 +698,9 @@ function PersonaRow(props: { > void) | null>(null); + const leaveThen = (run: () => void) => { + if (Platform.OS !== "ios") { + props.onClose(); + run(); + return; + } + setLeaving(() => run); + }; const providers = useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)); const rows = personaDetailRows(props.persona, models, props.usageLine, providers ?? []); return ( { + if (leaving === null) return; + props.onClose(); + leaving(); + }} > {/* SafeAreaView takes no className, so the theme surface and flex go on a View. */} @@ -109,7 +124,7 @@ export function PersonaSheet(props: { leaveThen(action.onPress)} {...(action.tone === undefined ? {} : { tone: action.tone })} />