An open-source, faster Devin alternative
TypeScript
schedules: promote to its own AgentDetail tab (design 015)
Igor Zalutski5efaa8e53c60
diff --git a/web/src/components/agent-schedules.tsx b/web/src/components/agent-schedules.tsxindex 9f23bcc0..73779e00 100644--- a/web/src/components/agent-schedules.tsx+++ b/web/src/components/agent-schedules.tsx@@ -1,6 +1,18 @@import { useState } from 'react'import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'-import { Pause, Play, PlayCircle, Plus, Trash2 } from 'lucide-react'+import {+ AlertTriangle,+ CalendarClock,+ ChevronDown,+ ChevronRight,+ GitBranch,+ Pause,+ Pencil,+ Play,+ PlayCircle,+ Plus,+ Trash2,+} from 'lucide-react'import { notifyError, notifySuccess } from '@/lib/errors'import {ApiError,@@ -8,15 +20,19 @@ import {deleteSchedule,fireSchedule,getDeploymentSource,+ getScheduleRuns,getSchedules,updateSchedule,type Schedule,+ type ScheduleOverlap,} from '@/api/client'import { Panel, PanelContent } from '@/components/panel'import { Button } from '@/components/ui/button'-import { Input } from '@/components/form'+import { Field, Input, Select, Textarea } from '@/components/form'++// ── helpers ────────────────────────────────────────────────────────────────────-// Relative time ("in 3h" / "5m ago") — no dependency; schedules are minute-resolution.+// Relative time ("in 3h" / "5m ago") — schedules are minute-resolution, so no dependency needed.function rel(iso: string | null): string {if (!iso) return '—'const delta = new Date(iso).getTime() - Date.now()@@ -25,39 +41,82 @@ function rel(iso: string | null): string {return delta >= 0 ? `in ${unit}` : `${unit} ago`}-function StatePill({ s }: { s: Schedule }) {+// A friendly gloss for the common crons; unknown expressions just show the raw fields.+const CRON_HINTS: Record<string, string> = {+ '0 9 * * 1-5': 'weekdays at 09:00',+ '0 9 * * *': 'every day at 09:00',+ '0 * * * *': 'every hour',+ '*/15 * * * *': 'every 15 minutes',+ '*/30 * * * *': 'every 30 minutes',+ '0 0 * * 0': 'Sundays at midnight',+ '0 0 1 * *': 'first of the month',+ '0 0 * * *': 'every day at midnight',+}+const CRON_PRESETS: { label: string; cron: string }[] = [+ { label: 'Weekdays 9am', cron: '0 9 * * 1-5' },+ { label: 'Daily 9am', cron: '0 9 * * *' },+ { label: 'Hourly', cron: '0 * * * *' },+ { label: 'Every 15m', cron: '*/15 * * * *' },+]++function StateBadge({ s }: { s: Schedule }) {const cls =s.state === 'active'? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400': s.state === 'auto_paused'? 'bg-red-100 text-red-700 dark:bg-red-900/30 dark:text-red-400': 'bg-muted text-muted-foreground'+ return <span className={`rounded px-1.5 py-0.5 text-[10px] font-medium ${cls}`}>{s.state.replace('_', ' ')}</span>+}++function OutcomeBadge({ outcome }: { outcome: string }) {+ const cls =+ outcome === 'enacted'+ ? 'text-green-700 dark:text-green-400'+ : outcome === 'failed'+ ? 'text-red-600 dark:text-red-500'+ : 'text-muted-foreground'+ return <span className={`font-medium ${cls}`}>{outcome}</span>+}++// Recent runs for a schedule — lazily fetched when a row is expanded.+function ScheduleRuns({ agentId, scheduleId }: { agentId: string; scheduleId: string }) {+ const { data: runs, isLoading } = useQuery({+ queryKey: ['schedule-runs', agentId, scheduleId],+ queryFn: () => getScheduleRuns(agentId, scheduleId, 5),+ })+ if (isLoading) return <p className="text-muted-foreground px-3 py-2 text-xs">Loading runs…</p>+ if (!runs || runs.length === 0) return <p className="text-muted-foreground px-3 py-2 text-xs">No runs yet.</p>return (- <span- className={`rounded px-1.5 py-0.5 text-[10px] font-medium ${cls}`}- title={s.state === 'auto_paused' && s.last_error ? s.last_error : undefined}- >- {s.state.replace('_', ' ')}- </span>+ <ul className="divide-border/60 divide-y text-xs">+ {runs.map((r) => (+ <li key={r.id} className="flex items-center gap-2 px-3 py-1.5">+ <OutcomeBadge outcome={r.outcome} />+ <span className="text-muted-foreground">{rel(r.fired_at)}</span>+ {r.session_id ? (+ <code className="text-muted-foreground ml-auto font-mono text-[11px]" title={r.session_id}>+ {r.session_id.slice(0, 12)}…+ </code>+ ) : r.error ? (+ <span className="ml-auto max-w-[16rem] truncate text-red-600 dark:text-red-500" title={r.error}>+ {r.error}+ </span>+ ) : null}+ </li>+ ))}+ </ul>)}-/**- * Schedules card (Overview right rail) — cron for agents (design 015). Lists the agent's schedules- * with their next fire + state, a pause/resume toggle, a test-fire, and delete; a compact create- * form for name/cron/tz/input. Read-only (except pause/resume) when the agent is repo-driven — the- * agent.toml owns the schedules then, matching the deploy-source convention.- */-export function AgentSchedules({ agentId }: { agentId: string }) {+type FormState = { id?: string; name: string; cron: string; tz: string; input: string; overlap: ScheduleOverlap }++// ── the tab ─────────────────────────────────────────────────────────────────────++export function AgentSchedulesTab({ agentId }: { agentId: string }) {const queryClient = useQueryClient()- const [showForm, setShowForm] = useState(false)- const [name, setName] = useState('')- const [cron, setCron] = useState('0 9 * * 1-5')- const [tz, setTz] = useState('')- const [input, setInput] = useState('')+ const [form, setForm] = useState<FormState | null>(null)+ const [expanded, setExpanded] = useState<string | null>(null)- // Repo-driven agents manage schedules via agent.toml → the API rejects edits other than- // pause/resume (409). Share the deploy-source card's query cache so the two stay consistent.const { data: repoManaged } = useQuery({queryKey: ['agent-deploy-source', agentId],queryFn: async () => {@@ -83,22 +142,25 @@ export function AgentSchedules({ agentId }: { agentId: string }) {const invalidate = () => void queryClient.invalidateQueries({ queryKey: ['agent-schedules', agentId] })- const create = useMutation({- mutationFn: () =>- createSchedule(agentId, {- name: name.trim(),- cron: cron.trim(),- tz: tz.trim() || null,- input: input.trim(),- }),+ const openCreate = () => setForm({ name: '', cron: '0 9 * * 1-5', tz: '', input: '', overlap: 'skip' })+ const openEdit = (s: Schedule) =>+ setForm({ id: s.id, name: s.name, cron: s.cron, tz: s.tz ?? '', input: s.input, overlap: s.overlap })++ const save = useMutation({+ mutationFn: () => {+ const f = form!+ const patch = { cron: f.cron.trim(), tz: f.tz.trim() || null, input: f.input.trim(), overlap: f.overlap }+ return f.id+ ? updateSchedule(agentId, f.id, patch)+ : createSchedule(agentId, { name: f.name.trim(), ...patch })+ },onSuccess: () => {+ const editing = !!form?.idinvalidate()- setShowForm(false)- setName('')- setInput('')- notifySuccess('Schedule created.')+ setForm(null)+ notifySuccess(editing ? 'Schedule updated.' : 'Schedule created.')},- onError: (e) => notifyError("Couldn't create the schedule.", e),+ onError: (e) => notifyError("Couldn't save the schedule.", e),})const toggle = useMutation({@@ -106,20 +168,16 @@ export function AgentSchedules({ agentId }: { agentId: string }) {onSuccess: () => invalidate(),onError: (e) => notifyError("Couldn't update the schedule.", e),})-const fire = useMutation({mutationFn: (s: Schedule) => fireSchedule(agentId, s.id),- onSuccess: (run) => {+ onSuccess: (run, s) => {+ void queryClient.invalidateQueries({ queryKey: ['schedule-runs', agentId, s.id] })invalidate()- if (run.outcome === 'enacted' && run.session_id) {- notifySuccess(`Fired — session ${run.session_id}`)- } else {- notifyError(`Fire ${run.outcome}`, new Error(run.error ?? run.outcome))- }+ if (run.outcome === 'enacted' && run.session_id) notifySuccess(`Fired — session ${run.session_id}`)+ else notifyError(`Fire ${run.outcome}`, new Error(run.error ?? run.outcome))},onError: (e) => notifyError("Couldn't fire the schedule.", e),})-const remove = useMutation({mutationFn: (s: Schedule) => deleteSchedule(agentId, s.id),onSuccess: () => {@@ -129,139 +187,252 @@ export function AgentSchedules({ agentId }: { agentId: string }) {onError: (e) => notifyError("Couldn't delete the schedule.", e),})- const canCreate = name.trim() && cron.trim() && input.trim()+ const f = form+ const canSave = f && (f.id || f.name.trim()) && f.cron.trim() && f.input.trim()+ const cronGloss = f ? CRON_HINTS[f.cron.trim()] : undefinedreturn (- <Panel className="overflow-hidden">- <PanelContent className="space-y-3">+ <div className="max-w-3xl space-y-5">+ <div className="flex items-start justify-between gap-4"><div>- <h3 className="text-sm font-medium">Schedules</h3>- <p className="text-muted-foreground text-xs">Run this agent on a cron — each firing starts a session.</p>+ <h2 className="text-base font-medium">Schedules</h2>+ <p className="text-muted-foreground mt-0.5 text-sm">+ Run this agent on a cron — each firing starts a new session with a fixed message.+ </p></div>+ {!repoManaged && !form ? (+ <Button size="sm" onClick={openCreate}>+ <Plus className="size-4" />+ New schedule+ </Button>+ ) : null}+ </div>- {isLoading ? (- <p className="text-muted-foreground text-xs">Loading…</p>- ) : isError ? (- <div className="space-y-2">- <p className="text-xs text-red-600 dark:text-red-500">Couldn’t load schedules.</p>- <Button size="sm" variant="outline" onClick={() => void refetch()}>- Retry- </Button>- </div>- ) : (- <>- {repoManaged ? (- <p className="text-muted-foreground text-xs">- Managed by the linked repository — edit <code className="font-mono">agent.toml</code> to change. You can- still pause/resume here.+ {repoManaged ? (+ <div className="border-border bg-panel-2 flex items-start gap-2 rounded-md border px-3 py-2.5 text-xs">+ <GitBranch className="text-muted-foreground mt-0.5 size-3.5 shrink-0" />+ <p className="text-muted-foreground">+ Managed from the connected repo — edit the <span className="font-mono">[[schedules]]</span> table in{' '}+ <span className="font-mono">agent.toml</span> and push. You can still pause, resume, and test-fire here.+ </p>+ </div>+ ) : null}++ {/* Create / edit form */}+ {form ? (+ <Panel>+ <PanelContent className="space-y-4">+ <Field label="Name" htmlFor="sch-name">+ <Input+ id="sch-name"+ value={form.name}+ onChange={(e) => setForm({ ...form, name: e.target.value })}+ placeholder="Morning docs sweep"+ disabled={!!form.id}+ />+ {form.id ? <p className="text-muted-foreground mt-1 text-xs">Name can’t be changed after creation.</p> : null}+ </Field>++ <Field label="Schedule" htmlFor="sch-cron">+ <div className="flex gap-2">+ <Input+ id="sch-cron"+ value={form.cron}+ onChange={(e) => setForm({ ...form, cron: e.target.value })}+ placeholder="0 9 * * 1-5"+ className="font-mono"+ />+ <Input+ value={form.tz}+ onChange={(e) => setForm({ ...form, tz: e.target.value })}+ placeholder="UTC"+ className="max-w-40"+ aria-label="Time zone"+ />+ </div>+ <div className="mt-2 flex flex-wrap items-center gap-1.5">+ {CRON_PRESETS.map((p) => (+ <button+ key={p.cron}+ type="button"+ onClick={() => setForm({ ...form, cron: p.cron })}+ className={+ 'rounded-full border px-2 py-0.5 text-xs transition-colors ' ++ (form.cron.trim() === p.cron+ ? 'border-foreground text-foreground'+ : 'border-border text-muted-foreground hover:text-foreground')+ }+ >+ {p.label}+ </button>+ ))}+ <span className="text-muted-foreground ml-auto text-xs">+ {cronGloss ? cronGloss : '5-field cron · IANA time zone (UTC if blank)'}+ </span>+ </div>+ </Field>++ <Field label="Message" htmlFor="sch-input">+ <Textarea+ id="sch-input"+ value={form.input}+ onChange={(e) => setForm({ ...form, input: e.target.value })}+ placeholder="Reconcile docs/ against changes since the last run; open a draft PR if anything drifted."+ className="min-h-32"+ />+ <p className="text-muted-foreground mt-1 text-xs">+ Sent as the first message on every run. Write it as a complete instruction — no human is in the loop to+ clarify.</p>- ) : null}+ </Field>++ <Field label="If the previous run is still going" htmlFor="sch-overlap">+ <Select+ id="sch-overlap"+ value={form.overlap}+ onValueChange={(v) => setForm({ ...form, overlap: v as ScheduleOverlap })}+ className="max-w-xs"+ options={[+ { value: 'skip', label: 'Skip this firing (default)' },+ { value: 'allow', label: 'Run them concurrently' },+ ]}+ />+ </Field>++ <div className="flex items-center gap-2">+ <Button size="sm" variant="outline" disabled={save.isPending || !canSave} onClick={() => save.mutate()}>+ {save.isPending ? 'Saving…' : form.id ? 'Save changes' : 'Create schedule'}+ </Button>+ <Button size="sm" variant="ghost" onClick={() => setForm(null)}>+ Cancel+ </Button>+ </div>+ </PanelContent>+ </Panel>+ ) : null}- {schedules && schedules.length > 0 ? (- <ul className="space-y-2">- {schedules.map((s) => (- <li key={s.id} className="bg-muted/40 space-y-1 rounded-md p-2 text-xs">- <div className="flex items-center justify-between gap-2">+ {/* List */}+ {isLoading ? (+ <p className="text-muted-foreground text-sm">Loading…</p>+ ) : isError ? (+ <div className="space-y-2">+ <p className="text-sm text-red-600 dark:text-red-500">Couldn’t load schedules.</p>+ <Button size="sm" variant="outline" onClick={() => void refetch()}>+ Retry+ </Button>+ </div>+ ) : schedules && schedules.length > 0 ? (+ <ul className="space-y-3">+ {schedules.map((s) => {+ const gloss = CRON_HINTS[s.cron]+ const open = expanded === s.id+ return (+ <li key={s.id}>+ <Panel>+ <PanelContent className="space-y-2.5">+ <div className="flex items-center gap-2"><span className="truncate font-medium">{s.name}</span>- <StatePill s={s} />- </div>- <div className="text-muted-foreground flex flex-wrap items-center gap-x-2">- <code className="font-mono">{s.cron}</code>- {s.tz ? <span>{s.tz}</span> : null}- <span>· next {s.state === 'active' ? rel(s.next_fire_at) : '—'}</span>- {s.last_fired_at ? <span>· last {rel(s.last_fired_at)}</span> : null}- </div>- <div className="flex items-center gap-1 pt-0.5">- <Button- size="sm"- variant="ghost"- title={s.state === 'active' ? 'Pause' : 'Resume'}- disabled={toggle.isPending}- onClick={() => toggle.mutate(s)}- >- {s.state === 'active' ? <Pause className="size-3.5" /> : <PlayCircle className="size-3.5" />}- </Button>- <Button- size="sm"- variant="ghost"- title="Test-fire now"- disabled={fire.isPending}- onClick={() => fire.mutate(s)}- >- <Play className="size-3.5" />- </Button>- {!repoManaged ? (+ <StateBadge s={s} />+ <div className="ml-auto flex items-center gap-0.5"><Buttonsize="sm"variant="ghost"- className="text-muted-foreground hover:text-red-600"- title="Delete"- disabled={remove.isPending}- onClick={() => remove.mutate(s)}+ title={s.state === 'active' ? 'Pause' : 'Resume'}+ disabled={toggle.isPending}+ onClick={() => toggle.mutate(s)}>- <Trash2 className="size-3.5" />+ {s.state === 'active' ? <Pause className="size-4" /> : <PlayCircle className="size-4" />}</Button>- ) : null}+ <Button+ size="sm"+ variant="ghost"+ title="Test-fire now"+ disabled={fire.isPending}+ onClick={() => fire.mutate(s)}+ >+ <Play className="size-4" />+ </Button>+ {!repoManaged ? (+ <>+ <Button size="sm" variant="ghost" title="Edit" onClick={() => openEdit(s)}>+ <Pencil className="size-4" />+ </Button>+ <Button+ size="sm"+ variant="ghost"+ className="text-muted-foreground hover:text-red-600"+ title="Delete"+ disabled={remove.isPending}+ onClick={() => remove.mutate(s)}+ >+ <Trash2 className="size-4" />+ </Button>+ </>+ ) : null}+ </div></div>- </li>- ))}- </ul>- ) : (- <p className="text-muted-foreground text-xs">No schedules yet.</p>- )}- {!repoManaged ? (- showForm ? (- <div className="bg-muted/40 space-y-2 rounded-md p-2">- <Input value={name} onChange={(e) => setName(e.target.value)} placeholder="name (e.g. morning-sweep)" />- <div className="flex gap-2">- <Input- value={cron}- onChange={(e) => setCron(e.target.value)}- placeholder="0 9 * * 1-5"- className="font-mono"- />- <Input- value={tz}- onChange={(e) => setTz(e.target.value)}- placeholder="UTC"- className="max-w-32"- />- </div>- <Input- value={input}- onChange={(e) => setInput(e.target.value)}- placeholder="first message of every run"- />- <div className="flex items-center gap-2">- <Button- size="sm"- variant="outline"- disabled={create.isPending || !canCreate}- onClick={() => create.mutate()}+ <div className="text-muted-foreground flex flex-wrap items-center gap-x-2 gap-y-1 text-xs">+ <code className="text-foreground font-mono">{s.cron}</code>+ {gloss ? <span>{gloss}</span> : null}+ <span className="text-border">·</span>+ <span>{s.tz ?? 'UTC'}</span>+ <span className="text-border">·</span>+ <span className="inline-flex items-center gap-1">+ <CalendarClock className="size-3" />+ next {s.state === 'active' ? rel(s.next_fire_at) : '—'}+ </span>+ {s.last_fired_at ? <span>· last ran {rel(s.last_fired_at)}</span> : null}+ </div>++ {s.state === 'auto_paused' && s.last_error ? (+ <div className="flex items-start gap-1.5 text-xs text-red-600 dark:text-red-500">+ <AlertTriangle className="mt-0.5 size-3.5 shrink-0" />+ <span className="min-w-0">+ Auto-paused after repeated failures — {s.last_error}. Resume once fixed.+ </span>+ </div>+ ) : null}++ <button+ type="button"+ onClick={() => setExpanded(open ? null : s.id)}+ className="text-muted-foreground hover:text-foreground inline-flex items-center gap-1 text-xs transition-colors">- {create.isPending ? 'Creating…' : 'Create'}- </Button>- <Button size="sm" variant="ghost" onClick={() => setShowForm(false)}>- Cancel- </Button>- </div>- </div>- ) : (- <Button size="sm" variant="outline" onClick={() => setShowForm(true)}>- <Plus className="size-4" />- New schedule- </Button>- )- ) : null}+ {open ? <ChevronDown className="size-3.5" /> : <ChevronRight className="size-3.5" />}+ Recent runs+ </button>+ {open ? (+ <div className="bg-muted/40 -mx-1 rounded-md">+ <ScheduleRuns agentId={agentId} scheduleId={s.id} />+ </div>+ ) : null}+ </PanelContent>+ </Panel>+ </li>+ )+ })}+ </ul>+ ) : !form ? (+ <div className="border-border rounded-lg border border-dashed py-12 text-center">+ <CalendarClock className="text-muted-foreground mx-auto size-6" />+ <p className="mt-3 text-sm font-medium">No schedules yet</p>+ <p className="text-muted-foreground mx-auto mt-1 max-w-sm text-sm">+ Run this agent automatically — a draft PR every morning, a nightly audit, a periodic sweep.+ </p>+ {!repoManaged ? (+ <Button size="sm" className="mt-4" onClick={openCreate}>+ <Plus className="size-4" />+ Create a schedule+ </Button>+ ) : null}+ </div>+ ) : null}- <p className="text-muted-foreground text-xs">- Or use the CLI: <code className="font-mono">oc agent schedule create</code>- </p>- </>- )}- </PanelContent>- </Panel>+ <p className="text-muted-foreground text-xs">+ Or from the CLI: <code className="font-mono">oc agent schedule create <name> --cron "0 9 * * 1-5" --input …</code>+ </p>+ </div>)}diff --git a/web/src/pages/AgentDetail.tsx b/web/src/pages/AgentDetail.tsxindex eecd3c46..71cb0f00 100644--- a/web/src/pages/AgentDetail.tsx+++ b/web/src/pages/AgentDetail.tsx@@ -30,7 +30,7 @@ import { Skeleton } from '@/components/ui/skeleton'import { SlackConnect } from '@/components/slack-connect'import { AgentSkills } from '@/components/agent-skills'import { AgentDeploySource } from '@/components/agent-deploy-source'-import { AgentSchedules } from '@/components/agent-schedules'+import { AgentSchedulesTab } from '@/components/agent-schedules'import { AgentRevisions } from '@/components/agent-revisions'import {WorkingRepoField,@@ -46,7 +46,7 @@ const ORG_DEFAULT = '__default__' // no pinned credential → org default resolvconst NEW_CRED = '__new__' // create one inlineconst MANAGED = 'managed' // run via OpenComputer, no BYO key (token-billing §6.6)-type Tab = 'overview' | 'revisions' | 'sessions' | 'settings'+type Tab = 'overview' | 'revisions' | 'sessions' | 'schedules' | 'settings'export default function AgentDetail() {const { agentId = '', tab } = useParams()@@ -57,9 +57,11 @@ export default function AgentDetail() {? 'revisions': tab === 'sessions'? 'sessions'- : tab === 'settings'- ? 'settings'- : 'overview'+ : tab === 'schedules'+ ? 'schedules'+ : tab === 'settings'+ ? 'settings'+ : 'overview'// Each tab is a thin control panel over one API resource — surface the call it drives// (REST + SDK), same as the other pages, so the dashboard reads as programmable.@@ -67,6 +69,7 @@ export default function AgentDetail() {overview: { method: 'GET', path: `/v3/agents/${agentId}`, sdk: 'oc.agents.get(id)', docs: `${DOCS}/agents` },revisions: { method: 'GET', path: `/v3/agents/${agentId}/revisions`, sdk: 'oc.agents.revisions.list(id)', docs: `${DOCS}/revisions` },sessions: { method: 'POST', path: '/v3/sessions', sdk: 'oc.sessions.create({ agent })', docs: `${DOCS}/sessions` },+ schedules: { method: 'GET', path: `/v3/agents/${agentId}/schedules`, sdk: 'oc.agents.schedules.list(id)', docs: `${DOCS}/schedules` },settings: { method: 'PATCH', path: `/v3/agents/${agentId}`, sdk: 'oc.agents.update(id, …)', docs: `${DOCS}/agents` },}@@ -321,6 +324,11 @@ export default function AgentDetail() {label="Sessions"current={active === 'sessions'}/>+ <TabLink+ to={`${base}/schedules`}+ label="Schedules"+ current={active === 'schedules'}+ /><TabLinkto={`${base}/settings`}label="Settings"@@ -438,16 +446,16 @@ export default function AgentDetail() {</Panel><AgentSkills agentId={agent.id} /></div>- {/* Right rail: connect-or-status for the agent's source + Slack + schedules. */}+ {/* Right rail: connect-or-status for the agent's source + Slack. */}<div className="space-y-4"><AgentDeploySource agentId={agent.id} />- <AgentSchedules agentId={agent.id} /><SlackConnect agentId={agent.id} agentName={agent.name} /></div></div>)}{active === 'revisions' && <AgentRevisions agentId={agent.id} />}+ {active === 'schedules' && <AgentSchedulesTab agentId={agent.id} />}{active === 'sessions' && (<Panel className="overflow-hidden">