Files
archie/ui/src/tasks/TaskApproval.vue
T
sam 3915441cdf feat(workflow): approve a PRD as one structured document
The prd step returns the PRD as structured fields and human.approve takes
them as its document. The plan text every surface reads and the approval
card's layout are both rendered from that one document, so what the human
approves is what the implement workflow is handed. Replaces the separately
generated OpenUI view, which could drift from the plan.
2026-10-25 16:53:17 +11:00

105 lines
3.1 KiB
Vue

<script setup lang="ts">
import { computed, ref } from "vue";
import { ChevronDown } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Section } from "@/components/ui/section";
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
import PlanDocumentView from "./PlanDocument.vue";
import type { PlanDocument, TaskRecord } from "./task-run";
import type { Task } from "./task";
import TaskRowActions from "./TaskRowActions.vue";
/**
* The decision a task waiting on a plan asks for: the plan, and the two
* answers beside it. A long plan is held to a readable height until opened,
* so the decision stays in reach.
*/
const props = defineProps<{ task: TaskRecord }>();
const emit = defineEmits<{ done: [] }>();
const plan = computed(() => props.task.plan?.trim() ?? "");
// A plan written as a document is laid out from its fields; one that does not
// decode is shown as its text, which the server rendered from the same fields.
const doc = computed<PlanDocument | null>(() => {
try {
const parsed = JSON.parse(props.task.plan_document || "null");
return parsed?.problem && parsed?.solution ? parsed : null;
} catch {
return null;
}
});
// A plan's own heading names what is being decided; the card shows it once.
const heading = computed(
() =>
doc.value?.title?.trim() ||
(plan.value
.match(/^#{1,3}\s+(.+)$/m)?.[1]
?.replace(/[`*_]/g, "")
.trim() ??
""),
);
const body = computed(() =>
heading.value ? plan.value.replace(/^#{1,3}\s+.+$/m, "").trim() : plan.value,
);
const open = ref(false);
// A plan short enough to read whole is never folded.
const long = computed(() => body.value.length > 1200);
</script>
<template>
<Section
title="Approve the plan"
:description="heading || undefined"
class="mb-0 min-w-0 ring-1 ring-warn/40"
>
<template #action>
<div class="flex items-center gap-2">
<TaskRowActions
:task="task as Task"
:only="['reject']"
@done="emit('done')"
/>
<TaskRowActions
:task="task as Task"
:only="['approve']"
@done="emit('done')"
/>
</div>
</template>
<div class="mx-auto max-w-[75ch]">
<div class="relative">
<div
:class="[
'overflow-hidden text-sm leading-relaxed',
long && !open && 'max-h-96',
]"
>
<PlanDocumentView v-if="doc" :doc="doc" />
<ChatMarkdown v-else :text="body" />
</div>
<div
v-if="long && !open"
class="pointer-events-none absolute inset-x-0 bottom-0 h-20 bg-gradient-to-t from-card to-transparent"
/>
</div>
<Button
v-if="long"
variant="ghost"
size="sm"
class="mt-2"
:aria-expanded="open"
@click="open = !open"
>
{{ open ? "Collapse plan" : "Read the full plan" }}
<ChevronDown
:class="[
'size-4 transition-transform motion-reduce:transition-none',
open && 'rotate-180',
]"
/>
</Button>
</div>
</Section>
</template>