diff --git a/FORK.md b/FORK.md index 92fac016ab9c..013fe23f5761 100644 --- a/FORK.md +++ b/FORK.md @@ -527,7 +527,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 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. +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 `j5SettingsFormRoutes` (`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. Starting a playbook opens upstream's new-chat draft instead of a page of its own ([#963](https://github.com/Jacksondr5/j5code/issues/963)). 104. A Crew notice with nothing for the person takes no timeline row ([#741](https://github.com/Jacksondr5/j5code/issues/741), Bryant 2026-10-27). `apps/web/src/components/chat/MessagesTimeline.tsx` carries one J5 import and one changed line in `ConversationTimeline`: `const rows = useStableRows(withoutHiddenCrewNotices(rawRows), listIdentityKey)`, J5-owned in `apps/web/src/j5/crew/crewNotices.logic.ts`. It drops the message rows of platform Crew notices (`createdBy === "system"`) whose `crewNoticeLines` are empty, a clean launch report or a clean finish, after upstream has derived the rows, so each notice still bounds the Captain turn it started (`deriveActiveVisualResponseRunIds`, terminal assistant messages and rollback all read user messages as turn boundaries), and returns the same array when nothing is hidden, cached per input array, because `useStableRows` compares its source by identity. Upstream's minimap reads the filtered rows, so an ask's reply preview can run past a hidden notice; that is accepted. Proof: `apps/web/src/j5/crew/crewNotices.logic.test.ts`, "keeps the rows a hidden notice bounded". On a pin advance: if upstream stops deriving rows through `useStableRows`, apply the filter to whatever the list renders, after turn boundaries are computed, never to the entries before them. diff --git a/apps/mobile/src/j5/agents/SettingsFormScreen.tsx b/apps/mobile/src/j5/agents/SettingsFormScreen.tsx index 5207f0d18faa..09b9a4364b51 100644 --- a/apps/mobile/src/j5/agents/SettingsFormScreen.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, ProjectId } from "@t3tools/contracts"; +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"; @@ -27,12 +27,6 @@ export type SettingsFormRoutes = { 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 useSettingsFormNavigation() { diff --git a/apps/mobile/src/j5/agents/routes.ts b/apps/mobile/src/j5/agents/routes.ts index 0c739cc7d003..4eec716c04f2 100644 --- a/apps/mobile/src/j5/agents/routes.ts +++ b/apps/mobile/src/j5/agents/routes.ts @@ -2,9 +2,8 @@ import { createNativeStackScreen } from "@react-navigation/native-stack"; import { AgentCreateScreen } from "./AgentCreateScreen"; import { AgentEditorScreen } from "./AgentEditorScreen"; -import { PlaybookConversationScreen } from "../playbooks/PlaybookConversationScreen"; -/** The Personas page's forms, beside upstream's settings pages (FORK.md case 103). */ +/** The persona forms, beside upstream's settings pages (FORK.md case 103). */ export const j5SettingsFormRoutes = (options: Options) => ({ SettingsPersonaNew: createNativeStackScreen({ screen: AgentCreateScreen, @@ -14,8 +13,4 @@ export const j5SettingsFormRoutes = (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/PlaybookConversationScreen.tsx b/apps/mobile/src/j5/playbooks/PlaybookConversationScreen.tsx deleted file mode 100644 index 8b29a484a2c8..000000000000 --- a/apps/mobile/src/j5/playbooks/PlaybookConversationScreen.tsx +++ /dev/null @@ -1,185 +0,0 @@ -import { useAtomValue } from "@effect/atom-react"; -import { StackActions, useNavigation } from "@react-navigation/native"; -import { - ensurePlaybookAuthor, - playbookAuthorLaunch, - playbookWorkspaces, -} from "@t3tools/client-runtime/j5/playbooks"; -import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; -import { CommandId, MessageId, ThreadId } from "@t3tools/contracts"; -import { useRef, useState } from "react"; -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"; -import { useServerConfigs } from "../../state/entities"; -import { environmentProjects } from "../../state/projects"; -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 PlaybookConversationScreen() { - const { environmentId, name, projectId } = - useSettingsFormParams<"SettingsPlaybookConversation">(); - const navigation = useNavigation(); - const projects = useAtomValue(environmentProjects.projectsAtom); - const workspaces = playbookWorkspaces( - // As upstream's pickers: an archived project is not offered, unless the link named it. - projects.filter( - (project) => - project.environmentId === environmentId && - (project.archivedAt == null || project.id === projectId), - ), - [], - ); - const [selected, setSelected] = useState( - (workspaces.find((entry) => entry.projectId === projectId) ?? workspaces[0])?.key ?? "", - ); - 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, - refresh: true, - }); - const readAuthor = useAtomCommand(agentPersonaEnvironment.readAgentPersona, { - reportFailure: false, - }); - const editAuthor = useAtomCommand(agentPersonaEnvironment.editImportedAgentPersona, { - reportFailure: false, - }); - const createPersona = useAtomCommand(agentPersonaEnvironment.createAgentPersona, { - reportFailure: false, - }); - const startTurn = useAtomCommand(threadEnvironment.startTurn, { reportFailure: false }); - const launch = useRef<{ key: string; target: Parameters[0] } | null>(null); - async function submit() { - if (!workspace || busy) return; - setBusy(true); - setError(null); - const opened = await settlePromise(async () => { - if (name !== null) { - const draftId = preparePlaybookDraft(workspace, `Start playbook ${name}`); - exit.allowLeaving(); - navigation.dispatch( - StackActions.replace("Thread", { - draft: { - environmentId, - projectId: workspace.projectId, - title: workspace.title, - draftId, - }, - }), - ); - } else { - if (launch.current?.key !== workspace.key) { - const modelSelection = await ensurePlaybookAuthor({ - providers: serverConfigs.get(environmentId)?.providers ?? [], - readCatalog: async () => { - const result = await readCatalog({ environmentId, input: {} }); - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - return result.value; - }, - readDefinition: async (personaId) => { - const result = await readAuthor({ environmentId, input: { personaId } }); - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - return result.value.definition; - }, - editPersona: async (input) => { - const result = await editAuthor({ environmentId, input }); - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - }, - createPersona: async (input) => { - const result = await createPersona({ environmentId, input }); - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - }, - }); - const metadata = makeTurnCommandMetadata(); - launch.current = { - key: workspace.key, - target: playbookAuthorLaunch({ - workspace, - modelSelection, - commandId: CommandId.make(metadata.commandId), - threadId: ThreadId.make(metadata.threadId), - messageId: MessageId.make(metadata.messageId), - createdAt: metadata.createdAt, - }), - }; - } - const { target } = launch.current; - const result = await startTurn(target); - if (result._tag === "Failure") throw squashAtomCommandFailure(result); - exit.allowLeaving(); - navigation.dispatch( - StackActions.replace("Thread", { environmentId, threadId: target.input.threadId }), - ); - } - }); - setBusy(false); - if (opened._tag === "Failure") { - const cause = squashAtomCommandFailure(opened); - setError(cause instanceof Error ? cause.message : "Could not open the conversation."); - } - } - return ( - - - {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 b060ffdac3ba..854fde826477 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 { useSettingsFormNavigation } from "../agents/SettingsFormScreen"; +import { useStartPlaybookConversation } from "./startPlaybookConversation"; export function PlaybookLibrarySettingsSection({ environmentId, @@ -76,13 +76,9 @@ function PlaybookLibrary({ const [yaml, setYaml] = useState(""); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); - const navigation = useSettingsFormNavigation(); + const startConversation = useStartPlaybookConversation(environmentId); const openConversation = (playbook: string | null) => - navigation.navigate("SettingsPlaybookConversation", { - environmentId, - name: playbook, - projectId: project?.id ?? null, - }); + void act(() => startConversation({ playbook, projects, projectId: project?.id ?? null })); const [details, setDetails] = useState(null); const [copyTarget, setCopyTarget] = useState<{ name: string; diff --git a/apps/mobile/src/j5/playbooks/startPlaybookConversation.ts b/apps/mobile/src/j5/playbooks/startPlaybookConversation.ts new file mode 100644 index 000000000000..e294e56c738c --- /dev/null +++ b/apps/mobile/src/j5/playbooks/startPlaybookConversation.ts @@ -0,0 +1,89 @@ +import { StackActions, useNavigation } from "@react-navigation/native"; +import { + ensurePlaybookAuthor, + PLAYBOOK_AUTHOR_ID, + PLAYBOOK_AUTHOR_PROMPT, + playbookWorkspaces, +} from "@t3tools/client-runtime/j5/playbooks"; +import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime"; +import type { EnvironmentId, ProjectId } from "@t3tools/contracts"; + +import { useServerConfigs } from "../../state/entities"; +import { useAtomCommand } from "../../state/use-atom-command"; +import { useAtomQueryRunner } from "../../state/use-atom-query-runner"; +import { selectDraftAgent } from "../agents/agentDraftState"; +import { agentPersonaEnvironment } from "../agents/agentPersonaAtoms"; +import { preparePlaybookDraft } from "./preparePlaybookDraft"; + +/** + * Opens upstream's new chat on a prepared draft, so the person picks the project from its heading. + * Prepare chat fills "Start playbook "; Create picks Playbook Author and its opening prompt. + */ +export function useStartPlaybookConversation(environmentId: EnvironmentId) { + const navigation = useNavigation(); + const serverConfigs = useServerConfigs(); + const readCatalog = useAtomQueryRunner(agentPersonaEnvironment.catalog, { + reportFailure: false, + refresh: true, + }); + const readAuthor = useAtomCommand(agentPersonaEnvironment.readAgentPersona, { + reportFailure: false, + }); + const editAuthor = useAtomCommand(agentPersonaEnvironment.editImportedAgentPersona, { + reportFailure: false, + }); + const createPersona = useAtomCommand(agentPersonaEnvironment.createAgentPersona, { + reportFailure: false, + }); + return async (input: { + readonly playbook: string | null; + readonly projects: Parameters[0]; + /** The project Settings is showing, so a project playbook's chat opens where it lives. */ + readonly projectId: ProjectId | null; + }) => { + const workspaces = playbookWorkspaces(input.projects, []); + const workspace = + workspaces.find((entry) => entry.projectId === input.projectId) ?? workspaces[0]; + if (!workspace) + throw new Error( + "Add a project to open a conversation. You can import playbooks without one.", + ); + if (input.playbook === null) + await ensurePlaybookAuthor({ + providers: serverConfigs.get(environmentId)?.providers ?? [], + readCatalog: async () => { + const result = await readCatalog({ environmentId, input: {} }); + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + return result.value; + }, + readDefinition: async (personaId) => { + const result = await readAuthor({ environmentId, input: { personaId } }); + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + return result.value.definition; + }, + editPersona: async (edit) => { + const result = await editAuthor({ environmentId, input: edit }); + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + }, + createPersona: async (definition) => { + const result = await createPersona({ environmentId, input: definition }); + if (result._tag === "Failure") throw squashAtomCommandFailure(result); + }, + }); + const draftId = preparePlaybookDraft( + workspace, + input.playbook === null ? PLAYBOOK_AUTHOR_PROMPT : `Start playbook ${input.playbook}`, + ); + if (input.playbook === null) selectDraftAgent(draftId, PLAYBOOK_AUTHOR_ID); + navigation.dispatch( + StackActions.push("Thread", { + draft: { + environmentId, + projectId: workspace.projectId, + title: workspace.title, + draftId, + }, + }), + ); + }; +} diff --git a/apps/server/src/j5/playbooks/PlaybookLibrary.ts b/apps/server/src/j5/playbooks/PlaybookLibrary.ts index eaf845bd1a0e..47bb4df88ddb 100644 --- a/apps/server/src/j5/playbooks/PlaybookLibrary.ts +++ b/apps/server/src/j5/playbooks/PlaybookLibrary.ts @@ -160,7 +160,10 @@ export const makePlaybookLibrary = Effect.gen(function* () { const selected = selectPlaybookSource(yield* sources(workspaceRoot || undefined), stem); if (selected.issue) return yield* selected.issue; if (!selected.entry) - return yield* playbookError("not_found", `No playbook named ${stem}. Use j5_playbook_list.`); + return yield* playbookError( + "not_found", + `No playbook named ${stem} on this server. Use j5_playbook_list.`, + ); return { stem, source: selected.entry.source, diff --git a/apps/server/src/j5/playbooks/PlaybookStore.ts b/apps/server/src/j5/playbooks/PlaybookStore.ts index c27ad3231e28..2f1336c0311a 100644 --- a/apps/server/src/j5/playbooks/PlaybookStore.ts +++ b/apps/server/src/j5/playbooks/PlaybookStore.ts @@ -459,7 +459,10 @@ export const makePlaybookStore = Effect.gen(function* () { const readPath = Effect.fn("PlaybookStore.readPath")(function* (definitionPath: string) { const stem = path.basename(definitionPath, ".yaml"); if (!(yield* fs.exists(definitionPath))) - return yield* playbookError("not_found", `No playbook named ${stem}. Use j5_playbook_list.`); + return yield* playbookError( + "not_found", + `No playbook named ${stem} on this server. Use j5_playbook_list.`, + ); const definition = yield* readDefinition(definitionPath); return { name: stem, diff --git a/packages/client-runtime/src/j5/playbooks.ts b/packages/client-runtime/src/j5/playbooks.ts index 6a66b037cdb8..9bd45473210d 100644 --- a/packages/client-runtime/src/j5/playbooks.ts +++ b/packages/client-runtime/src/j5/playbooks.ts @@ -24,7 +24,10 @@ import { defaultAgentPersonaModelRoute } from "./agentPersonas.ts"; import type { StartThreadTurnInput } from "../operations/commands.ts"; import type { EnvironmentProject, EnvironmentThreadShell } from "../state/shell.ts"; -const PLAYBOOK_AUTHOR_ID = "playbook-author"; +export const PLAYBOOK_AUTHOR_ID = "playbook-author"; +/** What a person asks Playbook Author first; mobile prefills it in a new chat. */ +export const PLAYBOOK_AUTHOR_PROMPT = + "Help me create a playbook, available across all projects and worktrees in this environment. Save the final YAML with j5_playbook_save. Start by asking what I want it to accomplish."; const PLAYBOOK_AUTHOR_INSTRUCTIONS = `You are Playbook Author. Help the user turn a repeatable task into a small, clear agent-led playbook shared across this environment. 1. Start by asking what the playbook should accomplish. Clarify the desired result, inputs, constraints, and evidence of success one focused question at a time. Use details already provided instead of asking again. @@ -131,7 +134,7 @@ export function playbookAuthorLaunch(input: { message: { messageId, role: "user", - text: "Help me create a playbook, available across all projects and worktrees in this environment. Save the final YAML with j5_playbook_save. Start by asking what I want it to accomplish.", + text: PLAYBOOK_AUTHOR_PROMPT, attachments: [], }, modelSelection,