feat(ui): replace the drafts page with proposals (#1995)

This commit is contained in:
sam committed 2026-11-24 02:44:31 +11:00
1 parent b47e98e25f
commit 2ae793cc94
5 files changed
+385

No files matched your search

+74
View File
@@ -192,6 +192,22 @@ export const api = {
request<Run>(`/api/runs/${encodeURIComponent(id)}/retry`, { method: "POST", body: from ? { from } : {} }),
/** Asks a run that has not ended to stop, along with the runs it called. */
cancelRun: (id: string) => request<Run>(`/api/runs/${encodeURIComponent(id)}/cancel`, { method: "POST", body: {} }),
proposals: (state?: ProposalState) => request<Proposal[]>("/api/proposals" + qs({ state })),
proposal: (id: string) => request<Proposal>(`/api/proposals/${encodeURIComponent(id)}`),
/** Approves a proposal and the actions it lists; the server applies it. */
approveProposal: (id: string, assertion?: ApprovalAssertion) =>
request<Proposal>(`/api/proposals/${encodeURIComponent(id)}/approve`, { method: "POST", body: { assertion } }),
rejectProposal: (id: string, reason: string) =>
request<Proposal>(`/api/proposals/${encodeURIComponent(id)}/reject`, { method: "POST", body: { reason } }),
/** Starts the passkey confirmation that approving an irreversible action needs. */
beginProposalConfirmation: (id: string) =>
request<ApprovalConfirmation>(`/api/proposals/${encodeURIComponent(id)}/confirmation`, { method: "POST", body: {} }),
/** Replays a stored event, the newest by default, against a trigger proposal. */
dryRunProposal: (id: string, eventId?: string) =>
request<Proposal>(`/api/proposals/${encodeURIComponent(id)}/dry-run`, { method: "POST", body: eventId ? { event_id: eventId } : {} }),
/** Proposes a trigger and workflow for a group of unmatched events. */
proposeForGroup: (groupId: string) =>
request<Proposal>(`/api/groups/${encodeURIComponent(groupId)}/proposal`, { method: "POST", body: {} }),
approvals: () => request<Approval[]>("/api/approvals"),
answerApproval: (id: string, approved: boolean, assertion?: ApprovalAssertion) =>
request<Approval>(`/api/approvals/${encodeURIComponent(id)}/answer`, { method: "POST", body: { approved, assertion } }),
@@ -846,6 +862,64 @@ export interface Bootstrap {
sealing_identity_set: boolean;
}
export type ProposalState = "pending" | "approved" | "rejected" | "published" | "superseded" | "withdrawn";
export interface ProposalAction {
seq: number;
connector: string;
action: string;
target_kind: string;
target_id: string;
input: unknown;
decision_id: string;
/** How far judgement lets the action run, as shown when it was proposed. */
level?: string;
reason?: string;
refused_by?: string;
verdicts?: { guard: string; ceiling: string; findings?: { text: string }[]; failed?: string }[];
state: "pending" | "ran" | "failed" | "unknown" | "refused" | "skipped";
outcome?: string;
settled_at?: string;
}
export interface ProposalTrigger {
group_id: string;
name: string;
source_id: string;
event_type: string;
filter: Record<string, string>;
workflow: string;
policy_kind: "hard_rules" | "change_request";
policy: string;
dry_run?: { run_id: string; state: string; error?: string; findings?: string; actions: { action: string; target: string; level: string; outcome: string; why?: string }[] };
dry_event_id?: string;
installed_version?: number;
}
export interface Proposal {
id: string;
kind: "root_cause_fix" | "trigger" | "workflow_change" | "ceiling_raise" | "policy_change";
state: ProposalState;
/** Who must approve: the owner, or a person with authority over policies. */
needs: "owner" | "authority";
title: string;
summary: string;
evidence: unknown;
change?: unknown;
trigger?: ProposalTrigger;
target_kind: string;
target_id?: string;
actions: ProposalAction[];
prompted_by: string[];
run_id?: string;
proposed_by_id: string;
created_at: string;
answered_by_id?: string;
answered_at?: string;
answer_reason?: string;
published_at?: string;
}
export interface ApprovalConfirmation {
token: string;
options: { publicKey: Record<string, unknown> };
+167
View File
@@ -0,0 +1,167 @@
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { RouterLink, useRoute } from "vue-router";
import CodeView from "@/base/CodeView.vue";
import PageHeader from "@/base/PageHeader.vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { CodeBlockCopyButton } from "@/components/ui/code-block";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { MetadataList } from "@/components/ui/metadata-list";
import { ReadError } from "@/components/ui/read-error";
import { Section } from "@/components/ui/section";
import { Skeleton } from "@/components/ui/skeleton";
import { Textarea } from "@/components/ui/textarea";
import { Timestamp } from "@/components/ui/timestamp";
import { errors } from "@/copy/errors";
import { api, describeError } from "@/lib/api";
import { emptyValue } from "@/lib/format";
import { usePoll, useRead } from "@/lib/use-read";
import { useLiveResource } from "@/stores/session";
import { stateLabel, stateTone } from "@/runs/state";
import { actionTone, approveProposal, kindLabel, proposalTone } from "./state";
/** A proposal with its evidence, the actions it will take and how each was
* judged, and the answer that approves or rejects it. */
const route = useRoute();
const id = String(route.params.id);
const { data, error, reload } = useRead(() => api.proposal(id));
onMounted(reload);
useLiveResource(null, () => void reload());
usePoll(() => {
if (data.value && (data.value.state === "pending" || data.value.state === "approved")) void reload();
});
const pending = computed(() => data.value?.state === "pending");
const details = computed(() => {
const p = data.value;
if (!p) return [];
return [
{ label: "Kind", value: kindLabel(p.kind) },
{ label: "Approval", value: p.needs === "authority" ? "A person with authority over policies" : "The owner" },
...(p.target_id ? [{ label: "Target", value: `${p.target_kind} ${p.target_id}` }] : []),
{ label: "Proposed by", value: p.proposed_by_id, mono: true },
...(p.answered_by_id ? [{ label: p.state === "rejected" ? "Rejected by" : "Approved by", value: p.answered_by_id, mono: true }] : []),
...(p.answer_reason ? [{ label: "Reason", value: p.answer_reason }] : []),
{ label: "Proposal", value: p.id, mono: true },
];
});
const evidence = computed(() => (data.value && !emptyValue(data.value.evidence) ? JSON.stringify(data.value.evidence, null, 2) : ""));
const change = computed(() => (data.value && !emptyValue(data.value.change) ? JSON.stringify(data.value.change, null, 2) : ""));
const busy = ref(false);
const actionError = ref("");
async function act(work: () => Promise<unknown>): Promise<void> {
busy.value = true;
actionError.value = "";
try {
await work();
} catch (cause) {
actionError.value = describeError(cause, errors.common.unknown);
} finally {
busy.value = false;
await reload();
}
}
const approve = () => act(() => approveProposal(id));
const dryRun = () => act(() => api.dryRunProposal(id));
const rejecting = ref(false);
const reason = ref("");
async function reject(): Promise<void> {
await act(() => api.rejectProposal(id, reason.value.trim()));
if (!actionError.value) rejecting.value = false;
}
</script>
<template>
<div>
<PageHeader :title="data ? data.title : 'Proposal'">
<Badge v-if="data" :variant="proposalTone(data.state)">{{ data.state }}</Badge>
<span v-if="data" class="text-caption text-fg-muted">Proposed <Timestamp :at="data.created_at" /></span>
<Button v-if="pending" variant="outline" size="sm" :disabled="busy" @click="rejecting = true">Reject</Button>
<Button v-if="pending" size="sm" :disabled="busy" @click="approve">Approve</Button>
</PageHeader>
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
<div v-else-if="!data" role="status" aria-label="Loading proposal" class="space-y-2"><Skeleton class="h-24 w-full" /><Skeleton class="h-48 w-full" /></div>
<template v-else>
<p v-if="actionError" role="alert" class="mb-2 text-caption text-danger">{{ actionError }}</p>
<Section title="Summary">
<p class="mb-3 text-label whitespace-pre-wrap">{{ data.summary }}</p>
<MetadataList :rows="details">
<template #value="{ row }">
<span v-if="row.label === 'Proposal'" class="inline-flex items-center gap-1">{{ row.value }}<CodeBlockCopyButton :value="row.value ?? ''" /></span>
<template v-else>{{ row.value }}</template>
</template>
</MetadataList>
</Section>
<Section v-if="evidence" title="Evidence"><CodeView :code="evidence" /></Section>
<Section v-if="data.trigger" title="Trigger">
<MetadataList
:rows="[
{ label: 'Name', value: data.trigger.name },
{ label: 'Source', value: data.trigger.source_id },
{ label: 'Event type', value: data.trigger.event_type },
...Object.entries(data.trigger.filter ?? {}).map(([k, v]) => ({ label: k, value: v })),
]"
/>
<CodeView class="mt-3" :code="data.trigger.workflow" />
<CodeView v-if="data.trigger.policy" class="mt-3" :code="data.trigger.policy" />
</Section>
<Section v-if="data.trigger" title="Dry run">
<template v-if="pending" #action><Button variant="outline" size="sm" :disabled="busy" @click="dryRun">Test on an event</Button></template>
<template v-if="data.trigger.dry_run">
<div class="flex flex-wrap items-center gap-2">
<Badge :variant="stateTone(data.trigger.dry_run.state)">{{ stateLabel(data.trigger.dry_run.state) }}</Badge>
<RouterLink class="text-caption underline" :to="`/runs/${data.trigger.dry_run.run_id}`">Run</RouterLink>
</div>
<p v-if="data.trigger.dry_run.error" class="mt-2 text-caption text-danger">{{ data.trigger.dry_run.error }}</p>
<p v-if="data.trigger.dry_run.findings" class="mt-2 text-label whitespace-pre-wrap">{{ data.trigger.dry_run.findings }}</p>
<ul v-if="data.trigger.dry_run.actions.length" class="mt-2 divide-y divide-border">
<li v-for="a in data.trigger.dry_run.actions" :key="a.action + a.target" class="py-2 text-caption">
<span class="font-mono text-label">{{ a.action }}</span> on {{ a.target }}: {{ a.outcome }}<template v-if="a.why"> ({{ a.why }})</template>
</li>
</ul>
</template>
<Empty v-else><EmptyHeader><EmptyTitle>Not tested</EmptyTitle></EmptyHeader></Empty>
</Section>
<Section v-if="change" title="Change"><CodeView :code="change" /></Section>
<Section v-if="data.actions.length" title="Actions">
<ol class="divide-y divide-border">
<li v-for="action in data.actions" :key="action.seq" class="space-y-1 py-3">
<div class="flex flex-wrap items-center gap-2">
<span class="font-mono text-label">{{ action.connector }}.{{ action.action }}</span>
<span v-if="action.target_id" class="text-caption text-fg-muted">{{ action.target_kind }} {{ action.target_id }}</span>
<Badge v-if="action.level" variant="outline">{{ stateLabel(action.level) }}</Badge>
<Badge v-if="action.refused_by" variant="danger">Refused by {{ action.refused_by }}</Badge>
<Badge v-if="data.state !== 'pending' && data.state !== 'rejected'" :variant="actionTone(action.state)">{{ action.state }}</Badge>
</div>
<p v-if="action.reason" class="text-caption text-fg-muted">{{ action.reason }}</p>
<ul v-if="action.verdicts?.length" class="text-caption text-fg-muted">
<li v-for="v in action.verdicts" :key="v.guard">
<span class="font-mono">{{ v.guard }}</span>: {{ stateLabel(v.ceiling) }}<template v-if="v.findings?.length"> ({{ v.findings.map((f) => f.text).join("; ") }})</template><template v-if="v.failed">, failed: {{ v.failed }}</template>
</li>
</ul>
<CodeView :code="JSON.stringify(action.input, null, 2)" />
<p v-if="action.outcome" class="text-caption" :class="action.state === 'ran' ? 'text-fg-muted' : 'text-danger'">{{ action.outcome }}</p>
</li>
</ol>
</Section>
<p v-if="data.run_id" class="text-caption"><RouterLink class="underline" :to="`/runs/${data.run_id}`">Run that takes the actions</RouterLink></p>
</template>
<Dialog v-model:open="rejecting">
<DialogContent>
<DialogHeader><DialogTitle>Reject this proposal</DialogTitle></DialogHeader>
<Textarea v-model="reason" rows="3" aria-label="Reason" placeholder="Why" />
<p v-if="actionError" role="alert" class="text-caption text-danger">{{ actionError }}</p>
<DialogFooter>
<Button variant="ghost" :disabled="busy" @click="rejecting = false">Cancel</Button>
<Button variant="destructive" :disabled="busy || !reason.trim()" @click="reject">Reject</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
</template>
+68
View File
@@ -0,0 +1,68 @@
<script setup lang="ts">
import { onMounted, ref, watch } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Badge } from "@/components/ui/badge";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { ReadError } from "@/components/ui/read-error";
import { Skeleton } from "@/components/ui/skeleton";
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Timestamp } from "@/components/ui/timestamp";
import { api, type Proposal, type ProposalState } from "@/lib/api";
import { usePoll, useRead } from "@/lib/use-read";
import { useLiveResource } from "@/stores/session";
import { kindLabel, proposalTone, STATES } from "./state";
const state = ref<ProposalState>("pending");
const { data, error, reload } = useRead(() => api.proposals(state.value));
onMounted(reload);
watch(state, () => {
data.value = undefined;
void reload();
});
useLiveResource(null, () => void reload());
usePoll(reload);
const columns: DataTableColumn<Proposal>[] = [
{ id: "title", label: "Proposal", fixed: true, width: "auto", sort: (p) => p.title },
{ id: "kind", label: "Kind", hide: "sm", width: "10rem", sort: (p) => p.kind },
{ id: "state", label: "State", fixed: true, width: "8rem", sort: (p) => p.state },
{ id: "needs", label: "Needs", hide: "md", width: "8rem" },
{ id: "created", label: "Proposed", hide: "sm", width: "8rem", sort: (p) => Date.parse(p.created_at) },
];
</script>
<template>
<div>
<PageHeader title="Proposals">
<Tabs v-model="state">
<TabsList>
<TabsTrigger v-for="s in STATES" :key="s.value" :value="s.value">{{ s.label }}</TabsTrigger>
</TabsList>
</Tabs>
</PageHeader>
<ReadError v-if="error" :message="error" retry-label="Retry" @retry="reload" />
<div v-else-if="!data" role="status" aria-label="Loading proposals" class="space-y-2"><Skeleton class="h-10 w-full" /><Skeleton class="h-10 w-full" /></div>
<Empty v-else-if="!data.length"><EmptyHeader><EmptyTitle>No proposals</EmptyTitle></EmptyHeader></Empty>
<DataTable
v-else
:columns="columns"
:rows="data"
:row-key="(p) => p.id"
:row-link="(p) => `/proposals/${p.id}`"
:row-label="(p) => p.title"
storage-key="proposals"
:initial-sort="{ id: 'created', desc: true }"
>
<template #cell-title="{ row }">
<span class="font-medium">{{ row.title }}</span>
<span v-if="row.actions.length" class="ml-2 text-caption text-fg-subtle">{{ row.actions.length }} {{ row.actions.length === 1 ? "action" : "actions" }}</span>
</template>
<template #cell-kind="{ row }">{{ kindLabel(row.kind) }}</template>
<template #cell-state="{ row }"><Badge :variant="proposalTone(row.state)">{{ row.state }}</Badge></template>
<template #cell-needs="{ row }"><span class="text-caption text-fg-muted">{{ row.needs === "authority" ? "A person with authority" : "The owner" }}</span></template>
<template #cell-created="{ row }"><Timestamp :at="row.created_at" /></template>
</DataTable>
</div>
</template>
+64
View File
@@ -0,0 +1,64 @@
import { getAssertion } from "@/accounts/accounts";
import { api, ApiError, type Proposal, type ProposalAction, type ProposalState } from "@/lib/api";
export const STATES: { value: ProposalState; label: string }[] = [
{ value: "pending", label: "Waiting" },
{ value: "published", label: "Published" },
{ value: "approved", label: "Applying" },
{ value: "rejected", label: "Rejected" },
];
const KINDS: Record<Proposal["kind"], string> = {
root_cause_fix: "Root-cause fix",
trigger: "Trigger",
workflow_change: "Workflow change",
ceiling_raise: "Raised ceiling",
policy_change: "Policy change",
};
export const kindLabel = (kind: Proposal["kind"]): string => KINDS[kind] ?? kind;
/** The Badge tone for a proposal's state. */
export function proposalTone(state: ProposalState): "ok" | "warn" | "danger" | "info" | "idle" {
switch (state) {
case "published":
return "ok";
case "pending":
return "warn";
case "approved":
return "info";
case "rejected":
return "danger";
default:
return "idle";
}
}
/** The Badge tone for how a proposed action ended. */
export function actionTone(state: ProposalAction["state"]): "ok" | "warn" | "danger" | "idle" {
switch (state) {
case "ran":
return "ok";
case "failed":
case "refused":
return "danger";
case "unknown":
return "warn";
default:
return "idle";
}
}
/** Approves a proposal. The server asks for a fresh passkey assertion (428)
* when one of its actions can't be undone; the person confirms with their
* passkey and the approval is sent again with it. */
export async function approveProposal(id: string): Promise<Proposal> {
try {
return await api.approveProposal(id);
} catch (cause) {
if (!(cause instanceof ApiError) || cause.status !== 428) throw cause;
}
const confirmation = await api.beginProposalConfirmation(id);
const credential = await getAssertion(confirmation.options);
return api.approveProposal(id, { token: confirmation.token, credential });
}
+12
View File
@@ -83,6 +83,18 @@ export const routes: RouteRecordRaw[] = [
component: () => import("@/runs/RunPage.vue"),
meta: { label: "Run", nav: false, navPath: "/runs", section: "runs" },
},
{
path: "/proposals",
name: "proposals",
component: () => import("@/proposals/ProposalsPage.vue"),
meta: { label: "Proposals", description: "Changes Archie proposes, with their evidence and the actions they take.", section: "proposals" },
},
{
path: "/proposals/:id",
name: "proposal",
component: () => import("@/proposals/ProposalPage.vue"),
meta: { label: "Proposal", nav: false, navPath: "/proposals", section: "proposals" },
},
{
path: "/controls",
name: "controls",