Watch
0
0
Fork
You've already forked hyperhive
0

swarm ui: ask before actions that cannot be undone, with a danger button and a useConfirm hook

Button gains a danger variant and an autofocus prop; ConfirmDialog gains danger (red confirm, focus on cancel). Destroy, delete linked account, delete claude login, remove schedule and delete flow use it. New useConfirm hook asks from inside a handler (await confirm({...})) without a dialog's state at the call site. It now guards: removing a swarm-wide egress domain, removing a domain for every agent from an agent's popover, removing a stored API-key environment, firing a schedule now, moving an agent's internet to a looser mode, the /clear message, and reload over unsaved instructions (replacing window.confirm). The review try-out's button is now called push a branch for a PR, since it pushes a branch and does not open one, and asks first. loosensInternet is a tested helper.
This commit is contained in:
iris 2026-11-19 18:42:34 +01:00 • committed by mara
commit c3e24fe2c6
8 changed files with 353 additions and 60 deletions

View file

@ -125,6 +125,7 @@ export function AgentClaudeLogin({ agent }: { agent: string }) {
open={confirming}
label={`delete the stored claude login for ${agent}`}
confirmLabel={deleting ? "deleting…" : "delete login"}
danger
confirmDisabled={deleting}
onCancel={() => setConfirming(false)}
onConfirm={() => void confirmDelete()}

View file

@ -18,6 +18,7 @@ import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
import { Badge } from "@hive/shared/badge.js";
import { ActionRow } from "../../ui/action-row/ActionRow.js";
import { Button } from "../../ui/button/Button.js";
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
import { Preformatted } from "../../ui/preformatted/Preformatted.js";
import { Dialog } from "../../ui/dialog/Dialog.js";
import { Panel } from "../../ui/panel/Panel.js";
@ -113,6 +114,22 @@ function InstructionsForm({
const [busy, setBusy] = useState(false);
const [problem, setProblem] = useState<ProblemDetails | null>(null);
const [saved, setSaved] = useState(false);
const [confirm, confirmDialog] = useConfirm();
// Loading the agent's file drops what is typed, so unsaved edits ask first.
async function askReload() {
if (
!dirty ||
(await confirm({
label: "drop unsaved changes",
confirmLabel: "drop and reload",
danger: true,
body: <p>Drop your unsaved changes and load {agent}'s file?</p>,
}))
) {
reload();
}
}
useEffect(() => {
let cancelled = false;
@ -294,24 +311,14 @@ function InstructionsForm({
>
undo my changes
</Button>
<Button
disabled={busy}
onClick={() => {
if (
!dirty ||
window.confirm(
"Drop your unsaved changes and load the agent's file?",
)
)
reload();
}}
>
<Button disabled={busy} onClick={() => void askReload()}>
reload from {agent}
</Button>
</ActionRow>
</form>
) : null}
</div>
{confirmDialog}
</Panel>
);
}

View file

@ -22,6 +22,7 @@ import { readApiError, type ProblemDetails } from "@hive/shared/api-error.js";
import { Badge } from "@hive/shared/badge.js";
import { BadgePopover } from "../../ui/badge-popover/BadgePopover.js";
import { Button } from "../../ui/button/Button.js";
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
import { BadgeSkeleton } from "../../ui/skeleton/BadgeSkeleton.js";
import { Hint } from "../../ui/hint/Hint.js";
import { TextField } from "../../ui/text-field/TextField.js";
@ -40,6 +41,7 @@ import {
maxReposBody,
parseMaxRepos,
reposSummary,
loosensInternet,
type InternetMode,
} from "./permissions.js";
import "./AgentLimits.css";
@ -257,9 +259,37 @@ export function AgentPermissions({
export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
const { grant, busy, saveError, loading, send } = g;
const [confirm, confirmDialog] = useConfirm();
if (grant === null) return loading;
const mode = internetMode(grant.unrestricted_internet, grant.internet_log);
// Letting more traffic out is asked first, and says what it lets out; going
// back to a tighter mode is not.
async function choose(next: InternetMode) {
if (grant === null) return;
if (loosensInternet(mode, next)) {
const meaning = INTERNET_MODES.find(([m]) => m === next)?.[2] ?? "";
const yes = await confirm({
label: `set ${agent} internet to ${next}`,
confirmLabel: `set ${next}`,
danger: next === "unrestricted",
body: (
<p>
Set <strong>{agent}</strong>'s internet to <strong>{next}</strong>?
This will {meaning}.
</p>
),
});
if (!yes) return;
}
void send({
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify(internetBody(grant.permissions, next)),
});
}
return (
<div class="ui-agent-limits">
<BadgePopover
@ -284,18 +314,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
value={label}
title={`${meaning} for ${agent}`}
disabled={busy}
onClick={
m === mode
? undefined
: () =>
void send({
method: "PUT",
headers: { "content-type": "application/json" },
body: JSON.stringify(
internetBody(grant.permissions, m),
),
})
}
onClick={m === mode ? undefined : () => void choose(m)}
/>{" "}
<Hint as="span">{meaning}</Hint>
</li>
@ -308,6 +327,7 @@ export function AgentInternet({ agent, g }: { agent: string; g: GrantState }) {
/>
) : null}
</BadgePopover>
{confirmDialog}
</div>
);
}

View file

@ -27,6 +27,7 @@ import { Badge } from "@hive/shared/badge.js";
import { ActionRow } from "../../ui/action-row/ActionRow.js";
import { BadgePopover } from "../../ui/badge-popover/BadgePopover.js";
import { Button } from "../../ui/button/Button.js";
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
import { FormStack } from "../../ui/form-stack/FormStack.js";
import { CheckboxField } from "../../ui/checkbox-field/CheckboxField.js";
import { Dialog } from "../../ui/dialog/Dialog.js";
@ -66,6 +67,30 @@ function groupHelp(source: EntryGroup["source"], agent: string): string {
export function AllowedDomains({ agent }: { agent: string }) {
const { entries, error, busy, remove, refetch } = useAllowedDomains();
const [adding, setAdding] = useState(false);
const [confirm, confirmDialog] = useConfirm();
// A removal that applies to every agent asks first; one for this agent only
// is easy to add back.
async function removeEntry(e: Parameters<typeof remove>[0]) {
if (
e.agent === undefined &&
!(await confirm({
label: `stop allowing ${e.domain} for every agent`,
confirmLabel: "stop allowing",
danger: true,
body: (
<p>
Stop allowing <code>{e.domain}</code> for{" "}
<strong>every agent</strong>? Agents lose access to it through the
proxy, not just {agent}.
</p>
),
}))
) {
return;
}
void remove(e);
}
// A list already loaded stays under a failed refetch, so a change that
// worked is not hidden by a read that did not.
@ -114,7 +139,7 @@ export function AllowedDomains({ agent }: { agent: string }) {
e.agent === undefined ? "every agent" : agent
}`}
disabled={busy}
onClick={() => void remove(e)}
onClick={() => void removeEntry(e)}
/>
)}
</li>
@ -147,6 +172,7 @@ export function AllowedDomains({ agent }: { agent: string }) {
/>
) : null}
</Dialog>
{confirmDialog}
</div>
);
}

View file

@ -107,6 +107,7 @@ export function LinkedAccounts({
onCancel={() => setDeleteTarget(null)}
onConfirm={() => void confirmDelete()}
confirmLabel="delete"
danger
confirmDisabled={deleting}
>
{deleteTarget ? (

View file

@ -25,6 +25,17 @@ export function grantSummary(stored: string[] | undefined): string {
/** The three modes of an agent's internet access. */
export type InternetMode = "unrestricted" | "log" | "restricted";
const INTERNET_OPENNESS: Record<InternetMode, number> = {
restricted: 0,
log: 1,
unrestricted: 2,
};
/** Whether a change of mode lets more traffic through: the one that is asked first. */
export function loosensInternet(from: InternetMode, to: InternetMode): boolean {
return INTERNET_OPENNESS[to] > INTERNET_OPENNESS[from];
}
/**
* How the panel reads the stored `unrestricted_internet` and `internet_log`.
* An absent flag counts as on, and says "legacy" because the swarm never set

View file

@ -325,6 +325,7 @@ export function useAgentActions(
onCancel={() => setDestroyTarget(null)}
onConfirm={() => destroyTarget && void destroyAgent(destroyTarget)}
confirmLabel="destroy"
danger
>
{destroyTarget ? (
<p>

View file

@ -34,6 +34,7 @@ import {
moveSelection,
type AgentCommand,
} from "./command-menu.js";
import { useConfirm } from "../../ui/confirm-dialog/useConfirm.js";
import { useAgentCommands } from "./useAgentCommands.js";
import "./AgentInputForm.css";
@ -42,6 +43,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
const [selected, setSelected] = useState(0);
const [closed, setClosed] = useState(false);
const { state, submitting, run } = useSubmit();
const [confirm, confirmDialog] = useConfirm();
const commands = useAgentCommands(agentName);
const query = menuQuery(body);
@ -57,10 +59,27 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
setClosed(false);
}, [body]);
function submit(e: Event) {
async function submit(e: Event) {
e.preventDefault();
const base = `/api/agents/${encodeURIComponent(agentName)}`;
const route = controlRoute(body, commands);
// /clear drops the agent's conversation, so it is asked first.
if (
route === "new-session" &&
!(await confirm({
label: "start a new session",
confirmLabel: "start a new session",
danger: true,
body: (
<p>
Start a new session for <strong>{agentName}</strong>? Its current
conversation is dropped on its next turn.
</p>
),
}))
) {
return;
}
void run(
() =>
route
@ -142,6 +161,7 @@ export function AgentInputForm({ agentName }: { agentName: string }) {
{submitting ? <Spinner /> : <SendIcon />}
</button>
</form>
{confirmDialog}
</div>
);
}