feat(webui): the harness settings page and its setup terminal

A Settings > Runtime page lists every credential binding with the capture
state of its OAuth token set (expiry, scopes, time; never the tokens), and
offers the setup terminal for the Kit profiles the daemon advertises. The
terminal is xterm.js over the WebSocket the harness route upgrades, lazy
loaded so xterm stays out of the shell bundle. The page reports the
terminal as unavailable when the process cannot open one, rather than
offering a control that fails (archie-core-egkf.7).

Wire shapes and URL building live in ui/src/harness/harness.ts and are
covered by ui/test/harness.test.ts; ui/dist is regenerated.
This commit is contained in:
sam committed 2026-10-02 09:42:26 +10:00
1 parent 2d200de224
commit 95e88245da
13 files changed
+518 -4

No files matched your search

+203
View File
@@ -0,0 +1,203 @@
<script setup lang="ts">
/**
* Harness: the OAuth credential bindings a Kit profile resolves, and the
* setup terminal that captures a binding's tokens
* (docs/prds/external-agent-harness.md). The binding list is a State Store
* read; the terminal is the webui route's WebSocket, and it reports
* explicitly when this process cannot open one rather than offering a
* control that would fail.
*/
import { onMounted, ref } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
import { Badge } from "@/components/ui/badge";
import type { BadgeVariants } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
import {
Empty,
EmptyDescription,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import { Skeleton } from "@/components/ui/skeleton";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { api, ApiError } from "@/lib/api";
import SetupTerminal from "./SetupTerminal.vue";
import {
bindingStatus,
type BindingStatus,
type HarnessBinding,
type HarnessState,
} from "./harness";
const state = ref<HarnessState | null>(null);
const loading = ref(true);
const failure = ref<string | null>(null);
// "unconfigured" is a process with no control-plane resource or no token
// store (501/503) -- the feature is off, which reads differently from a
// process that answered badly.
const unconfigured = ref(false);
const profile = ref("");
const terminalOpen = ref(false);
const statuses: Record<
BindingStatus,
{ label: string; variant: BadgeVariants["variant"] }
> = {
ready: { label: "Ready", variant: "ok" },
expiring: { label: "Expiring soon", variant: "warn" },
expired: { label: "Expired", variant: "danger" },
unconfigured: { label: "Not set up", variant: "idle" },
};
onMounted(load);
async function load(): Promise<void> {
loading.value = true;
failure.value = null;
unconfigured.value = false;
try {
const got = await api.harnessBindings<HarnessState>();
state.value = {
terminal: got.terminal,
bindings: got.bindings ?? [],
profiles: got.profiles ?? [],
};
profile.value = state.value.profiles[0] ?? "";
} catch (err) {
const status = err instanceof ApiError ? err.status : undefined;
if (status === 501 || status === 503) {
unconfigured.value = true;
} else {
failure.value = err instanceof Error ? err.message : String(err);
}
state.value = null;
} finally {
loading.value = false;
}
}
function openTerminal(): void {
if (!state.value?.terminal || !profile.value) return;
terminalOpen.value = true;
}
function formatTimestamp(value?: string): string {
if (!value) return "—";
const at = new Date(value);
return Number.isNaN(at.getTime()) ? value : at.toLocaleString();
}
function scopes(binding: HarnessBinding): string {
return binding.scopes?.length ? binding.scopes.join(", ") : "—";
}
</script>
<template>
<div>
<PageHeader title="Harness" />
<p v-if="failure" class="mb-4 text-sm text-danger" role="alert">
{{ failure }}
</p>
<div v-if="loading" class="space-y-2">
<Skeleton class="h-24 w-full" />
<Skeleton class="h-40 w-full" />
</div>
<Empty v-else-if="unconfigured">
<EmptyHeader>
<EmptyTitle>Harness bindings are not configured</EmptyTitle>
<EmptyDescription>
This process cannot read credential bindings or captured OAuth tokens,
so there is nothing to set up here.
</EmptyDescription>
</EmptyHeader>
</Empty>
<template v-else-if="state">
<Alert v-if="!state.terminal" class="mb-4">
<AlertTitle>Setup terminal unavailable</AlertTitle>
<AlertDescription>
This process cannot open a Kit container. The bindings below are still
listed; the setup terminal needs a container-capable process.
</AlertDescription>
</Alert>
<Card v-else class="mb-4">
<CardContent class="flex flex-wrap items-end gap-3">
<label class="flex flex-col gap-1 text-sm">
<span class="text-muted-foreground">Kit profile</span>
<select
v-model="profile"
class="h-9 min-w-48 rounded-md border border-input bg-background px-2 text-sm"
:disabled="!state.profiles.length"
>
<option v-if="!state.profiles.length" value="">
No Kit profiles configured
</option>
<option v-for="name in state.profiles" :key="name" :value="name">
{{ name }}
</option>
</select>
</label>
<Button :disabled="!profile" @click="openTerminal">
Open setup terminal
</Button>
</CardContent>
</Card>
<Card v-if="terminalOpen && profile" class="mb-4">
<CardContent class="h-96">
<SetupTerminal :profile="profile" />
</CardContent>
</Card>
<Card>
<CardContent>
<Table>
<TableHeader>
<TableRow>
<TableHead>Service</TableHead>
<TableHead>Status</TableHead>
<TableHead>Expires</TableHead>
<TableHead>Scopes</TableHead>
<TableHead>Updated</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-if="!state.bindings.length">
<TableCell colspan="5" class="text-muted-foreground">
No credential bindings are configured.
</TableCell>
</TableRow>
<TableRow v-for="binding in state.bindings" :key="binding.service">
<TableCell class="font-medium">{{ binding.service }}</TableCell>
<TableCell>
<Badge :variant="statuses[bindingStatus(binding)].variant">
{{ statuses[bindingStatus(binding)].label }}
</Badge>
</TableCell>
<TableCell>{{ formatTimestamp(binding.expires_at) }}</TableCell>
<TableCell class="text-muted-foreground">{{ scopes(binding) }}</TableCell>
<TableCell class="text-muted-foreground">
{{ formatTimestamp(binding.updated_at) }}
</TableCell>
</TableRow>
</TableBody>
</Table>
</CardContent>
</Card>
</template>
</div>
</template>
+117
View File
@@ -0,0 +1,117 @@
<script setup lang="ts">
/**
* The setup terminal: an xterm.js surface over the WebSocket the webui route
* upgrades to a Kit container's PTY
* (docs/prds/external-agent-harness.md, "Setup terminal"). The browser cannot
* set headers on a WebSocket, so the shared-token gate reads the same
* HttpOnly cookie the SSE stream uses.
*
* The transport is raw bytes in both directions. Sizing the remote PTY is a
* contract detail the daemon side will own with the session, so this
* component fits the local surface but does not claim to resize the
* container.
*/
import { onBeforeUnmount, onMounted, ref } from "vue";
import { Terminal } from "@xterm/xterm";
import { FitAddon } from "@xterm/addon-fit";
import "@xterm/xterm/css/xterm.css";
import { setupTerminalURL } from "./harness";
const props = defineProps<{ profile: string }>();
const host = ref<HTMLDivElement | null>(null);
const status = ref<"connecting" | "open" | "closed" | "failed">("connecting");
let term: Terminal | null = null;
let socket: WebSocket | null = null;
let fit: FitAddon | null = null;
let observer: ResizeObserver | null = null;
function fitLocal(): void {
try {
fit?.fit();
} catch {
// xterm throws when the host has no measurable box yet; the next resize
// (or open) retries. Fitting is cosmetic and must not fail the session.
}
}
onMounted(() => {
const mount = host.value;
if (!mount) return;
term = new Terminal({
convertEol: true,
cursorBlink: true,
fontFamily: "'IBM Plex Mono', ui-monospace, monospace",
fontSize: 13,
theme: {
background: "#0b0f14",
foreground: "#e6edf3",
cursor: "#e6edf3",
selectionBackground: "#264f78",
},
});
fit = new FitAddon();
term.loadAddon(fit);
term.open(mount);
fitLocal();
term.focus();
const ws = new WebSocket(setupTerminalURL(props.profile, window.location));
socket = ws;
ws.binaryType = "arraybuffer";
ws.onopen = () => {
status.value = "open";
};
ws.onmessage = (event: MessageEvent) => {
if (!term) return;
if (typeof event.data === "string") {
term.write(event.data);
} else {
term.write(new Uint8Array(event.data as ArrayBuffer));
}
};
ws.onerror = () => {
status.value = "failed";
};
ws.onclose = () => {
status.value = "closed";
};
term.onData((data) => {
if (ws.readyState === WebSocket.OPEN) ws.send(data);
});
observer = new ResizeObserver(fitLocal);
observer.observe(mount);
});
onBeforeUnmount(() => {
observer?.disconnect();
observer = null;
socket?.close();
socket = null;
term?.dispose();
term = null;
fit = null;
});
</script>
<template>
<div class="flex h-full min-h-0 flex-col gap-2">
<p
v-if="status !== 'open'"
class="text-sm text-muted-foreground"
role="status"
>
<template v-if="status === 'connecting'">Connecting…</template>
<template v-else-if="status === 'closed'">The terminal session ended.</template>
<template v-else>Could not open the setup terminal.</template>
</p>
<div
ref="host"
class="min-h-0 flex-1 overflow-hidden rounded-md border border-border bg-[#0b0f14] p-2"
/>
</div>
</template>
+67
View File
@@ -0,0 +1,67 @@
/**
* The harness page's wire shapes and payload building, kept in a plain
* module beside the components so it runs under the dashboard's module test
* runner (docs/development/frontend-ui.md, "Testing the dashboard").
*
* The setup terminal is a WebSocket because the browser cannot set headers on
* a terminal connection: the shared-token gate reads the same HttpOnly cookie
* the SSE stream uses.
*/
/** One credential binding as GET /api/harness/bindings reports it. */
export interface HarnessBinding {
service: string;
captured: boolean;
/** RFC 3339; absent when no token set has been captured. */
expires_at?: string;
updated_at?: string;
scopes?: string[];
}
/** The page's whole read. */
export interface HarnessState {
/** Whether this process can open a setup terminal at all. */
terminal: boolean;
bindings: HarnessBinding[];
/** The agent profiles that name a Kit, i.e. what a terminal can target. */
profiles: string[];
}
/** How a captured token reads on the page. */
export type BindingStatus = "unconfigured" | "expired" | "expiring" | "ready";
/** A captured token this close to expiry reads as "expiring". */
export const EXPIRING_WINDOW_MS = 30 * 60 * 1000;
/**
* bindingStatus classifies a binding's capture state. A binding with no
* captured set is "unconfigured" whatever else it carries; a captured set
* with no parseable expiry counts as ready, because the provider did not tell
* archie when it lapses and guessing would be wrong.
*/
export function bindingStatus(
binding: HarnessBinding,
now: number = Date.now(),
): BindingStatus {
if (!binding.captured) return "unconfigured";
if (!binding.expires_at) return "ready";
const expires = Date.parse(binding.expires_at);
if (Number.isNaN(expires)) return "ready";
if (expires <= now) return "expired";
if (expires - now <= EXPIRING_WINDOW_MS) return "expiring";
return "ready";
}
/**
* setupTerminalURL builds the WebSocket URL for one Kit profile. The location
* is a parameter rather than window so the module stays runnable outside a
* browser.
*/
export function setupTerminalURL(
profile: string,
location: Pick<Location, "protocol" | "host">,
): string {
const scheme = location.protocol === "https:" ? "wss:" : "ws:";
const query = new URLSearchParams({ profile }).toString();
return `${scheme}//${location.host}/api/harness/terminal?${query}`;
}
+1
View File
@@ -258,6 +258,7 @@ export const api = {
request<T>(`/api/bindings/${encodeURIComponent(id)}/approve`, {
method: "POST",
}),
harnessBindings: <T = unknown>() => request<T>("/api/harness/bindings"),
sources: <T = unknown>() => request<T>("/api/sources"),
sourceCreate: <T = unknown>(path: string) =>
request<T>("/api/sources", { method: "POST", body: { path } }),
+1
View File
@@ -51,6 +51,7 @@ const settings: NavSpec = {
paths: [
"/settings/task-execution",
"/settings/container-runtime",
"/settings/harness",
"/settings/status",
"/settings/advanced",
],
+13
View File
@@ -270,6 +270,19 @@ const routes = [
section: "settings",
},
},
{
path: "/settings/harness",
name: "settings-harness",
// Lazy so xterm.js stays out of the shell every page loads.
component: () => import("@/harness/HarnessPage.vue"),
meta: {
navPath: "/settings",
settings: true,
label: "Harness",
description: "OAuth credential bindings and the Kit setup terminal.",
section: "settings",
},
},
{
path: "/settings/advanced",
name: "system-advanced",