Skip to content

Commit ed17993

Browse files
authored
feat(ui): surface approvals passively and redesign the approval card (#124767)
* feat(ui): surface approvals passively and redesign the approval card Approvals no longer auto-open the centered modal: the queue is reachable only through the sidebar attention chip, while the owning session shows the inline card and other sessions surface via the session-row shield icon, agent badges, and the chip. Deletes the inline-vs-modal exclusion machinery (modalApprovalQueue, inlineApprovalId, forceShowAll) and makes modal dismissal close the view instead of denying the active request. Card: severity now drives the accent color instead of a table row, plugin/agent render as header chips, the session key moves behind a collapsed Details disclosure (modal only), and low-value exec rows (Resolved/Security/Ask) collapse into the same disclosure. The codex app-server bridge stops duplicating the session key into description text; the envelope already carries it. * fix(ui): gate settings Escape on the approval dialog's recorded open state ClawSweeper caught that shouldIgnoreSettingsEscape still inferred an open approval dialog from queue non-emptiness; with passive approvals a pending queue no longer implies a visible dialog, so settings would swallow Escape. The exec-approval element now records dialogOpen as a fact and the guard reads it.
1 parent d8ebe85 commit ed17993

18 files changed

Lines changed: 429 additions & 180 deletions

‎extensions/codex/src/app-server/approval-bridge.test.ts‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ describe("Codex app-server approval bridge", () => {
21412141
});
21422142

21432143
expect(gatewayRequestPayload().description).toBe(
2144-
"Command: pnpm test --watch extensions/codex/src/app-server\nSession: agent:main:session-1",
2144+
"Command: pnpm test --watch extensions/codex/src/app-server",
21452145
);
21462146
findApprovalEvent(params, {
21472147
status: "pending",
@@ -2196,9 +2196,7 @@ describe("Codex app-server approval bridge", () => {
21962196
...codexTestTurnIds(),
21972197
});
21982198

2199-
expect(gatewayRequestPayload().description).toBe(
2200-
"Command: prefix VISIBLE suffix\nSession: agent:main:session-1",
2201-
);
2199+
expect(gatewayRequestPayload().description).toBe("Command: prefix VISIBLE suffix");
22022200
findApprovalEvent(params, { command: "prefix VISIBLE suffix" });
22032201
});
22042202

@@ -2219,9 +2217,7 @@ describe("Codex app-server approval bridge", () => {
22192217
...codexTestTurnIds(),
22202218
});
22212219

2222-
expect(gatewayRequestPayload().description).toBe(
2223-
"Command: echo safe cod.exe hidden done\nSession: agent:main:session-1",
2224-
);
2220+
expect(gatewayRequestPayload().description).toBe("Command: echo safe cod.exe hidden done");
22252221
findApprovalEvent(params, { command: "echo safe cod.exe hidden done" });
22262222
});
22272223

@@ -2245,7 +2241,7 @@ describe("Codex app-server approval bridge", () => {
22452241
});
22462242

22472243
expect(gatewayRequestPayload().description).toBe(
2248-
"Command: [preview truncated or unsafe content omitted]\nSession: agent:main:session-1",
2244+
"Command: [preview truncated or unsafe content omitted]",
22492245
);
22502246
const omittedEvent = findApprovalEvent(params, {});
22512247
expect(omittedEvent.commandPreviewOmitted).toBe(true);
@@ -2536,9 +2532,7 @@ describe("Codex app-server approval bridge", () => {
25362532
...codexTestTurnIds(),
25372533
});
25382534

