# Routines

> Schedules and triggers that start an agent or an automation: one routine's detail, and recurring tasks written as plain sentences with their last and next run.

Page: https://uicontext.com/docs/components/routines

Group: Agents.

## When to use

Schedules and triggers that start an agent or an automation: one routine's detail, and recurring tasks written as plain sentences with their last and next run. Use [Flow Diagram](https://uicontext.com/docs/components/flow-diagram.md) instead when you edit what the automation does, not when it runs.

## Usage

```ts
import { RoutineCard } from "./ui/uicontext/components/Routine.ts"

const Message = UiSchema.TaggedEnum({
	PausedRoutine: { id: Schema.String },
	ResumedRoutine: { id: Schema.String },
	RescheduledRoutine: { id: Schema.String, text: Schema.String, timeZone: Schema.String },
})

export const DigestRoutine = (h: Html.H<typeof Message.Type>, state: "active" | "paused", nextRun: string | null) =>
	RoutineCard(h, {
		props: {
			id: "digest",
			title: "Post the pipeline digest",
			trigger: { kind: "schedule", text: "Every weekday at 9", parsed: "Mon–Fri 09:00" },
			state,
			nextRun,
			timeZone: "Europe/London",
			can: ["pause", "resume", "reschedule"],
		},
		onEmit: {
			RequestedPause: ({ id }) => Message.PausedRoutine({ id }),
			RequestedResume: ({ id }) => Message.ResumedRoutine({ id }),
			RequestedReschedule: ({ id, text, timeZone }) => Message.RescheduledRoutine({ id, text, timeZone }),
			RequestedTest: () => undefined,
			RequestedApprove: () => undefined,
			RequestedDecline: () => undefined,
			RequestedPreview: () => undefined,
			RequestedDelete: () => undefined,
		},
	})
```

## Examples

Each example is a complete file. Its imports point where the CLI installs the source.

### Schedules

Pause, resume, or edit a schedule in plain words: the app reads it back with the next runs before Save turns on.

