A desktop coding agent with free access to frontier models.
TypeScript
feat: permission mode picker
Samrat Talukdar07774146725b
diff --git a/apps/app/src/app/lib/omnirush-server.ts b/apps/app/src/app/lib/omnirush-server.tsindex 2070d530..2aeacfbf 100644--- a/apps/app/src/app/lib/omnirush-server.ts+++ b/apps/app/src/app/lib/omnirush-server.ts@@ -429,7 +429,8 @@ export type OmniRushRuntimeConfigStatus = {};};-export type OmniRushApprovalMode = "guarded" | "full";+/** Stored engine approval mode: careful ("Careful"), guarded ("Normal", the default), full ("Auto"). */+export type OmniRushApprovalMode = "careful" | "guarded" | "full";export type OmniRushRuntimeApprovals = {/** Effective mode: the environment override, else the setting, else guarded. */mode: OmniRushApprovalMode;diff --git a/apps/app/src/i18n/locales/en.ts b/apps/app/src/i18n/locales/en.tsindex 67a3ef6a..15ea9c91 100644--- a/apps/app/src/i18n/locales/en.ts+++ b/apps/app/src/i18n/locales/en.ts@@ -1496,7 +1496,7 @@ export default {"settings.desktop_notifications.all": "All","settings.desktop_notifications.important": "Important","settings.desktop_notifications.mode": "Notify me",- "settings.desktop_notifications.mode_desc": "Choose which omnirush.ai events can appear as native operating system notifications.",+ "settings.desktop_notifications.mode_desc": "Choose which omnirush.ai events can appear as native operating system notifications while the app is in the background. All covers finished tasks and approvals.","settings.desktop_notifications.off": "Off","settings.desktop_notifications.section_desc": "Native notifications from the desktop app, separate from the in-app notification bell.","settings.desktop_notifications.title": "Desktop Notifications",@@ -2120,4 +2120,26 @@ export default {"session_management.empty_group": "No sessions","session_management.ungrouped": "Ungrouped","session_management.archived_label": "Archived",+ "permissions.title": "Permissions",+ "permissions.mode.careful": "Careful",+ "permissions.mode.careful_summary": "Asks before every file change and every command. Reading and searching run freely.",+ "permissions.mode.normal": "Normal",+ "permissions.mode.normal_summary": "Asks only before risky actions: recursive deletes, sudo, git push or hard resets, changes outside the project, reading secrets, piping downloads into a shell, publishing packages.",+ "permissions.mode.auto": "Auto",+ "permissions.mode.auto_summary": "Never asks. The agent runs everything it decides to run.",+ "permissions.status_mode": "{mode} mode.",+ "permissions.status_reloaded": "Engine reloaded.",+ "permissions.status_reload_needed": "Reload the engine to apply it.",+ "permissions.status_reload_failed": "Engine reload failed: {reason} Use Reload in Settings to apply it.",+ "permissions.status_switching": "Switching to {mode}…",+ "permissions.menu_label": "How often should the agent ask first?",+ "permissions.menu_footer": "Applies to every chat. Organisation policies still apply.",+ "permissions.trigger_label": "Permissions: {mode}",+ "permissions.loading": "Loading the permission mode…",+ "permissions.policy_lock": "Locked by your organisation: its policy does not allow changing app settings.",+ "permissions.card_desc": "How often the agent stops to ask you before it acts.",+ "permissions.shortcut_hint": "Keys: Y allow once, A allow for this chat, N or Esc deny.",+ "settings.desktop_notifications.all_desc": "Finished tasks, approvals and questions",+ "settings.desktop_notifications.important_desc": "Approvals, questions and failures",+ "settings.desktop_notifications.off_desc": "No desktop notifications",} as const;diff --git a/apps/app/src/react-app/domains/session/surface/composer/full-permissions-toggle.tsx b/apps/app/src/react-app/domains/session/surface/composer/full-permissions-toggle.tsxindex 56d2b3f3..b7460878 100644--- a/apps/app/src/react-app/domains/session/surface/composer/full-permissions-toggle.tsx+++ b/apps/app/src/react-app/domains/session/surface/composer/full-permissions-toggle.tsx@@ -1,22 +1,38 @@/** @jsxImportSource react */-import { LoaderCircle, ShieldAlert, ShieldCheck } from "lucide-react";+import { useState } from "react";+import { LoaderCircle, ShieldAlert, ShieldCheck, ShieldEllipsis } from "lucide-react";+import type { OmniRushApprovalMode } from "@/app/lib/omnirush-server";import { toast } from "@/components/ui/sonner";-import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";+import {+ DropdownMenu,+ DropdownMenuContent,+ DropdownMenuGroup,+ DropdownMenuLabel,+ DropdownMenuRadioGroup,+ DropdownMenuRadioItem,+ DropdownMenuSeparator,+ DropdownMenuTrigger,+} from "@/components/ui/dropdown-menu";+import { t } from "@/i18n";import { useDesktopRestriction } from "@/react-app/domains/cloud/desktop-config-provider";import {+ APPROVAL_MODES,+ approvalModeLabel,approvalsEnvironmentHint,useApprovalMode,type ApprovalsClient,} from "@/react-app/domains/settings/approval-mode";-export const FULL_PERMISSIONS_ON_HINT =- "Full permissions on: nothing asks for approval. Switch off to return to guarded mode.";-export const FULL_PERMISSIONS_OFF_HINT =- "Guarded mode: the engine asks before risky commands. Switch on to run every command and edit files without asking. Organisation policies still apply.";export const FULL_PERMISSIONS_POLICY_LOCK ="Locked by your organisation: its policy does not allow changing app settings.";-export const FULL_PERMISSIONS_LOADING_HINT = "Loading the approval mode…";+export const FULL_PERMISSIONS_LOADING_HINT = "Loading the permission mode…";++const MODE_ICONS: Record<OmniRushApprovalMode, typeof ShieldCheck> = {+ careful: ShieldEllipsis,+ guarded: ShieldCheck,+ full: ShieldAlert,+};type Props = {client: ApprovalsClient | null;@@ -25,33 +41,38 @@ type Props = {};/**- * The composer's "Full permissions" switch, beside the model selector. It- * shares state with Settings > General > Approvals through useApprovalMode,- * so the two never disagree. Hidden until a server client exists.+ * The composer's permissions menu (Careful / Normal / Auto), beside the model+ * selector. It shares state with Settings > General > Permissions through+ * useApprovalMode, so the two never disagree. Hidden until a server client+ * exists. The export keeps its earlier name for the composer slots.*/export function FullPermissionsToggle(props: Props) {const policyLocked = useDesktopRestriction("allowControlSettings");if (!props.client) return null;- return <FullPermissionsSwitch client={props.client} workspaceId={props.workspaceId} policyLocked={policyLocked} />;+ return <PermissionModeMenu client={props.client} workspaceId={props.workspaceId} policyLocked={policyLocked} />;}-function FullPermissionsSwitch(props: { client: ApprovalsClient; workspaceId: string | null; policyLocked: boolean }) {- const { approvals, busy, status, setFullPermissions } = useApprovalMode(props.client, props.workspaceId);- const full = approvals?.mode === "full";+function PermissionModeMenu(props: { client: ApprovalsClient; workspaceId: string | null; policyLocked: boolean }) {+ const [open, setOpen] = useState(false);+ const { approvals, busy, status, setApprovalMode } = useApprovalMode(props.client, props.workspaceId);+ const mode = approvals?.mode ?? null;const lockReason = props.policyLocked? FULL_PERMISSIONS_POLICY_LOCK: approvals? approvalsEnvironmentHint(approvals): null;- // Disabled while the mode loads, while a change is in flight and while the- // environment or the organisation forces the mode.- const disabled = busy || !approvals || lockReason !== null;- const hint = lockReason- ?? (!approvals ? (status || FULL_PERMISSIONS_LOADING_HINT) : full ? FULL_PERMISSIONS_ON_HINT : FULL_PERMISSIONS_OFF_HINT);+ // Choices are disabled while the mode loads, while a change is in flight and+ // while the environment or the organisation forces the mode; the menu still+ // opens so it can say why.+ const locked = busy || !approvals || lockReason !== null;+ const label = mode ? approvalModeLabel(mode) : null;+ const hint = lockReason ?? (label ? label.summary : (status || FULL_PERMISSIONS_LOADING_HINT));+ const Icon = mode ? MODE_ICONS[mode] : ShieldCheck;- const toggle = async () => {- if (disabled) return;- const change = await setFullPermissions(!full);+ const select = async (next: OmniRushApprovalMode) => {+ if (locked || next === mode) return;+ setOpen(false);+ const change = await setApprovalMode(next);if (!change) return;if (change.tone === "success") toast.success(change.status);else if (change.tone === "warning") toast.warning(change.status);@@ -59,37 +80,59 @@ function FullPermissionsSwitch(props: { client: ApprovalsClient; workspaceId: st};return (- <Tooltip>- <TooltipTrigger- render={- <button- type="button"- role="switch"- aria-checked={full}- aria-label="Full permissions"- aria-disabled={disabled || undefined}- aria-busy={busy || undefined}- data-testid="full-permissions-toggle"- data-state={full ? "on" : "off"}- data-lock-reason={lockReason ?? undefined}- onClick={() => void toggle()}- // Same height, radius, padding and text size as the model selector- // trigger. Kept focusable while disabled (aria-disabled, not- // disabled) so the tooltip can explain why. On reads as a warning- // (orange, alert shield): nothing asks for approval.- className={`flex h-9 max-h-9 shrink-0 items-center gap-1.5 rounded-md px-2.5 text-sm transition-colors aria-disabled:cursor-not-allowed aria-disabled:opacity-60 ${- full- ? "text-orange-11 hover:bg-orange-3 aria-disabled:hover:bg-transparent"- : "text-gray-10 hover:bg-gray-3 hover:text-gray-12 aria-disabled:hover:bg-transparent aria-disabled:hover:text-gray-10"- }`}- />- }+ <DropdownMenu open={open} onOpenChange={setOpen}>+ <DropdownMenuTrigger+ data-testid="full-permissions-toggle"+ data-state={mode ?? "loading"}+ data-lock-reason={lockReason ?? undefined}+ aria-label={t("permissions.trigger_label", { mode: label?.title ?? "…" })}+ aria-busy={busy || undefined}+ title={hint}+ // Same height, radius, padding and text size as the model selector+ // trigger. Auto reads as a warning (orange, alert shield): nothing asks.+ className={`flex h-9 max-h-9 shrink-0 items-center gap-1.5 rounded-md px-2.5 text-sm transition-colors ${+ mode === "full"+ ? "text-orange-11 hover:bg-orange-3"+ : "text-gray-10 hover:bg-gray-3 hover:text-gray-12"+ } ${locked ? "opacity-60" : ""}`}>- {busy ? <LoaderCircle className="size-4 animate-spin" /> : full ? <ShieldAlert className="size-4" /> : <ShieldCheck className="size-4" />}- {/* An icon (its label in the tooltip and aria-label) until the composer is wide enough. */}- <span className="hidden whitespace-nowrap @min-[760px]/composer:inline">Full permissions</span>- </TooltipTrigger>- <TooltipContent>{hint}</TooltipContent>- </Tooltip>+ {busy ? <LoaderCircle className="size-4 animate-spin" /> : <Icon className="size-4" />}+ {/* An icon (its mode in the aria-label and title) until the composer is wide enough. */}+ <span className="hidden whitespace-nowrap @min-[760px]/composer:inline" data-testid="full-permissions-label">+ {label?.title ?? t("permissions.title")}+ </span>+ </DropdownMenuTrigger>+ <DropdownMenuContent side="top" sideOffset={10} className="w-[min(380px,calc(100vw-32px))] p-2">+ <DropdownMenuGroup>+ <DropdownMenuLabel className="px-3 text-sm">{t("permissions.menu_label")}</DropdownMenuLabel>+ <DropdownMenuRadioGroup value={mode ?? ""}>+ {APPROVAL_MODES.map((item) => {+ const ItemIcon = MODE_ICONS[item];+ const itemLabel = approvalModeLabel(item);+ return (+ <DropdownMenuRadioItem+ key={item}+ value={item}+ disabled={locked}+ data-testid={`permission-mode-${item}`}+ aria-label={itemLabel.title}+ onClick={() => void select(item)}+ className={`gap-3 py-2.5 ${item === "full" ? "text-orange-11" : ""}`}+ >+ <ItemIcon className="size-5 shrink-0" />+ <span className="min-w-0">+ <span className="block">{itemLabel.title}</span>+ <span className="mt-0.5 block text-xs font-normal text-muted-foreground">{itemLabel.summary}</span>+ </span>+ </DropdownMenuRadioItem>+ );+ })}+ </DropdownMenuRadioGroup>+ </DropdownMenuGroup>+ <DropdownMenuSeparator />+ <p className="px-3 py-2 text-xs text-muted-foreground">{t("permissions.menu_footer")}</p>+ {lockReason ? <p role="status" data-testid="permission-mode-lock" className="px-3 pb-2 text-xs text-muted-foreground">{lockReason}</p> : null}+ </DropdownMenuContent>+ </DropdownMenu>);}diff --git a/apps/app/src/react-app/domains/settings/approval-mode.ts b/apps/app/src/react-app/domains/settings/approval-mode.tsindex 593adef8..a8bc7be0 100644--- a/apps/app/src/react-app/domains/settings/approval-mode.ts+++ b/apps/app/src/react-app/domains/settings/approval-mode.ts@@ -1,12 +1,13 @@-// Shared approval-mode state. The Settings > General "Approvals" card and the-// composer's "Full permissions" switch both read it through useApprovalMode,-// so they show the same mode and a change in either updates the other at once.+// Shared approval-mode state. The Settings > General "Permissions" card and the+// composer's permissions menu both read it through useApprovalMode, so they+// show the same mode and a change in either updates the other at once.// State is keyed by server (client.baseUrl): the mode is a server-wide setting,// not a workspace one, and a remote workspace talks to a different server.import { useCallback, useEffect } from "react";import { create } from "zustand";-import type { OmniRushRuntimeApprovals, OmniRushServerClient } from "@/app/lib/omnirush-server";+import type { OmniRushApprovalMode, OmniRushRuntimeApprovals, OmniRushServerClient } from "@/app/lib/omnirush-server";+import { t } from "@/i18n";import { reloadEngineWithDesktopFallback } from "@/react-app/shell/engine-reload-escalation";export type ApprovalsClient = Pick<OmniRushServerClient, "getRuntimeApprovals" | "setRuntimeApprovals" | "reloadEngine"> & {@@ -14,6 +15,24 @@ export type ApprovalsClient = Pick<OmniRushServerClient, "getRuntimeApprovals" |baseUrl?: string;};+/** The modes in the order the app lists them. Stored values: careful, guarded (Normal), full (Auto). */+export const APPROVAL_MODES: readonly OmniRushApprovalMode[] = ["careful", "guarded", "full"];++/**+ * Title and summary of a mode. The summaries are the `labels` of the rules+ * file shared with the CLI (apps/server/src/permissions/permission-modes.json).+ */+export function approvalModeLabel(mode: OmniRushApprovalMode): { title: string; summary: string } {+ switch (mode) {+ case "careful":+ return { title: t("permissions.mode.careful"), summary: t("permissions.mode.careful_summary") };+ case "full":+ return { title: t("permissions.mode.auto"), summary: t("permissions.mode.auto_summary") };+ default:+ return { title: t("permissions.mode.normal"), summary: t("permissions.mode.normal_summary") };+ }+}+export const FULL_PERMISSIONS_HELP = "Runs every command and edits files without asking. Organisation policies still apply.";/** Shown while OMNIRUSH_APPROVALS in the launch environment forces the mode. */@@ -35,24 +54,33 @@ export type FullPermissionsOutcome = {* rules apply within seconds. A failed reload keeps the saved setting and says* what to do next.*/-export async function applyFullPermissions(+export async function applyApprovalMode(client: ApprovalsClient,workspaceId: string | null,- enabled: boolean,+ requested: OmniRushApprovalMode,): Promise<FullPermissionsOutcome> {- const { mode, source, setting } = await client.setRuntimeApprovals(enabled ? "full" : "guarded");+ const { mode, source, setting } = await client.setRuntimeApprovals(requested);const approvals: OmniRushRuntimeApprovals = { mode, source, setting };- const label = mode === "full" ? "Full permissions on." : "Guarded mode.";- if (!workspaceId) return { approvals, status: `${label} Reload the engine to apply it.`, tone: "warning" };+ const label = t("permissions.status_mode", { mode: approvalModeLabel(mode).title });+ if (!workspaceId) return { approvals, status: `${label} ${t("permissions.status_reload_needed")}`, tone: "warning" };try {await reloadEngineWithDesktopFallback(client, workspaceId);- return { approvals, status: `${label} Engine reloaded.`, tone: "success" };+ return { approvals, status: `${label} ${t("permissions.status_reloaded")}`, tone: "success" };} catch (error) {const reason = error instanceof Error ? error.message : String(error);- return { approvals, status: `${label} Engine reload failed: ${reason} Use Reload in Settings to apply it.`, tone: "warning" };+ return { approvals, status: `${label} ${t("permissions.status_reload_failed", { reason })}`, tone: "warning" };}}+/** Earlier on/off form: on is Auto, off is Normal. */+export function applyFullPermissions(+ client: ApprovalsClient,+ workspaceId: string | null,+ enabled: boolean,+): Promise<FullPermissionsOutcome> {+ return applyApprovalMode(client, workspaceId, enabled ? "full" : "guarded");+}+export type ApprovalModeEntry = {/** Null until the server has answered (or while the load keeps failing). */approvals: OmniRushRuntimeApprovals | null;@@ -135,13 +163,13 @@ export function useApprovalMode(client: ApprovalsClient | null, workspaceId: strvoid loadApprovalMode(client);}, [client]);- const setFullPermissions = useCallback(async (enabled: boolean): Promise<ApprovalModeChange | null> => {+ const setApprovalMode = useCallback(async (mode: OmniRushApprovalMode): Promise<ApprovalModeChange | null> => {if (!client || !key) return null;const { patch } = useApprovalModeStore.getState();markApprovalChange(key);- patch(key, { busy: true, status: enabled ? "Turning full permissions on…" : "Switching to guarded mode…" });+ patch(key, { busy: true, status: t("permissions.status_switching", { mode: approvalModeLabel(mode).title }) });try {- const outcome = await applyFullPermissions(client, workspaceId, enabled);+ const outcome = await applyApprovalMode(client, workspaceId, mode);patch(key, { approvals: outcome.approvals, busy: false, status: outcome.status });return outcome;} catch (error) {@@ -151,5 +179,11 @@ export function useApprovalMode(client: ApprovalsClient | null, workspaceId: str}}, [client, key, workspaceId]);- return { approvals: entry.approvals, busy: entry.busy, status: entry.status, setFullPermissions };+ /** Earlier on/off form: on is Auto, off is Normal. */+ const setFullPermissions = useCallback(+ (enabled: boolean) => setApprovalMode(enabled ? "full" : "guarded"),+ [setApprovalMode],+ );++ return { approvals: entry.approvals, busy: entry.busy, status: entry.status, setApprovalMode, setFullPermissions };}diff --git a/apps/app/src/react-app/domains/settings/pages/general-view.tsx b/apps/app/src/react-app/domains/settings/pages/general-view.tsxindex c7e9f645..342d4ae5 100644--- a/apps/app/src/react-app/domains/settings/pages/general-view.tsx+++ b/apps/app/src/react-app/domains/settings/pages/general-view.tsx@@ -28,12 +28,13 @@ import {omnirushAccountSignOut,omnirushAccountStatus,} from "../../../../app/lib/desktop";-import type { OmniRushRuntimeApprovals } from "../../../../app/lib/omnirush-server";+import type { OmniRushApprovalMode, OmniRushRuntimeApprovals } from "../../../../app/lib/omnirush-server";import { captureAnalyticsEvent, resetAnalyticsAccount, syncAnalyticsAccount } from "../../../../app/lib/analytics";import { omnirushUsageSummary } from "../../../../app/lib/omnirush-usage";import { isElectronRuntime } from "../../../../app/utils";import {- FULL_PERMISSIONS_HELP,+ APPROVAL_MODES,+ approvalModeLabel,approvalsEnvironmentHint,useApprovalMode,type ApprovalsClient,@@ -156,42 +157,78 @@ export function accountServerLine(account: Pick<NativeAccountStatus, "connected"}/**- * Settings > General > Approvals. The mode, busy flag and status come from- * useApprovalMode, which the composer's "Full permissions" switch shares.+ * Settings > General > Permissions: Careful / Normal / Auto. The mode, busy+ * flag and status come from useApprovalMode, which the composer's permissions+ * menu shares.*/export function ApprovalsCard(props: {approvals: OmniRushRuntimeApprovals | null;busy: boolean;status: string;- onToggle: (enabled: boolean) => void;+ onSelect: (mode: OmniRushApprovalMode) => void;+ /** Set when the organisation's policy does not allow changing app settings. */+ policyLocked?: boolean;}) {- const hint = props.approvals ? approvalsEnvironmentHint(props.approvals) : null;- const full = props.approvals?.mode === "full";+ const hint = props.policyLocked+ ? t("permissions.policy_lock")+ : props.approvals ? approvalsEnvironmentHint(props.approvals) : null;+ const current = props.approvals?.mode ?? null;+ const disabled = props.busy || !props.approvals || hint !== null;+ const summary = current ? approvalModeLabel(current).summary : t("permissions.card_desc");return (<div className="space-y-3"><div className="text-[11px] font-semibold uppercase tracking-[0.15em] text-dls-secondary">- Approvals+ {t("permissions.title")}</div>- <div className="flex items-center gap-4 rounded-2xl border border-dls-border bg-dls-surface p-4">+ <div className="flex items-start gap-4 rounded-2xl border border-dls-border bg-dls-surface p-4" data-testid="approvals-card"><div className="flex h-10 w-10 shrink-0 items-center justify-center rounded-xl border border-dls-border bg-dls-hover">- <ShieldCheck size={17} className={full ? "text-amber-400" : "text-dls-secondary"} />+ <ShieldCheck size={17} className={current === "full" ? "text-amber-400" : "text-dls-secondary"} /></div>- <div className="min-w-0 flex-1">- <div className="text-[13px] font-medium text-dls-text">Full permissions</div>- <div className="text-[11px] text-dls-secondary">{FULL_PERMISSIONS_HELP}</div>+ <div className="min-w-0 flex-1 space-y-2">+ <div>+ <div className="text-[13px] font-medium text-dls-text">{t("permissions.card_desc")}</div>+ <div className="text-[11px] text-dls-secondary" id="approval-mode-summary" data-testid="approval-mode-summary">{summary}</div>+ </div>+ <div+ role="radiogroup"+ aria-label={t("permissions.title")}+ aria-describedby="approval-mode-summary"+ aria-disabled={disabled || undefined}+ className="inline-flex rounded-lg border border-dls-border bg-dls-hover p-0.5"+ >+ {APPROVAL_MODES.map((mode) => {+ const selected = current === mode;+ return (+ <button+ key={mode}+ type="button"+ role="radio"+ aria-checked={selected}+ disabled={disabled}+ data-testid={`approval-mode-${mode}`}+ onClick={() => {+ if (!selected) props.onSelect(mode);+ }}+ className={`rounded-md px-3 py-1 text-[12px] font-medium transition-colors disabled:cursor-not-allowed ${+ selected+ ? mode === "full"+ ? "bg-dls-surface text-orange-11 shadow-sm"+ : "bg-dls-surface text-dls-text shadow-sm"+ : "text-dls-secondary hover:text-dls-text disabled:hover:text-dls-secondary"+ } ${disabled && !selected ? "opacity-60" : ""}`}+ >+ {approvalModeLabel(mode).title}+ </button>+ );+ })}+ </div>{hint ? (- <div className="mt-0.5 text-[11px] text-dls-secondary" data-testid="approvals-env-hint">{hint}</div>+ <div className="text-[11px] text-dls-secondary" data-testid="approvals-env-hint">{hint}</div>) : null}{props.status ? (- <div className="mt-0.5 text-[11px] text-dls-secondary" data-testid="approvals-status">{props.status}</div>+ <div className="text-[11px] text-dls-secondary" role="status" data-testid="approvals-status">{props.status}</div>) : null}</div>- <Switch- aria-label="Full permissions"- checked={full}- disabled={props.busy || !props.approvals || hint !== null}- onCheckedChange={props.onToggle}- /></div></div>);@@ -505,7 +542,7 @@ export function GeneralSettingsView(props: GeneralSettingsViewProps) {approvals={approvalMode.approvals}busy={approvalMode.busy}status={approvalMode.status}- onToggle={(enabled) => void approvalMode.setFullPermissions(enabled)}+ onSelect={(mode) => void approvalMode.setApprovalMode(mode)}/>) : null}diff --git a/apps/app/tests/approvals-settings-card.test.tsx b/apps/app/tests/approvals-settings-card.test.tsxindex 3f25051a..1e242a04 100644--- a/apps/app/tests/approvals-settings-card.test.tsx+++ b/apps/app/tests/approvals-settings-card.test.tsx@@ -3,8 +3,9 @@ import { renderToStaticMarkup } from "react-dom/server";import type { OmniRushApprovalMode, OmniRushRuntimeApprovals } from "../src/app/lib/omnirush-server";import {- FULL_PERMISSIONS_HELP,+ applyApprovalMode,applyFullPermissions,+ approvalModeLabel,type ApprovalsClient,} from "../src/react-app/domains/settings/approval-mode";import { ApprovalsCard, BestPracticesCard, GeneralSettingsView } from "../src/react-app/domains/settings/pages/general-view";@@ -36,64 +37,93 @@ function switchMarkup(markup: string): string {return match[0];}-describe("approvals settings card", () => {- test("shows the switch with its helper text and reflects the current mode", () => {+/** The mode buttons of the Permissions card: `aria-checked` carries the mode, `disabled` the locked state. */+function modeButton(markup: string, mode: OmniRushApprovalMode): string {+ const match = markup.match(new RegExp(`<button[^>]*data-testid="approval-mode-${mode}"[^>]*>`));+ if (!match) throw new Error(`no ${mode} button in ${markup}`);+ return match[0];+}++describe("permissions settings card", () => {+ test("shows Careful / Normal / Auto with the selected mode's summary", () => {const markup = renderToStaticMarkup(- <ApprovalsCard approvals={{ mode: "full", source: "settings", setting: "full" }} busy={false} status="" onToggle={() => {}} />,+ <ApprovalsCard approvals={{ mode: "full", source: "settings", setting: "full" }} busy={false} status="" onSelect={() => {}} />,);- expect(markup).toContain("Approvals");- expect(markup).toContain("Full permissions");- expect(markup).toContain(FULL_PERMISSIONS_HELP);- expect(switchMarkup(markup)).toContain('aria-checked="true"');- expect(switchMarkup(markup)).not.toContain('aria-disabled="true"');+ expect(markup).toContain("Permissions");+ expect(markup).toContain('role="radiogroup"');+ for (const [mode, title] of [["careful", "Careful"], ["guarded", "Normal"], ["full", "Auto"]] as const) {+ expect(modeButton(markup, mode)).toContain('role="radio"');+ expect(markup).toContain(`>${title}</button>`);+ }+ expect(modeButton(markup, "full")).toContain('aria-checked="true"');+ expect(modeButton(markup, "guarded")).toContain('aria-checked="false"');+ expect(modeButton(markup, "careful")).not.toContain('disabled=""');+ expect(markup).toContain(approvalModeLabel("full").summary);expect(markup).not.toContain("Set by environment");- const off = renderToStaticMarkup(- <ApprovalsCard approvals={{ mode: "guarded", source: "default", setting: null }} busy={false} status="Guarded mode. Engine reloaded." onToggle={() => {}} />,+ const normal = renderToStaticMarkup(+ <ApprovalsCard approvals={{ mode: "guarded", source: "default", setting: null }} busy={false} status="Normal mode. Engine reloaded." onSelect={() => {}} />,);- expect(switchMarkup(off)).toContain('aria-checked="false"');- expect(off).toContain("Guarded mode. Engine reloaded.");+ expect(modeButton(normal, "guarded")).toContain('aria-checked="true"');+ expect(normal).toContain("Asks only before risky actions");+ expect(normal).toContain("Normal mode. Engine reloaded.");++ const careful = renderToStaticMarkup(+ <ApprovalsCard approvals={{ mode: "careful", source: "settings", setting: "careful" }} busy={false} status="" onSelect={() => {}} />,+ );+ expect(modeButton(careful, "careful")).toContain('aria-checked="true"');+ expect(careful).toContain("Asks before every file change and every command.");});- test("disables the switch and says so while the environment forces the mode", () => {+ test("disables the choice and says so while the environment or the organisation forces the mode", () => {const markup = renderToStaticMarkup(- <ApprovalsCard approvals={{ mode: "full", source: "environment", setting: "guarded" }} busy={false} status="" onToggle={() => {}} />,+ <ApprovalsCard approvals={{ mode: "full", source: "environment", setting: "guarded" }} busy={false} status="" onSelect={() => {}} />,);- expect(switchMarkup(markup)).toContain('aria-checked="true"');- expect(switchMarkup(markup)).toContain('aria-disabled="true"');+ expect(modeButton(markup, "full")).toContain('aria-checked="true"');+ for (const mode of ["careful", "guarded", "full"] as const) expect(modeButton(markup, mode)).toContain('disabled=""');expect(markup).toContain("Set by environment (OMNIRUSH_APPROVALS=full)");+ const locked = renderToStaticMarkup(+ <ApprovalsCard approvals={{ mode: "guarded", source: "default", setting: null }} busy={false} status="" onSelect={() => {}} policyLocked />,+ );+ expect(modeButton(locked, "careful")).toContain('disabled=""');+ expect(locked).toContain("Locked by your organisation");// Nothing is claimed before the server has answered.- const loading = renderToStaticMarkup(<ApprovalsCard approvals={null} busy={false} status="" onToggle={() => {}} />);- expect(switchMarkup(loading)).toContain('aria-disabled="true"');+ const loading = renderToStaticMarkup(<ApprovalsCard approvals={null} busy={false} status="" onSelect={() => {}} />);+ expect(modeButton(loading, "guarded")).toContain('disabled=""');+ expect(modeButton(loading, "guarded")).toContain('aria-checked="false"');});- test("toggling persists the mode, then reloads the workspace engine", async () => {+ test("choosing persists the mode, then reloads the workspace engine", async () => {const { client, calls } = fakeClient();+ const careful = await applyApprovalMode(client, "ws_1", "careful");+ expect(calls).toEqual(["set:careful", "reload:ws_1"]);+ expect(careful.approvals).toEqual({ mode: "careful", source: "settings", setting: "careful" });+ expect(careful.status).toBe("Careful mode. Engine reloaded.");+ expect(careful.tone).toBe("success");+const on = await applyFullPermissions(client, "ws_1", true);- expect(calls).toEqual(["set:full", "reload:ws_1"]);- expect(on.approvals).toEqual({ mode: "full", source: "settings", setting: "full" });- expect(on.status).toBe("Full permissions on. Engine reloaded.");- expect(on.tone).toBe("success");+ expect(calls.slice(2)).toEqual(["set:full", "reload:ws_1"]);+ expect(on.status).toBe("Auto mode. Engine reloaded.");const off = await applyFullPermissions(client, "ws_1", false);- expect(calls.slice(2)).toEqual(["set:guarded", "reload:ws_1"]);- expect(off.status).toBe("Guarded mode. Engine reloaded.");+ expect(calls.slice(4)).toEqual(["set:guarded", "reload:ws_1"]);+ expect(off.status).toBe("Normal mode. Engine reloaded.");expect(off.tone).toBe("success");expect(await client.getRuntimeApprovals()).toEqual({ mode: "guarded", source: "settings", setting: "guarded" });});test("keeps the saved setting and explains when the reload fails or no workspace is active", async () => {const failing = fakeClient({ reloadError: new Error("engine busy") });- const result = await applyFullPermissions(failing.client, "ws_1", true);+ const result = await applyApprovalMode(failing.client, "ws_1", "full");expect(failing.calls).toEqual(["set:full", "reload:ws_1"]);expect(result.approvals.mode).toBe("full");- expect(result.status).toBe("Full permissions on. Engine reload failed: engine busy Use Reload in Settings to apply it.");+ expect(result.status).toBe("Auto mode. Engine reload failed: engine busy Use Reload in Settings to apply it.");expect(result.tone).toBe("warning");const idle = fakeClient();- const saved = await applyFullPermissions(idle.client, null, true);- expect(idle.calls).toEqual(["set:full"]);- expect(saved.status).toBe("Full permissions on. Reload the engine to apply it.");+ const saved = await applyApprovalMode(idle.client, null, "careful");+ expect(idle.calls).toEqual(["set:careful"]);+ expect(saved.status).toBe("Careful mode. Reload the engine to apply it.");expect(saved.tone).toBe("warning");});});@@ -114,7 +144,7 @@ describe("best practices settings card", () => {);expect(switchMarkup(markup)).toContain('aria-label="Best practices"');expect(switchMarkup(markup)).toContain('aria-disabled="true"');- expect(markup).not.toContain('aria-label="Full permissions"');+ expect(markup).not.toContain('data-testid="approvals-card"');});test("labels the switch, describes only guides, and waits for the server choice", () => {diff --git a/apps/app/tests/full-permissions-toggle.test.tsx b/apps/app/tests/full-permissions-toggle.test.tsxindex c348d91b..04a7bd90 100644--- a/apps/app/tests/full-permissions-toggle.test.tsx+++ b/apps/app/tests/full-permissions-toggle.test.tsx@@ -28,7 +28,7 @@ if (typeof globalThis.window === "undefined" || typeof globalThis.document === "Object.defineProperty(globalThis, "IS_REACT_ACT_ENVIRONMENT", { configurable: true, value: true });const [- { FullPermissionsToggle, FULL_PERMISSIONS_OFF_HINT, FULL_PERMISSIONS_POLICY_LOCK },+ { FullPermissionsToggle, FULL_PERMISSIONS_POLICY_LOCK },{ useApprovalMode, useApprovalModeStore },{ ApprovalsCard },{ TooltipProvider },@@ -104,7 +104,7 @@ async function waitFor(predicate: () => boolean, label: string) {function toggleIn(container: HTMLElement): HTMLButtonElement {const button = container.querySelector<HTMLButtonElement>('[data-testid="full-permissions-toggle"]');- if (!button) throw new Error("the Full permissions switch is not rendered");+ if (!button) throw new Error("the permissions menu is not rendered");return button;}@@ -114,107 +114,109 @@ async function click(button: HTMLElement) {});}+function item(mode: OmniRushApprovalMode): HTMLElement | null {+ return document.querySelector<HTMLElement>(`[data-testid="permission-mode-${mode}"]`);+}++/** Opens the menu and picks a mode. */+async function choose(container: HTMLElement, mode: OmniRushApprovalMode) {+ await click(toggleIn(container));+ await waitFor(() => item(mode) !== null, `the ${mode} item`);+ await click(item(mode)!);+}+const guardedByDefault: OmniRushRuntimeApprovals = { mode: "guarded", source: "default", setting: null };+const loaded = (container: HTMLElement) => toggleIn(container).dataset.state !== "loading";-test("shows the current mode on load and reads as active while full permissions are on", async () => {+test("shows the current mode on load; Auto reads as a warning", async () => {const guarded = fakeClient("http://guarded.test", guardedByDefault);const container = await mount(<FullPermissionsToggle client={guarded.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(container).getAttribute("aria-disabled") === null, "the guarded mode to load");- const off = toggleIn(container);- expect(off.getAttribute("role")).toBe("switch");- expect(off.getAttribute("aria-checked")).toBe("false");- expect(off.textContent).toContain("Full permissions");- expect(off.dataset.state).toBe("off");- expect(off.dataset.lockReason).toBeUndefined();- expect(off.className).not.toContain("text-orange-11");+ await waitFor(() => loaded(container), "the normal mode to load");+ const normal = toggleIn(container);+ expect(normal.dataset.state).toBe("guarded");+ expect(normal.getAttribute("aria-label")).toBe("Permissions: Normal");+ expect(normal.textContent).toContain("Normal");+ expect(normal.dataset.lockReason).toBeUndefined();+ expect(normal.className).not.toContain("text-orange-11");const full = fakeClient("http://full.test", { mode: "full", source: "settings", setting: "full" });const active = await mount(<FullPermissionsToggle client={full.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(active).getAttribute("aria-checked") === "true", "the full mode to load");- expect(toggleIn(active).dataset.state).toBe("on");- expect(toggleIn(active).getAttribute("aria-disabled")).toBeNull();- // On reads as a warning: orange, no accent fill.+ await waitFor(() => toggleIn(active).dataset.state === "full", "the auto mode to load");+ expect(toggleIn(active).textContent).toContain("Auto");expect(toggleIn(active).className).toContain("text-orange-11");- expect(toggleIn(active).className).not.toContain("--dls-accent");++ const careful = fakeClient("http://careful.test", { mode: "careful", source: "settings", setting: "careful" });+ const asking = await mount(<FullPermissionsToggle client={careful.client} workspaceId="ws_1" />);+ await waitFor(() => toggleIn(asking).dataset.state === "careful", "the careful mode to load");+ expect(toggleIn(asking).textContent).toContain("Careful");+ expect(toggleIn(asking).className).not.toContain("text-orange-11");// Nothing renders without a server client.const none = await mount(<FullPermissionsToggle client={null} workspaceId="ws_1" />);expect(none.querySelector('[data-testid="full-permissions-toggle"]')).toBeNull();});-test("is disabled with a tooltip while the environment or the organisation forces the mode", async () => {+test("lists the three modes and disables them while the environment or the organisation forces the mode", async () => {const env = fakeClient("http://env.test", { mode: "full", source: "environment", setting: "guarded" });const container = await mount(<FullPermissionsToggle client={env.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(container).getAttribute("aria-checked") === "true", "the environment mode to load");- const button = toggleIn(container);- expect(button.getAttribute("aria-disabled")).toBe("true");- expect(button.dataset.lockReason).toBe("Set by environment (OMNIRUSH_APPROVALS=full); change it where the app is launched.");- await click(button);+ await waitFor(() => toggleIn(container).dataset.state === "full", "the environment mode to load");+ expect(toggleIn(container).dataset.lockReason).toBe("Set by environment (OMNIRUSH_APPROVALS=full); change it where the app is launched.");+ await choose(container, "careful");+ expect(item("careful")?.textContent).toContain("Asks before every file change");+ expect(item("guarded")?.textContent).toContain("Normal");+ expect(item("full")?.getAttribute("aria-checked")).toBe("true");+ expect(item("careful")?.getAttribute("aria-disabled")).toBe("true");+ expect(document.querySelector('[data-testid="permission-mode-lock"]')?.textContent).toContain("Set by environment");expect(env.calls).toEqual([]);expect(toasts).toEqual([]);-- await act(async () => {- button.dispatchEvent(new PointerEvent("pointerover", { bubbles: true, pointerType: "mouse" }));- button.dispatchEvent(new MouseEvent("mouseenter"));- });- await waitFor(- () => document.querySelector('[data-slot="tooltip-content"]')?.textContent?.includes("Set by environment (OMNIRUSH_APPROVALS=full)") === true,- "the environment tooltip",- );+ await act(async () => document.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true })));policyLocked = true;const guarded = fakeClient("http://policy.test", guardedByDefault);const locked = await mount(<FullPermissionsToggle client={guarded.client} workspaceId="ws_1" />);await waitFor(() => toggleIn(locked).dataset.lockReason === FULL_PERMISSIONS_POLICY_LOCK, "the policy lock");- expect(toggleIn(locked).getAttribute("aria-disabled")).toBe("true");- await click(toggleIn(locked));+ await choose(locked, "full");expect(guarded.calls).toEqual([]);});-test("clicking persists the mode, reloads the engine and stays disabled while the reload is in flight", async () => {+test("choosing persists the mode, reloads the engine and stays busy while the reload is in flight", async () => {const held = fakeClient("http://toggle.test", guardedByDefault, { holdSet: true });const container = await mount(<FullPermissionsToggle client={held.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(container).getAttribute("aria-disabled") === null, "the guarded mode to load");+ await waitFor(() => loaded(container), "the normal mode to load");- await click(toggleIn(container));+ await choose(container, "full");await waitFor(() => toggleIn(container).getAttribute("aria-busy") === "true", "the in-flight state");- expect(toggleIn(container).getAttribute("aria-disabled")).toBe("true");- expect(held.calls).toEqual(["set:full"]);- // A second click while in flight is ignored.- await click(toggleIn(container));expect(held.calls).toEqual(["set:full"]);await act(async () => held.release());- await waitFor(() => toggleIn(container).getAttribute("aria-checked") === "true", "the full mode");+ await waitFor(() => toggleIn(container).dataset.state === "full", "the auto mode");expect(held.calls).toEqual(["set:full", "reload:ws_1"]);expect(toggleIn(container).getAttribute("aria-busy")).toBeNull();- expect(toggleIn(container).getAttribute("aria-disabled")).toBeNull();- expect(toasts).toEqual(["success:Full permissions on. Engine reloaded."]);+ expect(toasts).toEqual(["success:Auto mode. Engine reloaded."]);- await click(toggleIn(container));+ await choose(container, "careful");await act(async () => held.release());- await waitFor(() => toggleIn(container).getAttribute("aria-checked") === "false", "the guarded mode again");- expect(held.calls.slice(2)).toEqual(["set:guarded", "reload:ws_1"]);- expect(toasts[1]).toBe("success:Guarded mode. Engine reloaded.");+ await waitFor(() => toggleIn(container).dataset.state === "careful", "the careful mode");+ expect(held.calls.slice(2)).toEqual(["set:careful", "reload:ws_1"]);+ expect(toasts[1]).toBe("success:Careful mode. Engine reloaded.");});-test("reports a failed reload or a refused change without losing the switch", async () => {+test("reports a failed reload or a refused change without losing the mode", async () => {const reloadFails = fakeClient("http://reload-fails.test", guardedByDefault, { reloadError: new Error("engine busy") });const container = await mount(<FullPermissionsToggle client={reloadFails.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(container).getAttribute("aria-disabled") === null, "the guarded mode to load");- await click(toggleIn(container));- await waitFor(() => toggleIn(container).getAttribute("aria-checked") === "true", "the saved full mode");- expect(toasts).toEqual(["warning:Full permissions on. Engine reload failed: engine busy Use Reload in Settings to apply it."]);+ await waitFor(() => loaded(container), "the normal mode to load");+ await choose(container, "full");+ await waitFor(() => toggleIn(container).dataset.state === "full", "the saved auto mode");+ expect(toasts).toEqual(["warning:Auto mode. Engine reload failed: engine busy Use Reload in Settings to apply it."]);const refused = fakeClient("http://refused.test", guardedByDefault, { setError: new Error("settings are locked") });const other = await mount(<FullPermissionsToggle client={refused.client} workspaceId="ws_1" />);- await waitFor(() => toggleIn(other).getAttribute("aria-disabled") === null, "the second guarded mode to load");- await click(toggleIn(other));+ await waitFor(() => loaded(other), "the second normal mode to load");+ await choose(other, "careful");await waitFor(() => toasts.length === 2, "the error toast");expect(toasts[1]).toBe("error:settings are locked");- expect(toggleIn(other).getAttribute("aria-checked")).toBe("false");- expect(toggleIn(other).getAttribute("aria-disabled")).toBeNull();- expect(refused.calls).toEqual(["set:full"]);+ expect(toggleIn(other).dataset.state).toBe("guarded");+ expect(refused.calls).toEqual(["set:careful"]);});/** The Settings card exactly as GeneralSettingsView wires it. */@@ -225,7 +227,7 @@ function SettingsCard(props: { client: ApprovalsClient }) {approvals={mode.approvals}busy={mode.busy}status={mode.status}- onToggle={(enabled) => void mode.setFullPermissions(enabled)}+ onSelect={(next) => void mode.setApprovalMode(next)}/>);}@@ -238,25 +240,24 @@ test("shares its state with the Settings card, so a change in either shows in th<SettingsCard client={shared.client} /></>,);- const cardSwitch = () => {- const element = container.querySelector<HTMLButtonElement>('[role="switch"][data-slot="switch"]');- if (!element) throw new Error("the Settings switch is not rendered");+ const cardButton = (mode: OmniRushApprovalMode) => {+ const element = container.querySelector<HTMLButtonElement>(`[data-testid="approval-mode-${mode}"]`);+ if (!element) throw new Error("the Settings card is not rendered");return element;};- await waitFor(() => toggleIn(container).getAttribute("aria-disabled") === null, "the shared load");+ await waitFor(() => loaded(container), "the shared load");expect(shared.gets()).toBe(1);- expect(cardSwitch().getAttribute("aria-checked")).toBe("false");+ expect(cardButton("guarded").getAttribute("aria-checked")).toBe("true");- await click(toggleIn(container));- await waitFor(() => cardSwitch().getAttribute("aria-checked") === "true", "the card to follow the composer");- expect(container.querySelector('[data-testid="approvals-status"]')?.textContent).toBe("Full permissions on. Engine reloaded.");- expect(toasts).toEqual(["success:Full permissions on. Engine reloaded."]);+ await choose(container, "full");+ await waitFor(() => cardButton("full").getAttribute("aria-checked") === "true", "the card to follow the composer");+ expect(container.querySelector('[data-testid="approvals-status"]')?.textContent).toBe("Auto mode. Engine reloaded.");+ expect(toasts).toEqual(["success:Auto mode. Engine reloaded."]);- await click(cardSwitch());- await waitFor(() => toggleIn(container).getAttribute("aria-checked") === "false", "the composer to follow the card");- expect(shared.calls).toEqual(["set:full", "reload:ws_1", "set:guarded", "reload:ws_1"]);+ await click(cardButton("careful"));+ await waitFor(() => toggleIn(container).dataset.state === "careful", "the composer to follow the card");+ expect(shared.calls).toEqual(["set:full", "reload:ws_1", "set:careful", "reload:ws_1"]);// Settings changes report inline, not through the composer toast.expect(toasts).toHaveLength(1);expect(toggleIn(container).dataset.lockReason).toBeUndefined();- expect(FULL_PERMISSIONS_OFF_HINT).toContain("Guarded mode");});