fix(webui): make task actions and dangerous approvals deliberate
Task rows render one primary control with the rest in an overflow menu instead of every catalog action at once; dangerous-action approvals and the daemon-restarting install confirm by name; the Needs-you tile reads the served attention statuses instead of a hardcoded pair; and dangerous.go stops calling the 24-hour approval permanent.
This commit is contained in:
5 files changed
+194
-33
No files matched your search
@@ -15,7 +15,9 @@ import (
|
||||
|
||||
const (
|
||||
dangerousApprovalLifetime = 10 * time.Minute
|
||||
permanentApprovalLifetime = 24 * time.Hour
|
||||
// The "permanent" decision on the wire grants an extended, but still
|
||||
// bounded, approval: 24 hours, then requests queue again.
|
||||
extendedApprovalLifetime = 24 * time.Hour
|
||||
)
|
||||
|
||||
// DangerousService adapts the daemon-owned sandbox authority to an
|
||||
@@ -24,9 +26,9 @@ const (
|
||||
type DangerousService struct {
|
||||
Authority messaging.DangerousCommandAuthority
|
||||
|
||||
mu sync.Mutex
|
||||
actions map[string]dangerousAction
|
||||
permanent map[string]time.Time
|
||||
mu sync.Mutex
|
||||
actions map[string]dangerousAction
|
||||
extended map[string]time.Time
|
||||
}
|
||||
|
||||
type dangerousAction struct {
|
||||
@@ -48,7 +50,7 @@ func NewDangerousService(authority messaging.DangerousCommandAuthority) *Dangero
|
||||
return &DangerousService{
|
||||
Authority: authority,
|
||||
actions: make(map[string]dangerousAction),
|
||||
permanent: make(map[string]time.Time),
|
||||
extended: make(map[string]time.Time),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +89,7 @@ func (s *DangerousService) Pending() []DangerousActionView {
|
||||
}
|
||||
|
||||
// Request creates a pending action unless the local operator has granted a
|
||||
// still-valid permanent approval for this operation family.
|
||||
// still-valid extended (24-hour) approval for this operation family.
|
||||
func (s *DangerousService) Request(ctx context.Context, kind, spec string) (DangerousActionView, string, bool, error) {
|
||||
if err := s.enabled(); err != nil {
|
||||
return DangerousActionView{}, "", false, err
|
||||
@@ -100,7 +102,7 @@ func (s *DangerousService) Request(ctx context.Context, kind, spec string) (Dang
|
||||
description := fmt.Sprintf("%s %s", kind, spec)
|
||||
s.mu.Lock()
|
||||
now := time.Now()
|
||||
if expires := s.permanent[kind]; expires.After(now) {
|
||||
if expires := s.extended[kind]; expires.After(now) {
|
||||
s.mu.Unlock()
|
||||
result, err := s.execute(ctx, kind, spec)
|
||||
return DangerousActionView{Kind: kind, Description: description, ExpiresAt: expires}, result, true, err
|
||||
@@ -131,8 +133,11 @@ func (s *DangerousService) Decide(ctx context.Context, id, decision string) (str
|
||||
case "approve":
|
||||
return s.execute(ctx, action.Kind, action.Spec)
|
||||
case "permanent":
|
||||
// Wire kind "permanent" grants the 24-hour extended approval, not an
|
||||
// unlimited one; the literal string is part of the contract with the
|
||||
// channels that dispatch decisions (see the telegram gateway).
|
||||
s.mu.Lock()
|
||||
s.permanent[action.Kind] = time.Now().Add(permanentApprovalLifetime)
|
||||
s.extended[action.Kind] = time.Now().Add(extendedApprovalLifetime)
|
||||
s.mu.Unlock()
|
||||
return s.execute(ctx, action.Kind, action.Spec)
|
||||
default:
|
||||
|
||||
@@ -3,6 +3,7 @@ import { computed } from "vue";
|
||||
|
||||
import StatTile from "@/base/StatTile.vue";
|
||||
import { compact } from "@/lib/format";
|
||||
import { attentionStatusIds } from "@/lib/task-meta";
|
||||
import { summary } from "./state";
|
||||
|
||||
/** The throughput row: what is running, what needs a human, what shipped. */
|
||||
@@ -12,7 +13,17 @@ const tokensByDay = computed(() => summary.value?.tokens_by_day ?? []);
|
||||
const series = computed(() => tokensByDay.value.map((d) => d.tokens || 0));
|
||||
|
||||
const done = computed(() => (counts.value.merged || 0) + (counts.value.pr_open || 0));
|
||||
const attention = computed(() => (counts.value.parked || 0) + (counts.value.waiting_human || 0));
|
||||
// "Needs you" is the server's grouping, not a local pair of ids: it is the
|
||||
// same attentionStatusIds() source TasksSummary and the needs_you filter read,
|
||||
// so a status that joins the grouping on the backend is counted here without
|
||||
// a frontend change.
|
||||
const attention = computed(() => {
|
||||
const attentionStatuses = attentionStatusIds();
|
||||
return Object.entries(counts.value).reduce(
|
||||
(sum, [status, n]) => (attentionStatuses.has(status) ? sum + (n || 0) : sum),
|
||||
0,
|
||||
);
|
||||
});
|
||||
const total = computed(() => Object.values(counts.value).reduce((a, b) => a + b, 0));
|
||||
const used = computed(() => series.value.reduce((a, b) => a + b, 0));
|
||||
|
||||
|
||||
@@ -1,4 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { decideDangerous } from "./state";
|
||||
import type { DangerousAction } from "./types";
|
||||
@@ -6,17 +18,65 @@ import type { DangerousAction } from "./types";
|
||||
/**
|
||||
* One queued request: what it would do, and the decisions open on it. Approve
|
||||
* runs it once, "Approve for 24h" runs it for a day, and Deny drops it.
|
||||
*
|
||||
* Both approves are destructive-weighted and confirmed first, because they
|
||||
* grant authority: approve for the one run, the 24h option for every future
|
||||
* request of the same family. Deny takes nothing away, so it stays plain.
|
||||
*/
|
||||
const props = defineProps<{ action: DangerousAction }>();
|
||||
|
||||
// Which approve decision is awaiting its confirmation, if any: one dialog
|
||||
// driven by the decision it will run, rather than two copies of the same
|
||||
// footer. The decision kinds are fixed by the endpoint ('approve' |
|
||||
// 'permanent' | 'deny') and must not be reworded here.
|
||||
const confirming = ref<"approve" | "permanent" | null>(null);
|
||||
|
||||
const description = computed(() => props.action.description || "this action");
|
||||
|
||||
function decide(decision: "approve" | "permanent" | "deny"): void {
|
||||
void decideDangerous(props.action.id, decision);
|
||||
}
|
||||
|
||||
function onConfirmationOpen(open: boolean): void {
|
||||
if (!open) confirming.value = null;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex flex-wrap items-center justify-between gap-3 border-t border-hairline py-3">
|
||||
<span class="text-sm">{{ props.action.description }}</span>
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Button variant="outline" @click="decideDangerous(props.action.id, 'approve')">Approve</Button>
|
||||
<Button variant="outline" @click="decideDangerous(props.action.id, 'permanent')">Approve for 24h</Button>
|
||||
<Button variant="outline" @click="decideDangerous(props.action.id, 'deny')">Deny</Button>
|
||||
<Button variant="destructive" @click="confirming = 'approve'">Approve</Button>
|
||||
<Button variant="destructive" @click="confirming = 'permanent'">Approve for 24h</Button>
|
||||
<Button variant="default" @click="decide('deny')">Deny</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<AlertDialog :open="confirming !== null" @update:open="onConfirmationOpen">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>
|
||||
{{ confirming === 'permanent' ? 'Approve for 24 hours?' : 'Approve this action?' }}
|
||||
</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
<template v-if="confirming === 'permanent'">
|
||||
This runs "{{ description }}" now, and approves its action family for 24 hours — further
|
||||
requests of the same kind run without asking again.
|
||||
</template>
|
||||
<template v-else>
|
||||
This runs "{{ description }}" once, now.
|
||||
</template>
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
variant="destructive"
|
||||
@click="confirming && decide(confirming)"
|
||||
>
|
||||
{{ confirming === 'permanent' ? 'Approve for 24h' : 'Approve' }}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</template>
|
||||
@@ -1,6 +1,16 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import ConfigCard from "./ConfigCard.vue";
|
||||
import { deferUpdate, installUpdate, update } from "./state";
|
||||
@@ -23,11 +33,21 @@ const summary = computed(() => {
|
||||
return "Archie is up to date.";
|
||||
});
|
||||
|
||||
// Installing restarts archied, so it is confirmed first: the operator needs
|
||||
// to know that this dashboard, and any tasks archied is running, go down with
|
||||
// it before the install call fires.
|
||||
const confirmingInstall = ref(false);
|
||||
|
||||
function defer(): void {
|
||||
void deferUpdate(update.value?.snapshot);
|
||||
}
|
||||
|
||||
function onInstallOpen(open: boolean): void {
|
||||
if (!open) confirmingInstall.value = false;
|
||||
}
|
||||
|
||||
function install(): void {
|
||||
confirmingInstall.value = false;
|
||||
void installUpdate(update.value?.snapshot);
|
||||
}
|
||||
</script>
|
||||
@@ -43,8 +63,24 @@ function install(): void {
|
||||
<div v-if="available.length" class="mt-3 flex flex-wrap gap-2">
|
||||
<Button variant="outline" @click="defer">Defer</Button>
|
||||
<!-- Installing restarts archied, so it is offered only when the server
|
||||
says it can perform one. -->
|
||||
<Button v-if="update.can_install" @click="install">Install update</Button>
|
||||
says it can perform one, and confirmed before it runs. -->
|
||||
<Button v-if="update.can_install" variant="destructive" @click="confirmingInstall = true">Install update</Button>
|
||||
</div>
|
||||
|
||||
<AlertDialog :open="confirmingInstall" @update:open="onInstallOpen">
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Install update</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Installing restarts archied. This dashboard will be unavailable until it comes back, and
|
||||
any tasks archied is running are interrupted.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="install">Install update</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</ConfigCard>
|
||||
</template>
|
||||
@@ -1,4 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { Ellipsis } from "@lucide/vue";
|
||||
import { computed, ref } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
@@ -13,6 +14,12 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
|
||||
import { actionFor, type ActionMeta } from "@/lib/task-meta";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
@@ -53,6 +60,20 @@ const controls = computed<Control[]>(() =>
|
||||
.map((meta) => ({ ...meta, href: meta.kind === "link" ? forgeLink(meta.id) : "" })),
|
||||
);
|
||||
|
||||
//
|
||||
// One primary plus overflow: a server-declared action list can hold seven
|
||||
// controls and two forge links, and a row that shows all of them as buttons in
|
||||
// one line is unreadable. So the first non-link control keeps a visible button
|
||||
// of its own; every other non-link control folds behind a '···' menu that runs
|
||||
// the identical request path, and the forge links stay inline after the
|
||||
// primary because they navigate rather than act.
|
||||
const nonLinkControls = computed<Control[]>(() => controls.value.filter((c) => c.kind !== "link"));
|
||||
const primaryControl = computed<Control | null>(() => nonLinkControls.value[0] ?? null);
|
||||
const overflowControls = computed<Control[]>(() => nonLinkControls.value.slice(1));
|
||||
const linkControls = computed<Control[]>(() => controls.value.filter((c) => c.kind === "link"));
|
||||
|
||||
const menuOpen = ref(false);
|
||||
|
||||
const confirmingMeta = computed(() => (confirmingId.value ? actionFor(confirmingId.value) : null));
|
||||
const confirmText = computed(() =>
|
||||
confirmingMeta.value?.confirm
|
||||
@@ -123,6 +144,14 @@ function onConfirmationOpen(open: boolean) {
|
||||
if (!open) confirming.value = null;
|
||||
}
|
||||
|
||||
// A menu item must close its menu before the dialog can take focus, so both
|
||||
// surfaces funnel through the same request() once the menu is down; the
|
||||
// inFlight disabling and the error handling stay identical either way.
|
||||
function requestFromMenu(id: string) {
|
||||
menuOpen.value = false;
|
||||
request(id);
|
||||
}
|
||||
|
||||
// A full reload, not a router navigation: the point is to re-establish the
|
||||
// session with whatever is in front of archied, which a client-side route
|
||||
// change would leave exactly as it was.
|
||||
@@ -149,29 +178,49 @@ function reloadPage() {
|
||||
|
||||
<!--
|
||||
One line, never wrapped: three controls on two lines doubled the height of
|
||||
every actionable row. Keystrokes stop at this container rather than
|
||||
bubbling to the row, which would open the task as well as press the button.
|
||||
every actionable row. The one-primary-plus-overflow rule (see the script)
|
||||
keeps the line short; keystrokes stop at this container rather than
|
||||
bubbling to the row, which would open the task as well as press the
|
||||
button.
|
||||
-->
|
||||
<div class="flex items-center gap-1" @keydown.stop>
|
||||
<template v-for="control in controls" :key="control.id">
|
||||
<template v-if="control.kind === 'link'">
|
||||
<Button v-if="control.href" as-child variant="outline" size="sm">
|
||||
<a :href="control.href" target="_blank" rel="noreferrer" @click.stop>{{ control.label }}</a>
|
||||
</Button>
|
||||
<Button v-else variant="outline" size="sm" disabled :title="`${control.label} is unavailable`">
|
||||
{{ control.label }}
|
||||
</Button>
|
||||
</template>
|
||||
<Button
|
||||
v-else
|
||||
:variant="variantFor(control.kind)"
|
||||
size="sm"
|
||||
:disabled="inFlight"
|
||||
@click.stop="request(control.id)"
|
||||
>
|
||||
<Button
|
||||
v-if="primaryControl"
|
||||
:variant="variantFor(primaryControl.kind)"
|
||||
size="sm"
|
||||
:disabled="inFlight"
|
||||
@click.stop="request(primaryControl.id)"
|
||||
>
|
||||
{{ primaryControl.label }}
|
||||
</Button>
|
||||
|
||||
<template v-for="control in linkControls" :key="control.id">
|
||||
<Button v-if="control.href" as-child variant="ghost" size="sm">
|
||||
<a :href="control.href" target="_blank" rel="noreferrer" @click.stop>{{ control.label }}</a>
|
||||
</Button>
|
||||
<Button v-else variant="ghost" size="sm" disabled :title="`${control.label} is unavailable`">
|
||||
{{ control.label }}
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<DropdownMenu v-if="overflowControls.length" v-model:open="menuOpen">
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button variant="ghost" size="icon-sm" aria-label="More actions" :disabled="inFlight" @click.stop>
|
||||
<Ellipsis :size="14" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
v-for="control in overflowControls"
|
||||
:key="control.id"
|
||||
:variant="control.kind === 'danger' ? 'destructive' : 'default'"
|
||||
:disabled="inFlight"
|
||||
@click.stop="requestFromMenu(control.id)"
|
||||
>
|
||||
{{ control.label }}
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
|
||||
<AlertDialog :open="confirming !== null" @update:open="onConfirmationOpen">
|
||||
|
||||
Reference in new issue
Block a user