```ts title="src/demo.ts" source="www/src/examples/routines/demo.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { RoutineCard, RoutineList, RoutineState } from "./ui/uicontext/components/Routine.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { previewOf } from "./schedule.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" } })

const Message = UiSchema.TaggedEnum({
	Paused: { id: Schema.String },
	Resumed: { id: Schema.String },
	Previewed: { id: Schema.String, text: Schema.String, timeZone: Schema.String, request: Schema.String },
	Rescheduled: { id: Schema.String, text: Schema.String, timeZone: Schema.String },
	Deleted: { id: Schema.String },
})

const Routine = Schema.Struct({ id: Schema.String, title: Schema.String, state: RoutineState, text: Schema.String, timeZone: Schema.String })
const zones = ["Europe/London", "America/New_York", "Asia/Tokyo"]

export const TeamRoutines = Html.component({
	name: "TeamRoutines",
	model: Schema.Struct({
		routines: Schema.Array(Routine),
		preview: Schema.NullOr(Schema.Struct({ id: Schema.String, text: Schema.String, timeZone: Schema.String, request: Schema.String })),
	}),
	message: Message,
}).make({
	init: () => ({
		routines: [
			{ id: "digest", title: "Post the pipeline digest", state: "active", text: "Every weekday at 9", timeZone: "Europe/London" },
			{ id: "sync", title: "Sync the sales sheet", state: "paused", text: "Every 2 hours", timeZone: "America/New_York" },
		],
		preview: null,
	}),
	update: {
		Paused: ($, { id }) => $.evolve({ routines: (rs) => rs.map((r) => (r.id === id ? { ...r, state: "paused" as const } : r)) }),
		Resumed: ($, { id }) => $.evolve({ routines: (rs) => rs.map((r) => (r.id === id ? { ...r, state: "active" as const } : r)) }),
		Previewed: ($, preview) => $.evolve({ preview }),
		Rescheduled: ($, { id, text, timeZone }) => $.evolve({ routines: (rs) => rs.map((r) => (r.id === id ? { ...r, text, timeZone } : r)), preview: null }),
		Deleted: ($, { id }) => $.evolve({ routines: (rs) => rs.filter((r) => r.id !== id) }),
	},
	view: (h, model) =>
		h.div.attrs(sx(styles.frame)).children(
			RoutineList(h, {
				status: "ready",
				empty: { title: "No routines yet", hint: "Schedule a workflow to run on its own." },
				children: model.routines.map((r) => {
					const parsed = previewOf(r.text, r.timeZone)
					const pending = model.preview?.id === r.id ? model.preview : null
					return RoutineCard(h, {
						key: r.id,
						props: {
							id: r.id,
							agentId: `routine-demo-${r.id}`,
							title: r.title,
							trigger: { kind: "schedule", text: r.text, ...(parsed.parsed === undefined ? {} : { parsed: parsed.parsed }) },
							state: r.state,
							...(r.state === "paused" ? { pausedReason: "Paused after 3 failures in a row." } : {}),
							nextRun: r.state === "active" ? (parsed.nextRuns[0] ?? null) : null,
							timeZone: r.timeZone,
							timeZones: zones,
							lastResults: r.id === "digest"
								? [
									{ id: "d3", at: "2026-11-30T09:00:00Z", status: "succeeded" },
									{ id: "d2", at: "2026-11-27T09:00:00Z", status: "failed", reason: "The chat account’s sign-in expired" },
									{ id: "d1", at: "2026-11-26T09:00:00Z", status: "succeeded" },
								]
								: [],
							can: ["pause", "resume", "test", "reschedule", "delete"],
							requirePreview: true,
							...(pending === null ? {} : { preview: { ...previewOf(pending.text, pending.timeZone), request: pending.request } }),
						},
						onEmit: {
							RequestedPause: ({ id }) => Message.Paused({ id }),
							RequestedResume: ({ id }) => Message.Resumed({ id }),
							RequestedTest: () => undefined,
							RequestedApprove: () => undefined,
							RequestedDecline: () => undefined,
							RequestedPreview: ({ id, text, timeZone, request }) => (request === undefined ? undefined : Message.Previewed({ id, text, timeZone, request })),
							RequestedReschedule: ({ id, text, timeZone }) => Message.Rescheduled({ id, text, timeZone }),
							RequestedDelete: ({ id }) => Message.Deleted({ id }),
						},
					})
				}),
			}),
		),
})
```

### Proposed by an agent

An agent suggests a routine; it does nothing until a person approves it.

```ts title="src/proposed.ts" source="www/src/examples/routines/proposed.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { RoutineCard, RoutineState } from "./ui/uicontext/components/Routine.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const styles = stylex.create({ frame: { inlineSize: "min(100%, 36rem)" } })

const Message = UiSchema.TaggedEnum({ Approved: {}, Declined: {} })

export const ProposedRoutine = Html.component({
	name: "ProposedRoutine",
	model: RoutineState,
	message: Message,
}).make({
	init: () => "proposed" as const,
	update: { Approved: () => "active" as const, Declined: () => "ended" as const },
	view: (h, state) =>
		h.div.attrs(sx(styles.frame)).children(
			RoutineCard(h, {
				props: {
					id: "triage",
					agentId: "routine-proposed",
					title: "Triage new support tickets",
					trigger: { kind: "event", text: "When a ticket arrives in the Support inbox" },
					state,
					...(state === "proposed" ? {} : { stateLabel: state === "active" ? "On" : "Declined" }),
					nextRun: null,
					timeZone: "Europe/London",
					can: state === "proposed" ? ["approve", "decline"] : [],
				},
				onEmit: {
					RequestedApprove: () => Message.Approved(),
					RequestedDecline: () => Message.Declined(),
					RequestedPause: () => undefined,
					RequestedResume: () => undefined,
					RequestedTest: () => undefined,
					RequestedPreview: () => undefined,
					RequestedReschedule: () => undefined,
					RequestedDelete: () => undefined,
				},
			}),
		),
})
```

### Routine detail

Turn it on or off, edit what it does and when, then Save or press ⌘S. A schedule without a time is refused with the reason. Test run adds to the history.

