diff --git a/FORK.md b/FORK.md index 29bcbb3a7001a..3a1416b36c71e 100644 --- a/FORK.md +++ b/FORK.md @@ -521,7 +521,7 @@ 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. +103. Mobile's persona forms and Playbook conversation form are pushed settings pages ([#894](https://github.com/Jacksondr5/j5code/issues/894), [#902](https://github.com/Jacksondr5/j5code/issues/902)), 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 `j5SettingsFormRoutes` (`apps/mobile/src/j5/agents/routes.ts`) and spreads it into `SETTINGS_SCREENS` after `SettingsAgents`, adding `SettingsPersonaNew`, `SettingsPersonaEdit` and `SettingsPlaybookConversation`. 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 diff --git a/apps/mobile/src/Stack.tsx b/apps/mobile/src/Stack.tsx index 24ce1dc45f84f..449b89580a4f6 100644 --- a/apps/mobile/src/Stack.tsx +++ b/apps/mobile/src/Stack.tsx @@ -48,7 +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 { j5SettingsFormRoutes } from "./j5/agents/routes"; import { j5InboxRoutes } from "./j5/inbox/routes"; import { AdaptiveWorkspaceLayout } from "./features/layout/AdaptiveWorkspaceLayout"; import { selectedPullRequestKey } from "./features/pull-requests/pullRequestSelection"; @@ -355,7 +355,7 @@ const SETTINGS_SCREENS = { title: "Personas", }, }), - ...j5PersonaFormRoutes(SETTINGS_PAGE_OPTIONS), + ...j5SettingsFormRoutes(SETTINGS_PAGE_OPTIONS), SettingsProjectGrouping: createNativeStackScreen({ screen: SettingsProjectGroupingRouteScreen, linking: "settings/project-grouping", diff --git a/apps/mobile/src/j5/agents/AgentCreateScreen.tsx b/apps/mobile/src/j5/agents/AgentCreateScreen.tsx index 0363eb7f68db1..26fffbcbe4eb9 100644 --- a/apps/mobile/src/j5/agents/AgentCreateScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentCreateScreen.tsx @@ -16,7 +16,11 @@ 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"; +import { + SettingsFormScreen, + useSettingsFormExit, + useSettingsFormParams, +} from "./SettingsFormScreen"; type PersonaDraft = { displayName: string; @@ -30,7 +34,7 @@ type PersonaDraft = { /** Author a personal agent; it is stored as an imported definition of this environment. */ export function AgentCreateScreen() { - const props = usePersonaFormParams<"SettingsPersonaNew">(); + const props = useSettingsFormParams<"SettingsPersonaNew">(); const providers = useAtomValue(serverEnvironment.providersValueAtom(props.environmentId)); const catalog = useEnvironmentQuery( agentPersonaEnvironment.catalog({ environmentId: props.environmentId, input: {} }), @@ -56,7 +60,7 @@ export function AgentCreateScreen() { const [draft, setDraft] = useState(startingDraft); const [saving, setSaving] = useState(false); const [error, setError] = useState(null); - const exit = usePersonaFormExit({ + const exit = useSettingsFormExit({ hasChanges: JSON.stringify(draft) !== JSON.stringify(startingDraft), saving, }); @@ -102,7 +106,7 @@ export function AgentCreateScreen() { exit.leaveAfterSave(); } return ( - @@ -197,6 +201,6 @@ export function AgentCreateScreen() { {saving ? "Creating…" : "Create persona"} - + ); } diff --git a/apps/mobile/src/j5/agents/AgentEditorScreen.tsx b/apps/mobile/src/j5/agents/AgentEditorScreen.tsx index 7c64e4d6015a2..a22c27c630738 100644 --- a/apps/mobile/src/j5/agents/AgentEditorScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentEditorScreen.tsx @@ -8,10 +8,14 @@ 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"; +import { + SettingsFormScreen, + useSettingsFormExit, + useSettingsFormParams, +} from "./SettingsFormScreen"; export function AgentEditorScreen() { - const props = usePersonaFormParams<"SettingsPersonaEdit">(); + const props = useSettingsFormParams<"SettingsPersonaEdit">(); const [draft, setDraft] = useState(props.initial); // Instructions are not in the catalog; load them once the page opens. const [instructions, setInstructions] = useState(null); @@ -21,7 +25,7 @@ export function AgentEditorScreen() { const catalog = useEnvironmentQuery( agentPersonaEnvironment.catalog({ environmentId: props.environmentId, input: {} }), ); - const exit = usePersonaFormExit({ + const exit = useSettingsFormExit({ hasChanges: instructions !== loadedInstructions || JSON.stringify(draft) !== JSON.stringify(props.initial), @@ -77,7 +81,7 @@ export function AgentEditorScreen() { exit.leaveAfterSave(); } return ( - + Changes apply to this imported copy and future launches. The original file and existing tasks stay unchanged. @@ -147,6 +151,6 @@ export function AgentEditorScreen() { {saving ? "Saving…" : "Save changes"} - + ); } diff --git a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx index 2b7a8545e8c0a..3c7aeabd6ff73 100644 --- a/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/agents/AgentLibrarySettingsScreen.tsx @@ -5,7 +5,7 @@ import { AgentImportConflictModal } from "./AgentImportConflictModal"; import { agentPersonaDuplicateDraft } from "@t3tools/client-runtime/j5/agent-personas"; import { AgentDetailsModal } from "./AgentDetailsModal"; import { AgentFolderPickerModal } from "./AgentFolderPickerModal"; -import { usePersonaFormNavigation } from "./PersonaFormScreen"; +import { useSettingsFormNavigation } from "./SettingsFormScreen"; import { sendWhenReconnected } from "./watchEnvironmentSessions"; import { personaRowActions } from "./personaRowActions"; import { Menu } from "../../components/ui/Menu"; @@ -131,7 +131,7 @@ 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 navigation = usePersonaFormNavigation(); + const navigation = useSettingsFormNavigation(); const [notification, setNotification] = useState(null); const [viewing, setViewing] = useState(null); const dismissNotification = useCallback(() => setNotification(null), []); diff --git a/apps/mobile/src/j5/agents/PersonaFormScreen.tsx b/apps/mobile/src/j5/agents/SettingsFormScreen.tsx similarity index 80% rename from apps/mobile/src/j5/agents/PersonaFormScreen.tsx rename to apps/mobile/src/j5/agents/SettingsFormScreen.tsx index 7bfefbc6c8413..5207f0d18faa5 100644 --- a/apps/mobile/src/j5/agents/PersonaFormScreen.tsx +++ b/apps/mobile/src/j5/agents/SettingsFormScreen.tsx @@ -6,7 +6,7 @@ import { } 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 type { AgentPersonaEditInput, EnvironmentId, ProjectId } from "@t3tools/contracts"; import { useRef, type ReactNode } from "react"; import { KeyboardAvoidingView, Platform } from "react-native"; import { useSafeAreaInsets } from "react-native-safe-area-context"; @@ -17,7 +17,7 @@ import { withNativeGlassHeaderItem } from "../../features/layout/native-glass-he import { SettingsScreen } from "../../features/settings/components/SettingsScreen"; import { NativeStackScreenOptions } from "../../native/StackHeader"; -export type PersonaFormRoutes = { +export type SettingsFormRoutes = { SettingsPersonaNew: { readonly environmentId: EnvironmentId; /** Prefill from an existing persona (Duplicate); the ID is treated as user-chosen. */ @@ -27,18 +27,24 @@ export type PersonaFormRoutes = { readonly environmentId: EnvironmentId; readonly initial: Omit; }; + SettingsPlaybookConversation: { + readonly environmentId: EnvironmentId; + readonly name: string | null; + /** The project Settings is showing, so a project playbook's chat opens where it lives. */ + readonly projectId: ProjectId | null; + }; }; -export function usePersonaFormNavigation() { - return useNavigation>(); +export function useSettingsFormNavigation() { + return useNavigation>(); } -export function usePersonaFormParams() { - return useRoute>().params as PersonaFormRoutes[Name]; +export function useSettingsFormParams() { + return useRoute>().params as SettingsFormRoutes[Name]; } -/** Asks before unsaved changes are lost, and returns how to leave once they are saved. */ -export function usePersonaFormExit(options: { +/** Asks before unsaved changes are lost, and returns how to leave once the work is done. */ +export function useSettingsFormExit(options: { readonly hasChanges: boolean; readonly saving: boolean; }) { @@ -52,7 +58,7 @@ export function usePersonaFormExit(options: { return; } if (options.saving) { - Dialog.alert("Saving persona", "Wait for the persona to finish saving before leaving."); + Dialog.alert("Still working", "Wait for this to finish before leaving."); return; } Dialog.alert("Discard changes?", "Your unsaved changes will be lost.", [ @@ -66,6 +72,10 @@ export function usePersonaFormExit(options: { }); return { guarded, + /** For a form that leaves by its own navigation action. */ + allowLeaving: () => { + saved.current = true; + }, leaveAfterSave: () => { saved.current = true; if (navigation.isFocused()) navigation.goBack(); @@ -74,7 +84,7 @@ export function usePersonaFormExit(options: { } /** A pushed settings page, because Android's Menu can't draw over an RN Modal or Sheet. */ -export function PersonaFormScreen(props: { +export function SettingsFormScreen(props: { readonly title: string; readonly guarded: boolean; readonly children: ReactNode; diff --git a/apps/mobile/src/j5/agents/routes.ts b/apps/mobile/src/j5/agents/routes.ts index f01ecd3a6d658..0c739cc7d0036 100644 --- a/apps/mobile/src/j5/agents/routes.ts +++ b/apps/mobile/src/j5/agents/routes.ts @@ -2,9 +2,10 @@ import { createNativeStackScreen } from "@react-navigation/native-stack"; import { AgentCreateScreen } from "./AgentCreateScreen"; import { AgentEditorScreen } from "./AgentEditorScreen"; +import { PlaybookConversationScreen } from "../playbooks/PlaybookConversationScreen"; -/** The persona forms, beside upstream's settings pages (FORK.md case 103). */ -export const j5PersonaFormRoutes = (options: Options) => ({ +/** The Personas page's forms, beside upstream's settings pages (FORK.md case 103). */ +export const j5SettingsFormRoutes = (options: Options) => ({ SettingsPersonaNew: createNativeStackScreen({ screen: AgentCreateScreen, options: { ...options, title: "Create persona" }, @@ -13,4 +14,8 @@ export const j5PersonaFormRoutes = (options: Options) => screen: AgentEditorScreen, options: { ...options, title: "Edit persona" }, }), + SettingsPlaybookConversation: createNativeStackScreen({ + screen: PlaybookConversationScreen, + options: { ...options, title: "Prepare chat" }, + }), }); diff --git a/apps/mobile/src/j5/playbooks/PlaybookConversationModal.tsx b/apps/mobile/src/j5/playbooks/PlaybookConversationScreen.tsx similarity index 61% rename from apps/mobile/src/j5/playbooks/PlaybookConversationModal.tsx rename to apps/mobile/src/j5/playbooks/PlaybookConversationScreen.tsx index 60a3081f71280..d87cd4d5ac1b3 100644 --- a/apps/mobile/src/j5/playbooks/PlaybookConversationModal.tsx +++ b/apps/mobile/src/j5/playbooks/PlaybookConversationScreen.tsx @@ -6,16 +6,9 @@ import { playbookWorkspaces, } from "@t3tools/client-runtime/j5/playbooks"; import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; -import { - CommandId, - MessageId, - ThreadId, - type EnvironmentId, - type ProjectId, -} from "@t3tools/contracts"; +import { CommandId, MessageId, ThreadId } from "@t3tools/contracts"; import { useRef, useState } from "react"; -import { Modal, Pressable, View } from "react-native"; -import { SafeAreaView } from "react-native-safe-area-context"; +import { Pressable, View } from "react-native"; import { AppText as Text } from "../../components/ui/AppText"; import { Menu } from "../../components/ui/Menu"; import { makeTurnCommandMetadata } from "../../lib/commandMetadata"; @@ -25,21 +18,17 @@ import { useAtomCommand } from "../../state/use-atom-command"; import { useAtomQueryRunner } from "../../state/use-atom-query-runner"; import { threadEnvironment } from "../../state/threads"; import { agentPersonaEnvironment } from "../agents/agentPersonaAtoms"; +import { + SettingsFormScreen, + useSettingsFormExit, + useSettingsFormParams, +} from "../agents/SettingsFormScreen"; import { preparePlaybookDraft } from "./preparePlaybookDraft"; /** Projects place conversations; the playbook itself belongs to the environment. */ -export function PlaybookConversationModal({ - environmentId, - name, - projectId = null, - onClose, -}: { - environmentId: EnvironmentId; - name: string | null; - /** The project Settings is showing, so a project playbook's chat opens where it lives. */ - projectId?: ProjectId | null; - onClose: () => void; -}) { +export function PlaybookConversationScreen() { + const { environmentId, name, projectId } = + useSettingsFormParams<"SettingsPlaybookConversation">(); const navigation = useNavigation(); const projects = useAtomValue(environmentProjects.projectsAtom); const workspaces = playbookWorkspaces( @@ -52,6 +41,7 @@ export function PlaybookConversationModal({ const workspace = workspaces.find((entry) => entry.key === selected) ?? workspaces[0]; const [busy, setBusy] = useState(false); const [error, setError] = useState(null); + const exit = useSettingsFormExit({ hasChanges: false, saving: busy }); const serverConfigs = useServerConfigs(); const readCatalog = useAtomQueryRunner(agentPersonaEnvironment.catalog, { reportFailure: false, @@ -75,8 +65,9 @@ export function PlaybookConversationModal({ const opened = await settlePromise(async () => { if (name !== null) { const draftId = preparePlaybookDraft(workspace, `Start playbook ${name}`); + exit.allowLeaving(); navigation.dispatch( - StackActions.push("Thread", { + StackActions.replace("Thread", { draft: { environmentId, projectId: workspace.projectId, @@ -124,8 +115,9 @@ export function PlaybookConversationModal({ const { target } = launch.current; const result = await startTurn(target); if (result._tag === "Failure") throw squashAtomCommandFailure(result); + exit.allowLeaving(); navigation.dispatch( - StackActions.push("Thread", { environmentId, threadId: target.input.threadId }), + StackActions.replace("Thread", { environmentId, threadId: target.input.threadId }), ); } }); @@ -133,75 +125,56 @@ export function PlaybookConversationModal({ if (opened._tag === "Failure") { const cause = squashAtomCommandFailure(opened); setError(cause instanceof Error ? cause.message : "Could not open the conversation."); - return; } - onClose(); } return ( - { - if (!busy) onClose(); - }} + - {/* SafeAreaView takes no className, so the theme surface and flex go on a View. */} - - - - - {name === null ? "Create playbook" : "Prepare chat"} - - - {name === null - ? "Choose a project for the conversation. New playbooks are saved to the environment library." - : "Choose the project to run the playbook in."} - - {workspace ? ( - ({ - id: entry.key, - title: entry.title, - state: entry.key === workspace.key ? "on" : "off", - }))} - onPressAction={({ nativeEvent }) => setSelected(nativeEvent.event)} - > - - {workspace.title} - - - ) : ( - - Add a project to open a conversation. You can import playbooks without one. - - )} - {error ? ( - - {error} - - ) : null} - - - Cancel - - void submit()} - > - - {name === null ? "Open Playbook Author" : "Prepare chat"} - - - - - - - + + {name === null + ? "Choose a project for the conversation. New playbooks are saved to the environment library." + : "Choose the project to run the playbook in."} + + {workspace ? ( + + ({ + id: entry.key, + title: entry.title, + state: entry.key === workspace.key ? "on" : "off", + }))} + onPressAction={({ nativeEvent }) => setSelected(nativeEvent.event)} + > + + {workspace.title} + + + + ) : ( + Add a project to open a conversation. You can import playbooks without one. + )} + {error ? ( + + {error} + + ) : null} + void submit()} + > + + {name === null ? "Open Playbook Author" : "Prepare chat"} + + + ); } diff --git a/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx b/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx index 038318e15fc21..ec172959b1b58 100644 --- a/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx +++ b/apps/mobile/src/j5/playbooks/PlaybookLibrarySettingsScreen.tsx @@ -16,7 +16,7 @@ import { useRemoteConnectionStatus } from "../../state/use-remote-environment-re import { AgentFolderPickerModal } from "../agents/AgentFolderPickerModal"; import { useOwnedEnvironmentIds } from "../sharing/guestAccess"; import { j5Environment } from "../state"; -import { PlaybookConversationModal } from "./PlaybookConversationModal"; +import { useSettingsFormNavigation } from "../agents/SettingsFormScreen"; export function PlaybookLibrarySettingsSection({ environmentId, @@ -73,7 +73,13 @@ function PlaybookLibrary({ const [yaml, setYaml] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); - const [conversation, setConversation] = useState<{ name: string | null } | null>(null); + const navigation = useSettingsFormNavigation(); + const openConversation = (playbook: string | null) => + navigation.navigate("SettingsPlaybookConversation", { + environmentId, + name: playbook, + projectId: project?.id ?? null, + }); const [details, setDetails] = useState(null); const [copyTarget, setCopyTarget] = useState<{ name: string; @@ -171,7 +177,7 @@ function PlaybookLibrary({ ]} onPressAction={({ nativeEvent }) => { const action = nativeEvent.event; - if (action === "create") setConversation({ name: null }); + if (action === "create") openConversation(null); else if (action === "import") { setError(null); setImporting(true); @@ -260,7 +266,7 @@ function PlaybookLibrary({ ]} onPressAction={({ nativeEvent }) => { const action = nativeEvent.event; - if (action === "chat") setConversation({ name: playbook.name }); + if (action === "chat") openConversation(playbook.name); else if (action === "steps") setDetails(playbook.name); else if (action.startsWith("copy:")) { const destination = environments.find( @@ -382,14 +388,6 @@ function PlaybookLibrary({ }} /> ) : null} - {conversation ? ( - setConversation(null)} - /> - ) : null} {detail ? ( = [ file: "Stack.tsx", record: "case 103: the persona forms' routes", from: "./j5/agents/routes", - reaches: ["...j5PersonaFormRoutes(SETTINGS_PAGE_OPTIONS)"], + reaches: ["...j5SettingsFormRoutes(SETTINGS_PAGE_OPTIONS)"], }, { file: "Stack.tsx",