From 1c564010d28d245a623dc9d5dff7c6f44efc9cca Mon Sep 17 00:00:00 2001 From: Sam Julien Date: Tue, 1 Dec 2026 16:05:15 -0800 Subject: [PATCH 1/3] Routines: on/off and next run on every row, compact routine page, New routine on one screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - /routines uses the standard page header ("Routines") with the box as its first content. - Each row has an on/off switch (pause/resume, the writes each page already makes), says Paused when off, and says when it runs next where that is known. - Group heads read the Bot's real name (read on its own when no list has the Bot) and "3 routines". - Routine, goal and check-in pages: on/off and Run now (and Edit on a routine) on the title's line, Delete in its own section at the bottom. A routine's page shows what it does first. - The routine page subtitle drops "· Acts". Time zones show only when they differ from the viewer's. - New routine: one card, labels above fields, When as one line of controls, and Done when, Posts in and Name under Advanced settings. It fits an 820px window with Create in view. --- CHANGELOG.md | 8 + .../components/responsibilities/goal-page.tsx | 140 ++- app/src/components/routines/bot-group.tsx | 180 ++- app/src/components/routines/delete-row.tsx | 6 +- .../components/routines/new-routine-page.tsx | 1051 ++++++++--------- app/src/components/routines/routine-page.tsx | 302 +++-- app/src/components/routines/routines-home.tsx | 107 +- app/src/components/routines/schedule-when.tsx | 6 +- .../components/suggestions/check-in-page.tsx | 143 ++- app/src/lib/routines/by-bot.ts | 17 + app/tests/new-routine-form.test.tsx | 60 +- app/tests/routines-bot-group.test.tsx | 41 +- app/tests/routines-by-bot.test.ts | 46 + app/tests/routines-home.test.tsx | 4 +- app/tests/routines-merged.test.tsx | 6 +- app/tests/strip-version-layout.test.tsx | 6 +- 16 files changed, 1147 insertions(+), 976 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e28105213f..fbe32a6999 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. widen it, so each new scope refused it. Now it reaches every scope, new ones included. A token of any other app is allowed exactly the scopes it was granted. +**Routines.** + +- **Routines shows what is on and what is paused.** Each row has its own on/off switch and says + when it runs next. A Bot's group heads with its name and "3 routines". A routine's page puts On, + Run now and Edit beside its title, shows what it does first, and moves Delete to the bottom of the + page. New routine fits on one screen: When is one line, and Done when, Posts in and Name are + under Advanced settings. Time zones show only when they differ from yours. + **Smaller addresses.** - **Lists travel in a body, not the address.** Reading an app for the actions a Bot needs, and the diff --git a/app/src/components/responsibilities/goal-page.tsx b/app/src/components/responsibilities/goal-page.tsx index 6f8b1a812a..21cbb1acbc 100644 --- a/app/src/components/responsibilities/goal-page.tsx +++ b/app/src/components/responsibilities/goal-page.tsx @@ -266,73 +266,62 @@ export function GoalPage({ return ( + + action.mutate({ + id: goal.id, + action: active ? "resume" : "pause", + }) + } + /> + + + + ) + } description={summaryFor(goal, triggers.data, routines)} title={goal.title} > - {/* What can be done to it now. The page title names it, so this first section has no heading. */} - + {/* + * What starts it, then what else can be done to it. The page title names it, so this first + * section has no heading. + */} + - {goal.status !== "completed" ? ( - <> - - - - - - Active - - {goal.status === "active" - ? `Its ${starters} start it.` - : `Paused. Its ${starters} won't start it.`} - - - - - action.mutate({ - id: goal.id, - action: active ? "resume" : "pause", - }) - } - /> - - - - - ) : null} - {goal.status === "active" ? ( - <> - { - // Bots can't run until a card is added: the dialog says why, in place of a run. - if (stopIfNeedsCard()) return; - action.mutate({ id: goal.id, action: "run" }); - }} - type="button" - /> - } - size="sm" - > - - - - - Run now - - Runs it now, for real. The Bot does the work and can post - and take actions. - - - - - - ) : null} {goal.status !== "completed" ? ( <> - - { - remove.reset(); - setConfirmingDelete(true); - }} - title="Delete goal" - /> {action.error ? (

@@ -555,6 +534,21 @@ export function GoalPage({ + {/* Away from the everyday controls, at the bottom. */} + + + { + remove.reset(); + setConfirmingDelete(true); + }} + title="Delete goal" + /> + + +

diff --git a/app/src/components/routines/bot-group.tsx b/app/src/components/routines/bot-group.tsx index 78e6e80a20..5c5cce3a21 100644 --- a/app/src/components/routines/bot-group.tsx +++ b/app/src/components/routines/bot-group.tsx @@ -1,3 +1,4 @@ +import { useMutation, useQuery } from "@tanstack/react-query"; import { Link } from "@tanstack/react-router"; import { AnimatePresence } from "motion/react"; import { BotOrb } from "@/components/agents/bot-orb"; @@ -11,20 +12,35 @@ import { import { KIND_LABEL } from "@/components/responsibilities/triggers"; import { useGoalTriggers } from "@/components/responsibilities/use-goal-reads"; import { Unfold } from "@/components/routines/unfold"; +import { Switch } from "@/components/ui/switch"; +import { agentQueryOptions } from "@/lib/agents/queries"; +import { changeProactiveSettingMutationOptions } from "@/lib/proactive"; +import { responsibilityActionMutationOptions } from "@/lib/responsibilities"; import { type BotGroup, isOff, isRunning, + nextRunWords, type RowTone, rowFact, rowName, } from "@/lib/routines/by-bot"; import { describeEvent } from "@/lib/routines/events"; import { goalStarts, type MergedRoutine } from "@/lib/routines/merged"; +import { setRoutineEnabledMutationOptions } from "@/lib/routines/mutations"; import { cn } from "@/lib/utils"; +import { queryClient } from "@/query-client"; +/* + * The row is a box holding two controls side by side: a link that opens the routine, stretched over + * the whole row with `after:`, and its on/off switch, raised above that stretch. A switch inside the + * link would be a control nested in a control. + */ const ROW_CLASS = - "flex flex-col gap-0.5 rounded-lg px-2 py-2 text-sm hover:bg-muted sm:flex-row sm:items-center sm:gap-3"; + "relative flex items-center gap-3 rounded-lg px-2 py-2 text-sm hover:bg-muted"; + +const LINK_CLASS = + "flex min-w-0 flex-1 flex-col gap-0.5 rounded-lg outline-none after:absolute after:inset-0 after:rounded-lg focus-visible:after:ring-3 focus-visible:after:ring-ring/50 sm:flex-row sm:items-center sm:gap-3"; const FACT_CLASS: Record = { running: "text-foreground", @@ -52,7 +68,58 @@ function RowIcon({ row }: { row: MergedRoutine }) { } } -/** A row's one line: its icon, its name, and the one fact about it. */ +/** + * A row's on/off switch, each kind with the write its own page already makes: a routine is paused + * and resumed, a goal paused and resumed, a check-in toggled. A completed goal has none: nothing + * turns it back on. + */ +function RowSwitch({ row }: { row: MergedRoutine }) { + const routine = useMutation(setRoutineEnabledMutationOptions(queryClient)); + const goal = useMutation(responsibilityActionMutationOptions(queryClient)); + const checkIn = useMutation( + changeProactiveSettingMutationOptions(queryClient), + ); + const pending = routine.isPending || goal.isPending || checkIn.isPending; + const failed = Boolean(routine.error || goal.error || checkIn.error); + if (row.kind === "goal" && row.goal.status === "completed") return null; + const on = + row.kind === "routine" + ? row.routine.enabled + : row.kind === "goal" + ? row.goal.status === "active" + : row.checkIn.enabled; + return ( + + {failed ? ( + + Couldn't switch it + + ) : null} + { + routine.reset(); + goal.reset(); + checkIn.reset(); + if (row.kind === "routine") + routine.mutate({ id: row.routine.id, enabled: next }); + else if (row.kind === "goal") + goal.mutate({ id: row.goal.id, action: next ? "resume" : "pause" }); + else if (next !== row.checkIn.enabled) + checkIn.mutate({ + setting: row.checkIn, + change: { kind: "toggle" }, + }); + }} + size="sm" + /> + + ); +} + +/** A row's line: its icon and name, then its state, and when it runs next where that is known. */ function RowLine({ row, starts, @@ -62,26 +129,31 @@ function RowLine({ starts: string | null; }) { const fact = rowFact(row, starts); + const next = fact.tone === "normal" ? nextRunWords(row) : null; return ( <> - + {rowName(row)} - - {fact.text} + + {fact.text} + {next ? ( + + + {next} + + ) : null} ); } -/** Dimmed when its fact is the muted one: paused, or a goal that is completed. */ -function rowClass(row: MergedRoutine, starts: string | null) { - return cn(ROW_CLASS, rowFact(row, starts).tone === "muted" && "opacity-60"); -} - /** * A goal's row. Its own component, so only an active goal reads its triggers (`useGoalTriggers`), * which its starts are made of. @@ -99,13 +171,16 @@ function GoalRow({ row }: { row: Extract }) { describeEvent, ); return ( - - - +
+ + + + +
); } @@ -114,53 +189,78 @@ export function GroupRow({ row }: { row: MergedRoutine }) { switch (row.kind) { case "routine": return ( - - - +
+ + + + +
); case "goal": return ; case "check-in": return ( - - - +
+ + + + +
); } } +/** + * The name a group heads with. A Bot no list has (one shared with you, or not listed for this + * person) is read on its own, so its group says its real name; "A Bot" only while that read is on + * its way or when it fails, as for a Bot that was deleted. + */ +function useGroupName(group: BotGroup): string { + const bot = useQuery({ + ...agentQueryOptions(group.botId), + enabled: !group.known, + retry: false, + }); + return group.known ? group.name : (bot.data?.name ?? group.name); +} + +/** "1 routine", "3 routines". */ +function routineCount(count: number): string { + return count === 1 ? "1 routine" : `${count} routines`; +} + /** * One Bot's routines on the Routines page: the Bot's orb, name and how many it has, then one line - * per row. The name opens the Bot's own Routines page, except for "A Bot", a Bot no list knows, - * which has none. + * per row. The name opens the Bot's own Routines page, except for a Bot no list knows, which has none. */ export function BotGroupSection({ group }: { group: BotGroup }) { + const name = useGroupName(group); return ( // Spaced with padding, not margin: the group's height opens and folds, and a margin outside it // would jump. -
+
- + {group.known ? ( - {group.name} + {name} ) : ( - {group.name} + {name} )} - {group.rows.length} + {routineCount(group.rows.length)}
{/* A routine made or removed while the page is open opens or folds; the rest just appear. */} diff --git a/app/src/components/routines/delete-row.tsx b/app/src/components/routines/delete-row.tsx index 3cea2ccdb9..c35569d356 100644 --- a/app/src/components/routines/delete-row.tsx +++ b/app/src/components/routines/delete-row.tsx @@ -8,9 +8,9 @@ import { } from "@/components/ui/item"; /** - * The last row of a goal's, a schedule's or a check-in's actions card: delete it, after a - * confirmation the page opens. A row in the card with the page's other actions, never a button left - * on its own under the page, which reads as something that fell out of the layout. + * Delete a goal, a schedule or a check-in, after a confirmation the page opens. A row in a card of + * its own, in the last section of the page: away from the everyday controls, so it is never pressed + * on the way to Run now, and still a row, never a button left on its own under the page. */ export function DeleteRow({ title, diff --git a/app/src/components/routines/new-routine-page.tsx b/app/src/components/routines/new-routine-page.tsx index db7b45088a..a3c4b5f8a4 100644 --- a/app/src/components/routines/new-routine-page.tsx +++ b/app/src/components/routines/new-routine-page.tsx @@ -1,18 +1,20 @@ import { useSelector } from "@tanstack/react-form"; import { useInfiniteQuery, useMutation, useQuery } from "@tanstack/react-query"; import { Link, linkOptions, useNavigate } from "@tanstack/react-router"; -import { useEffect, useRef } from "react"; +import { useEffect, useRef, useState } from "react"; import { AbstractAvatar } from "@/components/agents/abstract-avatar"; -import { - PageCard, - PageSection, - PageShell, -} from "@/components/layout/page-shell"; +import { IconChevronRight } from "@/components/icons"; +import { PageCard, PageShell } from "@/components/layout/page-shell"; import { ScheduleWhen, useRoutineForm, } from "@/components/routines/schedule-when"; import { Button } from "@/components/ui/button"; +import { + Collapsible, + CollapsibleContent, + CollapsibleTrigger, +} from "@/components/ui/collapsible"; import { Field, FieldDescription, @@ -67,6 +69,7 @@ import { import { openingOf } from "@/lib/voice/cut"; import { queryClient } from "@/query-client"; import { failureSaid } from "@/lib/load-failure"; +import { cn } from "@/lib/utils"; /** The conversations a routine for this Bot may post in: live ones the Bot is in. */ function conversationsWith( @@ -266,10 +269,106 @@ export function NewRoutinePage({ if (saved) goToRoutines.current?.focus(); }, [saved]); + /* + * Advanced settings: open from the start when what fills the form already set one of them (a + * sentence that named it, or the clock beside a conversation), and held open while one of them has + * a message, so Create can move focus to it. + */ + const [advanced, setAdvanced] = useState( + Boolean( + defaultValues.doneWhen || + defaultValues.title || + defaultValues.channelId !== NEW_CONVERSATION, + ), + ); + const advancedOpen = + advanced || "doneWhen" in shown || "title" in shown || "channelId" in shown; + const botItems = Object.fromEntries( (agents.data ?? []).map((agent) => [agent.id, agent.name]), ) as Record; + const startsSelect = ( + + {(field) => ( + + )} + + ); + + const buttons = saved ? ( + // Cancel says nothing was kept. After a partial or uncertain save the work is kept, and Go to + // Routines goes to the same list. + + ) : ( + <> + {createFromPlan.isPending ? ( + // Not a link while the writes are on their way: leaving now would hide what they answer. + + ) : ( + + )} + {/* Enabled while a message shows: pressing it takes the person to the first one. A + disabled button says nothing about why, and a keyboard can't reach it. */} + state.isSubmitting}> + {(isSubmitting) => ( + + )} + + + ); + return (
- {/* Sections rather than one card, as New skill is: who does it and what, when it starts, - when it is done, and where it shows up. Each is one decision with room for its words. */} - - - - - {(field) => { - const isInvalid = field.name in shown; - return ( - - Bot - - {isInvalid ? ( - - {shown[field.name]} - - ) : null} - - ); - }} - - - - {(field) => { - const isInvalid = field.name in shown; - return ( - - What to do - - Write it as one run of the work. Leave the schedule out. - -