Skip to content

Commit 430147f

Browse files
authored
feat(ui): approval UX overhaul — inline cards, fair queue, shortcuts, badges (#110989)
* feat(ui): overhaul approval experience * fix(ui): guard approval shortcuts against key auto-repeat and keep scoped errors on enqueue * fix(ui): arm approval shortcuts after focus settles and scope error clearing to the settled request * fix(ui): approval hardening — modifier-chord shortcuts, pinned active card, badge fallback, quiet countdown * fix(ui): scope approval errors per request * style(ui): format approval queue test * fix(ui): tolerate missing approval overlays * perf(ui): lazy-load approval modal controls * fix(ui): satisfy approval lazy-load guards * style(ui): satisfy approval card lint
1 parent 7b3a8db commit 430147f

27 files changed

Lines changed: 1426 additions & 297 deletions

‎ui/src/app/app-host.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ type ShellLazySurfaceState = ShellKeyboardState & {
6464
terminalPanelElement: TestOptionalCustomElement;
6565
};
6666

67+
type ShellApprovalLazyState = {
68+
approvalOverlay?: { show: () => void };
69+
execApprovalElement: TestOptionalCustomElement;
70+
openApprovals: () => void;
71+
};
72+
6773
type ShellUiCommandState = ShellKeyboardState & {
6874
handleGatewayEvent: (event: { event: string; payload: unknown }) => void;
6975
};
@@ -507,6 +513,25 @@ describe("OpenClaw shell keyboard shortcuts", () => {
507513
});
508514
});
509515