```ts title="src/editor.ts" source="www/src/examples/routines/editor.ts"
import { Command, UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Effect, Schema } from "effect"
import { accepted, Outcome, pending, refused } from "./ui/uicontext/components/domain/Outcome.ts"
import { RoutineResult } from "./ui/uicontext/components/Routine.ts"
import { RoutineEditor } from "./ui/uicontext/components/RoutineEditor.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"

const Draft = Schema.Struct({ name: Schema.String, instruction: Schema.String, schedules: Schema.Array(Schema.String) })

const Message = UiSchema.TaggedEnum({
	RequestedSave: { draft: Draft },
	RequestedActive: { active: Schema.Boolean },
	RequestedTestRun: {},
	RequestedDelete: {},
	CompletedSave: { draft: Draft },
	CompletedTestRun: { at: Schema.String },
})

// Stand in for the server: it saves after a moment, and a test run takes a little longer.
const Save = Command.make("SaveSampleRoutine", { args: { draft: Draft } }, ({ draft }) =>
	Effect.sleep("400 millis").pipe(Effect.as(Message.CompletedSave({ draft }))))
const TestRun = Command.make("TestSampleRoutine", {}, () =>
	Effect.sleep("900 millis").pipe(Effect.andThen(Effect.sync(() => Message.CompletedTestRun({ at: new Date().toISOString() })))))

const styles = stylex.create({ panel: { width: "min(100%, 22rem)" } })

const hasTime = (schedule: string) => /\d/u.test(schedule)

export const DailyBriefing = Html.component({
	name: "DailyBriefing",
	model: Schema.Struct({ routine: Draft, active: Schema.Boolean, runs: Schema.Array(RoutineResult), outcome: Schema.NullOr(Outcome), now: Schema.String }),
	message: Message,
}).make({
	init: () => ({
		routine: { name: "Morning briefing", instruction: "Check every agent's status, my calendar and my inbox. Send me five lines: what changed, what needs me today, and anything at risk.", schedules: ["Every day at 8:00 AM"] },
		active: true,
		runs: [{ id: "r1", at: "2026-11-30T13:00:00.000Z", status: "succeeded" }, { id: "r0", at: "2026-11-29T13:00:00.000Z", status: "succeeded" }],
		outcome: null,
		now: "2026-11-30T15:00:00.000Z",
	}),
	update: {
		RequestedSave: ($, { draft }) => {
			const bad = draft.schedules.find((s) => !hasTime(s))
			return bad !== undefined
				? $.evolve({ outcome: refused("save", `“${bad}” needs a time, like “Every weekday at 9:00 AM”.`) })
				: $.evolve({ outcome: pending("save") }).run(Save.make({ draft }))
		},
		CompletedSave: ($, { draft }) => $.evolve({ routine: draft, outcome: accepted("save") }),
		RequestedActive: ($, { active }) => $.evolve({ active }),
		RequestedTestRun: ($) => $.evolve({ outcome: pending("test") }).run(TestRun.make({})),
		CompletedTestRun: ($, { at }) => $.evolve({ outcome: accepted("test"), now: at, runs: (runs) => [{ id: `r${runs.length}`, at, status: "succeeded" }, ...runs] }),
		RequestedDelete: ($) => $.model,
	},
	view: (h, model) => h.div.attrs(sx(styles.panel)).children(RoutineEditor(h, {
		props: {
			id: "briefing", ...model.routine, active: model.active, runs: model.runs, now: model.now, timeZone: "America/New_York", locale: "en-US",
			can: ["edit", "toggle", "test"], outcome: model.outcome, agentId: "routine-editor-demo",
		},
		onEmit: {
			RequestedSave: ({ name, instruction, schedules }) => Message.RequestedSave({ draft: { name, instruction, schedules } }),
			RequestedActive: ({ active }) => Message.RequestedActive({ active }),
			RequestedTestRun: () => Message.RequestedTestRun(),
			RequestedDelete: () => Message.RequestedDelete(),
		},
	})),
})
```

### Scheduled tasks

What each does and when, in plain words, with when it last ran and runs next. Pause one with its switch, or delete it.

