Back

Autonomy Mode Switcher

A composer pill that sets how much the agent does on its own — Suggest, Confirm or Execute — with each mode's permissions per action type, a shortcut to cycle, and a distinct look for the top mode.

JobSteer
Seen in

Agent’s next steps

  • Edit pricing.tsApply the 20% annual discountDenyAllow
  • Run npm testpricing.test.tsDenyAllow

Add a 20% annual discount and check the tests…

"use client";

import * as React from "react";
import { AnimatePresence, motion } from "motion/react";
import { Check, ChevronDown } from "lucide-react";

import { cn } from "@/lib/utils";

/** What the agent does about one kind of action in a mode. */
export type Permission = "auto" | "ask" | "suggest";

export interface Capability {
  id: string;
  /** Short verb phrase: "Read files", "Edit files", "Run commands". */
  label: string;
}

export interface AutonomyMode {
  id: string;
  label: string;
  /** One line on what the agent does in this mode. */
  description: string;
  /** Permission per capability id. Missing ids read as "ask". */
  permissions: Record<string, Permission>;
}

export interface AutonomyModePickerProps {
  /** Ordered from least to most autonomous. */
  modes: AutonomyMode[];
  capabilities: Capability[];
  value: string;
  onChange: (id: string) => void;
  /** Cycle modes with ⌘. / Ctrl+. while focus is anywhere in the page. */
  shortcut?: boolean;
  side?: "up" | "down";
  className?: string;
}

const PERMISSION_TEXT: Record<Permission, string> = {
  auto: "runs without asking",
  ask: "asks first",
  suggest: "suggests only",
};

