Expose all task actions in the task detail header (archie) #1846

Merged
sam merged 1 commits from feat/1000000000000000-expose-all-task-actions-in-the-task-detail-header into main 2026-11-10 06:54:29 +00:00
6 changed files with 193 additions and 164 deletions

No files matched your search

-98
View File
@@ -1,98 +0,0 @@
<script setup lang="ts">
import { RefreshCw } from "@lucide/vue";
import { computed } from "vue";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { Spinner } from "@/components/ui/spinner";
import { statusLabel } from "@/lib/task-meta";
import { useTaskRun } from "./use-task-run";
/**
* Restarting a task as a new run.
*
* The control is only live where the task itself offers the action: a new run
* can only start from a parked task, so anywhere else the button is disabled
* and the title says why. The refusal that does arrive (the task moved between
* the read and the click) is rendered from the error class, because "you
* cannot do that", "your session has expired" and "the daemon did not answer"
* need three different responses from the operator.
*
* `compact` renders the bare control for the header's action row; on its own
* the component also renders the disabled reason.
*/
const props = defineProps<{ id?: string; compact?: boolean; class?: string }>();
const run = useTaskRun();
const confirmText = computed(
() =>
`Start a new run for "${run.task?.title || `task ${props.id}`}"? The previous attempt's commits are discarded.`,
);
const unavailable = computed(() => {
if (run.taskList === undefined) return "The task list has not loaded yet.";
if (run.canRetry) return "";
return run.task
? `Only a parked task can start a new run. This task is ${statusLabel(run.task.status ?? "")}.`
: "";
});
const errorText = computed(() => {
const err = run.retryError;
if (!err) return "";
if (err.kind === "session-expired")
return "Dashboard authentication is required.";
if (err.kind === "refused")
return `${err.message}. This run cannot be restarted from here.`;
return `${err.message}. Try again, or check the daemon.`;
});
</script>
<template>
<AlertDialog>
<Tooltip>
<TooltipTrigger as-child>
<span tabindex="0" class="inline-flex" :class="props.class">
<AlertDialogTrigger as-child>
<Button
:variant="run.retryKind === 'primary' ? 'default' : 'outline'"
:disabled="!run.canRetry || run.retryBusy"
>
<Spinner v-if="run.retryBusy" data-icon="inline-start" />{{ run.retryBusy ? "Starting…" : "New run" }}
</Button>
</AlertDialogTrigger>
</span>
</TooltipTrigger>
<TooltipContent v-if="unavailable">{{ unavailable }}</TooltipContent>
</Tooltip>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>New run</AlertDialogTitle>
<AlertDialogDescription>{{ confirmText }}</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction @click="run.performRetry">
<RefreshCw data-icon="inline-start" />
Start run</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<Alert v-if="errorText" variant="destructive" class="mt-2">
<AlertDescription>{{ errorText }}</AlertDescription>
</Alert>
</template>
+4 -14
View File
@@ -22,14 +22,13 @@ 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 StartNewRun from "./StartNewRun.vue";
import TaskRowActions from "./TaskRowActions.vue";
import { shownActionIds } from "./task-actions";
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
* the page's one decision, starting a new run. A parked task opens with the
* its server-authorized lifecycle controls. A parked task opens with the
* reason it stopped.
*/
const props = defineProps<{ id: string }>();
@@ -89,12 +88,6 @@ async function jumpToLog(): Promise<void> {
}
}
// The head has room for the reap an operator reaches for once a task is
// finished with. Whether this task offers it is the server's action list,
// never this page's opinion about the status. Approval answers live with the
// thing being approved.
const HEAD_ACTIONS = computed(() => ["archive", "merge"]);
// The run's inputs and written outputs, one row per name.
const rows = (values?: Record<string, unknown>) =>
Object.entries(values ?? {}).map(([label, value]) => ({
@@ -108,9 +101,7 @@ const sections = computed(() =>
{ title: "Outputs", rows: rows(run.attempts?.outputs) },
].filter((section) => section.rows.length),
);
const headerActions = computed(() =>
shownActionIds(run.task?.actions, HEAD_ACTIONS.value),
);
const headerActions = computed(() => headerActionIds(run.task));
</script>
<template>
@@ -152,10 +143,9 @@ const headerActions = computed(() =>
<TaskRowActions
v-if="run.task && headerActions.length"
:task="run.task"
:only="HEAD_ACTIONS"
:only="headerActions"
@done="run.refreshAll()"
/>
<StartNewRun compact :id="id" />
</div>
</div>
+40 -2
View File
@@ -1,11 +1,13 @@
import { reviewGateOffer } from "./review-gate.ts";
/**
* Which lifecycle controls a surface renders.
*
* A task offers whatever the server says it offers -- the action list rides
* with the task -- so a status the server will not archive is never offered an
* Archive control here. A surface may narrow that list to the controls it has
* room for (the task head has room for one), but narrowing can only ever
* remove: a control the server did not send cannot be conjured by naming it.
* room for, but narrowing can only ever remove: a control the server did not
* send cannot be conjured by naming it.
*/
export function shownActionIds(
actions: readonly string[] | null | undefined,
@@ -15,3 +17,39 @@ export function shownActionIds(
if (!only || only.length === 0) return [...actions];
return actions.filter((id) => only.includes(id));
}
const PLAN_PANEL_ACTIONS = new Set(["approve", "reject"]);
const REVIEW_GATE_PANEL_ACTIONS = new Set(["approve", "rereview", "reject"]);
/**
* Which lifecycle controls the task detail header (/tasks/:id) renders.
*
* Starts from the full server-authorized action list and omits only the
* approval controls already rendered by an active TaskApproval or
* TaskReviewGate panel on the page.
*/
export function headerActionIds(
task:
| {
status?: string;
approval?: string;
plan?: string;
review_gate?: string;
actions?: readonly string[] | null;
}
| null
| undefined,
): string[] {
const offered = shownActionIds(task?.actions);
if (!offered.length || !task) return offered;
const planActive = task.approval === "plan" && Boolean(task.plan?.trim());
const reviewGateActive =
task.status === "waiting_approval" &&
reviewGateOffer(task.review_gate) !== null;
if (!planActive && !reviewGateActive) return offered;
return offered.filter((id) => {
if (planActive && PLAN_PANEL_ACTIONS.has(id)) return false;
if (reviewGateActive && REVIEW_GATE_PANEL_ACTIONS.has(id)) return false;
return true;
});
}
+4 -1
View File
@@ -43,6 +43,7 @@ export interface TaskRecord {
id: number | string;
title?: string;
body?: string;
source?: string;
status?: string;
workflow?: string;
owner?: string;
@@ -52,6 +53,8 @@ export interface TaskRecord {
issue_url?: string;
pr_number?: number;
pr_url?: string;
branch?: string;
retry_mode?: string;
park_reason?: string;
tokens_used?: number;
actions?: string[];
@@ -59,7 +62,7 @@ export interface TaskRecord {
plan?: string;
/** The structured plan (JSON) the plan text was rendered from. */
plan_document?: string;
/** What a task waiting for approval asks: "plan" or "review". */
/** What a task waiting for approval asks: "plan", "review", or "budget". */
approval?: string;
rereview_rounds?: number;
}
+2 -48
View File
@@ -24,9 +24,8 @@ import {
} from "vue";
import { useRoute, useRouter } from "vue-router";
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
import { api } from "@/lib/api";
import { keepValue } from "@/lib/keep-unchanged";
import { actionFor } from "@/lib/task-meta";
import { useLiveResource } from "@/stores/session";
import {
@@ -48,11 +47,6 @@ import {
/** A keyed read has three states: pending, failed, or the response. */
type Cache<T> = Map<string, T | null | undefined>;
export interface RetryError {
kind: ActionErrorKind;
message: string;
}
export interface TaskRun {
tab: string;
attempts: AttemptsState | null | undefined;
@@ -60,15 +54,11 @@ export interface TaskRun {
events: TaskEvent[] | null | undefined;
missing: boolean;
filters: LogFilters;
retryBusy: boolean;
retryError: RetryError | null;
task: TaskRecord | null;
attemptNumber: number | null;
currentAttempt: number | null;
stageNames: string[];
retryKind: string;
canRetry: boolean;
logState: LogState | null | undefined;
changesState: ChangesState | null | undefined;
debugState: DebugState | null | undefined;
@@ -78,7 +68,6 @@ export interface TaskRun {
selectAttempt(attempt: number): void;
setFilters(next: LogFilters): void;
refreshAll(): void;
performRetry(): Promise<void>;
loadAttempts(): void;
loadEvents(): void;
loadTaskList(): void;
@@ -108,8 +97,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
const logs = ref<Cache<LogState>>(new Map());
const changes = ref<Cache<ChangesState>>(new Map());
const debug = ref<Cache<DebugState>>(new Map());
const retryBusy = ref(false);
const retryError = ref<RetryError | null>(null);
const refreshToken = ref(0);
const task = computed<TaskRecord | null>(() =>
@@ -140,11 +127,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
),
]);
const retryMeta = computed(() => actionFor("retry"));
const canRetry = computed(() =>
Boolean(retryMeta.value && (task.value?.actions || []).includes("retry")),
);
const logKey = computed(() =>
id.value == null || attemptNumber.value == null
? null
@@ -296,6 +278,7 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
function refreshAll(): void {
dropCaches();
requestedAttempt.value = null;
loadTaskList();
loadAttempts(true);
loadEvents(true);
@@ -327,30 +310,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
useLiveResource("tasks", refreshLive, 500);
async function performRetry(): Promise<void> {
if (id.value == null) return;
retryError.value = null;
retryBusy.value = true;
try {
await api.taskAction<void>(String(id.value), "retry");
// A new attempt starts here. Everything cached belongs to the attempt
// that just ended, so it is dropped rather than shown against the new
// run: the attempt history, the events, every cached log, capture and
// debug payload. The new attempt then becomes the selected run without a
// reload.
dropCaches();
requestedAttempt.value = null;
loadTaskList();
loadAttempts();
loadEvents();
refreshToken.value += 1;
} catch (err) {
retryError.value = classifyActionError(err);
} finally {
retryBusy.value = false;
}
}
onMounted(() => {
// The page loads once for the task it was opened for; the route remounts it
// when that changes (App.vue keys the outlet on the path).
@@ -396,14 +355,10 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
events,
missing,
filters,
retryBusy,
retryError,
task,
attemptNumber,
currentAttempt,
stageNames,
retryKind: computed(() => retryMeta.value?.kind || ""),
canRetry,
logState,
changesState,
debugState,
@@ -417,7 +372,6 @@ export function provideTaskRun(id: ComputedRef<number | null>): TaskRun {
filters.value = { ...next };
},
refreshAll,
performRetry,
loadAttempts,
loadEvents,
loadTaskList,
+143 -1
View File
@@ -1,6 +1,6 @@
import assert from "node:assert/strict";
import test from "node:test";
import { shownActionIds } from "../src/tasks/task-actions.ts";
import { headerActionIds, shownActionIds } from "../src/tasks/task-actions.ts";
test("task surfaces preserve server-authorized actions and their order", () => {
const cases: Array<[string[] | null | undefined, string[] | undefined, string[]]> = [
@@ -16,3 +16,145 @@ test("task surfaces preserve server-authorized actions and their order", () => {
assert.deepEqual(shownActionIds(offered, only), expected, JSON.stringify({ offered, only }));
}
});
test("task detail header exposes all server-authorized actions unless an approval panel owns them", () => {
const activeReviewGate = JSON.stringify({
head_sha: "abc123",
findings: [
{
key: "f1",
finding: {
Title: "Bug",
Body: "Fix it",
File: "a.go",
LineStart: 1,
LineEnd: 2,
Severity: "high",
Score: 90,
Confidence: 90,
},
},
],
});
const emptyReviewGate = JSON.stringify({ head_sha: "abc123", findings: [] });
const resolvedReviewGate = JSON.stringify({
head_sha: "abc123",
outcome: "approved",
findings: JSON.parse(activeReviewGate).findings,
});
const cases: Array<{
name: string;
task: Parameters<typeof headerActionIds>[0];
expected: string[];
}> = [
{
name: "null and undefined tasks",
task: null,
expected: [],
},
{
name: "parked task exposes retry, abandon, reject",
task: {
status: "parked",
actions: ["retry", "abandon", "reject"],
},
expected: ["retry", "abandon", "reject"],
},
{
name: "queued task exposes cancel and reject",
task: {
status: "queued",
actions: ["cancel", "reject"],
},
expected: ["cancel", "reject"],
},
{
name: "running task exposes stop and reject",
task: {
status: "running",
actions: ["stop", "reject"],
},
expected: ["stop", "reject"],
},
{
name: "waiting_approval with budget approval keeps approve, reject, rereview in header",
task: {
status: "waiting_approval",
approval: "budget",
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "waiting_approval with plan approval and non-empty plan omits approve and reject",
task: {
status: "waiting_approval",
approval: "plan",
plan: "# Plan\nDo the work",
actions: ["approve", "reject", "rereview"],
},
expected: ["rereview"],
},
{
name: "waiting_approval with plan approval and missing or blank plan keeps all actions in header",
task: {
status: "waiting_approval",
approval: "plan",
plan: " ",
actions: ["approve", "reject"],
},
expected: ["approve", "reject"],
},
{
name: "waiting_approval with active review gate findings omits approve, rereview, reject",
task: {
status: "waiting_approval",
approval: "review",
review_gate: activeReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: [],
},
{
name: "waiting_approval with empty review gate findings keeps actions in header",
task: {
status: "waiting_approval",
approval: "review",
review_gate: emptyReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "waiting_approval with already-resolved review gate keeps actions in header",
task: {
status: "waiting_approval",
approval: "review",
review_gate: resolvedReviewGate,
actions: ["approve", "reject", "rereview"],
},
expected: ["approve", "reject", "rereview"],
},
{
name: "pr_open task exposes merge, open_pr, open_issue, reject",
task: {
status: "pr_open",
actions: ["merge", "open_pr", "open_issue", "reject"],
},
expected: ["merge", "open_pr", "open_issue", "reject"],
},
{
name: "terminal task exposes archive",
task: {
status: "merged",
actions: ["archive"],
},
expected: ["archive"],
},
];
for (const { name, task, expected } of cases) {
assert.deepEqual(headerActionIds(task), expected, name);
}
});