Skip to content

Commit e302771

Browse files
authored
Routines: on/off and next run on every row, compact routine page, New routine on one screen (#2704)
* Routines: on/off and next run on every row, compact routine page, New routine on one screen - /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. * Routines: one shared routine row and switch, On/Paused everywhere, Run now back as a row - RoutineRow and RoutineSwitch (components/routines/routine-row.tsx): icon tile, the name as the link, one line, a default Switch beside the link. The routine, goal and check-in writes are in one hook. A failed switch says "Couldn't turn it on. Try again." (or off). Paused rows say "Paused · <schedule>". routineCount() is the one count format. - /routines draws each Bot's rows in one card with RoutineRow. - Every page's switch says On or Paused. The goal page no longer says Active twice. - Run now is a row again on the routine, goal and check-in pages. The header keeps the switch, and Edit on a routine. - The goal page's "Its ... start it." line is part of the page description. - Advanced settings is a ghost Button. - A run in progress says "Running now" on routine and goal pages. * Take main's CHANGELOG.md: the release note is in the PR description now
1 parent 1067ac4 commit e302771

20 files changed

Lines changed: 1288 additions & 969 deletions

‎app/src/components/responsibilities/goal-page.tsx‎

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -266,43 +266,45 @@ export function GoalPage({
266266
return (
267267
<PageShell
268268
backButton={{ label: "Routines", linkProps: back }}
269-
description={summaryFor(goal, triggers.data, routines)}
269+
action={
270+
goal.status === "completed" ? undefined : (
271+
<div className="flex shrink-0 items-center gap-2">
272+
<Switch
273+
aria-label="On"
274+
checked={goal.status === "active"}
275+
disabled={action.isPending}
276+
onCheckedChange={(active) =>
277+
action.mutate({
278+
id: goal.id,
279+
action: active ? "resume" : "pause",
280+
})
281+
}
282+
/>
283+
<span
284+
aria-hidden="true"
285+
className="-order-1 w-12 text-right text-muted-foreground text-sm"
286+
>
287+
{goal.status === "active" ? "On" : "Paused"}
288+
</span>
289+
</div>
290+
)
291+
}
292+
description={
293+
<>
294+
<span className="block">
295+
{summaryFor(goal, triggers.data, routines)}
296+
</span>
297+
{/* What starts it. A paused goal's summary already says nothing does. */}
298+
{goal.status === "active" ? (
299+
<span className="block">{`Its ${starters} start it.`}</span>
300+
) : null}
301+
</>
302+
}
270303
title={goal.title}
271304
>
272-
{/* What can be done to it now. The page title names it, so this first section has no heading. */}
305+
{/* What else can be done to it. The page title names it, so this first section has no heading. */}
273306
<PageSection>
274307
<PageRows>
275-
{goal.status !== "completed" ? (
276-
<>
277-
<Item size="sm">
278-
<ItemMedia variant="icon">
279-
<IconTarget />
280-
</ItemMedia>
281-
<ItemContent>
282-
<ItemTitle>Active</ItemTitle>
283-
<ItemDescription>
284-
{goal.status === "active"
285-
? `Its ${starters} start it.`
286-
: `Paused. Its ${starters} won't start it.`}
287-
</ItemDescription>
288-
</ItemContent>
289-
<ItemActions>
290-
<Switch
291-
aria-label="Active"
292-
checked={goal.status === "active"}
293-
disabled={action.isPending}
294-
onCheckedChange={(active) =>
295-
action.mutate({
296-
id: goal.id,
297-
action: active ? "resume" : "pause",
298-
})
299-
}
300-
/>
301-
</ItemActions>
302-
</Item>
303-
<Separator />
304-
</>
305-
) : null}
306308
{goal.status === "active" ? (
307309
<>
308310
<Item
@@ -379,16 +381,6 @@ export function GoalPage({
379381
<IconChevronRight className="size-4 text-muted-foreground" />
380382
</ItemActions>
381383
</Item>
382-
<Separator />
383-
<DeleteRow
384-
description={deleteWords(routines)}
385-
label={`Delete the goal ${goal.title}`}
386-
onClick={() => {
387-
remove.reset();
388-
setConfirmingDelete(true);
389-
}}
390-
title="Delete goal"
391-
/>
392384
</PageRows>
393385
{action.error ? (
394386
<p className="mt-3 text-destructive text-sm" role="alert">
@@ -555,6 +547,21 @@ export function GoalPage({
555547
<Triggers goal={goal} />
556548
<Runs channelId={goal.conversationId} goalId={goal.id} />
557549

550+
{/* Away from the everyday controls, at the bottom. */}
551+
<PageSection>
552+
<PageRows>
553+
<DeleteRow
554+
description={deleteWords(routines)}
555+
label={`Delete the goal ${goal.title}`}
556+
onClick={() => {
557+
remove.reset();
558+
setConfirmingDelete(true);
559+
}}
560+
title="Delete goal"
561+
/>
562+
</PageRows>
563+
</PageSection>
564+
558565
<Dialog onOpenChange={setConfirmingDelete} open={confirmingDelete}>
559566
<DialogContent>
560567
<DialogHeader>
@@ -603,7 +610,7 @@ export function GoalPage({
603610

604611
const RUN_LABEL: Record<string, string> = {
605612
queued: "Queued",
606-
running: "Running",
613+
running: "Running now",
607614
waiting: "Waiting for you",
608615
succeeded: "Succeeded",
609616
failed: "Failed",
Lines changed: 42 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,73 @@
1+
import { useQuery } from "@tanstack/react-query";
12
import { Link } from "@tanstack/react-router";
23
import { AnimatePresence } from "motion/react";
34
import { BotOrb } from "@/components/agents/bot-orb";
4-
import {
5-
IconClock,
6-
IconEye,
7-
IconLoader2,
8-
IconPlayerPause,
9-
IconTarget,
10-
} from "@/components/icons";
11-
import { KIND_LABEL } from "@/components/responsibilities/triggers";
12-
import { useGoalTriggers } from "@/components/responsibilities/use-goal-reads";
5+
import { PageRows } from "@/components/layout/page-shell";
6+
import { RoutineRow, routineCount } from "@/components/routines/routine-row";
137
import { Unfold } from "@/components/routines/unfold";
14-
import {
15-
type BotGroup,
16-
isOff,
17-
isRunning,
18-
type RowTone,
19-
rowFact,
20-
rowName,
21-
} from "@/lib/routines/by-bot";
22-
import { describeEvent } from "@/lib/routines/events";
23-
import { goalStarts, type MergedRoutine } from "@/lib/routines/merged";
24-
import { cn } from "@/lib/utils";
8+
import { Separator } from "@/components/ui/separator";
9+
import { agentQueryOptions } from "@/lib/agents/queries";
10+
import type { BotGroup } from "@/lib/routines/by-bot";
11+
import type { MergedRoutine } from "@/lib/routines/merged";
2512

26-
const ROW_CLASS =
27-
"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";
28-
29-
const FACT_CLASS: Record<RowTone, string> = {
30-
running: "text-foreground",
31-
warning: "text-warning",
32-
muted: "text-muted-foreground",
33-
normal: "text-muted-foreground",
34-
};
35-
36-
function RowIcon({ row }: { row: MergedRoutine }) {
37-
const className = "size-4 shrink-0 text-muted-foreground";
38-
if (isRunning(row))
39-
return (
40-
<IconLoader2
41-
className={cn(className, "animate-spin motion-reduce:animate-none")}
42-
/>
43-
);
44-
if (isOff(row)) return <IconPlayerPause className={className} />;
45-
switch (row.kind) {
46-
case "routine":
47-
return <IconClock className={className} />;
48-
case "goal":
49-
return <IconTarget className={className} />;
50-
case "check-in":
51-
return <IconEye className={className} />;
52-
}
53-
}
54-
55-
/** A row's one line: its icon, its name, and the one fact about it. */
56-
function RowLine({
57-
row,
58-
starts,
59-
}: {
60-
row: MergedRoutine;
61-
/** A goal's starts in words; the others have none. */
62-
starts: string | null;
63-
}) {
64-
const fact = rowFact(row, starts);
65-
return (
66-
<>
67-
<span className="flex min-w-0 flex-1 items-center gap-3">
68-
<RowIcon row={row} />
69-
<span className="truncate">{rowName(row)}</span>
70-
</span>
71-
<span
72-
className={cn("shrink-0 pl-7 text-sm sm:pl-0", FACT_CLASS[fact.tone])}
73-
>
74-
{fact.text}
75-
</span>
76-
</>
77-
);
78-
}
79-
80-
/** Dimmed when its fact is the muted one: paused, or a goal that is completed. */
81-
function rowClass(row: MergedRoutine, starts: string | null) {
82-
return cn(ROW_CLASS, rowFact(row, starts).tone === "muted" && "opacity-60");
13+
/**
14+
* One row as the Routines page draws it. The shared row (`RoutineRow`), kept under this name for the
15+
* Bot's page, which draws it too.
16+
*/
17+
export function GroupRow({ row }: { row: MergedRoutine }) {
18+
return <RoutineRow row={row} />;
8319
}
8420

8521
/**
86-
* A goal's row. Its own component, so only an active goal reads its triggers (`useGoalTriggers`),
87-
* which its starts are made of.
22+
* The name a group heads with. A Bot no list has (one shared with you, or not listed for this
23+
* person) is read on its own, so its group says its real name; "A Bot" only while that read is on
24+
* its way or when it fails, as for a Bot that was deleted.
8825
*/
89-
function GoalRow({ row }: { row: Extract<MergedRoutine, { kind: "goal" }> }) {
90-
const triggers = useGoalTriggers(row.goal.id, {
91-
enabled: row.goal.status === "active",
26+
function useGroupName(group: BotGroup): string {
27+
const bot = useQuery({
28+
...agentQueryOptions(group.botId),
29+
enabled: !group.known,
30+
retry: false,
9231
});
93-
const starts = goalStarts(
94-
row.goal,
95-
triggers.data
96-
?.filter((trigger) => trigger.enabled)
97-
.map((trigger) => `${KIND_LABEL[trigger.kind]} trigger`),
98-
row.routines,
99-
describeEvent,
100-
);
101-
return (
102-
<Link
103-
className={rowClass(row, starts)}
104-
params={{ goalId: row.goal.id }}
105-
to="/routines/goals/$goalId"
106-
>
107-
<RowLine row={row} starts={starts} />
108-
</Link>
109-
);
110-
}
111-
112-
/** One row as the Routines page draws it, opening the routine, goal or check-in it is. */
113-
export function GroupRow({ row }: { row: MergedRoutine }) {
114-
switch (row.kind) {
115-
case "routine":
116-
return (
117-
<Link
118-
className={rowClass(row, null)}
119-
params={{ routineId: row.routine.id }}
120-
to="/routines/schedules/$routineId"
121-
>
122-
<RowLine row={row} starts={null} />
123-
</Link>
124-
);
125-
case "goal":
126-
return <GoalRow row={row} />;
127-
case "check-in":
128-
return (
129-
<Link
130-
className={rowClass(row, null)}
131-
params={{ checkInId: row.checkIn.id }}
132-
to="/routines/check-ins/$checkInId"
133-
>
134-
<RowLine row={row} starts={null} />
135-
</Link>
136-
);
137-
}
32+
return group.known ? group.name : (bot.data?.name ?? group.name);
13833
}
13934

14035
/**
141-
* One Bot's routines on the Routines page: the Bot's orb, name and how many it has, then one line
142-
* per row. The name opens the Bot's own Routines page, except for "A Bot", a Bot no list knows,
143-
* which has none.
36+
* One Bot's routines on the Routines page: the Bot's orb, name and how many it has, then its rows in
37+
* one card. The name opens the Bot's own Routines page, except for a Bot no list knows, which has none.
14438
*/
14539
export function BotGroupSection({ group }: { group: BotGroup }) {
40+
const name = useGroupName(group);
14641
return (
14742
// Spaced with padding, not margin: the group's height opens and folds, and a margin outside it
14843
// would jump.
149-
<section aria-label={group.name} className="pb-6">
150-
<div className="flex items-center gap-2 px-2 pb-1.5 text-muted-foreground text-sm">
151-
<BotOrb name={group.name} seed={group.seed} size={18} />
44+
<section aria-label={name} className="pb-8">
45+
<div className="flex items-center gap-2 text-muted-foreground text-sm">
46+
<BotOrb name={name} seed={group.seed} size={18} />
15247
{group.known ? (
15348
<Link
15449
className="font-medium text-foreground hover:underline"
15550
params={{ agentId: group.botId }}
15651
to="/bots/$agentId/routines"
15752
>
158-
{group.name}
53+
{name}
15954
</Link>
16055
) : (
161-
<span className="font-medium text-foreground">{group.name}</span>
56+
<span className="font-medium text-foreground">{name}</span>
16257
)}
163-
<span className="tabular-nums">{group.rows.length}</span>
58+
<span className="tabular-nums">{routineCount(group.rows.length)}</span>
16459
</div>
165-
{/* A routine made or removed while the page is open opens or folds; the rest just appear. */}
166-
<AnimatePresence initial={false}>
167-
{group.rows.map((row) => (
168-
<Unfold key={`${row.kind}:${row.id}`}>
169-
<GroupRow row={row} />
170-
</Unfold>
171-
))}
172-
</AnimatePresence>
60+
<PageRows className="mt-3">
61+
{/* A routine made or removed while the page is open opens or folds; the rest just appear. */}
62+
<AnimatePresence initial={false}>
63+
{group.rows.map((row, index) => (
64+
<Unfold key={`${row.kind}:${row.id}`}>
65+
{index > 0 ? <Separator /> : null}
66+
<RoutineRow row={row} />
67+
</Unfold>
68+
))}
69+
</AnimatePresence>
70+
</PageRows>
17371
</section>
17472
);
17573
}

‎app/src/components/routines/delete-row.tsx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
} from "@/components/ui/item";
99

1010
/**
11-
* The last row of a goal's, a schedule's or a check-in's actions card: delete it, after a
12-
* confirmation the page opens. A row in the card with the page's other actions, never a button left
13-
* on its own under the page, which reads as something that fell out of the layout.
11+
* Delete a goal, a schedule or a check-in, after a confirmation the page opens. A row in a card of
12+
* its own, in the last section of the page: away from the everyday controls, so it is never pressed
13+
* on the way to Run now, and still a row, never a button left on its own under the page.
1414
*/
1515
export function DeleteRow({
1616
title,

0 commit comments

Comments
 (0)