export function AutonomyModePicker({
  modes,
  capabilities,
  value,
  onChange,
  shortcut = true,
  side = "up",
  className,
}: AutonomyModePickerProps) {
  const [open, setOpen] = React.useState(false);
  const [active, setActive] = React.useState(0);
  const [announcement, setAnnouncement] = React.useState("");
  const rootRef = React.useRef<HTMLDivElement>(null);
  const triggerRef = React.useRef<HTMLButtonElement>(null);
  const listRef = React.useRef<HTMLUListElement>(null);
  const id = React.useId();

  const index = Math.max(0, modes.findIndex((m) => m.id === value));
  const selected = modes[index];
  const level = index + 1;
  const highest = index === modes.length - 1;

  const select = React.useCallback(
    (i: number) => {
      const mode = modes[i];
      if (!mode) return;
      onChange(mode.id);
      setAnnouncement(`${mode.label} mode. ${mode.description}`);
    },
    [modes, onChange]
  );

  React.useEffect(() => {
    if (!shortcut) return;
    function handle(e: KeyboardEvent) {
      if (e.key === "." && (e.metaKey || e.ctrlKey)) {
        e.preventDefault();
        select((index + 1) % modes.length);
      }
    }
    window.addEventListener("keydown", handle);
    return () => window.removeEventListener("keydown", handle);
  }, [shortcut, index, modes.length, select]);

  React.useEffect(() => {
    if (!open) return;
    function handle(e: MouseEvent) {
      if (rootRef.current && !rootRef.current.contains(e.target as Node)) setOpen(false);
    }
    document.addEventListener("mousedown", handle);
    return () => document.removeEventListener("mousedown", handle);
  }, [open]);

  function openMenu() {
    setActive(index);
    setOpen(true);
    requestAnimationFrame(() => listRef.current?.focus());
  }

  function close() {
    setOpen(false);
    triggerRef.current?.focus();
  }

  function handleListKeyDown(e: React.KeyboardEvent) {
    if (e.key === "ArrowDown") {
      e.preventDefault();
      setActive((i) => (i + 1) % modes.length);
    } else if (e.key === "ArrowUp") {
      e.preventDefault();
      setActive((i) => (i - 1 + modes.length) % modes.length);
    } else if (e.key === "Enter" || e.key === " ") {
      e.preventDefault();
      select(active);
      close();
    } else if (e.key === "Escape" || e.key === "Tab") {
      if (e.key === "Escape") e.preventDefault();
      close();
    }
  }

  return (
    <div ref={rootRef} className={cn("relative inline-flex", className)}>
      <button
        ref={triggerRef}
        type="button"
        aria-haspopup="listbox"
        aria-expanded={open}
        aria-controls={open ? `${id}-list` : undefined}
        aria-label={`Mode: ${selected?.label}`}
        title={shortcut ? "Change mode (⌘.)" : undefined}
        onClick={() => (open ? setOpen(false) : openMenu())}
        onKeyDown={(e) => {
          if (e.key === "ArrowDown" || e.key === "ArrowUp") {
            e.preventDefault();
            openMenu();
          }
        }}
        className={cn(
          "flex h-8 items-center gap-1.5 rounded-lg px-2 text-xs font-medium transition-colors",
          // The most autonomous mode stays visibly different, so it's never on by accident.
          highest
            ? "bg-foreground text-background hover:bg-foreground/90"
            : "text-muted-foreground hover:bg-accent hover:text-foreground aria-expanded:bg-accent aria-expanded:text-foreground"
        )}
      >
        <LevelBars level={level} max={modes.length} />
        <span>{selected?.label}</span>
        <ChevronDown className={cn("size-3.5 transition-transform", open && "rotate-180")} aria-hidden />
      </button>

      <AnimatePresence>
        {open && (
          <motion.div
            initial={{ opacity: 0, y: side === "up" ? 4 : -4, scale: 0.98 }}
            animate={{ opacity: 1, y: 0, scale: 1 }}
            exit={{ opacity: 0, y: side === "up" ? 4 : -4, scale: 0.98 }}
            transition={{ duration: 0.14, ease: "easeOut" }}
            className={cn(
              "absolute left-0 z-20 w-80 overflow-hidden rounded-2xl bg-popover p-1 text-popover-foreground border",
              side === "up" ? "bottom-full mb-2 origin-bottom-left" : "top-full mt-2 origin-top-left"
            )}
          >
            <ul
              ref={listRef}
              id={`${id}-list`}
              role="listbox"
              tabIndex={-1}
              aria-label="How much the agent can do on its own"
              aria-activedescendant={`${id}-opt-${active}`}
              onKeyDown={handleListKeyDown}
              className="outline-none"
            >
              {modes.map((mode, i) => {
                const isSelected = i === index;
                return (
                  <li
                    key={mode.id}
                    id={`${id}-opt-${i}`}
                    role="option"
                    aria-selected={isSelected}
                    aria-describedby={`${id}-desc-${i}`}
                    onMouseEnter={() => setActive(i)}
                    onClick={() => {
                      select(i);
                      close();
                    }}
                    className={cn("cursor-pointer rounded-lg px-2.5 py-2", i === active && "bg-accent")}
                  >
                    <div className="flex items-center gap-2">
                      <LevelBars level={i + 1} max={modes.length} />
                      <span className="flex-1 text-sm font-medium">{mode.label}</span>
                      {isSelected && <Check className="size-4 shrink-0" aria-hidden />}
                    </div>
                    <div id={`${id}-desc-${i}`}>
                      <p className="mt-0.5 text-xs text-pretty text-muted-foreground">{mode.description}</p>
                      <ul className="mt-1.5 flex flex-wrap gap-1">
                        {capabilities.map((cap) => {
                          const p = mode.permissions[cap.id] ?? "ask";
                          return (
                            <li
                              key={cap.id}
                              className={cn(
                                "flex items-center gap-1 rounded-md border px-1.5 py-0.5 text-[11px]",
                                p === "auto" ? "border-foreground/40 text-foreground" : "text-muted-foreground",
                                p === "suggest" && "border-dashed"
                              )}
                            >
                              <PermissionMark permission={p} />
                              {cap.label}
                              <span className="sr-only">: {PERMISSION_TEXT[p]}</span>
                            </li>
                          );
                        })}
                      </ul>
                    </div>
                  </li>
                );
              })}
            </ul>
            <p className="mt-1 border-t px-2.5 pt-1.5 pb-1 text-[11px] text-muted-foreground">
              <PermissionMark permission="auto" /> runs · <PermissionMark permission="ask" /> asks ·{" "}
              <PermissionMark permission="suggest" /> suggests
              {shortcut && <span className="float-right">⌘. to switch</span>}
            </p>
          </motion.div>
        )}
      </AnimatePresence>

      <span className="sr-only" aria-live="polite">
        {announcement}
      </span>
    </div>
  );
}

/** Filled bars for how much the agent may do: one per mode, filled up to this one. */
function LevelBars({ level, max }: { level: number; max: number }) {
  return (
    <span className="flex h-3 items-end gap-px" aria-hidden>
      {Array.from({ length: max }, (_, i) => (
        <span
          key={i}
          className={cn("w-[3px] rounded-sm bg-current", i >= level && "opacity-25")}
          style={{ height: `${((i + 1) / max) * 100}%` }}
        />
      ))}
    </span>
  );
}

function PermissionMark({ permission }: { permission: Permission }) {
  return (
    <span
      aria-hidden
      className={cn(
        "inline-block align-middle",
        permission === "auto" && "size-2 rounded-full bg-current",
        permission === "ask" && "size-2 rounded-full border-[1.5px] border-current",
        // A dash: proposed, not done.
        permission === "suggest" && "h-[1.5px] w-2 rounded-full bg-current"
      )}
    />
  );
}

A UX spec for this pattern — written for agents implementing or reusing it, not the code.

