From 5928987af83bcb5379f191bf364b8556bb007f80 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 1 Nov 2026 21:41:22 -0500 Subject: [PATCH 1/4] fix(mobile): the persona editor's reasoning and runtime pickers use the native menu Runtime policy and Reasoning used J5's own EditorChoice, which expanded a list inline and pushed the row taller. Both now use upstream's Menu, as the Model picker beside them already does, so the choices float over the form. EditorChoice is deleted. Closes #894 Co-Authored-By: Claude Opus 5.5 --- .../src/j5/agents/AgentDefinitionFields.tsx | 139 ++++++++---------- 1 file changed, 58 insertions(+), 81 deletions(-) diff --git a/apps/mobile/src/j5/agents/AgentDefinitionFields.tsx b/apps/mobile/src/j5/agents/AgentDefinitionFields.tsx index 96112f9853b1b..2abd8a705aba5 100644 --- a/apps/mobile/src/j5/agents/AgentDefinitionFields.tsx +++ b/apps/mobile/src/j5/agents/AgentDefinitionFields.tsx @@ -12,8 +12,7 @@ import type { AgentPersonaModelTarget, EnvironmentId, } from "@t3tools/contracts"; -import { useState } from "react"; -import { Pressable, ScrollView, View } from "react-native"; +import { Pressable, View } from "react-native"; import { AppText as Text } from "../../components/ui/AppText"; import { Menu } from "../../components/ui/Menu"; @@ -26,64 +25,6 @@ export interface AgentRoutePolicyValue { readonly modelRoute: readonly [AgentPersonaModelTarget, AgentPersonaModelTarget]; } -export function EditorChoice(props: { - label: string; - accessibilityLabel?: string; - value: string; - disabled: boolean; - choices: ReadonlyArray<{ value: string; label: string }>; - onChange: (value: string) => void; -}) { - const [expanded, setExpanded] = useState(false); - return ( - - {props.label} - setExpanded(!expanded)} - > - - {props.choices.find(({ value }) => value === props.value)?.label ?? props.value} - - - {expanded ? ( - - {props.choices.map((choice) => ( - { - props.onChange(choice.value); - setExpanded(false); - }} - > - - {choice.label} - - - ))} - - ) : null} - - ); -} - /** Runtime policy plus primary/fallback route pickers, shared by the create and edit modals. */ export function AgentRoutePolicyFields(props: { environmentId: EnvironmentId; @@ -109,22 +50,44 @@ export function AgentRoutePolicyFields(props: { ); return ( <> - { - const policy = AGENT_PERSONA_POLICY_OPTIONS.find((item) => item.value === next); - if (policy) props.onChange({ ...value, authorityPolicy: policy.value }); - }} - /> + + Runtime policy + + ({ + id: policy.value, + title: policy.label, + state: policy.value === value.authorityPolicy ? "on" : "off", + }))} + onPressAction={({ nativeEvent }) => { + const policy = AGENT_PERSONA_POLICY_OPTIONS.find( + (item) => item.value === nativeEvent.event, + ); + if (policy) props.onChange({ ...value, authorityPolicy: policy.value }); + }} + > + + + {AGENT_PERSONA_POLICY_OPTIONS.find((item) => item.value === value.authorityPolicy) + ?.label ?? value.authorityPolicy} + + + + + {policyNote === null ? null : ( {policyNote} )} {value.modelRoute.map((target, index) => { const label = index === 0 ? "Primary model" : "Fallback model"; const selected = choices.find(({ id }) => id === agentPersonaModelChoiceId(target)); + const reasoningDisabled = disabled || !selected?.efforts.length; const updateTarget = (next: AgentPersonaModelTarget) => props.onChange({ ...value, @@ -172,17 +135,31 @@ export function AgentRoutePolicyFields(props: { - ({ - value: effort, - label: effort, - }))} - onChange={(reasoningEffort) => updateTarget({ ...target, reasoningEffort })} - /> + + Reasoning + + ({ + id: effort, + title: effort, + state: effort === target.reasoningEffort ? "on" : "off", + }))} + onPressAction={({ nativeEvent }) => + updateTarget({ ...target, reasoningEffort: nativeEvent.event }) + } + > + + {target.reasoningEffort} + + + + From 52b3c5434c03778557cdec4e9b0050ce76a3e948 Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 1 Nov 2026 23:17:16 -0500 Subject: [PATCH 2/4] fix(mobile): persona forms are pushed settings pages, so Android's menus open Android's Menu draws in the app's root window, behind an RN Modal, so every picker in the persona forms did nothing on Android, on trunk's model pickers too. Edit and Create become pushed settings pages, as upstream's scheduled-task editor is, with its guard against losing unsaved changes. Co-Authored-By: Claude Opus 5.5 --- FORK.md | 6 +- apps/mobile/src/Stack.tsx | 2 + .../mobile/src/j5/agents/AgentCreateModal.tsx | 237 ------------------ .../src/j5/agents/AgentCreateScreen.tsx | 202 +++++++++++++++ .../mobile/src/j5/agents/AgentEditorModal.tsx | 178 ------------- .../src/j5/agents/AgentEditorScreen.tsx | 152 +++++++++++ .../j5/agents/AgentLibrarySettingsScreen.tsx | 54 +--- .../src/j5/agents/PersonaFormScreen.tsx | 120 +++++++++ apps/mobile/src/j5/agents/routes.ts | 16 ++ apps/mobile/src/j5/upstreamSeams.test.ts | 6 + 10 files changed, 515 insertions(+), 458 deletions(-) delete mode 100644 apps/mobile/src/j5/agents/AgentCreateModal.tsx create mode 100644 apps/mobile/src/j5/agents/AgentCreateScreen.tsx delete mode 100644 apps/mobile/src/j5/agents/AgentEditorModal.tsx create mode 100644 apps/mobile/src/j5/agents/AgentEditorScreen.tsx create mode 100644 apps/mobile/src/j5/agents/PersonaFormScreen.tsx create mode 100644 apps/mobile/src/j5/agents/routes.ts diff --git a/FORK.md b/FORK.md index 853cb1e160cf9..59b4422350c7a 100644 --- a/FORK.md +++ b/FORK.md @@ -521,6 +521,8 @@ migrations after upstream migrations. 102. Mobile's thread list has an Inbox bell with the open count ([#830](https://github.com/Jacksondr5/j5code/issues/830)), as web's rail does. J5-owned `apps/mobile/src/j5/inbox/InboxBell.tsx` reads every connected server's open count (`inboxCountSourcesAtom`, case 101), says it through `inboxBellPresentation` (`packages/client-runtime/src/j5/inbox.ts`, shared with web's bell), and opens the `Inbox` screen. It counts open asks only; web's also counts Crew requests and seat approvals, which come to mobile with Crews. Two headers mount it, each with one import and one or two lines: `apps/mobile/src/features/home/ThreadListToolbar.tsx` (Android) adds it beside `filterButton` in the toolbar row's `filter` slot when a server is saved, and `apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx` adds it as a `Toolbar.Custom` in the right toolbar of the thread list on iPhone and iPad alike (iOS draws its sidebar's header natively, through this toolbar). Android's split view draws its sidebar header with the same `ThreadListToolbar`, so it gets the bell there; no other header holds the thread list's filter. Upstream's symbol set has no plain bell on Android, so J5's `BellGlyph` draws Tabler's there and the SF Symbol on iOS. On a pin advance: if upstream moves the thread list's filter, move the bell with it. +103. Mobile's persona forms are pushed settings pages ([#894](https://github.com/Jacksondr5/j5code/issues/894)), since Android's `Menu` draws in the app's root window and can't appear over an RN `Modal` or upstream's `Sheet`. `apps/mobile/src/Stack.tsx` imports J5-owned `j5PersonaFormRoutes` (`apps/mobile/src/j5/agents/routes.ts`) and spreads it into `SETTINGS_SCREENS` after `SettingsAgents`, adding `SettingsPersonaNew` and `SettingsPersonaEdit`. They follow upstream's `SettingsScheduledTaskNew` and `SettingsScheduledTaskEdit`, including the guard against losing unsaved changes. On a pin advance: if upstream reshapes `SETTINGS_SCREENS`, spread the routes among them again. + ## Pin and upstream advance runbook Current pin: `d2c440312e5f39d59827ed466838a623516454d6`, upstream's stable release tag `v0.1.3` on `main` (frozen 2026-10-27). The previous pin was `70d60e03a7a35c6fa131825bbfa05ec893e69912`, upstream's nightly tag `v0.1.1-nightly.20261017.3238`. @@ -738,7 +740,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, 98, 101, Role library | +| `apps/mobile/src/Stack.tsx` | A | 72, 98, 101, 103, Role library | | `apps/mobile/src/features/home/ThreadListToolbar.tsx` | N | 102 | | `apps/mobile/src/features/workspace/WorkspaceToolbar.ios.tsx` | N | 102 | | `apps/mobile/src/features/archive/ArchivedThreadsRouteScreen.tsx` | N | 72 | @@ -1060,7 +1062,7 @@ The source-agent removal correction adds `removeSourceAgentPersona` under `setti The agent-row cleanup places availability badges beside names and keeps switches plus accessible destructive trash icons in the action area on web/desktop/mobile. The current UI uses `removeAgentPersona` (`settings:write`): J5 library code excludes the source ID before deleting an imported copy, so removed overrides never reveal another definition. Existing import-only/source-only RPCs are retained for compatibility. Source files and snapshots remain intact; reimport restores an agent. Focused tests cover source, import, disabled override, restart, snapshot preservation, and explicit restoration. -The imported-agent editor removes input/output/policy/route metadata from library rows and mounts J5-owned `AgentEditorDialog.tsx` (web/desktop) and `AgentEditorModal.tsx` (mobile). Shared presentation supplies edit drafts and model options from the selected environment. Additive catalog metadata carries editable targets and a content digest, not instructions. The authenticated `editImportedAgentPersona` mutation validates the digest and full definition, increments version, preserves enabled state and unedited fields, and atomically saves only the imported copy. Instructions/source files/snapshots remain untouched. Source entries require importing a copy before editing. Focused tests cover edit persistence, source/snapshot preservation, invalid/stale/removed saves, and editing visibility/model choices. +The imported-agent editor removes input/output/policy/route metadata from library rows and mounts J5-owned `AgentEditorDialog.tsx` (web/desktop) and `AgentEditorScreen.tsx` (mobile). Shared presentation supplies edit drafts and model options from the selected environment. Additive catalog metadata carries editable targets and a content digest, not instructions. The authenticated `editImportedAgentPersona` mutation validates the digest and full definition, increments version, preserves enabled state and unedited fields, and atomically saves only the imported copy. Instructions/source files/snapshots remain untouched. Source entries require importing a copy before editing. Focused tests cover edit persistence, source/snapshot preservation, invalid/stale/removed saves, and editing visibility/model choices. The import-control cleanup removes the Replace existing IDs checkbox/switch on web/desktop/mobile. Current clients always submit `replaceExisting: false`; conflict errors direct users to edit, remove before reimporting, or choose a different ID. The existing RPC replacement capability remains compatible. This preserves duplicate-ID protection and prevents imports from silently overwriting in-app edits. diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 7f2433163508a..24ce1dc45f84f 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -48,6 +48,7 @@ import { useConnectOnboardingNavigation } from "./features/cloud/connectOnboardi import { AttachmentFileScreen } from "./features/files/AttachmentFileScreen"; import { ThreadFilesTreeScreen, ThreadFileScreen } from "./features/files/ThreadFilesRouteScreen"; import { j5ThreadArtifactRoutes } from "./j5/artifacts/routes"; +import { j5PersonaFormRoutes } from "./j5/agents/routes"; import { j5InboxRoutes } from "./j5/inbox/routes"; import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout"; import { selectedPullRequestKey } from "./features/pull-requests/pullRequestSelection"; @@ -354,6 +355,7 @@ const SETTINGS_SCREENS = { title: "Personas", }, }), + ...j5PersonaFormRoutes(SETTINGS_PAGE_OPTIONS), SettingsProjectGrouping: createNativeStackScreen({ screen: SettingsProjectGroupingRouteScreen, linking: "settings/project-grouping", diff --git a/apps/mobile/src/j5/agents/AgentCreateModal.tsx b/apps/mobile/src/j5/agents/AgentCreateModal.tsx deleted file mode 100644 index e04a3e7dc2d95..0000000000000 --- a/apps/mobile/src/j5/agents/AgentCreateModal.tsx +++ /dev/null @@ -1,237 +0,0 @@ -import { useAtomValue } from "@effect/atom-react"; -import { - agentPersonaIdError, - agentPersonaIdFromName, - agentPersonaPolicyDrivers, - defaultAgentPersonaModelRoute, - type AgentPersonaCreateDraft, -} from "@t3tools/client-runtime/j5/agent-personas"; -import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; -import type { - AgentPersonaAuthorityPolicy, - AgentPersonaModelTarget, - EnvironmentId, -} from "@t3tools/contracts"; -import { useState } from "react"; -import { KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, View } from "react-native"; -import { SafeAreaView } from "react-native-safe-area-context"; - -import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; -import { useEnvironmentQuery } from "../../state/query"; -import { serverEnvironment } from "../../state/server"; -import { useAtomCommand } from "../../state/use-atom-command"; -import { AgentRoutePolicyFields } from "./AgentDefinitionFields"; -import { agentPersonaEnvironment } from "./agentPersonaAtoms"; - -/** Author a personal agent; it is stored as an imported definition of this environment. */ -export function AgentCreateModal(props: { - environmentId: EnvironmentId; - /** Prefill from an existing agent (Duplicate); the ID is treated as user-chosen. */ - initial?: AgentPersonaCreateDraft; - onClose: () => void; - onCreated: (displayName: string) => void; -}) { - const providers = useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)); - const catalog = useEnvironmentQuery( - agentPersonaEnvironment.catalog({ environmentId: props.environmentId, input: {} }), - ); - // New personas start on read-only, so prefer a provider that sandboxes it. - const defaultRoute = defaultAgentPersonaModelRoute( - providers ?? [], - agentPersonaPolicyDrivers(catalog.data, "read-only"), - ); - const [draft, setDraft] = useState<{ - displayName: string; - id: string; - idEdited: boolean; - description: string; - instructions: string; - authorityPolicy: AgentPersonaAuthorityPolicy; - modelRoute: readonly [AgentPersonaModelTarget, AgentPersonaModelTarget] | null; - }>( - props.initial - ? { ...props.initial, idEdited: true } - : { - displayName: "", - id: "", - idEdited: false, - description: "", - instructions: "", - authorityPolicy: "read-only", - modelRoute: null, - }, - ); - const [saving, setSaving] = useState(false); - const [error, setError] = useState(null); - const modelRoute = draft.modelRoute ?? defaultRoute; - const idError = agentPersonaIdError(draft.id); - const create = useAtomCommand(agentPersonaEnvironment.createAgentPersona, { - reportFailure: false, - }); - // The sheet may outlive the grant it was opened with, so its action follows the live answer. - const canCreate = useAtomValue( - agentPersonaEnvironment.createAgentPersona.permissionAtom(props.environmentId), - ); - const ready = - !saving && - canCreate && - idError === null && - draft.displayName.trim() !== "" && - draft.description.trim() !== "" && - draft.instructions.trim() !== "" && - modelRoute !== null; - async function submit() { - if (!ready || modelRoute === null) return; - setSaving(true); - setError(null); - const result = await create({ - environmentId: props.environmentId, - input: { - id: draft.id, - displayName: draft.displayName.trim(), - description: draft.description.trim(), - instructions: draft.instructions, - authorityPolicy: draft.authorityPolicy, - modelRoute: [modelRoute[0], modelRoute[1]], - }, - }); - setSaving(false); - if (result._tag === "Failure") { - const cause = squashAtomCommandFailure(result); - setError(cause instanceof Error ? cause.message : String(cause)); - return; - } - props.onCreated(draft.displayName.trim()); - } - return ( - { - if (!saving) props.onClose(); - }} - > - {/* SafeAreaView takes no className, so the theme surface and flex go on a View. */} - - - - - - {props.initial ? "Duplicate persona" : "Create persona"} - - - Cancel - - - - - A personal persona for this environment. It joins the library like an import, so you - can edit, switch off, or remove it later. - - - Name - - setDraft({ - ...draft, - displayName, - id: draft.idEdited ? draft.id : agentPersonaIdFromName(displayName), - }) - } - /> - - - ID - setDraft({ ...draft, id: id.trim(), idEdited: true })} - /> - - {draft.id !== "" && idError !== null - ? idError - : "Stable identifier used in @persona: mentions. Lowercase letters, digits, hyphens."} - - - - Description - setDraft({ ...draft, description })} - /> - - - Instructions - setDraft({ ...draft, instructions })} - /> - - Markdown. Instructions describe behavior; the runtime policy below is what is - enforced. - - - {modelRoute === null ? ( - - Sign in to Codex or Claude on this environment to choose the persona's models. - - ) : ( - setDraft({ ...draft, ...next })} - /> - )} - {error ? ( - - {error} - - ) : null} - void submit()} - > - - {saving ? "Creating…" : "Create persona"} - - - - - - - - ); -} diff --git a/apps/mobile/src/j5/agents/AgentCreateScreen.tsx b/apps/mobile/src/j5/agents/AgentCreateScreen.tsx new file mode 100644 index 0000000000000..0363eb7f68db1 --- /dev/null +++ b/apps/mobile/src/j5/agents/AgentCreateScreen.tsx @@ -0,0 +1,202 @@ +import { useAtomValue } from "@effect/atom-react"; +import { + agentPersonaIdError, + agentPersonaIdFromName, + agentPersonaPolicyDrivers, + defaultAgentPersonaModelRoute, +} from "@t3tools/client-runtime/j5/agent-personas"; +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; +import type { AgentPersonaAuthorityPolicy, AgentPersonaModelTarget } from "@t3tools/contracts"; +import { useState } from "react"; +import { Pressable, View } from "react-native"; + +import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; +import { useEnvironmentQuery } from "../../state/query"; +import { serverEnvironment } from "../../state/server"; +import { useAtomCommand } from "../../state/use-atom-command"; +import { AgentRoutePolicyFields } from "./AgentDefinitionFields"; +import { agentPersonaEnvironment } from "./agentPersonaAtoms"; +import { PersonaFormScreen, usePersonaFormExit, usePersonaFormParams } from "./PersonaFormScreen"; + +type PersonaDraft = { + displayName: string; + id: string; + idEdited: boolean; + description: string; + instructions: string; + authorityPolicy: AgentPersonaAuthorityPolicy; + modelRoute: readonly [AgentPersonaModelTarget, AgentPersonaModelTarget] | null; +}; + +/** Author a personal agent; it is stored as an imported definition of this environment. */ +export function AgentCreateScreen() { + const props = usePersonaFormParams<"SettingsPersonaNew">(); + const providers = useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)); + const catalog = useEnvironmentQuery( + agentPersonaEnvironment.catalog({ environmentId: props.environmentId, input: {} }), + ); + // New personas start on read-only, so prefer a provider that sandboxes it. + const defaultRoute = defaultAgentPersonaModelRoute( + providers ?? [], + agentPersonaPolicyDrivers(catalog.data, "read-only"), + ); + const [startingDraft] = useState( + props.initial + ? { ...props.initial, idEdited: true } + : { + displayName: "", + id: "", + idEdited: false, + description: "", + instructions: "", + authorityPolicy: "read-only", + modelRoute: null, + }, + ); + const [draft, setDraft] = useState(startingDraft); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(null); + const exit = usePersonaFormExit({ + hasChanges: JSON.stringify(draft) !== JSON.stringify(startingDraft), + saving, + }); + const modelRoute = draft.modelRoute ?? defaultRoute; + const idError = agentPersonaIdError(draft.id); + const create = useAtomCommand(agentPersonaEnvironment.createAgentPersona, { + reportFailure: false, + }); + // The page may outlive the grant it was opened with, so its action follows the live answer. + const canCreate = useAtomValue( + agentPersonaEnvironment.createAgentPersona.permissionAtom(props.environmentId), + ); + const ready = + !saving && + canCreate && + idError === null && + draft.displayName.trim() !== "" && + draft.description.trim() !== "" && + draft.instructions.trim() !== "" && + modelRoute !== null; + async function submit() { + if (!ready || modelRoute === null) return; + setSaving(true); + setError(null); + const result = await create({ + environmentId: props.environmentId, + input: { + id: draft.id, + displayName: draft.displayName.trim(), + description: draft.description.trim(), + instructions: draft.instructions, + authorityPolicy: draft.authorityPolicy, + modelRoute: [modelRoute[0], modelRoute[1]], + }, + }); + setSaving(false); + if (result._tag === "Failure") { + const cause = squashAtomCommandFailure(result); + setError(cause instanceof Error ? cause.message : String(cause)); + return; + } + catalog.refresh(); + exit.leaveAfterSave(); + } + return ( + + + A personal persona for this environment. It joins the library like an import, so you can + edit, switch off, or remove it later. + + + Name + + setDraft({ + ...draft, + displayName, + id: draft.idEdited ? draft.id : agentPersonaIdFromName(displayName), + }) + } + /> + + + ID + setDraft({ ...draft, id: id.trim(), idEdited: true })} + /> + + {draft.id !== "" && idError !== null + ? idError + : "Stable identifier used in @persona: mentions. Lowercase letters, digits, hyphens."} + + + + Description + setDraft({ ...draft, description })} + /> + + + Instructions + setDraft({ ...draft, instructions })} + /> + + Markdown. Instructions describe behavior; the runtime policy below is what is enforced. + + + {modelRoute === null ? ( + + Sign in to Codex or Claude on this environment to choose the persona's models. + + ) : ( + setDraft({ ...draft, ...next })} + /> + )} + {error ? ( + + {error} + + ) : null} + void submit()} + > + + {saving ? "Creating…" : "Create persona"} + + + + ); +} diff --git a/apps/mobile/src/j5/agents/AgentEditorModal.tsx b/apps/mobile/src/j5/agents/AgentEditorModal.tsx deleted file mode 100644 index 64da2034622af..0000000000000 --- a/apps/mobile/src/j5/agents/AgentEditorModal.tsx +++ /dev/null @@ -1,178 +0,0 @@ -import { useAtomValue } from "@effect/atom-react"; -import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; -import type { AgentPersonaEditInput, EnvironmentId } from "@t3tools/contracts"; -import { useEffect, useState } from "react"; -import { KeyboardAvoidingView, Modal, Platform, Pressable, ScrollView, View } from "react-native"; -import { SafeAreaView } from "react-native-safe-area-context"; - -import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; -import { useAtomCommand } from "../../state/use-atom-command"; -import { AgentRoutePolicyFields } from "./AgentDefinitionFields"; -import { agentPersonaEnvironment } from "./agentPersonaAtoms"; - -export function AgentEditorModal(props: { - environmentId: EnvironmentId; - initial: Omit; - onClose: () => void; - onSaved: () => void; -}) { - const [draft, setDraft] = useState(props.initial); - // Instructions are not in the catalog; load them once the sheet opens. - const [instructions, setInstructions] = useState(null); - const [saving, setSaving] = useState(false); - const [error, setError] = useState(null); - // The sheet may outlive the grant it was opened with, so its action follows the live answer. - const canSave = useAtomValue( - agentPersonaEnvironment.editImportedAgentPersona.permissionAtom(props.environmentId), - ); - const save = useAtomCommand(agentPersonaEnvironment.editImportedAgentPersona, { - reportFailure: false, - }); - const read = useAtomCommand(agentPersonaEnvironment.readAgentPersona, { - reportFailure: false, - }); - // oxlint-disable-next-line t3code/react-effect-budget -- loads the persona's instructions once when the editor opens; the read is a command, not an atom. - useEffect(() => { - let cancelled = false; - void read({ environmentId: props.environmentId, input: { personaId: props.initial.personaId } }) - .then((result) => { - if (cancelled) return; - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - setInstructions(result.value.definition.instructions); - }) - .catch((cause: unknown) => { - if (!cancelled) setError(cause instanceof Error ? cause.message : String(cause)); - }); - return () => { - cancelled = true; - }; - }, [props.environmentId, props.initial.personaId, read]); - async function submit() { - if (saving || instructions === null) return; - setSaving(true); - setError(null); - const result = await save({ - environmentId: props.environmentId, - input: { - ...draft, - displayName: draft.displayName.trim(), - description: draft.description.trim(), - instructions, - }, - }); - setSaving(false); - if (result._tag === "Failure") { - const cause = squashAtomCommandFailure(result); - setError(cause instanceof Error ? cause.message : String(cause)); - return; - } - props.onSaved(); - } - return ( - { - if (!saving) props.onClose(); - }} - > - {/* SafeAreaView takes no className, so the theme surface and flex go on a View. */} - - - - - Edit persona - - Cancel - - - - - Changes apply to this imported copy and future launches. The original file and - existing tasks stay unchanged. - - - Name - setDraft({ ...draft, displayName })} - /> - - - Description - setDraft({ ...draft, description })} - /> - - - Instructions - - - Markdown. Instructions describe behavior; the runtime policy below is what is - enforced. - - - setDraft({ ...draft, ...next })} - /> - {error ? ( - - {error} - - ) : null} - void submit()} - > - - {saving ? "Saving…" : "Save changes"} - - - - - - - - ); -} diff --git a/apps/mobile/src/j5/agents/AgentEditorScreen.tsx b/apps/mobile/src/j5/agents/AgentEditorScreen.tsx new file mode 100644 index 0000000000000..7c64e4d6015a2 --- /dev/null +++ b/apps/mobile/src/j5/agents/AgentEditorScreen.tsx @@ -0,0 +1,152 @@ +import { useAtomValue } from "@effect/atom-react"; +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; +import { useEffect, useState } from "react"; +import { Pressable, View } from "react-native"; + +import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; +import { useEnvironmentQuery } from "../../state/query"; +import { useAtomCommand } from "../../state/use-atom-command"; +import { AgentRoutePolicyFields } from "./AgentDefinitionFields"; +import { agentPersonaEnvironment } from "./agentPersonaAtoms"; +import { PersonaFormScreen, usePersonaFormExit, usePersonaFormParams } from "./PersonaFormScreen"; + +export function AgentEditorScreen() { + const props = usePersonaFormParams<"SettingsPersonaEdit">(); + const [draft, setDraft] = useState(props.initial); + // Instructions are not in the catalog; load them once the page opens. + const [instructions, setInstructions] = useState(null); + const [loadedInstructions, setLoadedInstructions] = useState(null); + const [saving, setSaving] = useState(false); + const [error, setError] = useState(null); + const catalog = useEnvironmentQuery( + agentPersonaEnvironment.catalog({ environmentId: props.environmentId, input: {} }), + ); + const exit = usePersonaFormExit({ + hasChanges: + instructions !== loadedInstructions || + JSON.stringify(draft) !== JSON.stringify(props.initial), + saving, + }); + // The page may outlive the grant it was opened with, so its action follows the live answer. + const canSave = useAtomValue( + agentPersonaEnvironment.editImportedAgentPersona.permissionAtom(props.environmentId), + ); + const save = useAtomCommand(agentPersonaEnvironment.editImportedAgentPersona, { + reportFailure: false, + }); + const read = useAtomCommand(agentPersonaEnvironment.readAgentPersona, { + reportFailure: false, + }); + // oxlint-disable-next-line t3code/react-effect-budget -- loads the persona's instructions once when the editor opens; the read is a command, not an atom. + useEffect(() => { + let cancelled = false; + void read({ environmentId: props.environmentId, input: { personaId: props.initial.personaId } }) + .then((result) => { + if (cancelled) return; + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + setInstructions(result.value.definition.instructions); + setLoadedInstructions(result.value.definition.instructions); + }) + .catch((cause: unknown) => { + if (!cancelled) setError(cause instanceof Error ? cause.message : String(cause)); + }); + return () => { + cancelled = true; + }; + }, [props.environmentId, props.initial.personaId, read]); + async function submit() { + if (saving || instructions === null) return; + setSaving(true); + setError(null); + const result = await save({ + environmentId: props.environmentId, + input: { + ...draft, + displayName: draft.displayName.trim(), + description: draft.description.trim(), + instructions, + }, + }); + setSaving(false); + if (result._tag === "Failure") { + const cause = squashAtomCommandFailure(result); + setError(cause instanceof Error ? cause.message : String(cause)); + return; + } + catalog.refresh(); + exit.leaveAfterSave(); + } + return ( + + + Changes apply to this imported copy and future launches. The original file and existing + tasks stay unchanged. + + + Name + setDraft({ ...draft, displayName })} + /> + + + Description + setDraft({ ...draft, description })} + /> + + + Instructions + + + Markdown. Instructions describe behavior; the runtime policy below is what is enforced. + + + setDraft({ ...draft, ...next })} + /> + {error ? ( + + {error} + + ) : null} + void submit()} + > + + {saving ? "Saving…" : "Save changes"} + + + + ); +} diff --git a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx index 4dbb9f095cc35..2b7a8545e8c0a 100644 --- a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx @@ -2,14 +2,10 @@ 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"; -import { - agentPersonaDuplicateDraft, - type AgentPersonaCreateDraft, -} from "@t3tools/client-runtime/j5/agent-personas"; +import { agentPersonaDuplicateDraft } from "@t3tools/client-runtime/j5/agent-personas"; import { AgentDetailsModal } from "./AgentDetailsModal"; -import { AgentEditorModal } from "./AgentEditorModal"; import { AgentFolderPickerModal } from "./AgentFolderPickerModal"; +import { usePersonaFormNavigation } from "./PersonaFormScreen"; import { sendWhenReconnected } from "./watchEnvironmentSessions"; import { personaRowActions } from "./personaRowActions"; import { Menu } from "../../components/ui/Menu"; @@ -23,7 +19,6 @@ import { importAgentPersonasWithConfirmation, } from "@t3tools/client-runtime/j5/agent-personas"; import { - type AgentPersonaEditInput, type AgentPersonaImportConflict, type AgentPersonaImportConflictError, type AgentPersonaLibraryFolder, @@ -136,12 +131,8 @@ function OwnerAgentLibrarySettingsScreen() { } | null>(null); // oxlint-disable-next-line t3code/react-effect-budget -- a replaced or unmounted confirmation resolves its waiting import as cancelled. useEffect(() => () => confirmation?.resolve(null), [confirmation]); - const [editing, setEditing] = useState<{ - environmentId: EnvironmentId; - initial: Omit; - } | null>(null); + const navigation = usePersonaFormNavigation(); const [notification, setNotification] = useState(null); - const [creating, setCreating] = useState<{ initial?: AgentPersonaCreateDraft } | null>(null); const [viewing, setViewing] = useState(null); const dismissNotification = useCallback(() => setNotification(null), []); const importAgents = useAtomCommand(agentPersonaEnvironment.importAgentPersonas, { @@ -284,7 +275,11 @@ function OwnerAgentLibrarySettingsScreen() { setNotification(failureNotice("Persona action failed", read)); return; } - setCreating({ initial: agentPersonaDuplicateDraft(read.value.definition) }); + if (effectiveEnvironmentId === null) return; + navigation.navigate("SettingsPersonaNew", { + environmentId: effectiveEnvironmentId, + initial: agentPersonaDuplicateDraft(read.value.definition), + }); } async function exportPersona(personaId: string) { if (busy) return; @@ -331,7 +326,10 @@ function OwnerAgentLibrarySettingsScreen() { accessibilityLabel: "Create persona", icon: "plus", disabled: locked || effectiveEnvironmentId === null, - onPress: () => setCreating({}), + onPress: () => { + if (effectiveEnvironmentId !== null) + navigation.navigate("SettingsPersonaNew", { environmentId: effectiveEnvironmentId }); + }, }, ]} > @@ -439,7 +437,7 @@ function OwnerAgentLibrarySettingsScreen() { persona.edit && effectiveEnvironmentId && canOperate ? () => { if (persona.edit && effectiveEnvironmentId) - setEditing({ + navigation.navigate("SettingsPersonaEdit", { environmentId: effectiveEnvironmentId, initial: persona.edit, }); @@ -535,18 +533,6 @@ function OwnerAgentLibrarySettingsScreen() { }} /> ) : null} - {creating && effectiveEnvironmentId ? ( - setCreating(null)} - onCreated={(displayName) => { - setCreating(null); - setNotification({ type: "success", title: `Created ${displayName}` }); - catalog.refresh(); - }} - /> - ) : null} {viewedPersona && effectiveEnvironmentId ? ( setViewing(null)} /> ) : null} - {editing ? ( - { - setEditing(null); - catalog.refresh(); - }} - onSaved={() => { - setEditing(null); - catalog.refresh(); - }} - /> - ) : null} ); } diff --git a/apps/mobile/src/j5/agents/PersonaFormScreen.tsx b/apps/mobile/src/j5/agents/PersonaFormScreen.tsx new file mode 100644 index 0000000000000..80d8ce0a599b2 --- /dev/null +++ b/apps/mobile/src/j5/agents/PersonaFormScreen.tsx @@ -0,0 +1,120 @@ +import { + usePreventRemove, + useNavigation, + useRoute, + type RouteProp, +} from "@react-navigation/native"; +import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; +import type { AgentPersonaCreateDraft } from "@t3tools/client-runtime/j5/agent-personas"; +import type { AgentPersonaEditInput, EnvironmentId } from "@t3tools/contracts"; +import { useRef, type ReactNode } from "react"; +import { KeyboardAvoidingView, Platform } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; + +import * as Dialog from "../../components/ui/Dialog"; +import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView"; +import { withNativeGlassHeaderItem } from "../../features/layout/native-glass-header-items"; +import { SettingsScreen } from "../../features/settings/components/SettingsScreen"; +import { NativeStackScreenOptions } from "../../native/StackHeader"; + +export type PersonaFormRoutes = { + SettingsPersonaNew: { + readonly environmentId: EnvironmentId; + /** Prefill from an existing persona (Duplicate); the ID is treated as user-chosen. */ + readonly initial?: AgentPersonaCreateDraft; + }; + SettingsPersonaEdit: { + readonly environmentId: EnvironmentId; + readonly initial: Omit; + }; +}; + +export function usePersonaFormNavigation() { + return useNavigation>(); +} + +export function usePersonaFormParams() { + return useRoute>().params as PersonaFormRoutes[Name]; +} + +/** Asks before unsaved changes are lost, and returns how to leave once they are saved. */ +export function usePersonaFormExit(options: { + readonly hasChanges: boolean; + readonly saving: boolean; +}) { + const navigation = useNavigation(); + // Set once the save lands, so the removal guard lets the form close. + const saved = useRef(false); + const guarded = options.hasChanges || options.saving; + usePreventRemove(guarded, ({ data }) => { + if (saved.current) { + navigation.dispatch(data.action); + return; + } + if (options.saving) { + Dialog.alert("Saving persona", "Wait for the persona to finish saving before leaving."); + return; + } + Dialog.alert("Discard changes?", "Your unsaved changes will be lost.", [ + { text: "Keep editing", style: "cancel" }, + { + text: "Discard changes", + style: "destructive", + onPress: () => navigation.dispatch(data.action), + }, + ]); + }); + return { + guarded, + leaveAfterSave: () => { + saved.current = true; + if (navigation.isFocused()) navigation.goBack(); + }, + }; +} + +/** A pushed settings page, because Android's Menu can't draw over an RN Modal or Sheet. */ +export function PersonaFormScreen(props: { + readonly title: string; + readonly guarded: boolean; + readonly children: ReactNode; +}) { + const navigation = useNavigation(); + const insets = useSafeAreaInsets(); + return ( + + {Platform.OS === "ios" ? ( + [ + withNativeGlassHeaderItem({ + type: "button", + label: "", + accessibilityLabel: "Back", + icon: { type: "sfSymbol", name: "chevron.backward" }, + onPress: () => navigation.goBack(), + }), + ], + }} + /> + ) : null} + + + {props.children} + + + + ); +} diff --git a/apps/mobile/src/j5/agents/routes.ts b/apps/mobile/src/j5/agents/routes.ts new file mode 100644 index 0000000000000..f01ecd3a6d658 --- /dev/null +++ b/apps/mobile/src/j5/agents/routes.ts @@ -0,0 +1,16 @@ +import { createNativeStackScreen } from "@react-navigation/native-stack"; + +import { AgentCreateScreen } from "./AgentCreateScreen"; +import { AgentEditorScreen } from "./AgentEditorScreen"; + +/** The persona forms, beside upstream's settings pages (FORK.md case 103). */ +export const j5PersonaFormRoutes = (options: Options) => ({ + SettingsPersonaNew: createNativeStackScreen({ + screen: AgentCreateScreen, + options: { ...options, title: "Create persona" }, + }), + SettingsPersonaEdit: createNativeStackScreen({ + screen: AgentEditorScreen, + options: { ...options, title: "Edit persona" }, + }), +}); diff --git a/apps/mobile/src/j5/upstreamSeams.test.ts b/apps/mobile/src/j5/upstreamSeams.test.ts index 04e49b07b079b..02469153185f1 100644 --- a/apps/mobile/src/j5/upstreamSeams.test.ts +++ b/apps/mobile/src/j5/upstreamSeams.test.ts @@ -191,6 +191,12 @@ const SEAMS: ReadonlyArray = [ from: "../../j5/archive/confirmArchive", reaches: ['action === "archive" && !(await confirmJ5Archive(thread))'], }, + { + file: "Stack.tsx", + record: "case 103: the persona forms' routes", + from: "./j5/agents/routes", + reaches: ["...j5PersonaFormRoutes(SETTINGS_PAGE_OPTIONS)"], + }, { file: "Stack.tsx", record: "case 101: the Inbox route", From cb869f9e43f5830361ec1484555a1cd594a23c5e Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 1 Nov 2026 23:22:15 -0500 Subject: [PATCH 3/4] docs(fork): name the persona form's new file Co-Authored-By: Claude Opus 5.5 --- FORK.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FORK.md b/FORK.md index 59b4422350c7a..29bcbb3a7001a 100644 --- a/FORK.md +++ b/FORK.md @@ -1058,7 +1058,7 @@ The 2026-09-08 import correction adds bounded file-content schemas and shared se The imported-agent lifecycle follow-up adds `setImportedAgentPersonaEnabled` under `settings:write` authorization, an Owner's like every Persona change (People and access AC20). J5-owned library storage preserves an optional enabled flag (legacy records default on), strips it from portable definitions/snapshots, and preserves it on replacement. Catalogs expose a disabled availability reason; launch preparation rejects disabled IDs before creating a task. Shared presentation and J5 web/mobile Settings show On/Off beside Remove import. Tests cover persistence, re-enable, launch rejection/receipt replay, replacement, and removal without affecting saved tasks. -The source-agent removal correction adds `removeSourceAgentPersona` under `settings:write` authorization and exposes Remove from library for folder-loaded agents/examples in the J5 Settings screens. J5 library code atomically persists per-environment source-ID exclusions without deleting user files or snapshots; imported copies can restore excluded IDs. Regression tests cover My Local Scout, restart persistence, unchanged source files/snapshots, rejected new launches, reimport, concurrent removals, and stale source actions after import. The 2026-09-10 restore follow-up (Tyler Barton's #85 review) adds `restoreSourceAgentPersona` to the same J5 RPC group; the catalog lists excluded source and bundled definitions as `removed` entries and both J5 settings screens show a Restore action in place of the trash, so removing a bundled example is no longer a one-way door now that imports are YAML-only. The same day's personal-agent follow-up adds `createAgentPersona` to the J5 RPC group with J5-owned create dialogs on web and mobile (`AgentCreateDialog.tsx`, `AgentCreateModal.tsx`) sharing route and policy fields with the editors; created agents are ordinary imported definitions, so no upstream file changes. A further pass adds `readAgentPersona` (read scope) for instruction editing, Duplicate, and Export YAML on both clients, and makes `acceptedInput`, `inputArtifacts`, and `outputArtifact` optional in the J5 definition schema so personal agents carry no synthetic handoff fields. +The source-agent removal correction adds `removeSourceAgentPersona` under `settings:write` authorization and exposes Remove from library for folder-loaded agents/examples in the J5 Settings screens. J5 library code atomically persists per-environment source-ID exclusions without deleting user files or snapshots; imported copies can restore excluded IDs. Regression tests cover My Local Scout, restart persistence, unchanged source files/snapshots, rejected new launches, reimport, concurrent removals, and stale source actions after import. The 2026-09-10 restore follow-up (Tyler Barton's #85 review) adds `restoreSourceAgentPersona` to the same J5 RPC group; the catalog lists excluded source and bundled definitions as `removed` entries and both J5 settings screens show a Restore action in place of the trash, so removing a bundled example is no longer a one-way door now that imports are YAML-only. The same day's personal-agent follow-up adds `createAgentPersona` to the J5 RPC group with J5-owned create dialogs on web and mobile (`AgentCreateDialog.tsx`, `AgentCreateScreen.tsx`) sharing route and policy fields with the editors; created agents are ordinary imported definitions, so no upstream file changes. A further pass adds `readAgentPersona` (read scope) for instruction editing, Duplicate, and Export YAML on both clients, and makes `acceptedInput`, `inputArtifacts`, and `outputArtifact` optional in the J5 definition schema so personal agents carry no synthetic handoff fields. The agent-row cleanup places availability badges beside names and keeps switches plus accessible destructive trash icons in the action area on web/desktop/mobile. The current UI uses `removeAgentPersona` (`settings:write`): J5 library code excludes the source ID before deleting an imported copy, so removed overrides never reveal another definition. Existing import-only/source-only RPCs are retained for compatibility. Source files and snapshots remain intact; reimport restores an agent. Focused tests cover source, import, disabled override, restart, snapshot preservation, and explicit restoration. From 599168ed057367bbfd417533a34b6d732bf8609d Mon Sep 17 00:00:00 2001 From: Jackson Miller Date: Sun, 1 Nov 2026 23:34:28 -0500 Subject: [PATCH 4/4] fix(mobile): swipe back leaves a persona form with nothing unsaved iOS turns off the swipe gesture when a screen has a custom back item, whatever gestureEnabled says. The custom item is only needed so the unsaved-changes guard runs first, so a form with nothing to lose now uses the native back button. Co-Authored-By: Claude Opus 5.5 --- .../src/j5/agents/PersonaFormScreen.tsx | 37 ++++++++++++------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/apps/mobile/src/j5/agents/PersonaFormScreen.tsx b/apps/mobile/src/j5/agents/PersonaFormScreen.tsx index 80d8ce0a599b2..7bfefbc6c8413 100644 --- a/apps/mobile/src/j5/agents/PersonaFormScreen.tsx +++ b/apps/mobile/src/j5/agents/PersonaFormScreen.tsx @@ -85,20 +85,29 @@ export function PersonaFormScreen(props: { {Platform.OS === "ios" ? ( [ - withNativeGlassHeaderItem({ - type: "button", - label: "", - accessibilityLabel: "Back", - icon: { type: "sfSymbol", name: "chevron.backward" }, - onPress: () => navigation.goBack(), - }), - ], - }} + // A custom back item also turns off iOS's swipe back, so it stays only while guarded. + options={ + props.guarded + ? { + headerBackVisible: false, + gestureEnabled: false, + // Native Back pops before removal guards; a bar action lets the guard run first. + unstable_headerLeftItems: () => [ + withNativeGlassHeaderItem({ + type: "button", + label: "", + accessibilityLabel: "Back", + icon: { type: "sfSymbol", name: "chevron.backward" }, + onPress: () => navigation.goBack(), + }), + ], + } + : { + headerBackVisible: true, + gestureEnabled: true, + unstable_headerLeftItems: undefined, + } + } /> ) : null}