2539-
expect(gatewayRequestPayload().description).toBe(
2540-
"Reason: needs write access for /tmp please\nSession: agent:main:session-1",
2541-
);
2535+
expect(gatewayRequestPayload().description).toBe("Reason: needs write access for /tmp please");
25422536
findApprovalEvent(params, {
25432537
status: "unavailable",
25442538
reason: "needs write access for /tmp please",

‎extensions/codex/src/app-server/approval-bridge.ts‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -343,13 +343,7 @@ function buildApprovalContext(params: {
343343
const description =
344344
permissionLines.length > 0
345345
? joinDescriptionLinesWithinLimit(permissionLines, PERMISSION_DESCRIPTION_MAX_LENGTH)
346-
: [
347-
subject,
348-
...commandDetailLines,
349-
params.paramsForRun.sessionKey && `Session: ${params.paramsForRun.sessionKey}`,
350-
]
351-
.filter(Boolean)
352-
.join("\n");
346+
: [subject, ...commandDetailLines].join("\n");
353347
return {
354348
kind,
355349
title,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class OpenClawShell
137137
readonly execApprovalElement = EXEC_APPROVAL_ELEMENT;
138138
@query("openclaw-command-palette") commandPalette: CommandPaletteElement | undefined;
139139
@query("openclaw-exec-approval")
140-
approvalOverlay: (HTMLElement & { show(): void }) | undefined;
140+
approvalOverlay: (HTMLElement & { show(): void; dialogOpen?: boolean }) | undefined;
141141
commandPaletteTarget: CommandPaletteTargetDetail | undefined;
142142
navDrawerTrigger: HTMLElement | null = null;
143143
// Desktop and modal navigation are two slots for the same live sidebar.

‎ui/src/app/app-shell-chrome.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ export interface ShellChromeHost extends HTMLElement {
7474
readonly desktopPanelElement: OptionalCustomElement;
7575
readonly execApprovalElement: OptionalCustomElement;
7676
readonly commandPalette: CommandPaletteElement | undefined;
77-
readonly approvalOverlay: (HTMLElement & { show(): void }) | undefined;
77+
readonly approvalOverlay: (HTMLElement & { show(): void; dialogOpen?: boolean }) | undefined;
7878
routeState: ShellRouteState;
7979
navDrawerOpen: boolean;
8080
desktopNavigationExpanded: boolean;
@@ -407,7 +407,7 @@ export class ShellChromeOwner {
407407
if (
408408
host.commandPalette?.isOpen ||
409409
overlaySnapshot?.devicePairSetupOpen ||
410-
(overlaySnapshot?.approvalQueue.length ?? 0) > 0 ||
410+
host.approvalOverlay?.dialogOpen === true ||
411411
document.querySelector("dialog[open]")
412412
) {
413413
return true;

‎ui/src/app/app-shell-view.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import type { ShellRouteState } from "./app-host-route-state.ts";
2121
import { resolveTerminalThemeMode } from "./app-root.ts";
2222
import { isBrowserPanelAvailable, isDesktopPanelAvailable } from "./app-shell-chrome.ts";
2323
import type { OutboxStoreRuntime, StoredOutboxScopeHost } from "./app-shell-gateway.ts";
24-
import { findInlineApproval } from "./approval-presentation.ts";
2524
import type { ApplicationRuntime } from "./bootstrap.ts";
2625
import type { ApplicationContext, ApplicationNavigationOptions } from "./context.ts";
2726
import { resolveControlUiAuthToken } from "./control-ui-auth.ts";
@@ -347,9 +346,6 @@ export function renderApplicationShell(host: ShellViewHost) {
347346
// its scrolling and pins the composer dock to the bottom.
348347
const chatLikeRoute = isSessionRouteId(activeRoute) || activeRoute === "new-session";
349348
const custodianRoute = activeRoute === "custodian";
350-
const inlineApproval = isSessionRouteId(activeRoute)
351-
? findInlineApproval(overlaySnapshot.approvalQueue, host.activeSessionKey)
352-
: null;
353349
if (!settingsTakeover) {
354350
Object.assign(host.navigationSidebar, {
355351
basePath: context.basePath,
@@ -649,7 +645,6 @@ export function renderApplicationShell(host: ShellViewHost) {
649645
busy: overlaySnapshot.approvalBusy,
650646
errors: overlaySnapshot.approvalErrors,
651647
nowMs: overlaySnapshot.approvalNowMs,
652-
inlineApprovalId: inlineApproval?.id ?? null,
653648
onDecision: (
654649
approvalId: string,
655650
decision: Parameters<typeof context.overlays.decideApproval>[0],

‎ui/src/app/approval-presentation.test.ts‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { describe, expect, it } from "vitest";
33
import {
44
deriveApprovalBadgeSnapshot,
55
findInlineApproval,
6-
modalApprovalQueue,
76
sessionHasPendingApproval,
87
} from "./approval-presentation.ts";
98
import type { ExecApprovalRequest } from "./exec-approval.ts";
@@ -22,7 +21,7 @@ function approval(
2221
}
2322

2423
describe("approval presentation", () => {
25-
it("puts the oldest matching active-session request inline and suppresses only it", () => {
24+
it("puts the oldest matching active-session request inline", () => {
2625
const queue = [
2726
approval("approval-1", { sessionKey: "agent:main:current" }),
2827
approval("approval-2", { sessionKey: "agent:main:other" }),
@@ -32,28 +31,22 @@ describe("approval presentation", () => {
3231
const inline = findInlineApproval(queue, "agent:main:current");
3332

3433
expect(inline?.id).toBe("approval-1");
35-
expect(modalApprovalQueue(queue, inline?.id).map((entry) => entry.id)).toEqual([
36-
"approval-2",
37-
"approval-3",
38-
]);
3934
});
4035

41-
it("keeps every request in the modal when the active session does not match", () => {
36+
it("does not select an inline request when the active session does not match", () => {
4237
const queue = [approval("approval-1", { sessionKey: "agent:main:other" })];
4338

4439
const inline = findInlineApproval(queue, "agent:main:current");
4540

4641
expect(inline).toBeNull();
47-
expect(modalApprovalQueue(queue, inline?.id)).toBe(queue);
4842
});
4943

50-
it("keeps catalog-session requests modal because catalog chat cannot render them inline", () => {
44+
it("does not select catalog-session requests because catalog chat cannot render them inline", () => {
5145
const queue = [approval("approval-1", { sessionKey: "catalog:codex:host:thread" })];
5246

5347
const inline = findInlineApproval(queue, "catalog:codex:host:thread");
5448

5549
expect(inline).toBeNull();
56-
expect(modalApprovalQueue(queue, inline?.id)).toBe(queue);
5750
});
5851

5952
it("derives per-agent counts and per-session flags from one queue snapshot", () => {

‎ui/src/app/approval-presentation.ts‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ export function findInlineApproval(
2727
);
2828
}
2929

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-
3730
export function deriveApprovalBadgeSnapshot(
3831
queue: readonly ExecApprovalRequest[],
3932
): ApprovalBadgeSnapshot {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/* @vitest-environment jsdom */
2+
3+
import { render } from "lit";
4+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
5+
import type { ExecApprovalRequest } from "../app/exec-approval.ts";
6+
import { i18n } from "../i18n/index.ts";
7+
import { renderExecApprovalCard } from "./exec-approval-card.ts";
8+
9+
let container: HTMLDivElement;
10+
11+
function approval(overrides: Partial<ExecApprovalRequest> = {}): ExecApprovalRequest {
12+
return {
13+
id: "approval-1",
14+
kind: "plugin",
15+
request: {
16+
command: "Codex approval",
17+
agentId: "main",
18+
sessionKey: "agent:main:session-1",
19+
},
20+
pluginTitle: "Codex approval",
21+
pluginDescription: "Command: pnpm test",
22+
pluginId: "codex",
23+
createdAtMs: 1,
24+
expiresAtMs: 61_000,
25+
...overrides,
26+
};
27+
}
28+
29+
function renderCard(request: ExecApprovalRequest, variant: "inline" | "modal" = "modal") {
30+
render(
31+
renderExecApprovalCard({
32+
approval: request,
33+
busy: false,
34+
error: null,
35+
nowMs: 1_000,
36+
variant,
37+
onDecision: vi.fn(),
38+
}),
39+
container,
40+
);
41+
return container.querySelector<HTMLElement>(".exec-approval-card");
42+
}
43+
44+
describe("exec approval card", () => {
45+
beforeEach(async () => {
46+
await i18n.setLocale("en");
47+
container = document.createElement("div");
48+
document.body.append(container);
49+
});
50+
51+
afterEach(() => {
52+
container.remove();
53+
vi.restoreAllMocks();
54+
});
55+
56+
it.each([
57+
["warn", "warning"],
58+
["warning", "warning"],
59+
["danger", "danger"],
60+
["critical", "danger"],
61+
["error", "danger"],
62+
["unknown", "info"],
63+
[undefined, "info"],
64+
])("maps plugin severity %s to the %s accent", (pluginSeverity, expected) => {
65+
const card = renderCard(approval({ pluginSeverity }));
66+
67+
expect(card?.classList.contains(`exec-approval-card--severity-${expected}`)).toBe(true);
68+
});
69+
70+
it("always gives exec approvals the warning accent", () => {
71+
const card = renderCard(
72+
approval({
73+
kind: "exec",
74+
pluginSeverity: "critical",
75+
request: { command: "pnpm test" },
76+
}),
77+
);
78+
79+
expect(card?.classList.contains("exec-approval-card--severity-warning")).toBe(true);
80+
});
81+
82+
it("shows plugin and agent chips with session details in the modal", () => {
83+
const card = renderCard(approval());
84+
const details = card?.querySelector<HTMLDetailsElement>(".exec-approval-details");
85+
86+
expect(card?.querySelector('[data-approval-chip="plugin"]')?.textContent).toBe("codex");
87+
expect(card?.querySelector('[data-approval-chip="agent"]')?.textContent).toBe("main");
88+
expect(details?.open).toBe(false);
89+
expect(details?.textContent).toContain("Session");
90+
expect(details?.textContent).toContain("agent:main:session-1");
91+
expect(card?.textContent).not.toContain("Severity");
92+
});
93+
94+
it("keeps inline identity limited to the plugin chip", () => {
95+
const card = renderCard(approval(), "inline");
96+
97+
expect(card?.querySelector('[data-approval-chip="plugin"]')?.textContent).toBe("codex");
98+
expect(card?.querySelector('[data-approval-chip="agent"]')).toBeNull();
99+
expect(card?.querySelector(".exec-approval-details")).toBeNull();
100+
expect(card?.textContent).not.toContain("agent:main:session-1");
101+
});
102+
103+
it("keeps host and cwd visible while collapsing lower-value exec metadata", () => {
104+
const card = renderCard(
105+
approval({
106+
kind: "exec",
107+
request: {
108+
command: "pnpm test",
109+
host: "gateway",
110+
cwd: "/workspace",
111+
resolvedPath: "/usr/bin/pnpm",
112+
security: "allowlist",
113+
ask: "on-request",
114+
agentId: "main",
115+
sessionKey: "agent:main:session-1",
116+
},
117+
}),
118+
"inline",
119+
);
120+
const details = card?.querySelector<HTMLDetailsElement>(".exec-approval-details");
121+
122+
expect(card?.querySelector(".exec-approval-meta")?.textContent).toContain("gateway");
123+
expect(card?.querySelector(".exec-approval-meta")?.textContent).toContain("/workspace");
124+
expect(details?.open).toBe(false);
125+
expect(details?.textContent).toContain("Resolved");
126+
expect(details?.textContent).toContain("Security");
127+
expect(details?.textContent).toContain("Ask");
128+
expect(card?.querySelector('[data-approval-chip="agent"]')).toBeNull();
129+
expect(card?.textContent).not.toContain("agent:main:session-1");
130+
});
131+
});

0 commit comments

Comments
 (0)