```ts title="src/scheduled-tasks.ts" source="www/src/examples/routines/scheduled-tasks.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { ScheduledTask, ScheduledTaskCard } from "./ui/uicontext/components/ScheduledTasks.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { space } from "./ui/uicontext/components/tokens.stylex.ts"

const now = "2026-12-03T15:10:00.000Z"

const tasks: ReadonlyArray<ScheduledTask> = [
	{ id: "triage", title: "Morning inbox triage", instruction: "Every weekday morning, read new mail and DMs, answer what's simple, and list what needs me.",
		schedule: { repeat: "weekdays", time: "07:30" }, paused: false, lastRun: "2026-12-03T14:34:00.000Z" },
	{ id: "pipeline", title: "Weekly pipeline review", instruction: "Every Monday, refresh the pipeline sheet, say what moved and why, and flag deals at risk.",
		schedule: { repeat: "weekly", time: "08:00", day: 1 }, paused: false, lastRun: "2026-11-30T13:00:00.000Z" },
	{ id: "prices", title: "Vendor price watch", instruction: "Every Friday, check our main vendors' pricing pages and tell me if anything changed.",
		schedule: { repeat: "weekly", time: "16:00", day: 5 }, paused: true },
]

const Message = UiSchema.TaggedEnum({ ToggledPause: { id: Schema.String, paused: Schema.Boolean }, ClickedDelete: { id: Schema.String } })

const styles = stylex.create({ list: { display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(min(100%, 20rem), 1fr))", gap: space.lg, width: "100%", margin: 0, padding: 0, listStyle: "none" } })

export const Scheduled = Html.component({
	name: "ScheduledTasksExample",
	model: Schema.Struct({ tasks: Schema.Array(ScheduledTask) }),
	message: Message,
}).make({
	init: () => ({ tasks }),
	update: {
		ToggledPause: ($, { id, paused }) => $.evolve({ tasks: (all) => all.map((t) => (t.id === id ? { ...t, paused } : t)) }),
		ClickedDelete: ($, { id }) => $.evolve({ tasks: (all) => all.filter((t) => t.id !== id) }),
	},
	view: (h, model) => h.ul.attrs({ "aria-label": "Scheduled tasks", ...sx(styles.list) }).children(model.tasks.map((task) => h.li.key(task.id).children(ScheduledTaskCard(h, {
		task, now, timeZone: "America/New_York", locale: "en-US",
		onPause: (paused) => Message.ToggledPause({ id: task.id, paused }),
		onDelete: Message.ClickedDelete({ id: task.id }),
	})))),
})
```

### Make a scheduled task

Name it, say what to do, pick how often. The schedule reads back as a sentence while you choose; empty fields say what they need on Schedule.

```ts title="src/scheduled-task-form.ts" source="www/src/examples/routines/scheduled-task-form.ts"
import { UiSchema } from "effect/ui"
import { Html } from "effect/ui/html"
import * as stylex from "@stylexjs/stylex"
import { Schema } from "effect"
import { ScheduleDraft, ScheduleForm, scheduleSentence } from "./ui/uicontext/components/ScheduledTasks.ts"
import { sx } from "./ui/uicontext/components/Sx.ts"
import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"

const Message = UiSchema.TaggedEnum({ Submitted: { draft: ScheduleDraft }, Cancelled: {} })

const styles = stylex.create({
	frame: { width: "min(100%, 30rem)" },
	done: { margin: 0, color: color.muted, fontSize: font.sm },
})

export const NewSchedule = Html.component({
	name: "ScheduleFormExample",
	model: Schema.Struct({ saved: Schema.NullOr(Schema.String), round: Schema.Number }),
	message: Message,
}).make({
	init: () => ({ saved: null, round: 0 }),
	update: {
		Submitted: ($, { draft }) => $.evolve({ saved: `Scheduled “${draft.title}”: ${scheduleSentence(draft.schedule)}.`, round: (n) => n + 1 }),
		Cancelled: ($) => $.evolve({ saved: null, round: (n) => n + 1 }),
	},
	view: (h, model) => h.div.attrs(sx(styles.frame)).children(
		ScheduleForm(h, {
			key: `form-${model.round}`,
			props: { initial: { title: "Weekly pipeline review" }, timeZone: "America/New_York", today: "2026-12-03" },
			onEmit: { RequestedSubmit: ({ draft }) => Message.Submitted({ draft }), RequestedCancel: () => Message.Cancelled() },
		}),
		model.saved !== null && h.p.attrs({ role: "status", ...sx(styles.done) }).children(model.saved),
	),
})
```

