merge: t2db.40 sources and signing into pg/foundation

Resolves against t2db.36: captures carry both event_type and unsigned (proto field 10), the State Store serves sources and event types from the Postgres EDA store, the capture row shows event type and signature together, and the staterpc sentinels map both ways from one table.
This commit is contained in:
sam committed 2026-09-24 14:38:40 +10:00
commit 8a2b5b95f9
63 files changed
+3839 -1753

No files matched your search

+3 -46
View File
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { Check, Copy, RefreshCw } from "@lucide/vue";
import { computed, ref, watch } from "vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
@@ -7,14 +6,11 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Field, FieldDescription, FieldGroup, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
import { InputGroup, InputGroupAddon, InputGroupButton, InputGroupInput } from "@/components/ui/input-group";
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { Spinner } from "@/components/ui/spinner";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import {
draftFromBinding,
emptyDraft,
generateSecret,
type Binding,
type BindingDraft,
type MappingOption,
@@ -23,8 +19,7 @@ import {
/**
* The binding editor: name, the matcher source senders POST to, the field
* mapping, the workflow, an optional repo pin, and the shared secret their
* signature is checked against.
* mapping, the workflow and an optional repo pin. Signing is the source's.
*/
const props = defineProps<{
@@ -51,17 +46,11 @@ watch(
);
const title = computed(() => (props.binding ? "Edit binding" : "New binding"));
const copied = ref(false);
async function copySecret(): Promise<void> {
await navigator.clipboard.writeText(draft.value.secret);
copied.value = true;
setTimeout(() => (copied.value = false), 1500);
}
</script>
<template>
<Dialog v-model:open="open">
<!-- Seven fields make this taller than a short window; the dialog itself
<!-- Six fields make this taller than a short window; the dialog itself
scrolls rather than clipping its own Save button. -->
<DialogContent class="max-h-[85vh] overflow-y-auto sm:max-w-lg">
<DialogHeader>
@@ -81,7 +70,7 @@ async function copySecret(): Promise<void> {
<Field>
<FieldLabel for="binding-source">Source</FieldLabel>
<Input id="binding-source" v-model="draft.source" />
<FieldDescription>The path segment senders POST to, for example "sentry".</FieldDescription>
<FieldDescription>The path of a source, from the sources list above.</FieldDescription>
</Field>
<Field>
@@ -132,38 +121,6 @@ async function copySecret(): Promise<void> {
</FieldDescription>
</Field>
<Field>
<FieldLabel for="binding-secret">Signing secret</FieldLabel>
<InputGroup v-if="draft.secret">
<InputGroupInput id="binding-secret" :model-value="draft.secret" class="font-mono text-xs" readonly />
<InputGroupAddon align="inline-end">
<Tooltip>
<TooltipTrigger as-child>
<InputGroupButton size="icon-xs" aria-label="Copy secret" @click="copySecret">
<Check v-if="copied" />
<Copy v-else />
</InputGroupButton>
</TooltipTrigger>
<TooltipContent>Copy secret</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
<InputGroupButton size="icon-xs" aria-label="Regenerate secret" @click="draft.secret = generateSecret()">
<RefreshCw />
</InputGroupButton>
</TooltipTrigger>
<TooltipContent>Regenerate</TooltipContent>
</Tooltip>
</InputGroupAddon>
</InputGroup>
<div v-else class="flex h-9 items-center justify-between rounded-md border px-3 text-sm">
<span class="text-fg-muted">Stored · HMAC-SHA256</span>
<Button type="button" variant="ghost" size="sm" @click="draft.secret = generateSecret()">
<RefreshCw data-icon="inline-start" />
Replace
</Button>
</div>
</Field>
</FieldGroup>
<!-- Beside the buttons, not at the top: the dialog scrolls, and Save is
+7 -1
View File
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { Check, Pencil, Trash2 } from "@lucide/vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { TableCell, TableRow } from "@/components/ui/table";
import BindingStatusBadge from "./BindingStatusBadge.vue";
@@ -18,7 +19,12 @@ const emit = defineEmits<{
<template>
<TableRow>
<TableCell class="font-medium">{{ props.binding.name }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{ matcherSource(props.binding) }}</TableCell>
<TableCell class="font-mono text-fg-muted">
<div class="flex items-center gap-2">
{{ matcherSource(props.binding) }}
<Badge v-if="props.binding.unsigned" variant="warn">Unsigned</Badge>
</div>
</TableCell>
<TableCell>{{ props.binding.workflow || "—" }}</TableCell>
<TableCell class="font-mono text-fg-muted">{{ repoPin(props.binding) }}</TableCell>
<TableCell><BindingStatusBadge :status="props.binding.status" /></TableCell>
+3
View File
@@ -4,6 +4,7 @@ import { onMounted, ref } from "vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import SourcesPanel from "@/sources/SourcesPanel.vue";
import { useLiveResource } from "@/stores/live-updates";
import BindingEditor from "./BindingEditor.vue";
import BindingsTable from "./BindingsTable.vue";
@@ -69,6 +70,8 @@ async function handleDelete(binding: Binding): Promise<void> {
<template>
<div>
<SourcesPanel />
<!-- The tab owns the actions that belong to it. The page's header names the
page, not this panel, so nothing here repeats "Events". -->
<div class="mb-4 flex flex-wrap items-center justify-end gap-2">
+3 -15
View File
@@ -6,9 +6,8 @@
*/
/**
* A binding as GET /api/bindings returns it. Secret is never returned: the
* daemon strips it from every read, and a blank secret on update is its
* server-side "keep the current one".
* A binding as GET /api/bindings returns it. Signing belongs to the source the
* matcher names; unsigned is set when that source takes unsigned events.
*/
export interface Binding {
id: string;
@@ -21,6 +20,7 @@ export interface Binding {
repo?: string;
status?: string;
version?: number;
unsigned?: boolean;
}
/** The fields of GET /api/mappings this page needs. */
@@ -71,7 +71,6 @@ export interface BindingDraft {
workflow: string;
owner: string;
repo: string;
secret: string;
}
export function emptyDraft(): BindingDraft {
@@ -83,7 +82,6 @@ export function emptyDraft(): BindingDraft {
workflow: "",
owner: "",
repo: "",
secret: generateSecret(),
};
}
@@ -96,9 +94,6 @@ export function draftFromBinding(binding: Binding): BindingDraft {
workflow: binding.workflow || "",
owner: binding.owner || "",
repo: binding.repo || "",
// Deliberately blank: the secret is never sent to the browser, and an
// empty one on update keeps whatever the sender already signs with.
secret: "",
};
}
@@ -111,16 +106,9 @@ export function bindingPayload(draft: BindingDraft): Record<string, unknown> {
workflow: draft.workflow,
owner: draft.owner,
repo: draft.repo,
secret: draft.secret,
};
}
/** A 32-byte hex signing secret for a new binding. */
export function generateSecret(): string {
const bytes = crypto.getRandomValues(new Uint8Array(32));
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
}
/** The repo pin a row shows, or an em dash when the binding takes the
* single-configured-repo default. */
export function repoPin(binding: Binding): string {
+8 -1
View File
@@ -3,7 +3,9 @@ import { useMediaQuery } from "@vueuse/core";
import { computed, ref, watch } from "vue";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { ago } from "@/lib/format";
import { captureSignature } from "./capture-signature";
import CapturePayload from "./CapturePayload.vue";
import { selected } from "./state";
@@ -36,6 +38,8 @@ const stacked = useMediaQuery("(max-width: 1099px)");
const cap = computed(() => (stacked.value || !props.maxHeight ? undefined : `${props.maxHeight}px`));
const signature = computed(() => (selected.value ? captureSignature(selected.value) : null));
const meta = computed(() => {
const capture = selected.value;
if (!capture) return "";
@@ -54,7 +58,10 @@ watch(selected, () => {
<div v-if="selected" ref="pane" class="min-w-0">
<Card class="flex flex-col" :style="cap ? { maxHeight: cap } : undefined">
<CardHeader>
<CardTitle class="font-mono">{{ selected.source || "Unknown source" }}</CardTitle>
<CardTitle class="flex items-center gap-2 font-mono">
{{ selected.source || "Unknown source" }}
<Badge v-if="signature" :variant="signature.kind">{{ signature.label }}</Badge>
</CardTitle>
<CardDescription>{{ meta }}</CardDescription>
</CardHeader>
<!-- Stacked there is no sibling to be bound by, so the panel caps itself
+8 -3
View File
@@ -7,6 +7,7 @@ import { TableCell, TableRow } from "@/components/ui/table";
import { ago } from "@/lib/format";
import { eventTypes } from "./event-type-state";
import { captureIdentity } from "./event-types";
import { captureSignature } from "./capture-signature";
import { selected, type Capture } from "./state";
/**
@@ -19,6 +20,7 @@ const props = defineProps<{ capture: Capture }>();
const identity = computed(() => captureIdentity(props.capture, eventTypes.value));
const signature = computed(() => captureSignature(props.capture));
const isSelected = computed(() => selected.value?.id === props.capture.id);
// The name is set here because role="button" makes the cells presentational:
@@ -46,9 +48,12 @@ function open(): void {
<TableCell :title="props.capture.received_at || ''">{{ ago(props.capture.received_at) }}</TableCell>
<!-- An unidentified capture is never dispatched. -->
<TableCell>
<Badge :variant="identity.identified ? 'ok' : 'warn'" class="max-w-40">
<span class="truncate">{{ identity.label }}</span>
</Badge>
<div class="flex items-center gap-1">
<Badge :variant="identity.identified ? 'ok' : 'warn'" class="max-w-40">
<span class="truncate">{{ identity.label }}</span>
</Badge>
<Badge :variant="signature.kind">{{ signature.label }}</Badge>
</div>
</TableCell>
<TableCell class="font-mono">{{ props.capture.content_type || "—" }}</TableCell>
<TableCell class="text-right">
+15
View File
@@ -0,0 +1,15 @@
/**
* How a capture may dispatch: signed by its source's secret, taken on a
* source approved for unsigned events, or neither -- in which case nothing
* starts from it.
*/
export interface CaptureSignature {
label: "Signed" | "Unsigned" | "Unverified";
kind: "ok" | "warn" | "idle";
}
export function captureSignature(capture: { authenticated?: boolean; unsigned?: boolean }): CaptureSignature {
if (capture.unsigned) return { label: "Unsigned", kind: "warn" };
if (capture.authenticated) return { label: "Signed", kind: "ok" };
return { label: "Unverified", kind: "idle" };
}
+1
View File
@@ -28,6 +28,7 @@ export interface Capture {
authenticated?: boolean;
/** The event type it was identified as on arrival; empty is unidentified. */
event_type?: string;
unsigned?: boolean;
}
interface CapturesResponse {
+8
View File
@@ -178,6 +178,14 @@ export const api = {
request<T>(`/api/bindings/${encodeURIComponent(id)}`, { method: "PATCH", body: binding }),
bindingDelete: (id: string) => request<void>(`/api/bindings/${encodeURIComponent(id)}`, { method: "DELETE", parse: false }),
bindingApprove: <T = unknown>(id: string) => request<T>(`/api/bindings/${encodeURIComponent(id)}/approve`, { method: "POST" }),
sources: <T = unknown>() => request<T>("/api/sources"),
sourceCreate: <T = unknown>(path: string) => request<T>("/api/sources", { method: "POST", body: { path } }),
sourceSigning: <T = unknown>(path: string, signed: boolean) =>
request<T>(`/api/sources/${encodeURIComponent(path)}/signing`, { method: "POST", body: { signed } }),
sourceApproveUnsigned: <T = unknown>(path: string) =>
request<T>(`/api/sources/${encodeURIComponent(path)}/approve-unsigned`, { method: "POST" }),
sourceSecret: <T = unknown>(path: string) =>
request<T>(`/api/sources/${encodeURIComponent(path)}/secret`, { method: "POST" }),
chatSessions: <T = unknown>() => request<T>("/api/chat/sessions"),
chatMessages: <T = unknown>(id: string) => request<T>(`/api/chat/sessions/${encodeURIComponent(id)}/messages`),
chatTurns: <T = unknown>(id: string) => request<T>(`/api/chat/sessions/${encodeURIComponent(id)}/turns`),
+148
View File
@@ -0,0 +1,148 @@
<script setup lang="ts">
import { Check, Copy, KeyRound, Lock, LockOpen, Plus, X } from "@lucide/vue";
import { onMounted, ref } from "vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import { useLiveResource } from "@/stores/live-updates";
import { signingKind, signingLabel, sourceURL, type Source } from "./source-signing";
import { useSources } from "./use-sources";
/**
* Capture sources: the endpoint each sender posts to and its signing setting
* (docs/prds/event-automation.md "Sources"). Turning signing off is a request
* that takes effect only once approved.
*/
const { sources, failure, revealed, busy, load, create, newSecret, requestUnsigned, requireSigning, approveUnsigned } =
useSources();
const customPath = ref("");
const copied = ref<string | null>(null);
useLiveResource(null, () => void load());
onMounted(load);
async function copy(value: string): Promise<void> {
await navigator.clipboard.writeText(value);
copied.value = value;
setTimeout(() => (copied.value = null), 1500);
}
async function submit(): Promise<void> {
await create(customPath.value);
if (!failure.value) customPath.value = "";
}
function url(source: Source): string {
return sourceURL(window.location.origin, source.path);
}
</script>
<template>
<section class="mb-6 flex flex-col gap-3">
<form class="flex flex-wrap items-center justify-end gap-2" @submit.prevent="submit">
<Input v-model="customPath" class="w-64 font-mono" placeholder="Custom path (optional)" aria-label="Custom path" />
<Button type="submit" variant="outline" :disabled="busy">
<Plus data-icon="inline-start" />
New source
</Button>
</form>
<Alert v-if="failure" variant="destructive">
<AlertTitle>That did not take effect</AlertTitle>
<AlertDescription>{{ failure }}</AlertDescription>
</Alert>
<Alert v-if="revealed">
<KeyRound />
<AlertTitle class="flex items-center justify-between gap-2">
<span class="font-mono">{{ revealed.path }} · signing secret, shown once</span>
<Button variant="ghost" size="icon-sm" aria-label="Dismiss" @click="revealed = null"><X /></Button>
</AlertTitle>
<AlertDescription class="flex items-center gap-2">
<code class="min-w-0 break-all font-mono text-xs">{{ revealed.secret }}</code>
<Button variant="ghost" size="icon-sm" aria-label="Copy secret" @click="copy(revealed.secret || '')">
<Check v-if="copied === revealed.secret" />
<Copy v-else />
</Button>
</AlertDescription>
</Alert>
<Card v-if="sources && sources.length">
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Source</TableHead>
<TableHead>Signing</TableHead>
<TableHead />
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="source in sources" :key="source.path">
<TableCell class="max-w-0 truncate font-mono text-fg-muted" :title="url(source)">{{ source.path }}</TableCell>
<TableCell>
<Badge :variant="signingKind(source.signing)">{{ signingLabel(source.signing) }}</Badge>
</TableCell>
<TableCell>
<div class="flex items-center justify-end gap-1">
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon-sm" aria-label="Copy URL" @click="copy(url(source))">
<Check v-if="copied === url(source)" />
<Copy v-else />
</Button>
</TooltipTrigger>
<TooltipContent>Copy URL</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger as-child>
<Button variant="ghost" size="icon-sm" aria-label="New secret" :disabled="busy" @click="newSecret(source)">
<KeyRound />
</Button>
</TooltipTrigger>
<TooltipContent>New secret</TooltipContent>
</Tooltip>
<Button
v-if="source.signing === 'signed'"
variant="outline"
size="sm"
:disabled="busy"
@click="requestUnsigned(source)"
>
<LockOpen data-icon="inline-start" />
Turn off signing
</Button>
<Button
v-if="source.signing === 'unsigned_pending_approval'"
size="sm"
:disabled="busy"
@click="approveUnsigned(source)"
>
<Check data-icon="inline-start" />
Approve unsigned
</Button>
<Button
v-if="source.signing !== 'signed'"
variant="outline"
size="sm"
:disabled="busy"
@click="requireSigning(source)"
>
<Lock data-icon="inline-start" />
Require signing
</Button>
</div>
</TableCell>
</TableRow>
</TableBody>
</Table>
</CardContent>
</Card>
</section>
</template>
+41
View File
@@ -0,0 +1,41 @@
/**
* The sources vocabulary: the wire shape GET /api/sources returns and the
* signing states it carries. A source's secret is only ever in the response
* to the write that generated it.
*/
export interface Source {
path: string;
signing?: string;
/** Present only on create and on a new secret. */
secret?: string;
created_at?: string;
}
export type SigningKind = "ok" | "info" | "warn" | "idle";
const LABELS: Record<string, string> = {
signed: "signed",
unsigned_pending_approval: "unsigned pending approval",
unsigned: "unsigned",
};
const KINDS: Record<string, SigningKind> = {
signed: "ok",
unsigned_pending_approval: "info",
unsigned: "warn",
};
export function signingLabel(signing?: string): string {
if (!signing) return "unknown";
return LABELS[signing] ?? signing;
}
export function signingKind(signing?: string): SigningKind {
return KINDS[signing ?? ""] ?? "idle";
}
/** The URL a sender posts to. */
export function sourceURL(origin: string, path: string): string {
return `${origin}/webhooks/capture/${encodeURIComponent(path)}`;
}
+58
View File
@@ -0,0 +1,58 @@
import { ref } from "vue";
import { api } from "@/lib/api";
import type { Source } from "./source-signing";
/**
* The sources list and its writes. A write that generates a secret keeps the
* returned source in `revealed` until dismissed: it is the only time the
* browser ever holds that secret.
*/
export function useSources() {
// null means loading, [] means loaded and empty.
const sources = ref<Source[] | null>(null);
const failure = ref<string | null>(null);
const revealed = ref<Source | null>(null);
const busy = ref(false);
function message(err: unknown): string {
return err instanceof Error && err.message ? err.message : String(err);
}
async function load(): Promise<void> {
try {
const res = await api.sources<{ sources?: Source[] }>();
sources.value = res.sources || [];
failure.value = null;
} catch (err) {
failure.value = message(err);
}
}
async function run(write: () => Promise<Source | void>): Promise<void> {
busy.value = true;
failure.value = null;
try {
const result = await write();
if (result?.secret) revealed.value = result;
await load();
} catch (err) {
failure.value = message(err);
} finally {
busy.value = false;
}
}
return {
sources,
failure,
revealed,
busy,
load,
create: (path: string) => run(() => api.sourceCreate<Source>(path.trim())),
newSecret: (source: Source) => run(() => api.sourceSecret<Source>(source.path)),
requestUnsigned: (source: Source) => run(() => api.sourceSigning<Source>(source.path, false)),
requireSigning: (source: Source) => run(() => api.sourceSigning<Source>(source.path, true)),
approveUnsigned: (source: Source) => run(() => api.sourceApproveUnsigned<Source>(source.path)),
};
}
+5 -1
View File
@@ -21,7 +21,11 @@ const line = computed(() => describeTimelineEvent(props.event));
<template>
<li class="flex items-start gap-3">
<span class="mt-[5px] size-2 shrink-0 rounded-full bg-primary" aria-hidden="true" />
<span
class="mt-[5px] size-2 shrink-0 rounded-full"
:class="line.tone === 'warn' ? 'bg-warn' : 'bg-primary'"
aria-hidden="true"
/>
<div>
<div class="text-sm font-medium">{{ line.title }}</div>
<div v-if="line.detail" class="mt-0.5 text-xs text-fg-muted">{{ line.detail }}</div>
+6
View File
@@ -48,6 +48,8 @@ function text(value: unknown): string {
export interface TimelineLine {
title: string;
detail: string;
/** Set for an event a reader must not skim past. */
tone?: "warn";
}
export function describeTimelineEvent(ev: TaskEvent = {}): TimelineLine {
@@ -112,6 +114,10 @@ export function describeTimelineEvent(ev: TaskEvent = {}): TimelineLine {
detail: "The effective task-runtime configuration for this run.",
};
}
if (ev.kind === "unsigned_event") {
const source = text(data.source);
return { title: "Started by an unsigned event", detail: source ? `source ${source}` : "", tone: "warn" };
}
if (ev.kind === "changes_captured") {
const totals = (data.totals ?? {}) as { files?: unknown };
const fileCount = Number(totals.files);