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.
This commit is contained in:
1 parent
7a03e003a1
commit
d699b9afba
37 files changed
+509
-1021
No files matched your search
@@ -1,42 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { createParser, Renderer, type OpenUIError } from "@openuidev/vue-lang";
|
||||
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { viewLibrary } from "./library";
|
||||
|
||||
/**
|
||||
* An agent's generated view, or its text when there is no view or the view
|
||||
* does not hold up: a parse that drops components or leaves references
|
||||
* dangling would show a partial answer as if it were whole.
|
||||
*/
|
||||
const props = defineProps<{ view?: string; text: string }>();
|
||||
|
||||
const parser = createParser(viewLibrary.toJSONSchema());
|
||||
const failed = ref(false);
|
||||
watch(
|
||||
() => props.view,
|
||||
() => (failed.value = false),
|
||||
);
|
||||
|
||||
const usable = computed(() => {
|
||||
const source = props.view?.trim();
|
||||
if (!source || failed.value) return false;
|
||||
const { root, meta } = parser.parse(source);
|
||||
return !!root && meta.errors.length === 0 && meta.unresolved.length === 0;
|
||||
});
|
||||
|
||||
function onError(errors: OpenUIError[]) {
|
||||
if (errors.length > 0) failed.value = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Renderer
|
||||
v-if="usable"
|
||||
:response="view ?? null"
|
||||
:library="viewLibrary"
|
||||
:on-error="onError"
|
||||
/>
|
||||
<ChatMarkdown v-else :text="text" />
|
||||
</template>
|
||||
@@ -1,6 +0,0 @@
|
||||
import type { Library } from "@openuidev/vue-lang";
|
||||
|
||||
import { viewRenderers } from "./renderers";
|
||||
import { viewLibrary as defineViewLibrary } from "./view-library";
|
||||
|
||||
export const viewLibrary = defineViewLibrary(viewRenderers) as Library;
|
||||
@@ -1,106 +0,0 @@
|
||||
import { defineComponent, h, type Component, type PropType } from "vue";
|
||||
import type { ElementNode, RenderNodeResult } from "@openuidev/vue-lang";
|
||||
|
||||
import CodeView from "@/base/CodeView.vue";
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import type { ViewRenderers } from "./view-library";
|
||||
|
||||
type Props = Record<string, any>;
|
||||
|
||||
// Every renderer receives the parsed props and renderNode. Props may be
|
||||
// partial while a view streams, so each reads them defensively.
|
||||
function renderer(
|
||||
name: string,
|
||||
render: (p: Props, renderNode: (v: unknown) => RenderNodeResult) => ReturnType<typeof h>,
|
||||
): Component {
|
||||
return defineComponent({
|
||||
name,
|
||||
props: {
|
||||
props: { type: Object as PropType<Props>, required: true },
|
||||
renderNode: { type: Function as PropType<(v: unknown) => RenderNodeResult>, required: true },
|
||||
},
|
||||
setup: (p) => () => render(p.props, p.renderNode),
|
||||
});
|
||||
}
|
||||
|
||||
// A list item's own props, read by the parent that lays the list out.
|
||||
function itemProps(items: unknown): Props[] {
|
||||
return Array.isArray(items)
|
||||
? items.filter((i): i is ElementNode => i?.type === "element").map((i) => i.props)
|
||||
: [];
|
||||
}
|
||||
|
||||
const strings = (v: unknown): string[] => (Array.isArray(v) ? v.map(String) : []);
|
||||
|
||||
const changeVariant = { added: "ok", modified: "info", deleted: "danger" } as const;
|
||||
|
||||
export const viewRenderers: ViewRenderers<Component> = {
|
||||
Stack: renderer("ViewStack", (p, r) =>
|
||||
h("div", { class: "flex min-w-0 flex-col gap-5" }, [r(p.children ?? [])]),
|
||||
),
|
||||
Section: renderer("ViewSection", (p, r) =>
|
||||
h("section", { class: "flex min-w-0 flex-col gap-2" }, [
|
||||
h("h3", { class: "text-title font-semibold" }, p.title),
|
||||
r(p.children ?? []),
|
||||
]),
|
||||
),
|
||||
Columns: renderer("ViewColumns", (p, r) =>
|
||||
h("div", { class: "grid gap-5 sm:grid-cols-[repeat(auto-fit,minmax(14rem,1fr))]" }, [r(p.children ?? [])]),
|
||||
),
|
||||
Heading: renderer("ViewHeading", (p) => h("h4", { class: "text-label font-semibold" }, p.text)),
|
||||
Text: renderer("ViewText", (p) =>
|
||||
h("div", { class: "text-sm leading-relaxed" }, h(ChatMarkdown, { text: p.markdown ?? "" })),
|
||||
),
|
||||
Callout: renderer("ViewCallout", (p) =>
|
||||
h(Alert, { variant: p.tone === "risk" ? "destructive" : p.tone === "warning" ? "warn" : "default" }, () => [
|
||||
h(AlertTitle, () => p.title),
|
||||
p.body ? h(AlertDescription, () => p.body) : null,
|
||||
]),
|
||||
),
|
||||
Facts: renderer("ViewFacts", (p) =>
|
||||
h(MetadataList, {
|
||||
rows: itemProps(p.items).map((f) => ({ label: String(f.label ?? ""), value: String(f.value ?? "") })),
|
||||
}),
|
||||
),
|
||||
Fact: renderer("ViewFact", (p) =>
|
||||
h(MetadataList, { rows: [{ label: String(p.label ?? ""), value: String(p.value ?? "") }] }),
|
||||
),
|
||||
Files: renderer("ViewFiles", (p) =>
|
||||
h("ul", { class: "flex flex-col gap-1.5 text-sm" }, itemProps(p.items).map((f) => fileRow(f))),
|
||||
),
|
||||
File: renderer("ViewFile", (p) => h("ul", { class: "text-sm" }, [fileRow(p)])),
|
||||
Checklist: renderer("ViewChecklist", (p) =>
|
||||
h("ul", { class: "list-disc space-y-1 pl-5 text-sm" }, strings(p.items).map((item) => h("li", item))),
|
||||
),
|
||||
Table: renderer("ViewTable", (p) =>
|
||||
h(Table, () => [
|
||||
h(TableHeader, () => h(TableRow, () => strings(p.columns).map((c) => h(TableHead, () => c)))),
|
||||
h(TableBody, () =>
|
||||
(Array.isArray(p.rows) ? p.rows : []).map((row: unknown) =>
|
||||
h(TableRow, () => strings(row).map((cell) => h(TableCell, () => cell))),
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
Code: renderer("ViewCode", (p) => h(CodeView, { code: p.code ?? "", lang: p.language })),
|
||||
};
|
||||
|
||||
function fileRow(f: Props) {
|
||||
const change = String(f.change ?? "") as keyof typeof changeVariant;
|
||||
return h("li", { class: "flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5" }, [
|
||||
h(Badge, { variant: changeVariant[change] ?? "idle" }, () => change),
|
||||
h("code", { class: "font-mono text-xs [overflow-wrap:anywhere]" }, f.path),
|
||||
f.note ? h("span", { class: "text-fg-muted" }, f.note) : null,
|
||||
]);
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
import {
|
||||
createLibrary,
|
||||
defineComponent,
|
||||
type Library,
|
||||
type PromptOptions,
|
||||
} from "@openuidev/lang-core";
|
||||
import { z } from "zod/v4";
|
||||
|
||||
/**
|
||||
* The components an agent may compose a view from. The schemas live here,
|
||||
* apart from the Vue renderers, so the agent prompt (generated in Node) and the
|
||||
* dashboard renderer are built from the same definitions.
|
||||
*/
|
||||
export interface ViewRenderers<C> {
|
||||
Stack: C;
|
||||
Section: C;
|
||||
Columns: C;
|
||||
Heading: C;
|
||||
Text: C;
|
||||
Callout: C;
|
||||
Facts: C;
|
||||
Fact: C;
|
||||
Files: C;
|
||||
File: C;
|
||||
Checklist: C;
|
||||
Table: C;
|
||||
Code: C;
|
||||
}
|
||||
|
||||
export function viewLibrary<C>(r: ViewRenderers<C>): Library<C> {
|
||||
const Heading = defineComponent({
|
||||
name: "Heading",
|
||||
description: "A short title for what follows.",
|
||||
props: z.object({ text: z.string() }),
|
||||
component: r.Heading,
|
||||
});
|
||||
const Text = defineComponent({
|
||||
name: "Text",
|
||||
description:
|
||||
"Prose in Markdown: paragraphs, lists, inline code, links. Use for explanation the other components cannot carry.",
|
||||
props: z.object({ markdown: z.string() }),
|
||||
component: r.Text,
|
||||
});
|
||||
const Callout = defineComponent({
|
||||
name: "Callout",
|
||||
description:
|
||||
"One point the reader must not miss: a risk, an open question, a caveat or a confirmation.",
|
||||
props: z.object({
|
||||
tone: z.enum(["info", "warning", "risk", "success"]),
|
||||
title: z.string(),
|
||||
body: z.string().optional(),
|
||||
}),
|
||||
component: r.Callout,
|
||||
});
|
||||
const Fact = defineComponent({
|
||||
name: "Fact",
|
||||
description: "One label and its short value.",
|
||||
props: z.object({ label: z.string(), value: z.string() }),
|
||||
component: r.Fact,
|
||||
});
|
||||
const Facts = defineComponent({
|
||||
name: "Facts",
|
||||
description:
|
||||
"Short label/value pairs read at a glance, e.g. estimated diff size, risk, scope.",
|
||||
props: z.object({ items: z.array(Fact.ref) }),
|
||||
component: r.Facts,
|
||||
});
|
||||
const File = defineComponent({
|
||||
name: "File",
|
||||
description: "One file and how the change touches it.",
|
||||
props: z.object({
|
||||
path: z.string(),
|
||||
change: z.enum(["added", "modified", "deleted"]),
|
||||
note: z.string().optional(),
|
||||
}),
|
||||
component: r.File,
|
||||
});
|
||||
const Files = defineComponent({
|
||||
name: "Files",
|
||||
description: "The files a change adds, modifies or deletes.",
|
||||
props: z.object({ items: z.array(File.ref) }),
|
||||
component: r.Files,
|
||||
});
|
||||
const Checklist = defineComponent({
|
||||
name: "Checklist",
|
||||
description: "Criteria or steps, each independently checkable.",
|
||||
props: z.object({ items: z.array(z.string()) }),
|
||||
component: r.Checklist,
|
||||
});
|
||||
const Table = defineComponent({
|
||||
name: "Table",
|
||||
description: "Rows that compare along the same columns.",
|
||||
props: z.object({
|
||||
columns: z.array(z.string()),
|
||||
rows: z.array(z.array(z.string())),
|
||||
}),
|
||||
component: r.Table,
|
||||
});
|
||||
const Code = defineComponent({
|
||||
name: "Code",
|
||||
description: "A code excerpt or proposed signature.",
|
||||
props: z.object({ code: z.string(), language: z.string().optional() }),
|
||||
component: r.Code,
|
||||
});
|
||||
|
||||
const block = z.union([
|
||||
Heading.ref,
|
||||
Text.ref,
|
||||
Callout.ref,
|
||||
Facts.ref,
|
||||
Files.ref,
|
||||
Checklist.ref,
|
||||
Table.ref,
|
||||
Code.ref,
|
||||
]);
|
||||
const Section = defineComponent({
|
||||
name: "Section",
|
||||
description: "A titled part of the view, e.g. Problem or Proposed solution.",
|
||||
props: z.object({ title: z.string(), children: z.array(block) }),
|
||||
component: r.Section,
|
||||
});
|
||||
const Columns = defineComponent({
|
||||
name: "Columns",
|
||||
description:
|
||||
"Two or three sections side by side, for content read in contrast, e.g. goals and non-goals.",
|
||||
props: z.object({ children: z.array(Section.ref) }),
|
||||
component: r.Columns,
|
||||
});
|
||||
const Stack = defineComponent({
|
||||
name: "Stack",
|
||||
description: "The view: its parts from top to bottom.",
|
||||
props: z.object({
|
||||
children: z.array(z.union([Section.ref, Columns.ref, block])),
|
||||
}),
|
||||
component: r.Stack,
|
||||
});
|
||||
|
||||
return createLibrary({
|
||||
root: "Stack",
|
||||
components: [
|
||||
Stack,
|
||||
Section,
|
||||
Columns,
|
||||
Heading,
|
||||
Text,
|
||||
Callout,
|
||||
Facts,
|
||||
Fact,
|
||||
Files,
|
||||
File,
|
||||
Checklist,
|
||||
Table,
|
||||
Code,
|
||||
],
|
||||
componentGroups: [
|
||||
{ name: "Layout", components: ["Stack", "Section", "Columns"] },
|
||||
{
|
||||
name: "Content",
|
||||
components: [
|
||||
"Heading",
|
||||
"Text",
|
||||
"Callout",
|
||||
"Facts",
|
||||
"Fact",
|
||||
"Files",
|
||||
"File",
|
||||
"Checklist",
|
||||
"Table",
|
||||
"Code",
|
||||
],
|
||||
notes: [
|
||||
"- Prefer Facts, Files, Checklist and Table to prose; use Text only for explanation.",
|
||||
"- Define each Section and each list item as its own line so the view streams.",
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
export const viewPromptOptions: PromptOptions = {
|
||||
preamble:
|
||||
"Besides your text answer, return a view of it with the `view` tool: an OpenUI Lang program the dashboard renders for the human reading your work. It presents the same content as the text, laid out for a quick decision; it never says anything the text does not.",
|
||||
additionalRules: [
|
||||
"The view holds only OpenUI Lang: no Markdown fences, no commentary.",
|
||||
"Lead with what the reader decides on; put supporting detail after it.",
|
||||
],
|
||||
examples: [
|
||||
`root = Stack([facts, problem, solution, scope, risk])
|
||||
facts = Facts([f1, f2])
|
||||
f1 = Fact("Estimated diff", "~40 lines")
|
||||
f2 = Fact("Risk", "Low")
|
||||
problem = Section("Problem", [problemText])
|
||||
problemText = Text("Callers compute percentages by hand; \`calc\` has no helper.")
|
||||
solution = Section("Proposed solution", [solutionText, sig, files])
|
||||
solutionText = Text("Add one exported function to \`calc/calc.go\`.")
|
||||
sig = Code("func Percent(part, whole int) (int, error)", "go")
|
||||
files = Files([file1, file2])
|
||||
file1 = File("calc/calc.go", "modified", "adds Percent")
|
||||
file2 = File("calc/calc_test.go", "modified")
|
||||
scope = Columns([accept, nongoals])
|
||||
accept = Section("Acceptance criteria", [acceptList])
|
||||
acceptList = Checklist(["Percent(1, 4) returns 25", "A zero whole returns an error"])
|
||||
nongoals = Section("Non-goals", [nongoalList])
|
||||
nongoalList = Checklist(["Floating-point percentages"])
|
||||
risk = Callout("info", "No existing callers change")`,
|
||||
],
|
||||
};
|
||||
@@ -0,0 +1,75 @@
|
||||
<script setup lang="ts">
|
||||
import ChatMarkdown from "@/chat/ChatMarkdown.vue";
|
||||
import { Alert, AlertTitle } from "@/components/ui/alert";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import type { PlanDocument } from "./task-run";
|
||||
|
||||
/**
|
||||
* A plan written as structured fields, laid out for a decision. The plan text
|
||||
* the next workflow reads is rendered from the same fields on the server.
|
||||
*/
|
||||
defineProps<{ doc: PlanDocument }>();
|
||||
|
||||
const changeVariant: Record<string, "ok" | "info" | "danger"> = {
|
||||
added: "ok",
|
||||
modified: "info",
|
||||
deleted: "danger",
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex min-w-0 flex-col gap-5">
|
||||
<MetadataList
|
||||
v-if="doc.diff_estimate"
|
||||
:rows="[{ label: 'Estimated diff', value: doc.diff_estimate }]"
|
||||
/>
|
||||
|
||||
<Alert v-if="doc.risks?.length" variant="warn">
|
||||
<AlertTitle>Risks</AlertTitle>
|
||||
<ul class="list-disc space-y-1 pl-5 text-sm">
|
||||
<li v-for="(risk, i) in doc.risks" :key="i">{{ risk }}</li>
|
||||
</ul>
|
||||
</Alert>
|
||||
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h3 class="text-title font-semibold">Problem</h3>
|
||||
<ChatMarkdown :text="doc.problem" />
|
||||
</section>
|
||||
|
||||
<section class="flex min-w-0 flex-col gap-2">
|
||||
<h3 class="text-title font-semibold">Proposed solution</h3>
|
||||
<ChatMarkdown :text="doc.solution" />
|
||||
</section>
|
||||
|
||||
<section v-if="doc.files?.length" class="flex min-w-0 flex-col gap-2">
|
||||
<h3 class="text-title font-semibold">Files</h3>
|
||||
<ul class="flex flex-col gap-1.5 text-sm">
|
||||
<li
|
||||
v-for="file in doc.files"
|
||||
:key="file.path"
|
||||
class="flex min-w-0 flex-wrap items-baseline gap-x-2 gap-y-0.5"
|
||||
>
|
||||
<Badge :variant="changeVariant[file.change] ?? 'idle'">{{ file.change }}</Badge>
|
||||
<code class="font-mono text-xs [overflow-wrap:anywhere]">{{ file.path }}</code>
|
||||
<span v-if="file.note" class="text-fg-muted">{{ file.note }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<div class="grid gap-5 sm:grid-cols-2">
|
||||
<section v-if="doc.acceptance?.length" class="flex min-w-0 flex-col gap-2">
|
||||
<h3 class="text-title font-semibold">Acceptance criteria</h3>
|
||||
<ul class="list-disc space-y-1 pl-5 text-sm">
|
||||
<li v-for="(item, i) in doc.acceptance" :key="i">{{ item }}</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section v-if="doc.non_goals?.length" class="flex min-w-0 flex-col gap-2">
|
||||
<h3 class="text-title font-semibold">Non-goals</h3>
|
||||
<ul class="list-disc space-y-1 pl-5 text-sm">
|
||||
<li v-for="(item, i) in doc.non_goals" :key="i">{{ item }}</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -4,8 +4,9 @@ import { ChevronDown } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import GeneratedView from "@/genui/GeneratedView.vue";
|
||||
import type { TaskRecord } from "./task-run";
|
||||
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";
|
||||
|
||||
@@ -18,13 +19,25 @@ 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(
|
||||
() =>
|
||||
plan.value
|
||||
doc.value?.title?.trim() ||
|
||||
(plan.value
|
||||
.match(/^#{1,3}\s+(.+)$/m)?.[1]
|
||||
?.replace(/[`*_]/g, "")
|
||||
.trim() ?? "",
|
||||
.trim() ??
|
||||
""),
|
||||
);
|
||||
const body = computed(() =>
|
||||
heading.value ? plan.value.replace(/^#{1,3}\s+.+$/m, "").trim() : plan.value,
|
||||
@@ -62,7 +75,8 @@ const long = computed(() => body.value.length > 1200);
|
||||
long && !open && 'max-h-96',
|
||||
]"
|
||||
>
|
||||
<GeneratedView :view="task.plan_view" :text="body" />
|
||||
<PlanDocumentView v-if="doc" :doc="doc" />
|
||||
<ChatMarkdown v-else :text="body" />
|
||||
</div>
|
||||
<div
|
||||
v-if="long && !open"
|
||||
|
||||
@@ -57,8 +57,8 @@ export interface TaskRecord {
|
||||
actions?: string[];
|
||||
review_gate?: string;
|
||||
plan?: string;
|
||||
/** An OpenUI Lang view of the plan; the plan text stands in when it does not render. */
|
||||
plan_view?: string;
|
||||
/** The structured plan (JSON) the plan text was rendered from. */
|
||||
plan_document?: string;
|
||||
/** What a task waiting for approval asks: "plan" or "review". */
|
||||
approval?: string;
|
||||
rereview_rounds?: number;
|
||||
@@ -235,3 +235,15 @@ export function logCacheKey(
|
||||
applied.stage || "",
|
||||
].join("|");
|
||||
}
|
||||
|
||||
/** A plan written as structured fields; the server renders the plan text from it. */
|
||||
export interface PlanDocument {
|
||||
title?: string;
|
||||
problem: string;
|
||||
solution: string;
|
||||
files?: { path: string; change: string; note?: string }[];
|
||||
acceptance?: string[];
|
||||
non_goals?: string[];
|
||||
diff_estimate?: string;
|
||||
risks?: string[];
|
||||
}
|
||||
Reference in new issue
Block a user