import { tr, localeTag } from '../lib/i18n'; import { Icon } from './ui'; import { Markdown } from './Markdown'; import { ErrorNotice } from './ui'; import type { Task } from '../lib/tasks'; const FREQUENCY: Record = { hourly: 'Every hour', daily: 'Every day', weekdays: 'Weekdays', weekly: 'Every week' }; const WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']; const MODE: Record = { plan: 'Look only, change nothing', manual: 'Stop and tell me before changing anything', bypass: 'Bypass permissions' }; const when = (iso?: string) => (iso ? new Date(iso).toLocaleString(localeTag(), { dateStyle: 'medium', timeStyle: 'short' }) : ''); /** The schedule in one line: "Weekdays · 08:00", "Every week · Friday · 16:00". */ export function scheduleText(t: Task): string { const base = tr(FREQUENCY[t.frequency] ?? t.frequency); if (t.frequency === 'hourly') return base; return [base, t.frequency === 'weekly' ? tr(WEEKDAYS[t.weekday] ?? '') : '', t.at].filter(Boolean).join(' · '); } export type TaskState = 'running' | 'active' | 'paused'; export const taskState = (t: Task): TaskState => (t.status === 'running' ? 'running' : t.enabled ? 'active' : 'paused'); /** * An opened task, skimmable: when it runs, what it may do, what it did last, then the instructions and the last answer. * The title, the state and the actions (pause or resume, delete, Edit, Run now) are in the header the screen draws. */ export function TaskDetail({ task }: { task: Task }) { const state = taskState(task); const result = task.status === 'running' ? { label: 'Running…', tone: '' } : task.error ? { label: 'Last run failed', tone: 'is-bad' } : task.lastRunAt || task.output ? { label: 'Done', tone: 'is-good' } : { label: 'Not run yet', tone: '' }; return

{task.title}

{tr("Schedule")}{scheduleText(task)} {tr(state === 'paused' ? 'Paused' : task.nextRunAt ? tr("Next: {0}", [when(task.nextRunAt)]) : 'Calculating the next run…')}
{tr("What it may do")}{tr(MODE[task.mode ?? 'plan'])}
{tr("Last result")}{result.tone === 'is-good' ? : null}{tr(result.label)} {when(task.lastRunAt)}

{tr("What it does")}

{task.prompt}

{tr("Last answer")}{task.demo ? tr(' · Example') : ''}

{task.error ? : task.output ?
:

{tr("Run this task to see its first result here.")}

}
; }