Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions apps/server/src/guide/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
179 changes: 171 additions & 8 deletions apps/web/src/components/ChatView.event-tasks.browser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { type NormalizedWsRpcRequestBody } from "../../test/wsRpcHarness";
import {
PROJECT_ID,
THREAD_ID,
THREAD_TITLE,
NOW_ISO,
rpcHarness,
wsRequests,
Expand Down Expand Up @@ -185,6 +186,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<HTMLElement>('[aria-label^="Access level"]');
expect(element).not.toBeNull();
return element!;
});
trigger.click();
const option = await vi.waitFor(() => {
const element = document.querySelector<HTMLElement>(`[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", () => {
Expand Down Expand Up @@ -225,14 +242,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");
Expand All @@ -253,15 +270,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));
Expand Down Expand Up @@ -300,7 +315,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),
);
Expand All @@ -314,6 +332,151 @@ 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<void>((resolve) => {
releaseCreate = resolve;
});
const mounted = await mountChatView({
viewport: WIDE_FOOTER_VIEWPORT,
snapshot: snapshot(),
initialPath: "/scheduled?view=new",
configureFixture: (nextFixture) => {
withScheduledCapabilities(true)(nextFixture);
withCodexModels(nextFixture);
},
// The create is held open until the test lets it finish.
resolveRpc: (body) =>
body._tag === WS_METHODS.scheduledTasksCreate
? Effect.promise(async () => {
await createHeld;
return { ...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 /,
),
);

// 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")!;
const pressSave = () =>
prompt.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Enter",
metaKey: true,
bubbles: true,
cancelable: true,
}),
);
pressSave();
await vi.waitFor(() => expect(requestsOf(WS_METHODS.scheduledTasksCreate)).toHaveLength(1));
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.",
checkout: "worktree",
cadence: { kind: "custom", cron: "0 9 * * 5" },
target: { kind: "new_thread" },
});
} finally {
await mounted.cleanup();
}
});

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,
Expand Down
45 changes: 9 additions & 36 deletions apps/web/src/components/chat/ChatComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down
36 changes: 12 additions & 24 deletions apps/web/src/components/chat/DraftEmptyState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -227,30 +227,18 @@ export function DraftEmptyState({
>
What's next in{" "}
<Menu>
<MenuTrigger
render={
<button
className="group inline-flex max-w-full min-w-0 cursor-pointer font-medium text-foreground"
type="button"
<InlinePickerTrigger>
{isGeneralChat ? (
<MessagesSquareIcon className="size-3.5 shrink-0 text-muted-foreground/70" />
) : currentProject ? (
<ProjectFavicon
cwd={currentProject.cwd}
environmentId={currentProject.environmentId}
name={currentProjectName ?? currentProject.name}
/>
}
>
{/* 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. */}
<span className="inline-flex max-w-full min-w-0 items-center gap-1 border-b border-dotted border-muted-foreground/50 pb-0.5 align-middle leading-none transition-colors group-hover:border-foreground group-data-popup-open:border-foreground">
{isGeneralChat ? (
<MessagesSquareIcon className="size-3.5 shrink-0 text-muted-foreground/70" />
) : currentProject ? (
<ProjectFavicon
cwd={currentProject.cwd}
environmentId={currentProject.environmentId}
name={currentProjectName ?? currentProject.name}
/>
) : null}
<span className="min-w-0 truncate">{targetName}</span>
</span>
</MenuTrigger>
) : null}
<span className="min-w-0 truncate">{targetName}</span>
</InlinePickerTrigger>
<MenuPopup align="center">
{generalChatsRef ? (
<>
Expand Down
Loading
Loading