Files
archie/ui/src/tasks/TaskHeader.vue
T
sam 5ea115746c
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
deploy / gate (push) Canceled after 5m37s
ci/woodpecker/push/deploy Pipeline was canceled
fix(dashboard): blocked tasks say what they need, and a provider refusal names its fix
2026-11-10 23:19:29 +11:00

206 lines
9.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { computed, nextTick, ref, watch } from "vue";
import { useRouter } from "vue-router";
import { ArrowUpRight, CircleAlert } from "@lucide/vue";
import {
Breadcrumb,
BreadcrumbItem,
BreadcrumbLink,
BreadcrumbList,
BreadcrumbPage,
BreadcrumbSeparator,
} from "@/components/ui/breadcrumb";
import { Badge } from "@/components/ui/badge";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { api } from "@/lib/api";
import { useOrgStore } from "@/stores/org";
import { runQuery, type LogState } from "./task-run";
import { firstLine } from "./first-line";
import { approvalLabels, statusKind, statusLabel } from "@/lib/task-meta";
import DispatchLinks from "@/bindings/DispatchLinks.vue";
import { MetadataList } from "@/components/ui/metadata-list";
import { Section } from "@/components/ui/section";
import TaskRowActions from "./TaskRowActions.vue";
import { headerActionIds } from "./task-actions";
import { useTaskRun } from "./use-task-run";
/**
* The task's head: where it sits, what it is, its state and forge links, and
* its server-authorized lifecycle controls. A parked task opens with the
* reason it stopped.
*/
const props = defineProps<{ id: string }>();
const run = useTaskRun();
const title = computed(() => firstLine(run.task?.title || `Task #${props.id}`));
const description = computed(() => run.task?.body?.trim() || (run.task?.title !== title.value ? run.task?.title : ""));
const status = computed(() => run.task?.status ?? "");
const router = useRouter();
const attempt = computed(() => run.attempts?.attempts?.find((a) => a.attempt === run.attemptNumber));
const failure = computed(() => {
const stage = attempt.value?.stages?.find((s) => s.error);
const current = run.attemptNumber === run.currentAttempt;
if (current && status.value === "parked") return { title: "Blocked", detail: run.task?.park_reason || stage?.error || "", parked: true };
if (attempt.value?.status === "failed" || (current && status.value === "dead")) return { title: `Attempt ${run.attemptNumber} failed${stage?.name ? ` during ${stage.name}` : ""}`, detail: stage?.error || run.task?.park_reason || "", parked: false };
return null;
});
// The daemon names a workflow's identity by its id in the parked reason; this
// page knows which ids are identities and shows each by name, linked to the
// page that manages it. An id this install does not know keeps its raw text.
const identities = useOrgStore();
identities.watchIdentities();
const detailParts = computed(() => {
const text = failure.value?.detail ?? "";
const known = identities.identities.map((actor) => actor.id).filter((id) => text.includes(id));
if (!known.length) return [{ text, to: "" }];
const pattern = new RegExp(`(${known.map((id) => id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|")})`, "g");
return text
.split(pattern)
.map((part) => (known.includes(part) ? { text: identities.identityName(part), to: "/org/agents" } : { text: part, to: "" }));
});
const jumping = ref(false);
const jumpError = ref("");
watch(() => run.attemptNumber, () => { jumpError.value = ""; });
async function jumpToLog(): Promise<void> {
const selected = run.attemptNumber;
if (selected == null) return;
jumping.value = true;
jumpError.value = "";
try {
const logs = await api.taskLogs<LogState>(props.id, { attempt: selected, level: "ERROR", limit: 1 });
if (selected !== run.attemptNumber) return;
const entry = logs.entries?.[0];
if (!entry?.id) {
jumpError.value = "No error log line was recorded for this attempt.";
return;
}
run.setFilters({ level: "ERROR", stage: "" });
run.setTab("log");
await nextTick();
await router.replace({ query: runQuery("log", selected), hash: `#log-line-${entry.id}` });
} catch {
if (selected === run.attemptNumber) jumpError.value = "Could not read this attempt’s error log.";
} finally {
jumping.value = false;
}
}
// The run's inputs and written outputs, one row per name.
const rows = (values?: Record<string, unknown>) =>
Object.entries(values ?? {}).map(([label, value]) => ({
label,
mono: true,
value: typeof value === "string" ? value : JSON.stringify(value),
}));
const sections = computed(() =>
[
{ title: "Inputs", rows: rows(run.attempts?.inputs) },
{ title: "Outputs", rows: rows(run.attempts?.outputs) },
].filter((section) => section.rows.length),
);
const headerActions = computed(() => headerActionIds(run.task));
</script>
<template>
<div class="mb-6">
<Breadcrumb class="mb-2">
<BreadcrumbList>
<BreadcrumbItem><BreadcrumbLink as-child><RouterLink to="/tasks">Tasks</RouterLink></BreadcrumbLink></BreadcrumbItem>
<BreadcrumbSeparator />
<BreadcrumbItem><BreadcrumbPage class="font-mono">#{{ id }}</BreadcrumbPage></BreadcrumbItem>
</BreadcrumbList>
</Breadcrumb>
<div class="flex flex-wrap items-start justify-between gap-4">
<div class="min-w-0">
<h1 class="text-title leading-tight font-semibold tracking-tight break-words text-balance sm:text-title sm:leading-7">{{ title }}</h1>
<div class="mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-label">
<Badge v-if="status" :variant="statusKind(status)">{{ statusLabel(status) }}</Badge>
<Badge v-if="run.task?.approval" variant="outline">{{ approvalLabels[run.task.approval] ?? run.task.approval }}</Badge>
<span v-if="run.task?.workflow" class="font-mono text-caption text-fg-muted">{{ run.task.workflow }}</span>
<a
v-if="run.task?.issue_url && run.task?.issue_number"
class="inline-flex items-center gap-0.5 font-mono text-caption text-fg-muted hover:text-foreground"
:href="run.task.issue_url"
target="_blank"
rel="noreferrer"
>{{ run.task.owner }}/{{ run.task.repo }} #{{ run.task.issue_number }}<ArrowUpRight class="size-3" aria-hidden="true"
/></a>
<DispatchLinks kind="tasks" :id="id" />
<a
v-if="run.task?.pr_url && run.task?.pr_number"
class="inline-flex items-center gap-0.5 font-mono text-caption text-fg-muted hover:text-foreground"
:href="run.task.pr_url"
target="_blank"
rel="noreferrer"
>PR #{{ run.task.pr_number }}<ArrowUpRight class="size-3" aria-hidden="true"
/></a>
</div>
</div>
<div class="flex flex-wrap items-center gap-2">
<TaskRowActions
v-if="run.task && headerActions.length"
:task="run.task"
:only="headerActions"
@done="run.refreshAll()"
/>
</div>
</div>
<Section v-if="description" title="Description" class="mt-4 mb-0">
<p class="whitespace-pre-wrap break-words text-label text-fg-muted">{{ description }}</p>
</Section>
<div v-if="sections.length || run.attempts?.called_by || run.attempts?.handed_off_from || run.attempts?.handed_off_to" class="mt-3 flex flex-wrap items-start gap-3">
<p v-if="run.attempts?.handed_off_from" class="text-caption text-fg-subtle">
Continues
<RouterLink :to="`/tasks/${run.attempts.handed_off_from}`" class="font-mono text-fg-muted hover:text-foreground hover:underline"
>task #{{ run.attempts.handed_off_from }}</RouterLink
>
</p>
<p v-if="run.attempts?.handed_off_to" class="text-caption text-fg-subtle">
Handed off to
<RouterLink :to="`/tasks/${run.attempts.handed_off_to}`" class="font-mono text-fg-muted hover:text-foreground hover:underline"
>task #{{ run.attempts.handed_off_to }}</RouterLink
>
</p>
<p v-if="run.attempts?.called_by" class="text-caption text-fg-subtle">
Called by
<RouterLink :to="`/tasks/${run.attempts.called_by}`" class="font-mono text-fg-muted hover:text-foreground hover:underline"
>task #{{ run.attempts.called_by }}</RouterLink
>
</p>
<Section v-for="section in sections" :key="section.title" :title="section.title" class="mb-0 min-w-0">
<MetadataList :rows="section.rows" class="text-fg-muted" />
</Section>
</div>
<Alert
v-if="failure"
:variant="failure.parked ? 'warn' : 'destructive'"
class="mt-4"
>
<CircleAlert aria-hidden="true" />
<AlertTitle class="flex flex-wrap items-center justify-between gap-2">
<span>{{ failure.title }}</span>
<Button variant="ghost" size="sm" :disabled="jumping || run.attemptNumber == null" @click="jumpToLog">Jump to log line</Button>
</AlertTitle>
<AlertDescription>
<p v-if="failure.detail" class="mt-0.5 font-mono text-caption text-fg-muted [overflow-wrap:anywhere]">
<template v-for="(part, index) in detailParts" :key="index">
<RouterLink v-if="part.to" :to="part.to" class="underline decoration-dotted hover:text-foreground">{{ part.text }}</RouterLink>
<template v-else>{{ part.text }}</template>
</template>
</p>
<Alert v-if="jumpError" variant="destructive" class="mt-1"><AlertDescription>{{ jumpError }}</AlertDescription></Alert>
<Button v-if="failure.parked && run.attempts?.recovery" as-child size="sm" class="mt-2">
<RouterLink :to="run.attempts.recovery.link">{{ run.attempts.recovery.label }}</RouterLink>
</Button>
</AlertDescription>
</Alert>
</div>
</template>