From 9ad5b0643e4635ae5597ab6e8aa18b5996979836 Mon Sep 17 00:00:00 2001
From: Badcuban <108198679+badcuban@users.noreply.github.com>
Date: Fri, 20 Nov 2026 16:12:35 -0500
Subject: [PATCH 1/4] feat(web): the scheduled task editor takes the new-thread
composer's layout
The scheduled task form was a long settings page. It is now laid out like
the new-thread screen (#1019): "New task in [project]", the composer's box
with the task name and one schedule button on top, the prompt, the real
model and access buttons and Create task (Save when editing). A sentence
under the box says where each run goes, with a menu in each part: a new
thread or one to continue (and the room agent), the local checkout or a
new worktree, and the computer. The schedule button opens the repeat
pattern, day, time and next runs, with the time zone, a custom cron rule
(started from the schedule picked so far) and event triggers one step
further in. Event settings sit under the sentence, unchanged.
Shared pieces moved out for reuse: the dotted inline picker trigger (also
on the new-thread heading), the composer's box class, and the model
button's effort summary.
---
apps/server/src/guide/topics.ts | 2 +
.../ChatView.event-tasks.browser.tsx | 107 ++-
apps/web/src/components/chat/ChatComposer.tsx | 45 +-
.../src/components/chat/DraftEmptyState.tsx | 36 +-
.../src/components/chat/composerSurface.ts | 9 +
apps/web/src/components/chat/traitControls.ts | 37 +
.../components/scheduled/ScheduleButton.tsx | 400 ++++++++++
.../scheduled/ScheduledTaskForm.tsx | 755 +++++++-----------
.../scheduled/ScheduledTaskWhere.tsx | 328 ++++++++
.../scheduled/scheduled.logic.test.ts | 26 +
.../components/scheduled/scheduled.logic.ts | 60 +-
apps/web/src/components/ui/inline-picker.tsx | 53 ++
12 files changed, 1309 insertions(+), 549 deletions(-)
create mode 100644 apps/web/src/components/chat/composerSurface.ts
create mode 100644 apps/web/src/components/scheduled/ScheduleButton.tsx
create mode 100644 apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
create mode 100644 apps/web/src/components/ui/inline-picker.tsx
diff --git a/apps/server/src/guide/topics.ts b/apps/server/src/guide/topics.ts
index 372b84a0b..111606878 100644
--- a/apps/server/src/guide/topics.ts
+++ b/apps/server/src/guide/topics.ts
@@ -216,6 +216,8 @@ A thread link from an assistant or a phone alert, opened in a computer's browser
],
body: `{place:scheduled} lists tasks that start an agent at set times (once, hourly, daily, weekdays, weekly or a cron rule) or when an event arrives at the task's address (a webhook, or GitHub events like a new issue or failed checks). Each run starts a new thread with the task's instructions, or sends them to one thread as a follow-up.
+New task opens an editor laid out like the new-thread screen: "New task in [project]" on top, then a box with the task's name, a schedule button ("Weekdays at 9:00 AM"), the instructions, the model and access buttons, and Create task (Save when editing). The schedule button opens the repeat pattern, the day and time and the next runs; the time zone, a custom cron rule and When something happens sit at the bottom of that panel. A line under the box says where each run goes, with a menu in each part: a new thread or one to continue (and which agent in a room), the local checkout or a new worktree, and the computer. An event task's settings show below that line. Run now, Pause, Resume and Delete are on the task's own page, and each row in the list has a switch to pause or resume it.
+
Tasks run while Threadlines is running on that computer. A time missed while it was off or asleep gets one catch-up run when it's back, if the missed time was within the last 7 days. A Mac that wakes only briefly for upkeep (screen off) starts nothing; runs wait until it's fully awake. The desktop app can keep the computer awake for them.
Agents can list, create and change scheduled tasks when {place:threads.agentThreads} isn't Off; with Ask me first, a card asks you before a change takes effect. A task an agent sets up on a model already in the room runs at the reasoning you set for that agent, unless the agent or you name another level.
diff --git a/apps/web/src/components/ChatView.event-tasks.browser.tsx b/apps/web/src/components/ChatView.event-tasks.browser.tsx
index 033e46290..e2667bfbc 100644
--- a/apps/web/src/components/ChatView.event-tasks.browser.tsx
+++ b/apps/web/src/components/ChatView.event-tasks.browser.tsx
@@ -185,6 +185,22 @@ async function openSelect(label: string) {
trigger.click();
}
+/** Picks an access level from the editor's access button, as on the composer. */
+async function pickAccess(mode: string) {
+ const trigger = await vi.waitFor(() => {
+ const element = document.querySelector('[aria-label^="Access level"]');
+ expect(element).not.toBeNull();
+ return element!;
+ });
+ trigger.click();
+ const option = await vi.waitFor(() => {
+ const element = document.querySelector(`[data-access-option="${mode}"]`);
+ expect(element).not.toBeNull();
+ return element!;
+ });
+ option.click();
+}
+
const detailPath = `/scheduled?environment=environment-local&task=${TASK_ID}`;
describe("ChatView (full app): event tasks", () => {
@@ -225,14 +241,14 @@ describe("ChatView (full app): event tasks", () => {
page.getByTestId("scheduled-form-prompt"),
"Read the issue and propose a fix.",
);
- await openSelect("Runs");
- await clickSelectItemContainingText("When something happens");
+ await page.getByTestId("scheduled-schedule-button").click();
+ await page.getByTestId("scheduled-schedule-events").click();
// The repository and the only sender come from the project and gh.
await expect.element(page.getByTestId("scheduled-event-repository")).toHaveValue("acme/app");
await expect.element(page.getByTestId("scheduled-event-person-badcuban")).toBeVisible();
// A new event task asks before changes.
- await expect.element(page.getByLabelText("Access")).toHaveTextContent("Supervised");
+ await expect.element(page.getByLabelText("Access level: Supervised")).toBeVisible();
expect(byTestId("scheduled-form-time-zone")).toBeNull();
await userEvent.fill(page.getByTestId("scheduled-event-label"), "agent");
@@ -253,15 +269,13 @@ describe("ChatView (full app): event tasks", () => {
await vi.waitFor(() => expect(byTestId("scheduled-event-people")).toBeNull());
// Full access with anyone is said before saving.
- await openSelect("Access");
- await clickSelectItemContainingText("Full access");
+ await pickAccess("full-access");
await expect
.element(
page.getByText("Anyone who can comment on acme/app can start a run with full access."),
)
.toBeVisible();
- await openSelect("Access");
- await clickSelectItemContainingText("Supervised");
+ await pickAccess("approval-required");
await page.getByTestId("scheduled-form-save").click();
await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
@@ -300,7 +314,10 @@ describe("ChatView (full app): event tasks", () => {
});
try {
await sendTasks([]);
- await openSelect("Runs");
+ await page.getByTestId("scheduled-schedule-button").click();
+ await expect.element(page.getByTestId("scheduled-schedule-cron")).toBeVisible();
+ expect(byTestId("scheduled-schedule-events")).toBeNull();
+ await openSelect("Repeat");
await vi.waitFor(() =>
expect(document.querySelectorAll('[data-slot="select-item"]').length).toBeGreaterThan(0),
);
@@ -314,6 +331,80 @@ describe("ChatView (full app): event tasks", () => {
}
});
+ it("creates a clock task from the editor's box, schedule popover and where-it-runs sentence", async () => {
+ const mounted = await mountChatView({
+ viewport: WIDE_FOOTER_VIEWPORT,
+ snapshot: snapshot(),
+ initialPath: "/scheduled?view=new",
+ configureFixture: (nextFixture) => {
+ withScheduledCapabilities(true)(nextFixture);
+ withCodexModels(nextFixture);
+ },
+ resolveRpc: (body) =>
+ body._tag === WS_METHODS.scheduledTasksCreate
+ ? { ...eventTask(), ...body, id: TASK_ID }
+ : undefined,
+ });
+ try {
+ await sendTasks([]);
+
+ // Saving empty says what's missing, and puts the cursor in the name.
+ await page.getByTestId("scheduled-form-save").click();
+ await vi.waitFor(() =>
+ expect(
+ [...document.querySelectorAll('[data-testid="scheduled-form-problems"] li')].map(
+ (item) => item.textContent,
+ ),
+ ).toEqual(["Give the task a name.", "Say what each run should do."]),
+ );
+ expect(document.activeElement).toBe(byTestId("scheduled-form-name"));
+ expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(0);
+
+ await userEvent.fill(page.getByTestId("scheduled-form-name"), "Friday review");
+ await userEvent.fill(page.getByTestId("scheduled-form-prompt"), "Summarize the week.");
+
+ // Weekly on Friday, then a cron rule that starts from it.
+ await page.getByTestId("scheduled-schedule-button").click();
+ await openSelect("Repeat");
+ await clickSelectItemContainingText("Weekly");
+ await page.getByTestId("scheduled-form-day-5").click();
+ await vi.waitFor(() =>
+ expect(byTestId("scheduled-schedule-button")?.textContent).toContain("Fridays at 9:00"),
+ );
+ await page.getByTestId("scheduled-schedule-cron").click();
+ await expect.element(page.getByTestId("scheduled-form-cron")).toHaveValue("0 9 * * 5");
+
+ // The time zone is one step further in, and back.
+ await page.getByTestId("scheduled-schedule-time-zone").click();
+ await expect.element(page.getByTestId("scheduled-form-time-zone")).toBeVisible();
+ await page.getByTestId("scheduled-schedule-back").click();
+ await expect.element(page.getByTestId("scheduled-form-cron")).toBeVisible();
+ await userEvent.keyboard("{Escape}");
+ await vi.waitFor(() => expect(byTestId("scheduled-schedule-popover")).toBeNull());
+
+ // Each run in a new worktree, from the sentence under the box.
+ await page.getByTestId("scheduled-form-checkout").click();
+ await page.getByRole("menuitemradio", { name: /New worktree/ }).click();
+ await vi.waitFor(() =>
+ expect(byTestId("scheduled-form-where")?.textContent).toMatch(
+ /^Each run starts a new thread in a new worktree on /,
+ ),
+ );
+
+ await page.getByTestId("scheduled-form-save").click();
+ await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
+ expect(requestsOf(WS_METHODS.scheduledTasksCreate)[0]).toMatchObject({
+ name: "Friday review",
+ prompt: "Summarize the week.",
+ checkout: "worktree",
+ cadence: { kind: "custom", cron: "0 9 * * 5" },
+ target: { kind: "new_thread" },
+ });
+ } finally {
+ await mounted.cleanup();
+ }
+ });
+
it("offers Add to GitHub, falls back to the steps by hand, and waits for the relay's address", async () => {
const mounted = await mountChatView({
viewport: WIDE_FOOTER_VIEWPORT,
diff --git a/apps/web/src/components/chat/ChatComposer.tsx b/apps/web/src/components/chat/ChatComposer.tsx
index 06ecca6f2..4142f4193 100644
--- a/apps/web/src/components/chat/ChatComposer.tsx
+++ b/apps/web/src/components/chat/ChatComposer.tsx
@@ -29,11 +29,7 @@ import {
PROVIDER_SEND_TURN_MAX_FILE_BYTES,
PROVIDER_SEND_TURN_MAX_IMAGE_BYTES,
} from "@threadlines/contracts";
-import {
- createModelSelection,
- getProviderOptionCurrentLabel,
- normalizeModelSlug,
-} from "@threadlines/shared/model";
+import { createModelSelection, normalizeModelSlug } from "@threadlines/shared/model";
import {
memo,
type ReactNode,
@@ -113,7 +109,8 @@ import {
ComposerPromptEditor,
} from "../ComposerPromptEditor";
import { type ComposerPromptSuggestionDisplay } from "./ComposerPromptSuggestion";
-import { type ModelPickerTriggerSummary, ProviderModelPicker } from "./ProviderModelPicker";
+import { COMPOSER_SURFACE_CLASS_NAME } from "./composerSurface";
+import { ProviderModelPicker } from "./ProviderModelPicker";
import { ModelPickerSettings, type ModelPickerTraitsTarget } from "./ModelPickerSettings";
import {
ComposerRunControls,
@@ -214,12 +211,7 @@ import { getPickerModelName } from "./providerIconUtils";
import { awaitingInvite } from "@threadlines/shared/roomAgentRequests";
import { shownSettingsChange } from "@threadlines/shared/settingsChangeState";
import { activeParticipants, hasAgentRecords } from "@threadlines/shared/threadParticipants";
-import {
- getTraitsSectionVisibility,
- getTraitSwitchControls,
- isFastModeControl,
- shouldRenderTraitsControls,
-} from "./traitControls";
+import { modelPickerTriggerSummary, shouldRenderTraitsControls } from "./traitControls";
import {
canRequestProviderRateLimitResetCredit,
useProviderRateLimitResetCredit,
@@ -1787,26 +1779,10 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
const runControlsOnRow = !isMobileViewport;
// What the settings button says besides the model: the effort and Fast Mode.
- const settingsTraits = settingsTraitsTarget
- ? getTraitsSectionVisibility({
- provider: settingsTraitsTarget.provider,
- models: settingsTraitsTarget.models,
- model: settingsTraitsTarget.model,
- modelOptions: settingsTraitsTarget.modelOptions,
- })
- : null;
- const settingsTriggerSummary: ModelPickerTriggerSummary = {
- effort: settingsTraits?.reasoningDescriptor
- ? (getProviderOptionCurrentLabel(settingsTraits.reasoningDescriptor) ?? null)
- : null,
- ultracode: settingsTraits?.ultracodeEnabled ?? false,
- fastMode: settingsTraits
- ? getTraitSwitchControls(settingsTraits.descriptors).some(
- (control) => isFastModeControl(control) && control.checked,
- )
- : false,
- working: settingsTraitsWorking,
- };
+ const settingsTriggerSummary = modelPickerTriggerSummary(
+ settingsTraitsTarget,
+ settingsTraitsWorking,
+ );
// Build/Plan and access, on the row's own buttons or in the panel. The
// panel's rows keep focus there, so several settings can change in one
@@ -3876,10 +3852,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
ref={composerSurfaceRef}
data-chat-composer-mobile-collapsed={isComposerCollapsedMobile ? "true" : "false"}
className={cn(
- // The one raised box on the canvas: card fill and a border. In light
- // mode a white box on the near-white canvas also needs the soft drop
- // to read; in dark the lighter fill does that on its own.
- "rounded-4xl border bg-card not-dark:elevate-raised transition-colors duration-200 has-focus-visible:border-focus-ring/45",
+ COMPOSER_SURFACE_CLASS_NAME,
!isComposerCollapsedMobile &&
hasComposerDockContent({ pullRequests, notices: dockedNotices }) &&
"rounded-t-none",
diff --git a/apps/web/src/components/chat/DraftEmptyState.tsx b/apps/web/src/components/chat/DraftEmptyState.tsx
index c1f78ce77..a0f6ab626 100644
--- a/apps/web/src/components/chat/DraftEmptyState.tsx
+++ b/apps/web/src/components/chat/DraftEmptyState.tsx
@@ -35,8 +35,8 @@ import {
MenuItem,
MenuPopup,
MenuSeparator,
- MenuTrigger,
} from "../ui/menu";
+import { InlinePickerTrigger } from "../ui/inline-picker";
/**
* How the new-thread screen is arranged. `hero` is the roomy layout: only the
@@ -227,30 +227,18 @@ export function DraftEmptyState({
>
What's next in{" "}
-
+ {isGeneralChat ? (
+
+ ) : currentProject ? (
+
- }
- >
- {/* Chrome never paints text-decoration under a replaced element, so
- the dotted rule is a border on a flex wrapper — that's what keeps
- the icon inside the underline instead of beside it. */}
-
- {isGeneralChat ? (
-
- ) : currentProject ? (
-
- ) : null}
- {targetName}
-
-
+ ) : null}
+ {targetName}
+
{generalChatsRef ? (
<>
diff --git a/apps/web/src/components/chat/composerSurface.ts b/apps/web/src/components/chat/composerSurface.ts
new file mode 100644
index 000000000..9b3ed4b5e
--- /dev/null
+++ b/apps/web/src/components/chat/composerSurface.ts
@@ -0,0 +1,9 @@
+/**
+ * The composer's box: the one raised box on the canvas, a card fill and a
+ * border, its border taking the focus color while a control inside has
+ * keyboard focus. In light mode a white box on the near-white canvas also
+ * needs the soft drop to read; in dark the lighter fill does that on its own.
+ * The scheduled task editor is drawn in the same box.
+ */
+export const COMPOSER_SURFACE_CLASS_NAME =
+ "rounded-4xl border bg-card not-dark:elevate-raised transition-colors duration-200 has-focus-visible:border-focus-ring/45";
diff --git a/apps/web/src/components/chat/traitControls.ts b/apps/web/src/components/chat/traitControls.ts
index 13b3bd44a..6b62617f3 100644
--- a/apps/web/src/components/chat/traitControls.ts
+++ b/apps/web/src/components/chat/traitControls.ts
@@ -22,6 +22,7 @@ import {
import { useCallback } from "react";
import { useComposerDraftStore, type DraftId } from "../../composerDraftStore";
import { getProviderModelCapabilities } from "../../providerModels";
+import type { ModelPickerTriggerSummary } from "./ProviderModelPicker";
export type ProviderOptions = ReadonlyArray;
export type SelectProviderOptionDescriptor = Extract;
@@ -347,6 +348,42 @@ export function getTraitsSectionVisibility(input: {
};
}
+/**
+ * What the model button says besides the model, for the agent `target`
+ * describes: its effort and Fast Mode, and Ultracode's look. Null target
+ * (no options to show): just the model.
+ */
+export function modelPickerTriggerSummary(
+ target: {
+ provider: ProviderDriverKind;
+ models: ReadonlyArray;
+ model: string | null | undefined;
+ modelOptions?: ProviderOptions | null | undefined;
+ } | null,
+ working: boolean,
+): ModelPickerTriggerSummary {
+ const traits = target
+ ? getTraitsSectionVisibility({
+ provider: target.provider,
+ models: target.models,
+ model: target.model,
+ modelOptions: target.modelOptions,
+ })
+ : null;
+ return {
+ effort: traits?.reasoningDescriptor
+ ? (getProviderOptionCurrentLabel(traits.reasoningDescriptor) ?? null)
+ : null,
+ ultracode: traits?.ultracodeEnabled ?? false,
+ fastMode: traits
+ ? getTraitSwitchControls(traits.descriptors).some(
+ (control) => isFastModeControl(control) && control.checked,
+ )
+ : false,
+ working,
+ };
+}
+
export function shouldRenderTraitsControls(input: {
provider: ProviderDriverKind;
models: ReadonlyArray;
diff --git a/apps/web/src/components/scheduled/ScheduleButton.tsx b/apps/web/src/components/scheduled/ScheduleButton.tsx
new file mode 100644
index 000000000..ea595b05a
--- /dev/null
+++ b/apps/web/src/components/scheduled/ScheduleButton.tsx
@@ -0,0 +1,400 @@
+import {
+ BracesIcon,
+ CalendarClockIcon,
+ CheckIcon,
+ ChevronLeftIcon,
+ ChevronRightIcon,
+ GlobeIcon,
+ type LucideIcon,
+ ZapIcon,
+} from "lucide-react";
+import { type ReactNode, useRef, useState } from "react";
+
+import { cn } from "../../lib/utils";
+import { Button } from "../ui/button";
+import { DatePicker } from "../ui/date-picker";
+import { Input } from "../ui/input";
+import { Popover, PopoverPopup, PopoverTrigger } from "../ui/popover";
+import { SegmentedControl, SegmentedControlItem } from "../ui/segmented-control";
+import {
+ DropdownChevron,
+ Select,
+ SelectItem,
+ SelectPopup,
+ SelectTrigger,
+ SelectValue,
+} from "../ui/select";
+import { TimePicker } from "../ui/time-picker";
+import { type TimeZoneSuggestion, TimeZonePicker } from "../ui/time-zone-picker";
+import {
+ CADENCE_KIND_LABELS,
+ type CadenceKind,
+ customCadencePatch,
+ formatWhen,
+ previewRuns,
+ REPEAT_KINDS,
+ type ScheduledTaskForm,
+ scheduleSummary,
+ todayIn,
+ WEEKDAY_LABELS,
+} from "./scheduled.logic";
+
+const HOURLY_MINUTES = Array.from({ length: 12 }, (_, index) => index * 5);
+
+/** Monday first, as calendars here read; values are the cadence's 0 (Sunday) to 6. */
+const WEEK_ORDER = [1, 2, 3, 4, 5, 6, 0] as const;
+
+/** The words the Repeat field shows for a kind it doesn't list. */
+const REPEAT_LABELS: Record = {
+ ...CADENCE_KIND_LABELS,
+ custom: "Custom cron rule",
+};
+
+/** The catch-up sentence the old page header carried, now beside the times it's about. */
+const CLOCK_NOTE =
+ "It runs while Threadlines is running on its computer. A time missed while the computer was off or asleep gets one catch-up run.";
+
+const ZONE_HINT =
+ "Times use this zone wherever you are. When clocks skip ahead, a skipped time runs right after. When they fall back, a set time runs once and hourly tasks still run every hour.";
+
+const CRON_HINT =
+ "Five fields: minute, hour, day of month, month, day of week. Every 15 minutes is */15 * * * *.";
+
+/** A labelled line of the popover: the label in a narrow column, the control filling the rest. */
+function PopoverRow({ label, children }: { readonly label: string; readonly children: ReactNode }) {
+ return (
+
+ );
+}
+
+/** A row one step further in: a choice that opens more, or switches the task to its kind. */
+function MoreRow({
+ icon: Icon,
+ label,
+ value,
+ selected = false,
+ opens = false,
+ onClick,
+ testId,
+}: {
+ readonly icon: LucideIcon;
+ readonly label: string;
+ readonly value?: string | undefined;
+ readonly selected?: boolean;
+ /** It opens a page of its own (a chevron); else it picks (a check while picked). */
+ readonly opens?: boolean;
+ readonly onClick: () => void;
+ readonly testId?: string;
+}) {
+ return (
+
+
+ {label}
+ {value ? (
+
+ {value}
+
+ ) : null}
+ {opens ? (
+
+ ) : selected ? (
+
+ ) : null}
+
+ );
+}
+
+/**
+ * The schedule button at the top of the task editor: the schedule in a few
+ * words, opening a popover with the repeat pattern, its day and time and the
+ * next runs. The time zone, a cron rule and event triggers sit one step
+ * further in. Picking events closes it: their settings sit under the editor.
+ */
+export function ScheduleButton({
+ form,
+ onChange,
+ eventsOffered,
+ problem,
+ computerTimeZone,
+ timeZoneSuggestions,
+ hour12,
+ nowMs,
+}: {
+ readonly form: ScheduledTaskForm;
+ readonly onChange: (patch: Partial) => void;
+ /** The computer runs event tasks, or the task already is one. */
+ readonly eventsOffered: boolean;
+ /** Why the schedule can't be saved, once a save was tried. */
+ readonly problem: string | undefined;
+ readonly computerTimeZone: string | undefined;
+ readonly timeZoneSuggestions: ReadonlyArray;
+ readonly hour12: boolean;
+ readonly nowMs: number;
+}) {
+ const [open, setOpen] = useState(false);
+ const [page, setPage] = useState<"main" | "timeZone">("main");
+ const cronRef = useRef(null);
+ const kind = form.cadenceKind;
+ const isEvent = kind === "webhook";
+ const clock = !isEvent && kind !== "manual";
+ const upcoming = clock ? previewRuns(form, new Date(nowMs), 3) : [];
+ const timed = kind === "daily" || kind === "weekdays" || kind === "weekly" || kind === "once";
+ const zoneLabel =
+ computerTimeZone !== undefined && form.timeZone === computerTimeZone
+ ? "This computer"
+ : form.timeZone;
+
+ return (
+ {
+ setOpen(next);
+ if (!next) setPage("main");
+ }}
+ >
+
+ }
+ >
+
+ {scheduleSummary(form)}
+
+
+
+ {page === "timeZone" ? (
+
+
setPage("main")}
+ >
+
+ Time zone
+
+
onChange({ timeZone, timeZoneChosen: true })}
+ suggestions={timeZoneSuggestions}
+ className="w-full"
+ aria-label="Time zone"
+ data-testid="scheduled-form-time-zone"
+ />
+ {ZONE_HINT}
+
+ ) : (
+
+
+ {
+ if (value) onChange({ cadenceKind: value as CadenceKind });
+ }}
+ >
+
+ {REPEAT_LABELS[kind]}
+
+
+ {REPEAT_KINDS.map((option) => (
+
+ {CADENCE_KIND_LABELS[option]}
+
+ ))}
+
+
+
+
+ {kind === "weekly" ? (
+
onChange({ weekday: Number(value) })}
+ aria-label="Day"
+ >
+ {WEEK_ORDER.map((day) => (
+
+ {WEEKDAY_LABELS[day].slice(0, 3)}
+
+ ))}
+
+ ) : null}
+
+ {kind === "once" ? (
+
+ onChange({ date })}
+ data-testid="scheduled-form-date"
+ />
+
+ ) : null}
+
+ {kind === "hourly" ? (
+
+ {
+ if (value !== null) onChange({ minute: Number(value) });
+ }}
+ >
+
+ {`at :${String(form.minute).padStart(2, "0")}`}
+
+
+ {[...new Set([...HOURLY_MINUTES, form.minute])]
+ .toSorted((a, b) => a - b)
+ .map((minute) => (
+
+ {`at :${String(minute).padStart(2, "0")}`}
+
+ ))}
+
+
+
+ ) : null}
+
+ {timed ? (
+
+ onChange({ time })}
+ data-testid="scheduled-form-time"
+ />
+
+ ) : null}
+
+ {kind === "custom" ? (
+
+
onChange({ cron: event.target.value, cronChosen: true })}
+ />
+
{CRON_HINT}
+
+ ) : null}
+
+ {kind === "manual" ? (
+
+ It runs only when you press Run now.
+
+ ) : null}
+ {isEvent ? (
+
+ It runs when an event arrives. Set up which events under the editor.
+
+ ) : null}
+
+ {upcoming.length > 0 ? (
+
+ {kind === "once" ? "Your time: " : "Next, your time: "}
+ {upcoming.map((slot) => formatWhen(slot.toISOString(), nowMs)).join(", ")}
+
+ ) : null}
+ {problem !== undefined && !isEvent ? (
+
{problem}
+ ) : null}
+ {isEvent ? null : (
+
{CLOCK_NOTE}
+ )}
+
+
+
+ {clock ? (
+ setPage("timeZone")}
+ />
+ ) : null}
+ {
+ if (kind !== "custom") onChange(customCadencePatch(form));
+ requestAnimationFrame(() => cronRef.current?.focus());
+ }}
+ />
+ {eventsOffered ? (
+ {
+ onChange({ cadenceKind: "webhook" });
+ setOpen(false);
+ }}
+ />
+ ) : null}
+
+
+ )}
+
+
+ );
+}
diff --git a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
index 70ce06c50..e76135e89 100644
--- a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
+++ b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
@@ -3,30 +3,30 @@ import {
RUNTIME_MODES,
type EnvironmentId,
type ModelSelection,
- type ProjectId,
- type RuntimeMode,
type ServerProvider,
type ThreadId,
} from "@threadlines/contracts";
+import { createModelSelection } from "@threadlines/shared/model";
import {
PROVIDER_NOT_READY_FIX,
providerAgentName,
providerNotReady,
providerNotReadySentence,
} from "@threadlines/shared/providerAuth";
-import { roomAgentKey } from "@threadlines/shared/threadParticipants";
-import { MessagesSquareIcon } from "lucide-react";
-import { useMemo, useState } from "react";
+import { useMemo, useRef, useState } from "react";
import { useShallow } from "zustand/react/shallow";
import { readEnvironmentConnection } from "../../environments/runtime";
import { useEnvironmentProviders } from "../../hooks/useEnvironmentProviders";
+import { useIsPhoneViewport } from "../../hooks/useMediaQuery";
+import { useRelativeTimeTick } from "../../hooks/useRelativeTimeTick";
import { useSettings } from "../../hooks/useSettings";
import {
useScheduledTaskEnvironments,
useScheduledTasksStore,
} from "../../lib/scheduledTasksState";
import { cn } from "../../lib/utils";
+import { getCustomModelOptionsByInstance } from "../../modelSelection";
import { uses12HourClock } from "../../timestampFormat";
import {
deriveProviderInstanceEntries,
@@ -39,42 +39,36 @@ import {
selectSidebarThreadsAcrossEnvironments,
useStore,
} from "../../store";
-import type { Project } from "../../types";
-import { ProjectFavicon } from "../ProjectFavicon";
-import { SETTINGS_GROUP_ROW_CLASS, SettingsSection } from "../settings/settingsLayout";
-import { ModelSelectionControl } from "../settings/TextGenerationModelControl";
+import { type ComposerAccessControl, ComposerRunControls } from "../chat/ComposerRunControls";
+import { COMPOSER_SURFACE_CLASS_NAME } from "../chat/composerSurface";
+import { ModelPickerSettings, type ModelPickerTraitsTarget } from "../chat/ModelPickerSettings";
+import { ProviderModelPicker } from "../chat/ProviderModelPicker";
+import { modelPickerTriggerSummary, shouldRenderTraitsControls } from "../chat/traitControls";
+import { SettingsSection } from "../settings/settingsLayout";
import { Button } from "../ui/button";
-import { Input } from "../ui/input";
-import { SegmentedControl, SegmentedControlItem } from "../ui/segmented-control";
-import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
-import { DatePicker } from "../ui/date-picker";
import { Switch } from "../ui/switch";
-import { Textarea } from "../ui/textarea";
-import { TimePicker } from "../ui/time-picker";
-import { TimeZonePicker } from "../ui/time-zone-picker";
import { failureNotice, toastManager } from "../ui/toast";
+import { TooltipProvider } from "../ui/tooltip";
import { addComputerNotConnectedNotice } from "../computerConnectionNotices";
import {
- CADENCE_KIND_LABELS,
- type CadenceKind,
- cadenceKindsFor,
EVENT_TASK_RUNTIME_MODE,
emptyTaskForm,
eventTaskAccessWarning,
+ type FormProblems,
formatWhen,
formDraft,
formProblems,
previewRuns,
type ScheduledTaskForm as FormState,
taskForm,
- todayIn,
viewerTimeZone,
- WEEKDAY_LABELS,
type WebhookForm,
webhookFormWithContext,
} from "./scheduled.logic";
+import { ScheduleButton } from "./ScheduleButton";
import { ScheduledEventFields } from "./ScheduledEventFields";
import { FieldRow } from "./ScheduledFormRow";
+import { TaskProjectHeading, TaskRunsSentence } from "./ScheduledTaskWhere";
import {
type LocatedTask,
taskRef,
@@ -83,29 +77,22 @@ import {
useScheduledNavigation,
} from "./useScheduledPage";
-const HOURLY_MINUTES = Array.from({ length: 12 }, (_, index) => index * 5);
+/** Hover labels on the model and access buttons wait a moment, as on the composer's row. */
+const ROW_TOOLTIP_DELAY_MS = 250;
-const lowerFirst = (text: string) => text.charAt(0).toLowerCase() + text.slice(1);
+/** The order problems are listed in under the editor, top of the editor first. */
+const PROBLEM_ORDER = [
+ "name",
+ "prompt",
+ "agent",
+ "schedule",
+ "project",
+ "thread",
+ "goesTo",
+ "computer",
+] as const satisfies ReadonlyArray;
-/** A project as the app's other project pickers show it: its logo (General Chats its own glyph) and name. */
-function ProjectLabel({ project }: { readonly project: Project }) {
- return (
-
- {project.kind === "general-chat" ? (
-
- ) : (
-
- )}
-
- {project.kind === "general-chat" ? "General Chats" : project.name}
-
-
- );
-}
+const lowerFirst = (text: string) => text.charAt(0).toLowerCase() + text.slice(1);
/** The model a new task starts with on a computer: its new-thread default, else its first agent. */
function defaultModelFor(
@@ -124,10 +111,12 @@ function defaultModelFor(
}
/**
- * The form for a new task or an edited one (docs/design/fleet.md, Part 6):
- * name and instructions; the computer that keeps and runs it, its project
- * and where each run works; the agent, model and access; the schedule; and
- * whether each run starts a new thread or continues one.
+ * The editor for a new task or an edited one (docs/design/fleet.md, Part 6),
+ * laid out like the new-thread screen: "New task in [project]", then the
+ * composer's box with the task's name and its schedule button on top, the
+ * prompt, and the model and access buttons beside Create task. A sentence
+ * under the box says where each run goes (a new thread or one to continue,
+ * which checkout, which computer); an event task's settings follow it.
*/
export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask | null }) {
const navigation = useScheduledNavigation();
@@ -136,6 +125,10 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
const settings = useSettings();
const projects = useStore(useShallow(selectProjectsAcrossEnvironments));
const threads = useStore(useShallow(selectSidebarThreadsAcrossEnvironments));
+ const isPhone = useIsPhoneViewport();
+ const nowMs = useRelativeTimeTick(30_000);
+ const nameRef = useRef(null);
+ const promptRef = useRef(null);
const [draftForm, setForm] = useState(() => {
if (editing) return taskForm(editing.task, editing.environment.environmentId);
@@ -161,7 +154,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
});
});
const computerZones = useScheduledTasksStore((state) => state.byEnvironment);
- // A computer, project or agent the page didn't have yet when the form
+ // A computer, project or agent the page didn't have yet when the editor
// opened (right after a reload) is filled in once it arrives; a choice the
// user made is never replaced. Until the user picks a time zone, a new task
// is in the chosen computer's own: it runs there, by that computer's clock.
@@ -285,8 +278,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
: `${providerNotReadySentence(
agentNotReady,
providerAgentName(chosenProvider, form.modelSelection.instanceId),
- environments.find((entry) => entry.environmentId === form.environmentId)?.label ??
- "this computer",
+ chosenEnvironment?.label ?? "this computer",
)} Its runs will fail until you ${lowerFirst(PROVIDER_NOT_READY_FIX[agentNotReady])}.`;
// The zones the picker leads with: where the task runs, where you are, UTC.
@@ -303,16 +295,26 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
];
}, [computerTimeZone]);
- const now = new Date();
- const problems = {
+ const now = new Date(nowMs);
+ const problems: FormProblems = {
...formProblems(form, now, editing?.task, goesTo?.left === true),
// The computer stopped offering event tasks (an older Threadlines took its place).
...(isEvent && !eventTasks
? { schedule: "This computer doesn't run event tasks. Update Threadlines on it first." }
: {}),
};
- const shownProblems = submitted ? problems : {};
- const upcoming = form.cadenceKind === "manual" || isEvent ? [] : previewRuns(form, now, 3);
+ const shownProblems: FormProblems = submitted
+ ? problems
+ : // An agent that left the continued thread is said at once.
+ goesTo?.left === true && problems.goesTo !== undefined
+ ? { goesTo: problems.goesTo }
+ : {};
+ // An event task's schedule problem is said with its settings, below.
+ const listedProblems = PROBLEM_ORDER.filter(
+ (key) => shownProblems[key] !== undefined && !(key === "schedule" && isEvent),
+ ).map((key) => shownProblems[key]!);
+ const nextRun =
+ form.cadenceKind === "manual" || isEvent ? undefined : previewRuns(form, now, 1)[0];
const accessWarning = eventTaskAccessWarning(form);
const chooseEnvironment = (environmentId: EnvironmentId) => {
@@ -336,10 +338,32 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
});
};
+ const continueThread = (threadId: ThreadId) => {
+ if (form.environmentId === null) return;
+ // Another thread: its runs are for that thread's own agent, and start
+ // from its model and access.
+ const shell = selectEnvironmentState(useStore.getState(), form.environmentId).threadShellById[
+ threadId
+ ];
+ update({
+ target: "thread",
+ threadId,
+ threadParticipantId: null,
+ ...(shell !== undefined
+ ? { modelSelection: shell.modelSelection, runtimeMode: shell.runtimeMode }
+ : {}),
+ });
+ };
+
const save = async () => {
setSubmitted(true);
const draft = formDraft(form);
- if (Object.keys(problems).length > 0 || draft === null || form.environmentId === null) return;
+ if (Object.keys(problems).length > 0 || draft === null || form.environmentId === null) {
+ // Back to the first field that needs words.
+ if (problems.name !== undefined) nameRef.current?.focus();
+ else if (problems.prompt !== undefined) promptRef.current?.focus();
+ return;
+ }
const environment = environments.find((entry) => entry.environmentId === form.environmentId);
const connection = readEnvironmentConnection(form.environmentId);
if (!connection || !environment) {
@@ -378,463 +402,236 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
else navigation.showAll({ replace: true });
};
- const timeField = (
- update({ time })}
- data-testid="scheduled-form-time"
- />
- );
+ // The model button and its panel, as the composer has them: effort and the
+ // model's other options in the panel, and on phones the access level too.
+ const selection = form.modelSelection;
+ const traitsTarget: ModelPickerTraitsTarget | null =
+ selection !== null && selectedEntry !== undefined
+ ? {
+ provider: selectedEntry.driverKind,
+ instanceId: selection.instanceId,
+ models: selectedEntry.models,
+ model: selection.model,
+ modelOptions: selection.options,
+ onModelOptionsChange: (options) =>
+ update({
+ modelSelection: createModelSelection(selection.instanceId, selection.model, options),
+ }),
+ }
+ : null;
+ const shownTraits =
+ traitsTarget !== null && shouldRenderTraitsControls(traitsTarget) ? traitsTarget : null;
+ const accessControl: ComposerAccessControl = {
+ value: access?.shown ?? form.runtimeMode,
+ options:
+ access?.options ??
+ RUNTIME_MODES.map((mode) => ({ mode, ...runtimeModeConfig[mode], disabled: false })),
+ onChange: (mode) => update({ runtimeMode: mode, runtimeModeChosen: true }),
+ planning: false,
+ };
return (
+ ) : form.cadenceKind === "manual" ? (
+
+ Runs only when you press Run now
+
) : null}
- {form.target === "new_thread" && !isGeneralChats ? (
-
- update({ checkout: value })}
- aria-label="Runs in"
- >
- Local checkout
- New worktree
-
-
+ {[agentWarning, accessWarning].map((warning) =>
+ warning === null ? null : (
+
+ {warning}
+
+ ),
+ )}
+ {listedProblems.length > 0 ? (
+
+ {listedProblems.map((problem) => (
+
+ {problem}
+
+ ))}
+
) : null}
-
-
-
-
- {form.modelSelection && instanceEntries.length > 0 ? (
- update({ modelSelection: selection })}
- />
- ) : (
-
- No agent is ready on this computer.
-
- )}
-
- option.mode === access.shown)?.description ??
- "What the agent may do without asking."
- }
- warning={accessWarning}
- >
- {
- if (value) update({ runtimeMode: value as RuntimeMode, runtimeModeChosen: true });
- }}
- >
-
-
- {access?.options.find((option) => option.mode === form.runtimeMode)?.label ??
- runtimeModeConfig[form.runtimeMode].label}
-
-
-
- {(
- access?.options ??
- RUNTIME_MODES.map((mode) => ({
- mode,
- label: runtimeModeConfig[mode].label,
- disabled: false,
- }))
- ).map((option) => (
-
- {option.label}
-
- ))}
-
-
-
-
+
-
-
- {
- if (value) update({ cadenceKind: value as CadenceKind });
- }}
- >
-
- {CADENCE_KIND_LABELS[form.cadenceKind]}
-
-
- {cadenceKindsFor(eventTasks || isEvent).map((kind) => (
-
- {CADENCE_KIND_LABELS[kind]}
-
- ))}
-
-
- {form.cadenceKind === "hourly" ? (
- {
- if (value !== null) update({ minute: Number(value) });
- }}
- >
-
- {`at :${String(form.minute).padStart(2, "0")}`}
-
-
- {[...new Set([...HOURLY_MINUTES, form.minute])]
- .toSorted((a, b) => a - b)
- .map((minute) => (
-
- {`at :${String(minute).padStart(2, "0")}`}
-
- ))}
-
-
- ) : null}
- {form.cadenceKind === "weekly" ? (
- {
- if (value !== null) update({ weekday: Number(value) });
- }}
- >
-
- {WEEKDAY_LABELS[form.weekday]}
-
-
- {WEEKDAY_LABELS.map((label, index) => (
-
- {label}
-
- ))}
-
-
- ) : null}
- {form.cadenceKind === "once" ? (
- update({ date })}
- data-testid="scheduled-form-date"
- />
+ updateWebhook({ onePerSubject: Boolean(checked) })}
+ />
+
) : null}
- {form.cadenceKind === "daily" ||
- form.cadenceKind === "weekdays" ||
- form.cadenceKind === "weekly" ||
- form.cadenceKind === "once"
- ? timeField
- : null}
-
- {form.cadenceKind === "custom" ? (
-
- update({ cron: event.target.value })}
- />
-
- ) : null}
- {isEvent ? (
- ) : null}
- {form.cadenceKind !== "manual" && !isEvent ? (
-
- update({ timeZone, timeZoneChosen: true })}
- suggestions={timeZoneSuggestions}
- className="w-full sm:w-52"
- aria-label="Time zone"
- data-testid="scheduled-form-time-zone"
- />
-
- ) : null}
- {upcoming.length > 0 ? (
-
-
- {form.cadenceKind === "once" ? "Your time:" : "Next runs, your time:"}{" "}
- {upcoming.map((slot) => formatWhen(slot.toISOString(), now.getTime())).join(", ")}
-
-
- ) : form.cadenceKind === "manual" ? (
-
-
- It runs only when you press Run now.
-
-
- ) : null}
-
-
-
-
- Cancel
-
-
- {editing ? "Save" : "Create task"}
-
-
+
+ ) : null}
);
}
diff --git a/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx b/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
new file mode 100644
index 000000000..1bdd9b964
--- /dev/null
+++ b/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
@@ -0,0 +1,328 @@
+import type { EnvironmentId, ScheduledTaskCheckout, ThreadId } from "@threadlines/contracts";
+import { roomAgentKey } from "@threadlines/shared/threadParticipants";
+import { MessagesSquareIcon } from "lucide-react";
+
+import type { ScheduledTaskEnvironment } from "../../lib/scheduledTasksState";
+import type { Project, SidebarThreadSummary } from "../../types";
+import { ProjectFavicon } from "../ProjectFavicon";
+import { InlinePickerTrigger } from "../ui/inline-picker";
+import {
+ Menu,
+ MenuGroup,
+ MenuGroupLabel,
+ MenuItem,
+ MenuPopup,
+ MenuRadioGroup,
+ MenuRadioItem,
+ MenuSeparator,
+} from "../ui/menu";
+import type { ContinuedAgent } from "./useScheduledPage";
+
+/** How many of a project's threads "Continue a thread" lists, most recent first. */
+const LISTED_THREADS = 50;
+
+const projectName = (project: Project) =>
+ project.kind === "general-chat" ? "General Chats" : project.name;
+
+/** A project as the app's other project pickers show it: its logo (General Chats its own glyph) and name. */
+function ProjectLabel({ project }: { readonly project: Project }) {
+ return (
+ <>
+ {project.kind === "general-chat" ? (
+
+ ) : (
+
+ )}
+ {projectName(project)}
+ >
+ );
+}
+
+/**
+ * The editor's heading, as the new-thread screen words its own: "New task in
+ * [project]", the project a menu of the chosen computer's projects.
+ */
+export function TaskProjectHeading({
+ editing,
+ projects,
+ selected,
+ onSelect,
+}: {
+ readonly editing: boolean;
+ readonly projects: ReadonlyArray;
+ readonly selected: Project | undefined;
+ readonly onSelect: (project: Project) => void;
+}) {
+ return (
+
+ {editing ? "Edit task in " : "New task in "}
+
+
+ {selected ? : "choose a project"}
+
+
+ {projects.length === 0 ? (
+ No projects on this computer
+ ) : (
+
+ {projects.map((project) => (
+ onSelect(project)}
+ >
+
+
+ ))}
+
+ )}
+
+
+
+ );
+}
+
+const CHECKOUT_OPTIONS: ReadonlyArray<{
+ readonly value: ScheduledTaskCheckout;
+ readonly label: string;
+ readonly inSentence: string;
+ readonly description: string;
+}> = [
+ {
+ value: "local",
+ label: "Local checkout",
+ inSentence: "the local checkout",
+ description: "The project folder as it is, your uncommitted changes included.",
+ },
+ {
+ value: "worktree",
+ label: "New worktree",
+ inSentence: "a new worktree",
+ description: "A new git worktree for each run, so runs never touch your checkout.",
+ },
+];
+
+/** Two lines in a menu row: what to pick, and what it means. */
+function OptionText({
+ label,
+ description,
+}: {
+ readonly label: string;
+ readonly description: string;
+}) {
+ return (
+
+ {label}
+ {description}
+
+ );
+}
+
+/**
+ * Where each run goes, as one sentence under the editor: "Each run starts [a
+ * new thread] in [the local checkout] on [MacBook Pro]", or "Each run
+ * continues [a thread] and goes to [an agent] on [MacBook Pro]". Each bracket
+ * is a menu. The checkout is left out where it can't apply (General Chats, a
+ * continued thread), and the computer is plain words where it can't change.
+ */
+export function TaskRunsSentence({
+ isEvent,
+ target,
+ threadId,
+ threadParticipantId,
+ checkout,
+ showCheckout,
+ threads,
+ agents,
+ environments,
+ environmentId,
+ computerFixed,
+ onNewThread,
+ onContinueThread,
+ onAgent,
+ onCheckout,
+ onComputer,
+}: {
+ readonly isEvent: boolean;
+ readonly target: "new_thread" | "thread";
+ readonly threadId: ThreadId | null;
+ readonly threadParticipantId: ContinuedAgent["id"];
+ readonly checkout: ScheduledTaskCheckout;
+ readonly showCheckout: boolean;
+ /** The project's open threads, most recent first. */
+ readonly threads: ReadonlyArray;
+ /** The continued thread's agents, where it has a room. */
+ readonly agents: ReadonlyArray;
+ readonly environments: ReadonlyArray;
+ readonly environmentId: EnvironmentId | null;
+ /** The task is saved on its computer (editing), or there is no other to pick. */
+ readonly computerFixed: boolean;
+ readonly onNewThread: () => void;
+ readonly onContinueThread: (threadId: ThreadId) => void;
+ readonly onAgent: (agent: ContinuedAgent) => void;
+ readonly onCheckout: (checkout: ScheduledTaskCheckout) => void;
+ readonly onComputer: (environmentId: EnvironmentId) => void;
+}) {
+ const continuing = target === "thread";
+ const thread = threads.find((entry) => entry.id === threadId);
+ const goesTo = agents.find((agent) => agent.id === threadParticipantId);
+ const computerLabel =
+ environments.find((entry) => entry.environmentId === environmentId)?.label ?? null;
+ const checkoutOption =
+ CHECKOUT_OPTIONS.find((option) => option.value === checkout) ?? CHECKOUT_OPTIONS[0]!;
+
+ const threadMenu = (
+
+
+
+ {continuing ? (thread?.title ?? "a thread you choose") : "a new thread"}
+
+
+
+
+
+
+
+
+
+ Continue a thread
+ {threads.length === 0 ? (
+ No open threads in this project
+ ) : (
+ threads.slice(0, LISTED_THREADS).map((entry) => (
+ onContinueThread(entry.id)}
+ >
+ {entry.title}
+
+ ))
+ )}
+
+
+
+
+ );
+
+ const agentMenu =
+ continuing && agents.length > 0 ? (
+
+
+
+ {goesTo === undefined
+ ? "an agent you choose"
+ : goesTo.left
+ ? `${goesTo.name} (left)`
+ : goesTo.name}
+
+
+
+
+ Which agent in that thread gets each run
+
+ {agents.map((agent) => (
+ {
+ if (!agent.left) onAgent(agent);
+ }}
+ >
+ {agent.left ? `${agent.name} (left the thread)` : agent.name}
+
+ ))}
+
+
+
+
+ ) : null;
+
+ const checkoutMenu = (
+
+
+ {checkoutOption.inSentence}
+
+
+
+ {CHECKOUT_OPTIONS.map((option) => (
+ onCheckout(option.value)}
+ >
+
+
+ ))}
+
+
+
+ );
+
+ const computer = computerFixed ? (
+
+ {computerLabel ?? "this computer"}
+
+ ) : (
+
+
+ {computerLabel ?? "a computer you choose"}
+
+
+
+ It keeps the task and runs it
+
+ {environments.map((environment) => (
+ onComputer(environment.environmentId)}
+ >
+ {environment.label}
+
+ ))}
+
+
+
+
+ );
+
+ return (
+
+ {isEvent ? "Each event " : "Each run "}
+ {continuing ? "continues " : "starts "}
+ {threadMenu}
+ {agentMenu ? <> and goes to {agentMenu}> : null}
+ {showCheckout && !continuing ? <> in {checkoutMenu}> : null} on {computer}
+
+ );
+}
diff --git a/apps/web/src/components/scheduled/scheduled.logic.test.ts b/apps/web/src/components/scheduled/scheduled.logic.test.ts
index 338977d13..685dc9966 100644
--- a/apps/web/src/components/scheduled/scheduled.logic.test.ts
+++ b/apps/web/src/components/scheduled/scheduled.logic.test.ts
@@ -11,6 +11,7 @@ import { describe, expect, it } from "vite-plus/test";
import {
checkBackThreads,
+ customCadencePatch,
DEFAULT_WEBHOOK_FORM,
describeNextRun,
describeScheduleCall,
@@ -23,6 +24,7 @@ import {
formatWhen,
githubEventFields,
parseScheduleCallResult,
+ scheduleSummary,
taskForm,
webhookFormWithContext,
} from "./scheduled.logic";
@@ -217,6 +219,30 @@ describe("the task form", () => {
} as const;
expect(formDraft(taskForm(task({ target: forAgent }), ENVIRONMENT))?.target).toEqual(forAgent);
});
+ it("starts a cron rule from the schedule picked so far, and keeps one the user wrote", () => {
+ const weekly = { ...form(), cadenceKind: "weekly" as const, weekday: 5 };
+ expect(customCadencePatch(weekly)).toEqual({ cadenceKind: "custom", cron: "0 9 * * 5" });
+ // A one-time date would repeat every year as a rule: the rule is left as it was.
+ expect(customCadencePatch({ ...form(), cadenceKind: "once" }).cron).toBe(form().cron);
+ expect(customCadencePatch({ ...weekly, cron: "*/15 * * * *", cronChosen: true }).cron).toBe(
+ "*/15 * * * *",
+ );
+ // A saved cron task opens with its rule as the user's own.
+ expect(
+ taskForm(task({ cadence: { kind: "custom", cron: "5 4 * * *" } }), ENVIRONMENT).cronChosen,
+ ).toBe(true);
+ });
+
+ it("words the schedule button as the task list does, or the kind while half set up", () => {
+ expect(scheduleSummary(form(), "UTC")).toMatch(/^Weekdays at 9:00/);
+ expect(scheduleSummary(form(), "Europe/Madrid")).toMatch(/ · UTC$/);
+ expect(scheduleSummary({ ...form(), cadenceKind: "custom", cron: " " }, "UTC")).toBe(
+ "Custom cron rule",
+ );
+ expect(scheduleSummary({ ...form(), cadenceKind: "webhook" }, "UTC")).toBe(
+ "When something happens",
+ );
+ });
});
describe("event tasks", () => {
diff --git a/apps/web/src/components/scheduled/scheduled.logic.ts b/apps/web/src/components/scheduled/scheduled.logic.ts
index fd6d46ea7..572345187 100644
--- a/apps/web/src/components/scheduled/scheduled.logic.ts
+++ b/apps/web/src/components/scheduled/scheduled.logic.ts
@@ -32,6 +32,7 @@ import {
type WebhookSignature,
} from "@threadlines/contracts";
import {
+ cadenceCronExpression,
cadenceSaveRefusal,
describeCadence,
sameCadence,
@@ -378,7 +379,20 @@ export const CADENCE_KIND_LABELS: Record = {
webhook: "When something happens",
};
-/** The kinds the Schedule field offers, in its order; event tasks only on a computer that runs them. */
+/**
+ * The patterns the schedule popover's Repeat field lists. A cron rule and
+ * event triggers sit one step further in, as rows of their own.
+ */
+export const REPEAT_KINDS = [
+ "manual",
+ "once",
+ "hourly",
+ "daily",
+ "weekdays",
+ "weekly",
+] as const satisfies readonly CadenceKind[];
+
+/** The kinds a task can have, in the popover's order; event tasks only on a computer that runs them. */
export function cadenceKindsFor(eventTasks: boolean): readonly CadenceKind[] {
const clock: CadenceKind[] = [
"manual",
@@ -771,6 +785,11 @@ export interface ScheduledTaskForm {
readonly minute: number;
readonly weekday: number;
readonly cron: string;
+ /**
+ * The user wrote the cron rule (or the task already ran on one): until
+ * then, switching to a cron rule starts from the schedule picked so far.
+ */
+ readonly cronChosen: boolean;
/** An event task's start (docs/design/event-tasks.md), kept while another kind is picked. */
readonly webhook: WebhookForm;
readonly timeZone: string;
@@ -829,6 +848,7 @@ export function emptyTaskForm(input: {
minute: 0,
weekday: 1,
cron: "0 9 * * 1-5",
+ cronChosen: false,
webhook: DEFAULT_WEBHOOK_FORM,
timeZone: input.timeZone,
timeZoneChosen: false,
@@ -864,7 +884,7 @@ export function taskForm(task: ScheduledTask, environmentId: EnvironmentId): Sch
...(cadence.kind === "once" ? { date: cadence.date } : {}),
...(cadence.kind === "hourly" ? { minute: cadence.minute } : {}),
...(cadence.kind === "weekly" ? { weekday: cadence.weekday } : {}),
- ...(cadence.kind === "custom" ? { cron: cadence.cron } : {}),
+ ...(cadence.kind === "custom" ? { cron: cadence.cron, cronChosen: true } : {}),
...(cadence.kind === "webhook" ? { webhook: webhookFormOf(cadence) } : {}),
timeZoneChosen: true,
target: task.target.kind,
@@ -894,6 +914,42 @@ export function formCadence(form: ScheduledTaskForm): ScheduledTaskCadence {
}
}
+/**
+ * The switch to a cron rule: one the user wrote stays, else it starts from
+ * the schedule picked so far ("Weekdays at 9:00" gives `0 9 * * 1-5`). A
+ * one-time schedule isn't carried over: as a rule it would repeat every year.
+ */
+export function customCadencePatch(
+ form: ScheduledTaskForm,
+): Pick {
+ if (form.cronChosen || form.cadenceKind === "once" || form.cadenceKind === "custom") {
+ return { cadenceKind: "custom", cron: form.cron };
+ }
+ const seeded = form.cadenceKind === "webhook" ? null : cadenceCronExpression(formCadence(form));
+ return { cadenceKind: "custom", cron: seeded ?? form.cron };
+}
+
+/**
+ * What the schedule button says: the schedule in a few words, as the task
+ * list words it ("Weekdays at 9:00 AM", "Mondays at 9:00 AM · Europe/Madrid"),
+ * or the kind while it's only half set up (a cron rule not written yet, an
+ * event task without its repository).
+ */
+export function scheduleSummary(
+ form: ScheduledTaskForm,
+ viewerZone: string = viewerTimeZone(),
+): string {
+ if (form.cadenceKind === "custom" && form.cron.trim().length === 0) return "Custom cron rule";
+ if (
+ form.cadenceKind === "webhook" &&
+ form.webhook.source === "github" &&
+ form.webhook.repository.trim().length === 0
+ ) {
+ return CADENCE_KIND_LABELS.webhook;
+ }
+ return describeTaskSchedule({ cadence: formCadence(form), timeZone: form.timeZone }, viewerZone);
+}
+
export type FormProblems = Partial<
Record<
"name" | "prompt" | "computer" | "project" | "agent" | "schedule" | "thread" | "goesTo",
diff --git a/apps/web/src/components/ui/inline-picker.tsx b/apps/web/src/components/ui/inline-picker.tsx
new file mode 100644
index 000000000..2ef41042f
--- /dev/null
+++ b/apps/web/src/components/ui/inline-picker.tsx
@@ -0,0 +1,53 @@
+import type { ReactNode } from "react";
+
+import { cn } from "~/lib/utils";
+import { MenuTrigger } from "./menu";
+
+/**
+ * A choice inside a sentence, drawn as its words with a dotted underline that
+ * darkens on hover and while its menu is open: the project in the new-thread
+ * screen's "What's next in web?", or where a scheduled task's runs go. Opens
+ * the `Menu` it sits in.
+ */
+export function InlinePickerTrigger({
+ children,
+ className,
+ labelClassName,
+ "aria-label": ariaLabel,
+ "data-testid": testId,
+}: {
+ readonly children: ReactNode;
+ readonly className?: string;
+ /** Classes for the underlined words (gap, size). */
+ readonly labelClassName?: string;
+ readonly "aria-label"?: string;
+ readonly "data-testid"?: string;
+}) {
+ return (
+
+ }
+ >
+ {/* Chrome never paints text-decoration under a replaced element, so
+ the dotted rule is a border on a flex wrapper — that's what keeps
+ the icon inside the underline instead of beside it. */}
+
+ {children}
+
+
+ );
+}
From ef8fc24058fce5d26143267d59093684e6a4d9a7 Mon Sep 17 00:00:00 2001
From: Badcuban <108198679+badcuban@users.noreply.github.com>
Date: Fri, 20 Nov 2026 16:27:46 -0500
Subject: [PATCH 2/4] fix(web): keep the task editor's access button on phones
when no model button shows
---
apps/web/src/components/scheduled/ScheduledTaskForm.tsx | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
index e76135e89..4f61a02c0 100644
--- a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
+++ b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
@@ -419,6 +419,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
}),
}
: null;
+ const hasModelPicker = selection !== null && instanceEntries.length > 0;
const shownTraits =
traitsTarget !== null && shouldRenderTraitsControls(traitsTarget) ? traitsTarget : null;
const accessControl: ComposerAccessControl = {
@@ -496,7 +497,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
- {selection !== null && instanceEntries.length > 0 ? (
+ {hasModelPicker ? (
)}
- {isPhone ? null : (
+ {/* On phones access lives in the model button's panel, as on the
+ composer; with no model button it stays on the row. */}
+ {isPhone && hasModelPicker ? null : (
Date: Fri, 20 Nov 2026 16:34:09 -0500
Subject: [PATCH 3/4] fix(web): task editor review fixes
- One save at a time, so a double Cmd/Ctrl+Enter creates one task.
- The access button shows the level the task saves, not the one its
agent offers today.
- A draft whose computer disconnected can still move to another one.
- Switching to a new thread and back keeps the continued thread's agent,
model and access, and the saved thread stays listed when it's older
than the recent ones or archived.
- Keyboard focus follows the schedule popover's time zone page and back.
- The schedule button follows the app's 12/24-hour setting.
- The fixed computer name keeps its hint as a hover label.
---
.../ChatView.event-tasks.browser.tsx | 15 +++++++++-
.../components/scheduled/ScheduleButton.tsx | 21 +++++++++----
.../scheduled/ScheduledTaskForm.tsx | 30 +++++++++++++++++--
.../scheduled/ScheduledTaskWhere.tsx | 27 ++++++++++++++---
.../scheduled/scheduled.logic.test.ts | 4 +++
.../components/scheduled/scheduled.logic.ts | 25 ++++++++++++----
6 files changed, 105 insertions(+), 17 deletions(-)
diff --git a/apps/web/src/components/ChatView.event-tasks.browser.tsx b/apps/web/src/components/ChatView.event-tasks.browser.tsx
index e2667bfbc..1ff7d1121 100644
--- a/apps/web/src/components/ChatView.event-tasks.browser.tsx
+++ b/apps/web/src/components/ChatView.event-tasks.browser.tsx
@@ -391,8 +391,21 @@ describe("ChatView (full app): event tasks", () => {
),
);
- await page.getByTestId("scheduled-form-save").click();
+ // Cmd/Ctrl+Enter in the prompt saves, once however fast it's pressed.
+ const prompt = byTestId("scheduled-form-prompt")!;
+ for (let press = 0; press < 2; press += 1) {
+ prompt.dispatchEvent(
+ new KeyboardEvent("keydown", {
+ key: "Enter",
+ metaKey: true,
+ bubbles: true,
+ cancelable: true,
+ }),
+ );
+ }
await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
+ await new Promise((resolve) => setTimeout(resolve, 100));
+ expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1);
expect(requestsOf(WS_METHODS.scheduledTasksCreate)[0]).toMatchObject({
name: "Friday review",
prompt: "Summarize the week.",
diff --git a/apps/web/src/components/scheduled/ScheduleButton.tsx b/apps/web/src/components/scheduled/ScheduleButton.tsx
index ea595b05a..e356a745e 100644
--- a/apps/web/src/components/scheduled/ScheduleButton.tsx
+++ b/apps/web/src/components/scheduled/ScheduleButton.tsx
@@ -143,6 +143,17 @@ export function ScheduleButton({
const [open, setOpen] = useState(false);
const [page, setPage] = useState<"main" | "timeZone">("main");
const cronRef = useRef(null);
+ const pageRef = useRef(null);
+ // Moving between pages keeps the keyboard's place: the page's first
+ // control, and back on the main page the row that opened the other.
+ const showPage = (next: "main" | "timeZone") => {
+ setPage(next);
+ const target =
+ next === "timeZone" ? "scheduled-form-time-zone" : "scheduled-schedule-time-zone";
+ requestAnimationFrame(() =>
+ pageRef.current?.querySelector(`[data-testid="${target}"]`)?.focus(),
+ );
+ };
const kind = form.cadenceKind;
const isEvent = kind === "webhook";
const clock = !isEvent && kind !== "manual";
@@ -178,7 +189,7 @@ export function ScheduleButton({
}
>
- {scheduleSummary(form)}
+ {scheduleSummary(form, undefined, hour12)}
{page === "timeZone" ? (
-
+
setPage("main")}
+ onClick={() => showPage("main")}
>
Time zone
@@ -209,7 +220,7 @@ export function ScheduleButton({
{ZONE_HINT}
) : (
-
+
setPage("timeZone")}
+ onClick={() => showPage("timeZone")}
/>
) : null}
{
if (form.environmentId === null) return;
+ // Back to the thread it continued: its agent, model and access stay as set.
+ if (threadId === form.threadId) {
+ update({ target: "thread" });
+ return;
+ }
// Another thread: its runs are for that thread's own agent, and start
// from its model and access.
const shell = selectEnvironmentState(useStore.getState(), form.environmentId).threadShellById[
@@ -355,7 +360,11 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
});
};
+ // One save at a time: the button is off while it runs, but the keyboard
+ // shortcut can submit again before it re-renders.
+ const savingRef = useRef(false);
const save = async () => {
+ if (savingRef.current) return;
setSubmitted(true);
const draft = formDraft(form);
if (Object.keys(problems).length > 0 || draft === null || form.environmentId === null) {
@@ -373,6 +382,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
});
return;
}
+ savingRef.current = true;
setSaving(true);
try {
if (editing) {
@@ -393,6 +403,7 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
}),
);
} finally {
+ savingRef.current = false;
setSaving(false);
}
};
@@ -422,8 +433,10 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
const hasModelPicker = selection !== null && instanceEntries.length > 0;
const shownTraits =
traitsTarget !== null && shouldRenderTraitsControls(traitsTarget) ? traitsTarget : null;
+ // The level the task saves, not the one its agent would run at today: a
+ // task runs later, unattended, at whatever its agent offers then.
const accessControl: ComposerAccessControl = {
- value: access?.shown ?? form.runtimeMode,
+ value: form.runtimeMode,
options:
access?.options ??
RUNTIME_MODES.map((mode) => ({ mode, ...runtimeModeConfig[mode], disabled: false })),
@@ -558,10 +571,23 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
checkout={form.checkout}
showCheckout={!isGeneralChats}
threads={projectThreads}
+ keptThread={
+ form.threadId === null
+ ? null
+ : {
+ id: form.threadId,
+ title:
+ threads.find((thread) => thread.id === form.threadId)?.title ??
+ "The thread it continued",
+ }
+ }
agents={continuedAgents}
environments={environments}
environmentId={form.environmentId}
- computerFixed={editing !== null || environments.length < 2}
+ // A draft on a computer that disconnected can still move to another.
+ computerFixed={
+ editing !== null || (environments.length < 2 && chosenEnvironment !== undefined)
+ }
onNewThread={() => update({ target: "new_thread" })}
onContinueThread={continueThread}
onAgent={(agent) =>
diff --git a/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx b/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
index 1bdd9b964..8619718bd 100644
--- a/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
+++ b/apps/web/src/components/scheduled/ScheduledTaskWhere.tsx
@@ -138,6 +138,7 @@ export function TaskRunsSentence({
checkout,
showCheckout,
threads,
+ keptThread,
agents,
environments,
environmentId,
@@ -156,6 +157,12 @@ export function TaskRunsSentence({
readonly showCheckout: boolean;
/** The project's open threads, most recent first. */
readonly threads: ReadonlyArray;
+ /**
+ * The thread the task continues, or last picked: listed even when it isn't
+ * among the recent open ones (older, or archived), so switching to a new
+ * thread and back can always return to it.
+ */
+ readonly keptThread: { readonly id: ThreadId; readonly title: string } | null;
/** The continued thread's agents, where it has a room. */
readonly agents: ReadonlyArray;
readonly environments: ReadonlyArray;
@@ -169,7 +176,15 @@ export function TaskRunsSentence({
readonly onComputer: (environmentId: EnvironmentId) => void;
}) {
const continuing = target === "thread";
- const thread = threads.find((entry) => entry.id === threadId);
+ const listedThreads = threads.slice(0, LISTED_THREADS).map((entry) => ({
+ id: entry.id,
+ title: entry.title,
+ }));
+ const shownThreads =
+ keptThread !== null && !listedThreads.some((entry) => entry.id === keptThread.id)
+ ? [keptThread, ...listedThreads]
+ : listedThreads;
+ const thread = shownThreads.find((entry) => entry.id === threadId);
const goesTo = agents.find((agent) => agent.id === threadParticipantId);
const computerLabel =
environments.find((entry) => entry.environmentId === environmentId)?.label ?? null;
@@ -198,10 +213,10 @@ export function TaskRunsSentence({
Continue a thread
- {threads.length === 0 ? (
+ {shownThreads.length === 0 ? (
No open threads in this project
) : (
- threads.slice(0, LISTED_THREADS).map((entry) => (
+ shownThreads.map((entry) => (
+
{computerLabel ?? "this computer"}
) : (
diff --git a/apps/web/src/components/scheduled/scheduled.logic.test.ts b/apps/web/src/components/scheduled/scheduled.logic.test.ts
index 685dc9966..18b3c5ecb 100644
--- a/apps/web/src/components/scheduled/scheduled.logic.test.ts
+++ b/apps/web/src/components/scheduled/scheduled.logic.test.ts
@@ -236,6 +236,10 @@ describe("the task form", () => {
it("words the schedule button as the task list does, or the kind while half set up", () => {
expect(scheduleSummary(form(), "UTC")).toMatch(/^Weekdays at 9:00/);
expect(scheduleSummary(form(), "Europe/Madrid")).toMatch(/ · UTC$/);
+ // Times follow the app's clock setting, not only the locale.
+ expect(scheduleSummary({ ...form(), time: { hour: 17, minute: 0 } }, "UTC", false)).toBe(
+ "Weekdays at 17:00",
+ );
expect(scheduleSummary({ ...form(), cadenceKind: "custom", cron: " " }, "UTC")).toBe(
"Custom cron rule",
);
diff --git a/apps/web/src/components/scheduled/scheduled.logic.ts b/apps/web/src/components/scheduled/scheduled.logic.ts
index 572345187..6c964b6d3 100644
--- a/apps/web/src/components/scheduled/scheduled.logic.ts
+++ b/apps/web/src/components/scheduled/scheduled.logic.ts
@@ -107,12 +107,16 @@ export function taskRunStatus(
/** The viewer's own zone. */
export { viewerTimeZone } from "../../lib/timeZones";
-/** A wall time in the viewer's locale ("9:00", "9:00 AM"). */
-export function formatClock(clock: ScheduledTaskClock): string {
+/**
+ * A wall time in the viewer's locale ("9:00", "9:00 AM"); `hour12` follows
+ * the app's clock setting where the caller has it, else the locale decides.
+ */
+export function formatClock(clock: ScheduledTaskClock, hour12?: boolean): string {
return new Intl.DateTimeFormat(undefined, {
hour: "numeric",
minute: "2-digit",
timeZone: "UTC",
+ ...(hour12 !== undefined ? { hour12 } : {}),
}).format(Date.UTC(2000, 0, 1, clock.hour, clock.minute));
}
@@ -136,8 +140,13 @@ export function formatCadenceDay(date: string, nowMs: number = Date.now()): stri
export function describeTaskSchedule(
task: Pick,
viewerZone: string = viewerTimeZone(),
+ hour12?: boolean,
): string {
- const words = describeCadence(task.cadence, formatClock, formatCadenceDay);
+ const words = describeCadence(
+ task.cadence,
+ (clock) => formatClock(clock, hour12),
+ formatCadenceDay,
+ );
return task.cadence.kind === "manual" ||
task.cadence.kind === "webhook" ||
task.timeZone === viewerZone
@@ -931,13 +940,15 @@ export function customCadencePatch(
/**
* What the schedule button says: the schedule in a few words, as the task
- * list words it ("Weekdays at 9:00 AM", "Mondays at 9:00 AM · Europe/Madrid"),
+ * list words it ("Weekdays at 9:00 AM", "Mondays at 9:00 AM · Europe/Madrid")
+ * with times in the app's clock setting (`hour12`),
* or the kind while it's only half set up (a cron rule not written yet, an
* event task without its repository).
*/
export function scheduleSummary(
form: ScheduledTaskForm,
viewerZone: string = viewerTimeZone(),
+ hour12?: boolean,
): string {
if (form.cadenceKind === "custom" && form.cron.trim().length === 0) return "Custom cron rule";
if (
@@ -947,7 +958,11 @@ export function scheduleSummary(
) {
return CADENCE_KIND_LABELS.webhook;
}
- return describeTaskSchedule({ cadence: formCadence(form), timeZone: form.timeZone }, viewerZone);
+ return describeTaskSchedule(
+ { cadence: formCadence(form), timeZone: form.timeZone },
+ viewerZone,
+ hour12,
+ );
}
export type FormProblems = Partial<
From 7e3b498e61560dedd5692cec667239c2d88f7624 Mon Sep 17 00:00:00 2001
From: Badcuban <108198679+badcuban@users.noreply.github.com>
Date: Fri, 20 Nov 2026 16:43:03 -0500
Subject: [PATCH 4/4] fix(web): task editor follow-ups from review
- The schedule is checked against the current moment on every change and
again at save, so a one-time time that just passed is never sent.
- The instructions hint is a visible line again, under the where-it-runs
sentence, so it shows once the prompt has text.
- The access button shows the level the agent runs at, as on the composer.
- The effort meter marks the model's default level with a small dot (and
says so on hover and to screen readers), as the old traits menu's
"default" tag did.
- Tests: a save shortcut pressed while the create is still out sends
nothing more, and switching to a new thread and back keeps the
continued thread's access.
---
.../ChatView.event-tasks.browser.tsx | 69 +++++++++++++++++--
apps/web/src/components/chat/EffortMeter.tsx | 15 +++-
.../scheduled/ScheduledTaskForm.tsx | 36 +++++++---
3 files changed, 102 insertions(+), 18 deletions(-)
diff --git a/apps/web/src/components/ChatView.event-tasks.browser.tsx b/apps/web/src/components/ChatView.event-tasks.browser.tsx
index 1ff7d1121..e2080f42e 100644
--- a/apps/web/src/components/ChatView.event-tasks.browser.tsx
+++ b/apps/web/src/components/ChatView.event-tasks.browser.tsx
@@ -20,6 +20,7 @@ import { type NormalizedWsRpcRequestBody } from "../../test/wsRpcHarness";
import {
PROJECT_ID,
THREAD_ID,
+ THREAD_TITLE,
NOW_ISO,
rpcHarness,
wsRequests,
@@ -332,6 +333,10 @@ describe("ChatView (full app): event tasks", () => {
});
it("creates a clock task from the editor's box, schedule popover and where-it-runs sentence", async () => {
+ let releaseCreate = () => {};
+ const createHeld = new Promise((resolve) => {
+ releaseCreate = resolve;
+ });
const mounted = await mountChatView({
viewport: WIDE_FOOTER_VIEWPORT,
snapshot: snapshot(),
@@ -340,9 +345,13 @@ describe("ChatView (full app): event tasks", () => {
withScheduledCapabilities(true)(nextFixture);
withCodexModels(nextFixture);
},
+ // The create is held open until the test lets it finish.
resolveRpc: (body) =>
body._tag === WS_METHODS.scheduledTasksCreate
- ? { ...eventTask(), ...body, id: TASK_ID }
+ ? Effect.promise(async () => {
+ await createHeld;
+ return { ...eventTask(), ...body, id: TASK_ID };
+ })
: undefined,
});
try {
@@ -391,9 +400,10 @@ describe("ChatView (full app): event tasks", () => {
),
);
- // Cmd/Ctrl+Enter in the prompt saves, once however fast it's pressed.
+ // Cmd/Ctrl+Enter in the prompt saves, and pressing it again while the
+ // create is still out sends nothing more.
const prompt = byTestId("scheduled-form-prompt")!;
- for (let press = 0; press < 2; press += 1) {
+ const pressSave = () =>
prompt.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Enter",
@@ -402,10 +412,13 @@ describe("ChatView (full app): event tasks", () => {
cancelable: true,
}),
);
- }
+ pressSave();
await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
- await new Promise((resolve) => setTimeout(resolve, 100));
+ pressSave();
+ pressSave();
+ await new Promise((resolve) => setTimeout(resolve, 150));
expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1);
+ releaseCreate();
expect(requestsOf(WS_METHODS.scheduledTasksCreate)[0]).toMatchObject({
name: "Friday review",
prompt: "Summarize the week.",
@@ -418,6 +431,52 @@ describe("ChatView (full app): event tasks", () => {
}
});
+ it("keeps a continued thread's access when switching to a new thread and back", async () => {
+ const mounted = await mountChatView({
+ viewport: WIDE_FOOTER_VIEWPORT,
+ snapshot: snapshot(),
+ initialPath: "/scheduled?view=new",
+ configureFixture: (nextFixture) => {
+ withScheduledCapabilities(true)(nextFixture);
+ withCodexModels(nextFixture);
+ },
+ resolveRpc: (body) =>
+ body._tag === WS_METHODS.scheduledTasksCreate
+ ? { ...eventTask(), ...body, id: TASK_ID }
+ : undefined,
+ });
+ const pickThread = async (name: string | RegExp) => {
+ await page.getByTestId("scheduled-form-target").click();
+ await page.getByRole("menuitemradio", { name }).click();
+ };
+ try {
+ await sendTasks([]);
+ await userEvent.fill(page.getByTestId("scheduled-form-name"), "Nightly follow-up");
+ await userEvent.fill(page.getByTestId("scheduled-form-prompt"), "Check on the build.");
+
+ // Continuing the thread starts from its access (full access), then the
+ // task sets its own.
+ await pickThread(THREAD_TITLE);
+ await expect.element(page.getByLabelText("Access level: Full access")).toBeVisible();
+ await pickAccess("approval-required");
+ await expect.element(page.getByLabelText("Access level: Supervised")).toBeVisible();
+
+ // Off to a new thread and back to the same one: the task's own access stays.
+ await pickThread(/A new thread/);
+ await pickThread(THREAD_TITLE);
+ await expect.element(page.getByLabelText("Access level: Supervised")).toBeVisible();
+
+ await page.getByTestId("scheduled-form-save").click();
+ await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
+ expect(requestsOf(WS_METHODS.scheduledTasksCreate)[0]).toMatchObject({
+ runtimeMode: "approval-required",
+ target: { kind: "thread", threadId: THREAD_ID },
+ });
+ } finally {
+ await mounted.cleanup();
+ }
+ });
+
it("offers Add to GitHub, falls back to the steps by hand, and waits for the relay's address", async () => {
const mounted = await mountChatView({
viewport: WIDE_FOOTER_VIEWPORT,
diff --git a/apps/web/src/components/chat/EffortMeter.tsx b/apps/web/src/components/chat/EffortMeter.tsx
index 46624563f..e37ffef32 100644
--- a/apps/web/src/components/chat/EffortMeter.tsx
+++ b/apps/web/src/components/chat/EffortMeter.tsx
@@ -4,8 +4,14 @@ import { cn } from "~/lib/utils";
export interface EffortMeterOption {
readonly id: string;
readonly label: string;
+ /** The model's own level when none is picked: a dot under its segment says so. */
+ readonly isDefault?: boolean | undefined;
}
+/** Whether a level is marked as the default: one named "Default" already says so. */
+const marksDefault = (option: EffortMeterOption) =>
+ option.isDefault === true && option.label.trim().toLowerCase() !== "default";
+
/** Stagger between segments as a level charges up (or drains), per segment. */
const CHARGE_STEP_MS = 55;
const DRAIN_STEP_MS = 45;
@@ -149,7 +155,8 @@ function RollingLevelName(props: { text: string; preview: boolean; up: boolean }
*
* Every effect moves or fades the segments only, runs once per change, and
* stays still under reduced motion. Keyboard: a radio group, where the arrow
- * keys step the level and focus follows it.
+ * keys step the level and focus follows it. A small dot under a segment
+ * marks the model's default level.
*/
export const EffortMeter = memo(function EffortMeter(props: {
options: ReadonlyArray;
@@ -271,7 +278,8 @@ export const EffortMeter = memo(function EffortMeter(props: {
type="button"
role="radio"
aria-checked={index === selectedIndex}
- aria-label={option.label}
+ aria-label={marksDefault(option) ? `${option.label}, default` : option.label}
+ title={marksDefault(option) ? `${option.label} (default)` : undefined}
tabIndex={leaving ? -1 : index === (selectedIndex < 0 ? 0 : selectedIndex) ? 0 : -1}
disabled={disabled || leaving}
data-effort-level={option.id}
@@ -285,6 +293,9 @@ export const EffortMeter = memo(function EffortMeter(props: {
"pointer-events-none animate-[effort-segment-out_300ms_ease_forwards] motion-reduce:animate-none",
entering && "animate-[effort-segment-in_300ms_ease] motion-reduce:animate-none",
index === hoverIndex && !leaving && "scale-y-[1.35]",
+ // The default level's dot, under its segment.
+ marksDefault(option) &&
+ "after:absolute after:top-[calc(100%+3px)] after:left-1/2 after:size-[3px] after:-translate-x-1/2 after:rounded-full after:bg-muted-foreground",
)}
onPointerEnter={() => {
if (!leaving && !disabled) setHoverId(option.id);
diff --git a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
index 845041d93..f676b940e 100644
--- a/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
+++ b/apps/web/src/components/scheduled/ScheduledTaskForm.tsx
@@ -295,14 +295,18 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
];
}, [computerTimeZone]);
- const now = new Date(nowMs);
- const problems: FormProblems = {
- ...formProblems(form, now, editing?.task, goesTo?.left === true),
+ const problemsAt = (at: Date): FormProblems => ({
+ ...formProblems(form, at, editing?.task, goesTo?.left === true),
// The computer stopped offering event tasks (an older Threadlines took its place).
...(isEvent && !eventTasks
? { schedule: "This computer doesn't run event tasks. Update Threadlines on it first." }
: {}),
- };
+ });
+ // Checked against this render's moment, as the form always was: a change
+ // re-checks at once, and the half-minute tick (nowMs) re-renders an idle
+ // form so a one-time run that passes meanwhile is said too.
+ const now = new Date();
+ const problems = problemsAt(now);
const shownProblems: FormProblems = submitted
? problems
: // An agent that left the continued thread is said at once.
@@ -366,11 +370,14 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
const save = async () => {
if (savingRef.current) return;
setSubmitted(true);
+ // Checked against this moment: a one-time run that passed since the last
+ // render isn't sent.
+ const current = problemsAt(new Date());
const draft = formDraft(form);
- if (Object.keys(problems).length > 0 || draft === null || form.environmentId === null) {
+ if (Object.keys(current).length > 0 || draft === null || form.environmentId === null) {
// Back to the first field that needs words.
- if (problems.name !== undefined) nameRef.current?.focus();
- else if (problems.prompt !== undefined) promptRef.current?.focus();
+ if (current.name !== undefined) nameRef.current?.focus();
+ else if (current.prompt !== undefined) promptRef.current?.focus();
return;
}
const environment = environments.find((entry) => entry.environmentId === form.environmentId);
@@ -433,10 +440,10 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
const hasModelPicker = selection !== null && instanceEntries.length > 0;
const shownTraits =
traitsTarget !== null && shouldRenderTraitsControls(traitsTarget) ? traitsTarget : null;
- // The level the task saves, not the one its agent would run at today: a
- // task runs later, unattended, at whatever its agent offers then.
+ // As on the composer: the level the agent runs at, which can differ from
+ // the one picked when the agent doesn't offer it.
const accessControl: ComposerAccessControl = {
- value: form.runtimeMode,
+ value: access?.shown ?? form.runtimeMode,
options:
access?.options ??
RUNTIME_MODES.map((mode) => ({ mode, ...runtimeModeConfig[mode], disabled: false })),
@@ -494,7 +501,8 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
ref={promptRef}
className="field-sizing-content block max-h-[50vh] min-h-24 w-full resize-none bg-transparent px-4.5 py-1.5 text-[16px] leading-relaxed text-foreground outline-none placeholder:text-muted-foreground/60 sm:px-5 sm:text-[14px]"
value={form.prompt}
- placeholder="What should each run do? It starts with only these words, so say everything it needs."
+ placeholder="Review yesterday's commits on main and list anything risky."
+ aria-describedby="scheduled-form-prompt-hint"
aria-label="Instructions"
aria-invalid={shownProblems.prompt !== undefined ? true : undefined}
data-testid="scheduled-form-prompt"
@@ -597,6 +605,12 @@ export function ScheduledTaskForm({ editing }: { readonly editing: LocatedTask |
onCheckout={(checkout) => update({ checkout })}
onComputer={chooseEnvironment}
/>
+
+ Each run starts with only these words, so say everything it needs.
+
{form.target === "thread" ? (
Each run goes to that thread as a message, run with the agent and access above, never