461 lines
15 KiB
Vue
461 lines
15 KiB
Vue
<script setup lang="ts">
|
|
import { Ellipsis } from "@lucide/vue";
|
|
import { computed, ref } from "vue";
|
|
import { useRouter } from "vue-router";
|
|
import { RadioGroupItem, RadioGroupRoot } from "reka-ui";
|
|
|
|
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import {
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from "@/components/ui/dropdown-menu";
|
|
import { Label } from "@/components/ui/label";
|
|
import { Textarea } from "@/components/ui/textarea";
|
|
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
|
|
import { actionFor, retryModes, type ActionMeta } from "@/lib/task-meta";
|
|
import type { Task } from "./TaskRow.vue";
|
|
import { shownActionIds } from "./task-actions";
|
|
import { reviewGateOffer } from "./review-gate";
|
|
import {
|
|
initialRetryChoice,
|
|
retryChoices,
|
|
retryPayload,
|
|
} from "./retry-mode";
|
|
|
|
/**
|
|
* The lifecycle controls for one task. A task offers whatever the server says
|
|
* it offers, so the decisions here are presentation only: which variant a
|
|
* control wears, whether it needs confirming, and how a refusal reads. A
|
|
* caller may narrow the list to the controls it has room for (`only`), and
|
|
* narrowing can only remove -- see task-actions.ts.
|
|
*/
|
|
|
|
/** A control with its forge target already resolved. */
|
|
interface Control {
|
|
id: string;
|
|
label: string;
|
|
kind: string;
|
|
confirm?: string;
|
|
href: string;
|
|
}
|
|
|
|
type ControlVariant = "default" | "ghost" | "destructive";
|
|
|
|
const props = defineProps<{
|
|
task: Task;
|
|
/** Render only these action ids, still only if the server offered them. */
|
|
only?: string[];
|
|
findings?: string[];
|
|
}>();
|
|
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
|
|
|
const router = useRouter();
|
|
const gate = computed(() => props.task.status === "waiting_human" ? reviewGateOffer(props.task.review_gate) : null);
|
|
// An empty selection means all findings to the server.
|
|
const approveDisabled = computed(() => !!gate.value && props.findings?.length === 0);
|
|
const inFlight = ref(false);
|
|
const error = ref<{ kind: ActionErrorKind; message: string } | null>(null);
|
|
|
|
// The dialog's open flag and the action it will run are two refs, not one:
|
|
// pressing the dialog's action closes it, and that close clears the open flag
|
|
// before the action's own handler reads it.
|
|
const confirming = ref<string | null>(null);
|
|
const confirmingId = ref<string | null>(null);
|
|
|
|
// A re-review carries instructions the plain confirm dialog cannot collect
|
|
// (docs/prds/pr-review-operator-response.md, Decision 1), and the server
|
|
// refuses a re-review without them, so it opens a dialog of its own.
|
|
const rereviewOpen = ref(false);
|
|
const rereviewId = ref<string | null>(null);
|
|
const instructions = ref("");
|
|
|
|
// A retry carries the operator's worktree mode (taskstate.RetryMode). The
|
|
// dialog opens on the task's persisted choice -- so a remediation retry keeps
|
|
// continuing its branch -- and the operator may pick the other mode. The
|
|
// chosen value travels in the action body and is persisted on the task.
|
|
const retryOpen = ref(false);
|
|
const retryId = ref<string | null>(null);
|
|
const retryMode = ref("");
|
|
const retryOptions = computed(() =>
|
|
retryChoices(retryModes(), props.task.branch),
|
|
);
|
|
|
|
const controls = computed<Control[]>(() =>
|
|
shownActionIds(props.task.actions, props.only)
|
|
.map((id) => actionFor(id))
|
|
.filter((meta): meta is ActionMeta => meta !== null)
|
|
.map((meta) => ({
|
|
...meta,
|
|
href: meta.kind === "link" ? forgeLink(meta.id) : "",
|
|
})),
|
|
);
|
|
|
|
//
|
|
// One primary plus overflow: a server-declared action list can hold seven
|
|
// controls and two forge links, and a row that shows all of them as buttons in
|
|
// one line is unreadable. So the first non-link control keeps a visible button
|
|
// of its own; every other non-link control folds behind a '···' menu that runs
|
|
// the identical request path, and the forge links stay inline after the
|
|
// primary because they navigate rather than act.
|
|
const nonLinkControls = computed<Control[]>(() =>
|
|
controls.value.filter((c) => c.kind !== "link"),
|
|
);
|
|
const primaryControl = computed<Control | null>(
|
|
() => nonLinkControls.value[0] ?? null,
|
|
);
|
|
const overflowControls = computed<Control[]>(() =>
|
|
nonLinkControls.value.slice(1),
|
|
);
|
|
const linkControls = computed<Control[]>(() =>
|
|
controls.value.filter((c) => c.kind === "link"),
|
|
);
|
|
|
|
const menuOpen = ref(false);
|
|
|
|
const confirmingMeta = computed(() =>
|
|
confirmingId.value ? actionFor(confirmingId.value) : null,
|
|
);
|
|
const confirmText = computed(() =>
|
|
confirmingMeta.value?.confirm
|
|
? confirmingMeta.value.confirm.replaceAll(
|
|
"{title}",
|
|
props.task.title || "this task",
|
|
)
|
|
: "",
|
|
);
|
|
const confirmLabel = computed(() => confirmingMeta.value?.label || "Confirm");
|
|
|
|
// A refused action ("you can't do that" -- bad input, a conflicting task state)
|
|
// is the operator's to correct; a broken one (5xx, network drop, timeout) is
|
|
// the daemon's, and says so. Authentication failures are surfaced by the app
|
|
// shell because they affect every request, not only this row.
|
|
const errorText = computed(() => {
|
|
if (!error.value) return "";
|
|
if (error.value.kind === "session-expired")
|
|
return "Dashboard authentication is required.";
|
|
if (error.value.kind === "refused")
|
|
return `${error.value.message} — you can't do that.`;
|
|
return `${error.value.message} — try again, or check the daemon.`;
|
|
});
|
|
|
|
// A link control points at the forge artefact the action names. Chat-sourced
|
|
// work has no issue on a forge, and a task that never opened a pull request has
|
|
// no PR to point at, so the control is disabled rather than a dead link.
|
|
function forgeLink(id: string): string {
|
|
if (id === "open_pr") {
|
|
return props.task.pr_url && props.task.pr_number ? props.task.pr_url : "";
|
|
}
|
|
if (id === "open_issue") {
|
|
if (props.task.source === "chat" || !props.task.issue_number) return "";
|
|
return props.task.issue_url ?? "";
|
|
}
|
|
return "";
|
|
}
|
|
|
|
function variantFor(kind: string): ControlVariant {
|
|
if (kind === "quiet") return "ghost";
|
|
if (kind === "danger") return "destructive";
|
|
return "default";
|
|
}
|
|
|
|
// A control that names a consequence is confirmed first; the two that only open
|
|
// a forge page are not, because they change nothing. A re-review needs
|
|
// instructions, which its own dialog collects; a retry needs a worktree mode,
|
|
// which its own dialog collects.
|
|
function request(id: string) {
|
|
error.value = null;
|
|
if (id === "approve" && gate.value && props.findings === undefined) {
|
|
void router.push(`/tasks/${props.task.id}`);
|
|
return;
|
|
}
|
|
if (id === "rereview") {
|
|
rereviewId.value = id;
|
|
rereviewOpen.value = true;
|
|
return;
|
|
}
|
|
if (id === "retry") {
|
|
retryId.value = id;
|
|
retryMode.value = initialRetryChoice(
|
|
retryOptions.value,
|
|
props.task.retry_mode,
|
|
);
|
|
retryOpen.value = true;
|
|
return;
|
|
}
|
|
if (actionFor(id)?.confirm) {
|
|
confirmingId.value = id;
|
|
confirming.value = id;
|
|
return;
|
|
}
|
|
void run(id);
|
|
}
|
|
|
|
async function run(
|
|
id: string,
|
|
payload?: { instructions?: string; retry_mode?: string; findings?: string[] },
|
|
) {
|
|
if (id === "approve" && gate.value) {
|
|
if (!props.findings?.length) return;
|
|
payload = { ...payload, findings: props.findings };
|
|
}
|
|
confirming.value = null;
|
|
inFlight.value = true;
|
|
error.value = null;
|
|
try {
|
|
// The route path and the API both address a task by string; the list serves
|
|
// ids as numbers, so the row's own id is narrowed once, here.
|
|
await api.taskAction(String(props.task.id), id, payload);
|
|
emit("done", props.task.id);
|
|
} catch (err) {
|
|
error.value = classifyActionError(err);
|
|
} finally {
|
|
inFlight.value = false;
|
|
}
|
|
}
|
|
|
|
function onRereviewOpen(open: boolean) {
|
|
rereviewOpen.value = open;
|
|
if (!open) instructions.value = "";
|
|
}
|
|
|
|
function submitRereview() {
|
|
const id = rereviewId.value;
|
|
const text = instructions.value.trim();
|
|
if (!id || !text) return;
|
|
rereviewOpen.value = false;
|
|
void run(id, { instructions: text });
|
|
}
|
|
|
|
function onRetryOpen(open: boolean) {
|
|
retryOpen.value = open;
|
|
}
|
|
|
|
function submitRetry() {
|
|
const id = retryId.value;
|
|
if (!id || !retryMode.value) return;
|
|
retryOpen.value = false;
|
|
void run(id, retryPayload(retryMode.value));
|
|
}
|
|
|
|
function onConfirmationOpen(open: boolean) {
|
|
if (!open) confirming.value = null;
|
|
}
|
|
|
|
// A menu item must close its menu before the dialog can take focus, so both
|
|
// surfaces funnel through the same request() once the menu is down; the
|
|
// inFlight disabling and the error handling stay identical either way.
|
|
function requestFromMenu(id: string) {
|
|
menuOpen.value = false;
|
|
request(id);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-col items-end gap-1">
|
|
<Alert
|
|
v-if="error"
|
|
variant="destructive"
|
|
class="w-56 gap-0.5 px-2 py-1.5 text-xs whitespace-normal"
|
|
>
|
|
<AlertTitle v-if="error.kind === 'session-expired'" class="text-xs"
|
|
>Authentication required</AlertTitle
|
|
>
|
|
<AlertDescription class="text-xs">{{ errorText }}</AlertDescription>
|
|
</Alert>
|
|
|
|
<!--
|
|
One line, never wrapped: three controls on two lines doubled the height of
|
|
every actionable row. The one-primary-plus-overflow rule (see the script)
|
|
keeps the line short; keystrokes stop at this container rather than
|
|
bubbling to the row, which would open the task as well as press the
|
|
button.
|
|
-->
|
|
<div class="flex items-center gap-1" @keydown.stop>
|
|
<Button
|
|
v-if="primaryControl"
|
|
:variant="variantFor(primaryControl.kind)"
|
|
size="sm"
|
|
:disabled="inFlight || (primaryControl.id === 'approve' && approveDisabled)"
|
|
@click.stop="request(primaryControl.id)"
|
|
>
|
|
{{ primaryControl.label }}
|
|
</Button>
|
|
|
|
<template v-for="control in linkControls" :key="control.id">
|
|
<Button v-if="control.href" as-child variant="ghost" size="sm">
|
|
<a
|
|
:href="control.href"
|
|
target="_blank"
|
|
rel="noreferrer"
|
|
@click.stop
|
|
>{{ control.label }}</a
|
|
>
|
|
</Button>
|
|
<Button
|
|
v-else
|
|
variant="ghost"
|
|
size="sm"
|
|
disabled
|
|
:title="`${control.label} is unavailable`"
|
|
>
|
|
{{ control.label }}
|
|
</Button>
|
|
</template>
|
|
|
|
<DropdownMenu v-if="overflowControls.length" v-model:open="menuOpen">
|
|
<DropdownMenuTrigger as-child>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon-sm"
|
|
aria-label="More actions"
|
|
:disabled="inFlight"
|
|
@click.stop
|
|
>
|
|
<Ellipsis :size="14" />
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end">
|
|
<DropdownMenuItem
|
|
v-for="control in overflowControls"
|
|
:key="control.id"
|
|
:variant="control.kind === 'danger' ? 'destructive' : 'default'"
|
|
:disabled="inFlight || (control.id === 'approve' && approveDisabled)"
|
|
@click.stop="requestFromMenu(control.id)"
|
|
>
|
|
{{ control.label }}
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
|
|
<Dialog :open="rereviewOpen" @update:open="onRereviewOpen">
|
|
<DialogContent class="sm:max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle>Re-review this pull request?</DialogTitle>
|
|
<DialogDescription>
|
|
The review phases run again with your instructions. Two re-reviews
|
|
are allowed; this is
|
|
{{ props.task.rereview_rounds ? "the next" : "the first" }} one.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<div class="flex flex-col gap-2">
|
|
<Label for="review-instructions"
|
|
>What should the reviewers focus on?</Label
|
|
>
|
|
<Textarea
|
|
id="review-instructions"
|
|
v-model="instructions"
|
|
class="min-h-24"
|
|
placeholder="e.g. check the migration ordering and the SQL path"
|
|
:disabled="inFlight"
|
|
/>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="ghost" :disabled="inFlight" @click="onRereviewOpen(false)">
|
|
Keep waiting
|
|
</Button>
|
|
<Button
|
|
:disabled="inFlight || !instructions.trim()"
|
|
@click="submitRereview"
|
|
>
|
|
Re-review
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
<!--
|
|
A retry opens this dialog rather than firing immediately: the operator
|
|
picks where the retry starts (taskstate.RetryMode), the choice rides the
|
|
action body and is persisted on the task, and the daemon's worktree
|
|
preparation reads it. Preselecting the task's persisted mode keeps a
|
|
remediation retry continuing its branch.
|
|
-->
|
|
<Dialog :open="retryOpen" @update:open="onRetryOpen">
|
|
<DialogContent class="sm:max-w-lg">
|
|
<DialogHeader>
|
|
<DialogTitle>Retry this task?</DialogTitle>
|
|
<DialogDescription>
|
|
Choose where the retry starts. The mode is saved on the task and
|
|
the daemon prepares the worktree from it.
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<RadioGroupRoot
|
|
v-model="retryMode"
|
|
class="grid grid-cols-1 gap-2"
|
|
aria-label="Retry worktree mode"
|
|
loop
|
|
>
|
|
<label
|
|
v-for="option in retryOptions"
|
|
:key="option.id"
|
|
class="flex items-start gap-3 rounded-md border border-border bg-card px-3 py-2.5 text-left transition-colors"
|
|
:class="
|
|
option.disabled
|
|
? 'cursor-not-allowed opacity-60'
|
|
: 'cursor-pointer hover:bg-secondary'
|
|
"
|
|
>
|
|
<RadioGroupItem
|
|
:value="option.id"
|
|
:disabled="option.disabled || inFlight"
|
|
class="mt-0.5 shrink-0"
|
|
/>
|
|
<span class="grid gap-0.5">
|
|
<span class="text-[13px] font-medium">{{ option.label }}</span>
|
|
<span class="text-xs text-fg-subtle">{{ option.description }}</span>
|
|
</span>
|
|
</label>
|
|
</RadioGroupRoot>
|
|
<DialogFooter>
|
|
<Button variant="ghost" :disabled="inFlight" @click="onRetryOpen(false)">
|
|
Keep it parked
|
|
</Button>
|
|
<Button :disabled="inFlight || !retryMode" @click="submitRetry">
|
|
Retry
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
|
|
<AlertDialog :open="confirming !== null" @update:open="onConfirmationOpen">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>{{ confirmLabel }} this task?</AlertDialogTitle>
|
|
<AlertDialogDescription>{{ confirmText }}</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Keep it</AlertDialogCancel>
|
|
<AlertDialogAction
|
|
:variant="variantFor(confirmingMeta?.kind ?? '')"
|
|
@click="confirmingId && run(confirmingId)"
|
|
>
|
|
{{ confirmLabel }}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
</template>
|