# Autonomy Mode Switcher

## Summary
A mode control in the composer that sets how much the agent may do on its own for the next run — Suggest (it proposes, you apply), Confirm (it acts after you approve each step) or Execute (it acts and you can stop it). Each mode lists, per kind of action, whether the agent runs it, asks first or only suggests, so the choice is about concrete permissions rather than a vague "autonomy" slider. The current mode is always visible, and the most autonomous one looks different so it's never on by accident.

## When to use
- An agent can take actions with side effects (edit files, run commands, send, buy) and the right amount of oversight changes from task to task.
- The same person moves between exploring ("just tell me what you'd change") and delegating ("go do it").
- Per-action approval prompts are useful sometimes but too noisy for long runs, and people need a way to turn them down and back up.

## When not to use
- The agent only reads and answers. Without side effects there's nothing for the modes to govern.
- Permissions need to be set per tool or per resource ("can email this domain", "can spend up to $50"). Put that in a settings page; the switcher is a quick, coarse dial on top.
- A single risky action. Ask about that action with an approval prompt instead of changing the whole mode.
- Unattended or shared runs where nobody sees the composer. Set policy where the run is configured, and show it on the run.

## Anatomy
- Trigger: a pill in the composer toolbar with a level glyph (bars filling up to the current mode), the mode name and a chevron. In the highest mode it switches to a filled, high-contrast style.
- Menu: modes ordered from least to most autonomous. Each has the same level glyph, a name, one line on what the agent does, and a row of capability tags — Read files, Edit files, Run commands — each marked runs, asks or suggests.
- Legend: a footer that explains the three marks and the shortcut.
- Live region: announces the new mode and its one-line description on every change.

## Behavior
- The mode applies to the next message and stays until changed; show it in the transcript next to runs started in it, so the history says how each change happened.
- The menu opens upward from the composer. Arrow keys move, Enter picks, Escape closes back to the trigger.
- A shortcut cycles modes without opening the menu (⌘. / Ctrl+. here, as Windsurf does). Don't take Tab or Shift+Tab in a web page — they move focus.
- Default to the middle mode. Never move people up to the most autonomous mode automatically; going down (to Suggest) can happen on its own when something risky is detected, as long as it's announced.
- Switching modes mid-run takes effect at the agent's next step. Switching to a less autonomous mode turns the remaining steps into approvals or suggestions; it doesn't undo what already ran.
- Capability tags come from the same policy the agent enforces. If the menu says "Run commands: asks first", the agent must ask.

## Content guidelines
- Name modes after what the agent does, with verbs people already use: Suggest, Confirm, Execute — or Ask, Plan, Agent. Avoid levels with no meaning on their own ("Level 2", "Turbo").
- Descriptions say who does what in one line: "Reads and proposes changes. You apply them."
- Capability labels are short verb phrases for real action types ("Edit files", "Run commands", "Send email"), three to five of them.
- In the highest mode, remind people how to stop: "Stop it any time".

## Accessibility
- The trigger is a button with `aria-haspopup="listbox"`, `aria-expanded`, and an accessible name that includes the current mode ("Mode: Confirm").
- The menu is a listbox with `aria-activedescendant`; each option is described by its description and capability row, and each capability tag carries its permission as text ("Edit files: asks first"), not only a dot style.
- Mode changes, including ones from the shortcut, are announced in a polite live region.
- The highest mode differs by more than color — the filled style and the full level glyph both change — and passes contrast in both themes.
- The menu animation is a short fade and scale; disable it under `prefers-reduced-motion`.

## Related patterns
- **Tool Approval** — Use it as well: it's what Confirm mode shows for each step, and what any mode shows for an action its policy doesn't cover.
- **Plan Review** — Use it as well for a plan-first mode, where the agent writes a plan to approve before it acts.
- **Model Picker** — Use it beside the switcher; it chooses which model runs, not what that model may do.
- **Stop Generation Button** — Use it as well, so a run in the most autonomous mode can always be stopped.

Do’s and don’ts

Do use it for

  • An agent can take actions with side effects (edit files, run commands, send, buy) and the right amount of oversight changes from task to task.
  • The same person moves between exploring ("just tell me what you'd change") and delegating ("go do it").
  • Per-action approval prompts are useful sometimes but too noisy for long runs, and people need a way to turn them down and back up.

Don’t use it for

  • The agent only reads and answers. Without side effects there's nothing for the modes to govern.
  • Permissions need to be set per tool or per resource ("can email this domain", "can spend up to $50"). Put that in a settings page; the switcher is a quick, coarse dial on top.
  • A single risky action. Ask about that action with an approval prompt instead of changing the whole mode.
  • Unattended or shared runs where nobody sees the composer. Set policy where the run is configured, and show it on the run.