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
26 changes: 19 additions & 7 deletions apps/desktop/src/ui/JobCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ export function JobCard({
agent,
machineLabel,
onOpen,
onEdit,
onDuplicate,
onDelete,
act,
Expand All @@ -146,6 +147,7 @@ export function JobCard({
/** Shown in the footer when the network has more than one machine, or for hub-dispatched jobs. */
machineLabel?: string;
onOpen: () => void;
onEdit: () => void;
onDuplicate: () => void;
onDelete: () => void;
act: (what: string, run: () => Promise<void>) => void;
Expand All @@ -169,7 +171,7 @@ export function JobCard({
<li
data-loop={loopKey(loop)}
className={cx(
"group/job relative flex min-w-0 flex-col gap-2 rounded-lg bg-surface px-4 pt-3 pb-2 hover:bg-fill-subtle",
"group/job relative flex min-w-0 flex-col gap-2 rounded-lg bg-surface p-4 hover:bg-fill-subtle",
reason && "ring-1 ring-danger/35",
loop.paused && !reason && "opacity-70",
)}
Expand All @@ -178,7 +180,7 @@ export function JobCard({
<button
type="button"
onClick={onOpen}
className="min-w-0 flex-1 text-left font-medium text-body text-fg after:absolute after:inset-0 after:rounded-lg focus-visible:outline-none focus-visible:after:ring-1 focus-visible:after:ring-accent"
className="min-w-0 flex-1 text-left font-semibold text-title3 text-fg after:absolute after:inset-0 after:rounded-lg focus-visible:outline-none focus-visible:after:ring-1 focus-visible:after:ring-accent"
>
<span className="line-clamp-2">{loop.name}</span>
</button>
Expand Down Expand Up @@ -223,7 +225,7 @@ export function JobCard({
)}
{loop.paused ? "Resume" : "Pause"}
</DropdownMenu.Item>
<DropdownMenu.Item className={menuItem} onSelect={onOpen}>
<DropdownMenu.Item className={menuItem} onSelect={onEdit}>
<Pencil size={13} className="text-fg-muted" /> Edit
</DropdownMenu.Item>
<DropdownMenu.Item className={menuItem} onSelect={onDuplicate}>
Expand All @@ -244,7 +246,7 @@ export function JobCard({
</div>

{agent && (
<span className="w-fit max-w-full truncate rounded-full bg-fill-subtle px-2 py-0.5 text-caption text-fg-muted">
<span title={agent} className="-mt-1 truncate text-caption text-fg-muted">
{agent}
</span>
)}
Expand Down Expand Up @@ -281,9 +283,6 @@ export function JobCard({
)}

<div className="mt-auto flex min-w-0 items-center gap-2 border-t border-border pt-2 text-caption text-fg-muted">
<span className="relative flex">
<RunHistory runs={loop.runs} />
</span>
<span className="min-w-0 flex-1 truncate">
{projectName(loop.workspace)}
{(machineLabel || loop.machine) && ` on ${machineLabel || loop.machine}`} ·{" "}
Expand Down Expand Up @@ -315,6 +314,19 @@ export function JobCard({
<span className="shrink-0 text-fg-faint">{nextRunText(loop, now)}</span>
)}
</div>
<div className="flex items-center justify-between gap-2 text-caption text-fg-muted">
<span className="flex items-center gap-2">
{loop.runs.length > 0 && (
<span>
{loop.runs.length} {loop.runs.length === 1 ? "run" : "runs"}
</span>
)}
<RunHistory runs={loop.runs} />
</span>
<span className="shrink-0">
Run history <ArrowUpRight size={12} className="inline" />
</span>
</div>
</li>
);
}
87 changes: 87 additions & 0 deletions apps/desktop/src/ui/JobDetails.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { Dialog } from "radix-ui";
import { useRef } from "react";
import { projectName } from "../acp/types";
import { runThreadKey } from "../state/fleetLoops";
import { type Loop, nextRunText, scheduleInWords } from "../state/loops";
import { selfName, useLocalIdentity, useMachines } from "../state/machines";
import { FULL_RUN_FORMAT, isFailedRun, RunList } from "./JobRuns";
import { Pill } from "./primitives";

export function JobDetails({
loop,
now,
machine,
onClose,
onEdit,
}: {
loop: Loop;
now: number;
machine: string;
onClose: () => void;
onEdit: () => void;
}) {
const returnFocus = useRef<HTMLElement | null>(null);
const machines = useMachines((s) => s.machines);
const local = useLocalIdentity();
const localName = local.displayName ?? selfName();
const next = !loop.paused && loop.schedule.kind !== "manual" ? loop.nextDueAt : undefined;
const stats = [
{ label: "Recorded runs", value: loop.runs.length },
{ label: "Succeeded", value: loop.runs.filter((run) => run.state === "succeeded").length },
{ label: "Failed", value: loop.runs.filter(isFailedRun).length },
];

return (
<Dialog.Root open onOpenChange={(open) => !open && onClose()}>
<Dialog.Portal>
<Dialog.Overlay className="rc-overlay fixed inset-0 z-50 bg-bg/60" />
<div className="pointer-events-none fixed inset-0 z-50 flex items-center justify-center p-4">
<Dialog.Content
onOpenAutoFocus={() => {
returnFocus.current =
document.activeElement instanceof HTMLElement ? document.activeElement : null;
}}
onCloseAutoFocus={(event) => {
event.preventDefault();
if (document.activeElement === document.body) returnFocus.current?.focus();
}}
className="elevated pointer-events-auto flex max-h-full w-full max-w-xl flex-col overflow-hidden"
>
<header className="shrink-0 px-5 pt-5 pb-4">
<Dialog.Title className="break-words font-semibold text-title2">{loop.name}</Dialog.Title>
<Dialog.Description className="mt-1 text-callout text-fg-muted">
{projectName(loop.workspace)} · {machine} · {scheduleInWords(loop.schedule)}
</Dialog.Description>
<p className="mt-1 text-caption text-fg-muted">
{next === undefined ? nextRunText(loop, now) : `Next run ${FULL_RUN_FORMAT.format(next)}`}
</p>
</header>
<div className="min-h-0 overflow-y-auto px-5 pb-4">
<dl className="grid grid-cols-3 gap-3 rounded-lg bg-fill-subtle p-3">
{stats.map(({ label, value }) => (
<div key={label} className="flex flex-col-reverse">
<dt className="text-caption text-fg-muted">{label}</dt>
<dd className="tabular font-semibold text-title2">{value}</dd>
</div>
))}
</dl>
<h3 className="mt-4 mb-1 font-semibold text-body">Run history</h3>
<RunList
runs={loop.runs}
now={now}
threadOf={(run) => runThreadKey(loop, run, machines, localName)}
onOpenThread={onClose}
/>
</div>
<footer className="flex shrink-0 justify-end gap-2 border-t border-border px-5 py-3">
<Pill onClick={onEdit}>Edit job</Pill>
<Dialog.Close asChild>
<Pill>Done</Pill>
</Dialog.Close>
</footer>
</Dialog.Content>
</div>
</Dialog.Portal>
</Dialog.Root>
);
}
36 changes: 31 additions & 5 deletions apps/desktop/src/ui/Loops.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* from the sidebar's Jobs row. Jobs live across the entire paired machine network: every connected
* computer's scheduler is read and managed directly over ACP, and a hub's members remain reachable
* too. Each job is a card with its agent, last result, schedule and next run; the card opens one
* dialog that edits the job beside its runs. Jobs paused by failures lead. Review is a timeline by
* dialog with its run history and a link to edit the job. Jobs paused by failures lead. Review is a timeline by
* day of failed runs and open threads, a repeated failure folded into one row.
*/

Expand Down Expand Up @@ -39,6 +39,7 @@ import { LOCAL_HOST } from "../state/threadKeys";
import { statusOf } from "../state/threadStatus";
import { CheckCheck, Plus, Repeat } from "./icons";
import { JobCard, listening } from "./JobCard";
import { JobDetails } from "./JobDetails";
import { JobReview } from "./JobReview";
import { showJob } from "./JobRunBar";
import { LoopDialog } from "./LoopDialog";
Expand Down Expand Up @@ -97,6 +98,7 @@ export function Loops() {
const [error, setError] = useState<string | null>(null);
const [scopeHost, setScopeHost] = useState<string>(ALL_MACHINES);
const [tab, setTab] = useState<Tab>("jobs");
const [detailsKey, setDetailsKey] = useState<string | null>(null);
const [editing, setEditing] = useState<Loop | null>(null);
const [duplicating, setDuplicating] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);
Expand Down Expand Up @@ -202,13 +204,13 @@ export function Loops() {
setTab("jobs");
if (effectiveScope !== ALL_MACHINES && effectiveScope !== match.host) setScopeHost(ALL_MACHINES);
useLoopThreads.setState({ reveal: null });
openJob(match);
setDetailsKey(loopKey(match));
requestAnimationFrame(() =>
listRef.current
?.querySelector(`[data-loop="${CSS.escape(loopKey(match))}"]`)
?.scrollIntoView({ block: "nearest" }),
);
}, [reveal, byHost, allLoops, effectiveScope, openJob]);
}, [reveal, byHost, allLoops, effectiveScope]);

const attention: Loop[] = [];
const upcoming: Loop[] = [];
Expand Down Expand Up @@ -354,11 +356,22 @@ export function Loops() {
const showToolbar = Boolean(byHost && (hasPeers || (anyDaemonRunning && loops.length > 0)));
const canCreate = Boolean(byHost && (anyDaemonRunning || hasPeers));

const details = allLoops.find((loop) => loopKey(loop) === detailsKey);

return (
<div className="flex min-h-0 flex-1 flex-col bg-bg">
<ViewHeader title="Jobs" />
<ViewHeader />
<div ref={listRef} className="min-h-0 flex-1 overflow-y-auto">
<div className="mx-auto flex w-full max-w-5xl flex-col gap-3 px-6 pt-2 pb-8">
<div className="flex flex-wrap items-end justify-between gap-x-4 gap-y-1">
<h1 className="font-semibold text-title tracking-tight text-fg">Jobs</h1>
{loops.length > 0 && (
<p className="text-callout text-fg-muted">
{loops.length} {loops.length === 1 ? "job" : "jobs"} · {upcoming.length} active ·{" "}
{attention.length} need attention
</p>
)}
</div>
{showToolbar && (
<div className="flex flex-wrap items-center gap-2 pb-1">
{(loops.length > 0 || tab === "review") && (
Expand Down Expand Up @@ -489,7 +502,8 @@ export function Loops() {
? loopMachineLabel(loop, machines, localName)
: undefined
}
onOpen={() => openJob(loop)}
onOpen={() => setDetailsKey(loopKey(loop))}
onEdit={() => openJob(loop)}
onDuplicate={() => openJob(loop, true)}
onDelete={() => confirmDelete(loop)}
act={act}
Expand All @@ -504,6 +518,18 @@ export function Loops() {
)}
</div>
</div>
{details && (
<JobDetails
loop={details}
now={now}
machine={loopMachineLabel(details, machines, localName)}
onClose={() => setDetailsKey(null)}
onEdit={() => {
setDetailsKey(null);
openJob(details);
}}
/>
)}
<LoopDialog
open={dialogOpen}
loop={editing}
Expand Down
12 changes: 8 additions & 4 deletions apps/desktop/src/ui/MainHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function SidebarCluster() {
}

/** A header for views that replace the chat: clear of the traffic lights and the window's controls. */
export function ViewHeader({ title, children }: { title: ReactNode; children?: ReactNode }) {
export function ViewHeader({ title, children }: { title?: ReactNode; children?: ReactNode }) {
const sidebarHidden = useApp((s) => s.sidebarHidden);
const lightsInset = useLightsInset();
const controlsInset = windowControlsInset(appPlatform());
Expand All @@ -90,9 +90,13 @@ export function ViewHeader({ title, children }: { title: ReactNode; children?: R
}}
>
{sidebarHidden && <SidebarCluster />}
<h1 className="min-w-0 flex-1 truncate font-semibold text-body" data-tauri-drag-region>
{title}
</h1>
{title == null ? (
<div className="flex-1 self-stretch" data-tauri-drag-region />
) : (
<h1 className="min-w-0 flex-1 truncate font-semibold text-body" data-tauri-drag-region>
{title}
</h1>
)}
{children}
</header>
);
Expand Down
Loading