### Sample data

The examples above import these files.

```ts title="src/schedule.ts" source="www/src/examples/routines/schedule.ts"
import type { SchedulePreview } from "./ui/uicontext/components/Routine.ts"

// Stands in for the app's schedule parser: "every N hours" and "every day at H". A real app asks
// its server, which knows the time zone rules and the plan's limits.
const hourly = /every (\d+) hours?/iu
const daily = /every (?:day|weekday) at (\d{1,2})/iu
const start = Date.parse("2026-12-01T00:00:00Z")

export const previewOf = (text: string, timeZone: string): SchedulePreview => {
	const h = hourly.exec(text)
	if (h !== null) {
		const n = Number(h[1])
		if (n < 1) return { text, nextRuns: [], error: "Routines can run at most every hour." }
		return { text, parsed: `every ${n} h`, nextRuns: [1, 2, 3].map((i) => new Date(start + i * n * 3_600_000).toISOString()) }
	}
	const d = daily.exec(text)
	if (d !== null) {
		return {
			text,
			parsed: `${/weekday/iu.test(text) ? "Mon–Fri" : "daily"} ${d[1]!.padStart(2, "0")}:00 (${timeZone})`,
			nextRuns: [0, 1, 2].map((i) => new Date(start + (i * 24 + Number(d[1])) * 3_600_000).toISOString()),
		}
	}
	if (/minute/iu.test(text)) return { text, nextRuns: [], error: "Routines can run at most every hour." }
	return { text, nextRuns: [], error: "Try “every 2 hours” or “every weekday at 9”." }
}
```

## API reference

### RoutineCard (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | The routine's id, sent back with every request |
| `title` (required) | `string` | What the routine does: "Summarize new support tickets" |
| `trigger` (required) | `RoutineTrigger` | What starts it: a schedule, an event or a webhook |
| `state` (required) | `RoutineState` | Whether it's active, paused, proposed or ended |
| `stateLabel` | `string` | The product's word for the state: "On", "Turned off" |
| `pausedReason` | `string` | Why it's paused: "Paused after 3 failures in a row" |
| `nextRun` | `string \| null` | ISO 8601, or null when nothing is scheduled |
| `timeZone` (required) | `string` | The person's time zone (IANA), for every time shown |
| `locale` | `string` | The locale dates are formatted in; the browser's by default |
| `showYear` | `boolean` | Include the year in next-run, schedule preview, and history timestamps. |
| `timeZones` | `string[]` | The time zones the editor offers; defaults to every zone the runtime knows |
| `lastResults` | `RoutineResult[]` | The most recent runs, newest first, shown as a row of results |
| `webhook` | `{ url, secret }` | A webhook trigger's address and key, shown once |
| `can` (required) | `RoutineAction[]` | What this person may do here; anything absent is hidden |
| `labels` | `{ test, delete }` | Labels the product uses: { test: "Run now", delete: "End routine" } |
| `readOnly` | `string` | Why this person can't change it: "Only the owner changes this routine" |
| `outcome` | `Outcome \| null` | The app's answer to the last request; its request is the action ("pause", "reschedule") |
| `preview` | `SchedulePreview` | The app's reading of the schedule being typed: its next runs, or why it can't be saved |
| `requirePreview` | `boolean` | Require a successful preview tied to the current request before Save. |
| `agentId` | `string` | This card's id for agents; defaults to routine:\<id> |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedPause` | `{ id: string }` | Stop the routine from starting until it's resumed |
| `RequestedResume` | `{ id: string }` | Start the paused routine again |
| `RequestedTest` | `{ id: string }` | Run the routine once now |
| `RequestedApprove` | `{ id: string }` | Turn on a routine an agent proposed |
| `RequestedDecline` | `{ id: string }` | Turn down a routine an agent proposed |
| `RequestedPreview` | `{ id: string; text: string; timeZone: string; request?: string }` | The person is typing a schedule: answer with `preview` |
| `RequestedReschedule` | `{ id: string; text: string; timeZone: string }` | Save the schedule the person typed, in the time zone they chose |
| `RequestedDelete` | `{ id: string }` | End the routine for good, after the person confirmed |

