feat(webui): add a command palette, live tasks, and a11y fixes
Ctrl/Cmd+K opens a palette over the capability-gated nav entries; the tasks board refreshes from the shared event stream; config tooltips are keyboard-reachable; live activity announces politely; and missing event timestamps render an em-dash instead of a fabricated now.
This commit is contained in:
1 parent
49af6c75bc
commit
b35b6c0049
8 files changed
+295
-39
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import { onMounted } from "vue";
|
||||
|
||||
import ChatLauncher from "@/chat/ChatLauncher.vue";
|
||||
import CommandPalette from "@/components/command-palette/CommandPalette.vue";
|
||||
import Topbar from "@/components/topbar/Topbar.vue";
|
||||
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||
import { hidden, loadCapabilities } from "@/lib/capabilities";
|
||||
@@ -60,5 +61,13 @@ onMounted(() => {
|
||||
ride off the bottom of a long page.
|
||||
-->
|
||||
<ChatLauncher />
|
||||
|
||||
<!--
|
||||
Outside the shell for the same reason as the launcher above: the frame's
|
||||
backdrop-filter would otherwise become the containing block for the
|
||||
palette's fixed overlay. One instance for the whole app -- its global
|
||||
shortcut listener lives and dies with this mount.
|
||||
-->
|
||||
<CommandPalette :hidden="hidden" />
|
||||
</TooltipProvider>
|
||||
</template>
|
||||
@@ -0,0 +1,194 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { Search } from "@lucide/vue";
|
||||
|
||||
import { navEntries, type NavEntry } from "@/lib/nav";
|
||||
|
||||
/**
|
||||
* The command palette: every section the nav can reach, opened with Cmd/Ctrl+K
|
||||
* or '/' from anywhere. It is a jump list, not a data search -- the topbar's
|
||||
* SearchBar owns the same list with prefix matching from a visible field; this
|
||||
* one adds substring matching and arrow-key selection from a shortcut.
|
||||
*
|
||||
* Styling and keyboard handling mirror ChatSlashPalette, the in-app palette
|
||||
* precedent: a bordered popover surface, mousedown prevented on the options so
|
||||
* choosing with the pointer never steals focus from the filter, and the list
|
||||
* scrolled so the highlighted row stays visible. Nothing here animates, so the
|
||||
* shell's prefers-reduced-motion rule has nothing to quiet.
|
||||
*/
|
||||
const props = defineProps<{ hidden: string[] }>();
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const open = ref(false);
|
||||
const query = ref("");
|
||||
const selection = ref(0);
|
||||
const field = ref<HTMLInputElement | null>(null);
|
||||
const list = ref<HTMLElement | null>(null);
|
||||
|
||||
// The same list the topbar's SearchBar and Nav read: navEntries flattens the
|
||||
// nav tree and drops what this composition cannot back, so the palette can
|
||||
// never offer a destination the server cannot serve.
|
||||
const allEntries = computed(() => navEntries(props.hidden).filter((entry) => !entry.soon));
|
||||
|
||||
// Substring, not prefix: an operator who remembers "where do channels live"
|
||||
// types a word from the description, not the start of the label.
|
||||
const matches = computed(() => {
|
||||
const needle = query.value.trim().toLowerCase();
|
||||
if (!needle) return allEntries.value;
|
||||
return allEntries.value.filter((entry) =>
|
||||
`${entry.label} ${entry.description} ${entry.path}`.toLowerCase().includes(needle),
|
||||
);
|
||||
});
|
||||
watch(query, () => {
|
||||
selection.value = 0;
|
||||
});
|
||||
// Capabilities can land while the palette is open and shrink the list; the
|
||||
// highlight must not point past the last row.
|
||||
watch(matches, () => {
|
||||
if (selection.value >= matches.value.length) selection.value = 0;
|
||||
});
|
||||
|
||||
function optionId(index: number): string {
|
||||
return `command-palette-option-${index}`;
|
||||
}
|
||||
|
||||
async function show(): Promise<void> {
|
||||
query.value = "";
|
||||
selection.value = 0;
|
||||
open.value = true;
|
||||
await nextTick();
|
||||
field.value?.focus();
|
||||
}
|
||||
|
||||
function close(): void {
|
||||
open.value = false;
|
||||
field.value?.blur();
|
||||
}
|
||||
|
||||
function toggle(): void {
|
||||
if (open.value) close();
|
||||
else void show();
|
||||
}
|
||||
|
||||
// '/' opens only when the keystroke was meant for a field, not for the page:
|
||||
// typing a slash into the composer or the topbar search must stay typing.
|
||||
function isEditableTarget(event: KeyboardEvent): boolean {
|
||||
const el = event.target;
|
||||
return (
|
||||
el instanceof HTMLElement &&
|
||||
(el.isContentEditable || el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.tagName === "SELECT")
|
||||
);
|
||||
}
|
||||
|
||||
// Registered on document in the bubble phase (capture: false): the palette is
|
||||
// the last thing that should see a keystroke, after any focused field has had
|
||||
// its turn.
|
||||
function onGlobalKeydown(event: KeyboardEvent): void {
|
||||
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === "k") {
|
||||
event.preventDefault();
|
||||
toggle();
|
||||
return;
|
||||
}
|
||||
if (event.key === "/" && !open.value && !isEditableTarget(event)) {
|
||||
event.preventDefault();
|
||||
void show();
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => document.addEventListener("keydown", onGlobalKeydown));
|
||||
onUnmounted(() => document.removeEventListener("keydown", onGlobalKeydown));
|
||||
|
||||
function onKeydown(event: KeyboardEvent): void {
|
||||
if (event.key === "Escape") {
|
||||
// Consumed here so closing the palette is not also read as a dismissal of
|
||||
// whatever is open behind it (ChatLauncher watches defaultPrevented).
|
||||
event.preventDefault();
|
||||
close();
|
||||
return;
|
||||
}
|
||||
if (event.key === "ArrowDown") {
|
||||
event.preventDefault();
|
||||
if (matches.value.length) selection.value = Math.min(selection.value + 1, matches.value.length - 1);
|
||||
return;
|
||||
}
|
||||
if (event.key === "ArrowUp") {
|
||||
event.preventDefault();
|
||||
selection.value = Math.max(selection.value - 1, 0);
|
||||
return;
|
||||
}
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
const entry = matches.value[selection.value];
|
||||
if (entry) choose(entry);
|
||||
}
|
||||
}
|
||||
|
||||
function choose(entry: NavEntry): void {
|
||||
void router.push(entry.path);
|
||||
close();
|
||||
}
|
||||
|
||||
// Keep the highlighted row visible once matches run past the rows that fit.
|
||||
// block: 'nearest' scrolls the minimum distance and never animates, so reduced
|
||||
// motion needs no handling here. Optional call: not every environment
|
||||
// implements scrollIntoView.
|
||||
watch([selection, matches], async () => {
|
||||
if (!open.value) return;
|
||||
await nextTick();
|
||||
list.value?.querySelector('[aria-selected="true"]')?.scrollIntoView?.({ block: "nearest" });
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="open" class="fixed inset-0 isolate z-50" @mousedown.self="close">
|
||||
<div class="bg-black/10 supports-backdrop-filter:backdrop-blur-xs absolute inset-0" aria-hidden="true" />
|
||||
<div
|
||||
role="dialog"
|
||||
aria-label="Command palette"
|
||||
class="bg-popover text-popover-foreground border-border-strong shadow-md mx-auto mt-[15vh] w-[calc(100%-2rem)] max-w-lg overflow-hidden rounded-xl border"
|
||||
>
|
||||
<div class="border-border flex items-center gap-2 border-b px-3">
|
||||
<Search :size="15" class="text-muted-foreground shrink-0" />
|
||||
<input
|
||||
ref="field"
|
||||
v-model="query"
|
||||
type="text"
|
||||
role="combobox"
|
||||
aria-label="Filter sections"
|
||||
aria-expanded="true"
|
||||
aria-controls="command-palette-list"
|
||||
:aria-activedescendant="matches[selection] ? optionId(selection) : undefined"
|
||||
class="h-11 w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground"
|
||||
placeholder="Jump to a section…"
|
||||
@keydown="onKeydown"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
id="command-palette-list"
|
||||
ref="list"
|
||||
role="listbox"
|
||||
aria-label="Sections"
|
||||
class="max-h-72 overflow-auto p-1.5"
|
||||
>
|
||||
<button
|
||||
v-for="(entry, index) in matches"
|
||||
:id="optionId(index)"
|
||||
:key="entry.path"
|
||||
type="button"
|
||||
role="option"
|
||||
:aria-selected="index === selection"
|
||||
class="hover:bg-muted aria-selected:bg-muted flex flex-col gap-0.5 rounded-md px-2.5 py-2 text-left outline-none"
|
||||
@mousedown.prevent
|
||||
@mousemove="selection = index"
|
||||
@click="choose(entry)"
|
||||
>
|
||||
<span class="truncate text-sm text-foreground">{{ entry.label }}</span>
|
||||
<span v-if="entry.description" class="text-fg-muted truncate text-xs">{{ entry.description }}</span>
|
||||
</button>
|
||||
<p v-if="!matches.length" class="text-fg-muted px-2.5 py-3 text-sm">No matching section.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -23,6 +23,11 @@ const detail = computed(() => activityDetail(props.event));
|
||||
function open() {
|
||||
if (taskID.value > 0) emit("open", taskID.value);
|
||||
}
|
||||
|
||||
// A missing timestamp gets an em-dash, not a call to ago(): substituting
|
||||
// Date.now() would render "just now" for an event whose time the daemon never
|
||||
// recorded -- a claim the row cannot back.
|
||||
const when = computed(() => (props.event.at ? ago(props.event.at) : "\u2014"));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -40,6 +45,6 @@ function open() {
|
||||
<TableCell class="w-[55%] max-w-0">
|
||||
<span class="block truncate" :title="detail.truncated ? detail.full : undefined">{{ detail.text }}</span>
|
||||
</TableCell>
|
||||
<TableCell>{{ ago(props.event.at || Date.now()) }}</TableCell>
|
||||
<TableCell>{{ when }}</TableCell>
|
||||
</TableRow>
|
||||
</template>
|
||||
@@ -27,29 +27,38 @@ function openTask(taskID: number) {
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Event</TableHead>
|
||||
<TableHead>Task</TableHead>
|
||||
<TableHead>Detail</TableHead>
|
||||
<TableHead>When</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!activity.length">
|
||||
<TableCell colspan="4">
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>Waiting for activity</EmptyTitle>
|
||||
<EmptyDescription>Events appear here as Archie works.</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<ActivityRow v-for="(event, i) in activity" v-else :key="i" :event="event" @open="openTask" />
|
||||
</TableBody>
|
||||
</Table>
|
||||
<!--
|
||||
role="region" names the table for landmark navigation; aria-live is
|
||||
polite, not assertive, because rows arrive constantly while the stream
|
||||
is live and an assertive region would talk over the operator. The live
|
||||
region is the table's wrapper, so new rows are announced as they
|
||||
appear without a second hidden summary to keep in sync.
|
||||
-->
|
||||
<div role="region" aria-label="Live activity" aria-live="polite">
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>Event</TableHead>
|
||||
<TableHead>Task</TableHead>
|
||||
<TableHead>Detail</TableHead>
|
||||
<TableHead>When</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!activity.length">
|
||||
<TableCell colspan="4">
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>Waiting for activity</EmptyTitle>
|
||||
<EmptyDescription>Events appear here as Archie works.</EmptyDescription>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<ActivityRow v-for="(event, i) in activity" v-else :key="i" :event="event" @open="openTask" />
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -100,7 +100,17 @@ async function reset(): Promise<void> {
|
||||
pushing every row apart. -->
|
||||
<Tooltip v-if="field?.description">
|
||||
<TooltipTrigger as-child>
|
||||
<span class="text-sm text-fg-muted">{{ label }}</span>
|
||||
<!--
|
||||
tabindex="0" is the keyboard path to the description: reka wires the
|
||||
trigger's focus/blur to the tooltip's open state, so Tab reaches the
|
||||
label and holding focus keeps the description on screen. The
|
||||
aria-label carries the label and the description together, because
|
||||
the tooltip content itself is out of the accessibility tree when the
|
||||
trigger is not hovered or focused. No visual change -- the focus
|
||||
floor in style.css draws the only new affordance, and only on
|
||||
keyboard focus.
|
||||
-->
|
||||
<span tabindex="0" :aria-label="`${label}: ${field.description}`" class="text-sm text-fg-muted">{{ label }}</span>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent :side-offset="8" class="max-w-80">{{ field.description }}</TooltipContent>
|
||||
</Tooltip>
|
||||
|
||||
@@ -15,12 +15,12 @@ export function revealBehavior(): ScrollBehavior {
|
||||
|
||||
<script setup lang="ts">
|
||||
import { RefreshCw } from "@lucide/vue";
|
||||
import { computed, nextTick, onMounted, ref, watch } from "vue";
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from "vue";
|
||||
import { useRoute, useRouter } from "vue-router";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { api } from "@/lib/api";
|
||||
import { api, subscribeEvents } from "@/lib/api";
|
||||
import TaskFilters, { initialTaskFilter, taskMatchesStatus } from "./TaskFilters.vue";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import TaskTable from "./TaskTable.vue";
|
||||
@@ -82,8 +82,37 @@ const state = computed<"loading" | "error" | "empty" | "no-match">(() => {
|
||||
|
||||
onMounted(() => {
|
||||
void load();
|
||||
unsubscribe = subscribeEvents(handleEvent);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearTimeout(refreshTimer);
|
||||
unsubscribe?.();
|
||||
});
|
||||
|
||||
// The live stream is an invalidation signal, not data (the same rule the
|
||||
// captures page follows): every task-shaped event says the authoritative list
|
||||
// changed, and load() asks for it again. Stage progress fires several events a
|
||||
// minute, so the re-read is debounced -- 500ms trailing, so a burst of events
|
||||
// collapses into one fetch that lands after the last one.
|
||||
const REFRESH_DEBOUNCE_MS = 500;
|
||||
let refreshTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
let unsubscribe: (() => void) | undefined;
|
||||
|
||||
function handleEvent(raw: unknown): void {
|
||||
const ev = raw as { kind?: string; task_id?: number | string } | null;
|
||||
if (!ev) return;
|
||||
// Task-shaped: anything carrying a task id (stage_start, agent_finish,
|
||||
// outcome, parked, human_approved, ...) or a lifecycle kind of its own
|
||||
// (task_queued, task_retried, ...). Chat turns and log lines never re-read
|
||||
// the board.
|
||||
if (!ev.task_id && !(typeof ev.kind === "string" && ev.kind.startsWith("task_"))) return;
|
||||
clearTimeout(refreshTimer);
|
||||
refreshTimer = setTimeout(() => {
|
||||
void load();
|
||||
}, REFRESH_DEBOUNCE_MS);
|
||||
}
|
||||
|
||||
async function load() {
|
||||
error.value = null;
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user