516+
it("opens approvals after the modal module loads on demand", async () => {
517+
const element = createLazyElementSpec("exec approval modal");
518+
const show = vi.fn();
519+
const shell = document.createElement("openclaw-app-shell") as unknown as ShellApprovalLazyState;
520+
shell.execApprovalElement = element;
521+
Object.defineProperty(shell, "updateComplete", {
522+
configurable: true,
523+
get: () => Promise.resolve(true),
524+
});
525+
Object.defineProperty(shell, "approvalOverlay", {
526+
configurable: true,
527+
get: () => (customElements.get(element.tagName) ? { show } : undefined),
528+
});
529+
530+
shell.openApprovals();
531+
532+
await vi.waitFor(() => expect(show).toHaveBeenCalledOnce());
533+
});
534+
510535
it("routes UI commands to navigation, panels, and chat fallback", () => {
511536
const update = vi.fn();
512537
const setSessionKey = vi.fn();

‎ui/src/app/app-host.ts‎

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import "../components/app-sidebar.ts";
1212
import "../components/app-topbar.ts";
1313
import "../components/connection-banner.ts";
14-
import "../components/exec-approval.ts";
1514
import "../components/gateway-url-confirmation.ts";
1615
import "../components/github-link-hovercard-registration.ts";
1716
import "../components/login-gate.ts";
@@ -55,6 +54,7 @@ import { findSettingsSearchBlocks } from "../pages/config/settings-search.ts";
5554
import { newSessionSearch, type NewSessionTarget } from "../pages/new-session/location.ts";
5655
import { renderDevicePairSetup } from "../pages/nodes/view-pairing.ts";
5756
import { pluginTabKey, pluginTabRefFromSearch } from "../pages/plugin/route.ts";
57+
import { findInlineApproval } from "./approval-presentation.ts";
5858
import { bootstrapApplication, type ApplicationRuntime } from "./bootstrap.ts";
5959
import {
6060
applicationContext,
@@ -66,6 +66,7 @@ import {
6666
APPROVAL_PAGE_ELEMENT,
6767
BROWSER_PANEL_ELEMENT,
6868
COMMAND_PALETTE_ELEMENT,
69+
EXEC_APPROVAL_ELEMENT,
6970
ensureOptionalElementForHost,
7071
isOptionalElementDefined,
7172
preloadOptionalElement,
@@ -458,6 +459,7 @@ class OpenClawShell extends OpenClawLightDomElement {
458459
private readonly commandPaletteElement = COMMAND_PALETTE_ELEMENT;
459460
private readonly terminalPanelElement = TERMINAL_PANEL_ELEMENT;
460461
private readonly browserPanelElement = BROWSER_PANEL_ELEMENT;
462+
private readonly execApprovalElement = EXEC_APPROVAL_ELEMENT;
461463
@query("openclaw-command-palette") private commandPalette?: CommandPaletteElement;
462464
@query("openclaw-exec-approval")
463465
private approvalOverlay?: HTMLElement & { show(): void };
@@ -1009,6 +1011,20 @@ class OpenClawShell extends OpenClawLightDomElement {
10091011
this.runWithCommandPalette((palette) => palette.togglePalette());
10101012
};
10111013

1014+
private readonly openApprovals = () => {
1015+
const show = () => this.approvalOverlay?.show();
1016+
if (isOptionalElementDefined(this.execApprovalElement)) {
1017+
show();
1018+
return;
1019+
}
1020+
void ensureOptionalElementForHost(this, this.execApprovalElement)
1021+
.then(async () => {
1022+
await this.updateComplete;
1023+
show();
1024+
})
1025+
.catch(() => undefined);
1026+
};
1027+
10121028
private deliverPanelEventAfterLoad(element: OptionalCustomElement, event: Event): void {
10131029
void ensureOptionalElementForHost(this, element)
10141030
.then(async () => {
@@ -1099,6 +1115,9 @@ class OpenClawShell extends OpenClawLightDomElement {
10991115
preloadOptionalElement(this, this.browserPanelElement);
11001116
}
11011117
}
1118+
if ((context.overlays?.snapshot.approvalQueue.length ?? 0) > 0) {
1119+
preloadOptionalElement(this, this.execApprovalElement);
1120+
}
11021121
const navState = {
11031122
collapsed: this.nativeNavCollapsed(),
11041123
width: context.navigation.snapshot.navWidth,
@@ -1296,6 +1315,10 @@ class OpenClawShell extends OpenClawLightDomElement {
12961315
// its scrolling and pins the composer dock to the bottom.
12971316
const chatLikeRoute =
12981317
activeRoute === "chat" || activeRoute === "custodian" || activeRoute === "new-session";
1318+
const inlineApproval =
1319+
activeRoute === "chat"
1320+
? findInlineApproval(overlaySnapshot.approvalQueue, this.activeSessionKey)
1321+
: null;
12991322
// Optional tags stay mounted before definition. Lit replays their properties on upgrade,
13001323
// and the upgraded panels catch the first toggle instead of dropping the event.
13011324
return html`
@@ -1414,7 +1437,7 @@ class OpenClawShell extends OpenClawLightDomElement {
14141437
.updateRunning=${overlaySnapshot.updateRunning}
14151438
.onUpdate=${() => void context.overlays.runUpdate()}
14161439
.onOpenPalette=${this.openPalette}
1417-
.onOpenApprovals=${() => this.approvalOverlay?.show()}
1440+
.onOpenApprovals=${this.openApprovals}
14181441
.onToggleSidebar=${() => this.toggleNavigationSurface()}
14191442
.onOpenNewSession=${(agentId: string, target?: NewSessionTarget) => {
14201443
const search = newSessionSearch(agentId, target);
@@ -1493,15 +1516,21 @@ class OpenClawShell extends OpenClawLightDomElement {
14931516
password: context.gateway.connection.password,
14941517
})}
14951518
></openclaw-browser-panel>
1496-
<openclaw-exec-approval
1497-
.props=${{
1498-
queue: overlaySnapshot.approvalQueue,
1499-
busy: overlaySnapshot.approvalBusy,
1500-
error: overlaySnapshot.approvalError,
1501-
onDecision: (decision: Parameters<typeof context.overlays.decideApproval>[0]) =>
1502-
context.overlays.decideApproval(decision),
1503-
}}
1504-
></openclaw-exec-approval>
1519+
${isOptionalElementDefined(this.execApprovalElement)
1520+
? html`<openclaw-exec-approval
1521+
.props=${{
1522+
queue: overlaySnapshot.approvalQueue,
1523+
busy: overlaySnapshot.approvalBusy,
1524+
errors: overlaySnapshot.approvalErrors,
1525+
nowMs: overlaySnapshot.approvalNowMs,
1526+
inlineApprovalId: inlineApproval?.id ?? null,
1527+
onDecision: (
1528+
approvalId: string,
1529+
decision: Parameters<typeof context.overlays.decideApproval>[0],
1530+
) => context.overlays.decideApproval(decision, approvalId),
1531+
}}
1532+
></openclaw-exec-approval>`
1533+
: nothing}
15051534
${renderDevicePairSetup({
15061535
open: overlaySnapshot.devicePairSetupOpen,
15071536
loading: overlaySnapshot.devicePairSetupLoading,
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// @vitest-environment node
2+
import { describe, expect, it } from "vitest";
3+
import {
4+
deriveApprovalBadgeSnapshot,
5+
findInlineApproval,
6+
modalApprovalQueue,
7+
sessionHasPendingApproval,
8+
} from "./approval-presentation.ts";
9+
import type { ExecApprovalRequest } from "./exec-approval.ts";
10+
11+
function approval(
12+
id: string,
13+
options: { agentId?: string; sessionKey?: string } = {},
14+
): ExecApprovalRequest {
15+
return {
16+
id,
17+
kind: "exec",
18+
request: { command: `echo ${id}`, ...options },
19+
createdAtMs: Number(id.replace(/\D/g, "")) || 1,
20+
expiresAtMs: Date.now() + 60_000,
21+
};
22+
}
23+
24+
describe("approval presentation", () => {
25+
it("puts the oldest matching active-session request inline and suppresses only it", () => {
26+
const queue = [
27+
approval("approval-1", { sessionKey: "agent:main:current" }),
28+
approval("approval-2", { sessionKey: "agent:main:other" }),
29+
approval("approval-3", { sessionKey: "AGENT:MAIN:CURRENT" }),
30+
];
31+
32+
const inline = findInlineApproval(queue, "agent:main:current");
33+
34+
expect(inline?.id).toBe("approval-1");
35+
expect(modalApprovalQueue(queue, inline?.id).map((entry) => entry.id)).toEqual([
36+
"approval-2",
37+
"approval-3",
38+
]);
39+
});
40+
41+
it("keeps every request in the modal when the active session does not match", () => {
42+
const queue = [approval("approval-1", { sessionKey: "agent:main:other" })];
43+
44+
const inline = findInlineApproval(queue, "agent:main:current");
45+
46+
expect(inline).toBeNull();
47+
expect(modalApprovalQueue(queue, inline?.id)).toBe(queue);
48+
});
49+
50+
it("keeps catalog-session requests modal because catalog chat cannot render them inline", () => {
51+
const queue = [approval("approval-1", { sessionKey: "catalog:codex:host:thread" })];
52+
53+
const inline = findInlineApproval(queue, "catalog:codex:host:thread");
54+
55+
expect(inline).toBeNull();
56+
expect(modalApprovalQueue(queue, inline?.id)).toBe(queue);
57+
});
58+
59+
it("derives per-agent counts and per-session flags from one queue snapshot", () => {
60+
const snapshot = deriveApprovalBadgeSnapshot([
61+
approval("approval-1", { agentId: "Main", sessionKey: "agent:main:one" }),
62+
approval("approval-2", { agentId: "main", sessionKey: "agent:main:two" }),
63+
approval("approval-3", { agentId: "worker", sessionKey: "agent:worker:one" }),
64+
approval("approval-4"),
65+
]);
66+
67+
expect(Object.fromEntries(snapshot.agentCounts)).toEqual({ main: 2, worker: 1 });
68+
expect(sessionHasPendingApproval(snapshot, "AGENT:MAIN:ONE")).toBe(true);
69+
expect(sessionHasPendingApproval(snapshot, "agent:main:missing")).toBe(false);
70+
});
71+
72+
it("falls back to the agent session key when agentId is absent", () => {
73+
const snapshot = deriveApprovalBadgeSnapshot([
74+
approval("approval-1", { sessionKey: "agent:worker:one" }),
75+
approval("approval-2", { sessionKey: "not-an-agent-key" }),
76+
]);
77+
78+
expect(Object.fromEntries(snapshot.agentCounts)).toEqual({ worker: 1 });
79+
});
80+
});
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import { parseCatalogSessionKey } from "../lib/sessions/catalog-key.ts";
2+
import {
3+
normalizeAgentId,
4+
normalizeSessionKeyForUiComparison,
5+
parseAgentSessionKey,
6+
} from "../lib/sessions/session-key.ts";
7+
import type { ExecApprovalRequest } from "./exec-approval.ts";
8+
9+
export type ApprovalBadgeSnapshot = {
10+
agentCounts: ReadonlyMap<string, number>;
11+
sessionKeys: ReadonlySet<string>;
12+
};
13+
14+
export function findInlineApproval(
15+
queue: readonly ExecApprovalRequest[],
16+
sessionKey: string | null | undefined,
17+
): ExecApprovalRequest | null {
18+
const normalizedSessionKey = normalizeSessionKeyForUiComparison(sessionKey);
19+
if (!normalizedSessionKey || parseCatalogSessionKey(normalizedSessionKey)) {
20+
return null;
21+
}
22+
return (
23+
queue.find(
24+
(entry) =>
25+
normalizeSessionKeyForUiComparison(entry.request.sessionKey) === normalizedSessionKey,
26+
) ?? null
27+
);
28+
}
29+
30+
export function modalApprovalQueue(
31+
queue: readonly ExecApprovalRequest[],
32+
inlineApprovalId: string | null | undefined,
33+
): readonly ExecApprovalRequest[] {
34+
return inlineApprovalId ? queue.filter((entry) => entry.id !== inlineApprovalId) : queue;
35+
}
36+
37+
export function deriveApprovalBadgeSnapshot(
38+
queue: readonly ExecApprovalRequest[],
39+
): ApprovalBadgeSnapshot {
40+
const agentCounts = new Map<string, number>();
41+
const sessionKeys = new Set<string>();
42+
for (const entry of queue) {
43+
// agentId is optional on approval events; an agent-scoped session key
44+
// still names the owner, and dropping it would badge the session row
45+
// while the agent card shows no pending count.
46+
const agentId =
47+
entry.request.agentId?.trim() || parseAgentSessionKey(entry.request.sessionKey)?.agentId;
48+
if (agentId) {
49+
const normalizedAgentId = normalizeAgentId(agentId);
50+
agentCounts.set(normalizedAgentId, (agentCounts.get(normalizedAgentId) ?? 0) + 1);
51+
}
52+
const sessionKey = normalizeSessionKeyForUiComparison(entry.request.sessionKey);
53+
if (sessionKey) {
54+
sessionKeys.add(sessionKey);
55+
}
56+
}
57+
return { agentCounts, sessionKeys };
58+
}
59+
60+
export function sessionHasPendingApproval(
61+
snapshot: ApprovalBadgeSnapshot,
62+
sessionKey: string | null | undefined,
63+
): boolean {
64+
const normalizedSessionKey = normalizeSessionKeyForUiComparison(sessionKey);
65+
return normalizedSessionKey ? snapshot.sessionKeys.has(normalizedSessionKey) : false;
66+
}

0 commit comments

Comments
 (0)