**Agent actions**

| Action | Description |
| --- | --- |
| `ClickedPause` | Pause the routine |
| `ClickedResume` | Resume the paused routine |
| `ClickedTest` | Run the routine once now, as a test |
| `ClickedApprove` | Approve the routine an agent proposed |
| `ClickedDecline` | Decline the routine an agent proposed |
| `ClickedEditSchedule` | Open the schedule editor |
| `UpdatedSchedule` | Type the schedule in plain words, as a person would: 'every weekday at 9am' |
| `ChoseTimeZone` | Choose the schedule's IANA time zone |
| `SubmittedSchedule` | Save the schedule being edited |
| `ClickedDelete` | Ask to delete the routine (opens the confirmation) |
| `ConfirmedDelete` (asks first) | Delete the routine. Name it as your target. |

### RoutineList (view function)

**Options**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `status` (required) | `"loading" \| "ready"` | — | `loading` shows a placeholder while the routines load |
| `label` | `string` | `Routines` | What the list is of, for screen readers; `Routines` by default |
| `empty` (required) | `{ readonly title: string; readonly hint?: string }` | — | "No routines yet", "Ask the agent to do something on a schedule" |
| `children` (required) | `View.Children` | — | The routine cards |

### RoutineEditor (component)

**Props**

| Name | Type | Description |
| --- | --- | --- |
| `id` (required) | `string` | — |
| `name` (required) | `string` | — |
| `instruction` (required) | `string` | What the agent does when it runs, in its own words |
| `schedules` (required) | `string[]` | When it runs, each in plain words: "Every day at 8:00 AM", "Weekdays at 6:00 PM" |
| `active` (required) | `boolean` | — |
| `runs` (required) | `RoutineResult[]` | Its runs, newest first |
| `now` (required) | `string` | The clock its runs are read in |
| `timeZone` (required) | `string` | — |
| `locale` | `string` | — |
| `can` (required) | `("edit" \| "toggle" \| "test" \| "delete")[]` | What this person may do; anything absent is hidden |
| `outcome` | `Outcome \| null` | The app's answer to the last request: "save", "active", "test" or "delete" |
| `agentId` | `string` | — |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedSave` | `{ id: string; name: string; instruction: string; schedules: string[] }` | — |
| `RequestedActive` | `{ id: string; active: boolean }` | — |
| `RequestedTestRun` | `{ id: string }` | — |
| `RequestedDelete` | `{ id: string }` | — |

**Agent actions**

| Action | Description |
| --- | --- |
| `RequestedChange` (asks first) | Change the routine's name, instruction or schedules (plain words, such as 'Every weekday at 9:00 AM') and save |
| `ToggledActive` (asks first) | Turn the routine on or off |
| `ClickedTestRun` | Run the routine once now |

### ScheduleForm (component)

**Props**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `initial` | `{ title, instruction, schedule }` | — | What the form starts with: a task's title and instruction when it's made recurring. Read once, as it mounts. |
| `submitLabel` | `string` | `"Schedule"` | The submit button's text; "Schedule" by default |
| `saving` | `boolean` | — | The app is saving it: the form waits |
| `error` | `string \| null` | — | Why the last save failed, from the app |
| `timeZone` | `string` | — | The reader's time zone, said under the time |
| `today` | `string` | — | "YYYY-MM-DD": today, the default for Once |

**Events**

| Event | Payload | Description |
| --- | --- | --- |
| `RequestedSubmit` | `{ draft: ScheduleDraft }` | — |
| `RequestedCancel` | `{}` | — |

### ScheduledTaskCard (view function)

**Options**

| Name | Type | Description |
| --- | --- | --- |
| `task` (required) | `ScheduledTask` | — |
| `now` (required) | `string` | ISO 8601: the app's clock, for "Ran 36m ago" and the next run |
| `timeZone` | `string` | — |
| `locale` | `string` | — |
| `onPause` (required) | `(paused: boolean) => Message` | The switch: true asks to pause it |
| `onRunNow` | `Message` | — |
| `onDelete` | `Message` | — |
| `running` | `boolean` | A Run now is on its way |
| `style` | `Style` | — |

## Keyboard and accessibility

- Each routine is a labelled card; its schedule, time zone and next run are a description list, and every time is a `<time>`.
- Editing a schedule is a form: the app's reading of it and its next runs are announced as you type.
- Deleting asks first, and agents must name the routine they end.

## Installation

```sh
pnpm dlx shadcn@latest add checkfu/uicontext/routines
```

With npm: `npx shadcn@latest add checkfu/uicontext/routines`. With yarn: `yarn dlx shadcn@latest add checkfu/uicontext/routines`. With bun: `bunx --bun shadcn@latest add checkfu/uicontext/routines`.

It writes these files:

- `src/ui/uicontext/components/Button.ts`
- `src/ui/uicontext/components/Callout.ts`
- `src/ui/uicontext/components/Dialog.ts`
- `src/ui/uicontext/components/FormControls.ts`
- `src/ui/uicontext/components/Glyph.ts`
- `src/ui/uicontext/components/IconStroke.ts`
- `src/ui/uicontext/components/InlineNotice.ts`
- `src/ui/uicontext/components/RequestNonce.ts`
- `src/ui/uicontext/components/Routine.ts`
- `src/ui/uicontext/components/RoutineEditor.ts`
- `src/ui/uicontext/components/ScheduledTasks.ts`
- `src/ui/uicontext/components/ShowText.ts`
- `src/ui/uicontext/components/Skeleton.ts`
- `src/ui/uicontext/components/States.ts`
- `src/ui/uicontext/components/StatusBadge.ts`
- `src/ui/uicontext/components/Switch.ts`
- `src/ui/uicontext/components/Sx.ts`
- `src/ui/uicontext/components/agent/Agent.ts`
- `src/ui/uicontext/components/button.stylex.ts`
- `src/ui/uicontext/components/domain/Format.ts`
- `src/ui/uicontext/components/domain/Glyph.ts`
- `src/ui/uicontext/components/domain/Outcome.ts`
- `src/ui/uicontext/components/domain/Run.ts`
- `src/ui/uicontext/components/domain/Time.ts`
- `src/ui/uicontext/components/safeArea.stylex.ts`
- `src/ui/uicontext/components/tokens.stylex.ts`
- `src/ui/uicontext/components/touch.stylex.ts`
- `src/ui/uicontext/components/variants.ts`

And installs the npm packages `@stylexjs/stylex`, `effect`.

## Source

- [src/Routine.ts](https://github.com/checkfu/uicontext/blob/main/src/Routine.ts)
- [src/RoutineEditor.ts](https://github.com/checkfu/uicontext/blob/main/src/RoutineEditor.ts)
- [src/ScheduledTasks.ts](https://github.com/checkfu/uicontext/blob/main/src/ScheduledTasks.ts)

## Used in

- [Work](https://uicontext.com/blocks/work.md)
- [Bots](https://uicontext.com/blocks/bot-console.md)

## Related

- [Agent Tools](https://uicontext.com/docs/components/agent-tools.md) (`agent-tools`): Lets agents in the browser read the page and act through the same controls people use.
- [Tool Confirmation](https://uicontext.com/docs/components/tool-confirmation.md) (`tool-confirmation`): Asks a person to confirm before an agent's action changes anything.
- [Prompt Template](https://uicontext.com/docs/components/prompt-template.md) (`prompt-template`): Write a prompt with {{variables}} the app fills in: they stand out, unknown ones are flagged, and a preview shows it with samples.
- [Agent Settings](https://uicontext.com/docs/components/agent-settings.md) (`agent-settings`): Edit an agent's name, instructions, tools and model.
- [Computer](https://uicontext.com/docs/components/computer.md) (`computer`): The machine an agent works on: a live view of its screen, full size or as a thumbnail with Take over, and its browser with tabs and an address bar.
- [Persona Avatar](https://uicontext.com/docs/components/persona-avatar.md) (`persona-avatar`): An agent's face: a shape and a color with eyes that move with what it's doing.
