agent-console 1.3.1: 全部自动同意 (Auto-approve all), split out of #727 (#747)

Auto-approve all (全部自动同意) ships in agent-console 1.3.1, split out of #727 (qingnian108).

The mode is off by default. In it, Codex runs with its sandbox off and Claude Code skips its checks. Cursor, OpenCode and dsh requests are answered allow-once by the console, never allow_always or acceptForSession. Each auto answer is saved with `auto: true` before the Agent goes on, and a banner shows while the mode is on. Plan confirmations and questions still ask. A 1.2 默认 of 全部放行 is not silently upgraded to real auto-approve. Pi keeps the `default` mode id ("Pi never asks"), so switching Agents before the first message never carries auto-approve into an Agent the user didn't pick.

Reviewed at 7e55c87ca merged onto main 20b89389:
- Linux (WSL2 Ubuntu 24.04): root `bun test packages/agent-console` 6/6; `bun scripts/check.mjs` OK; `npm run check` OK; vitest 461 passed / 17 skipped; `verify:build` 5/5 identical.
- Windows 11 (Edge): `e2e:v1` 29/29.
- Linux e2e stops at scenario 5 (steer timeout). It does the same on main 1.3.0, so it was filed as #753.
- Broken by hand:
  - Pi's modeMap back to bypassPermissions: 2 tests red.
  - The keeps line shown for every Agent: 1 test red.
  - Pi's label branch removed: 1 test red.
- An earlier round at 049449612 on macOS checked the daemon behaviour with probes. This version is published from the dist branch; the package isn't on npm.
This commit is contained in:
qingnian108
2026-11-05 14:02:29 +08:00
committed by GitHub
parent 20b893893f
commit 2c4e76dbba
38 changed files with 1378 additions and 136 deletions
@@ -0,0 +1,25 @@
// 1.3 全部自动同意 (#727 review 1): a persistent indicator for as long as the conversation is in auto-approve.
// One slim line (Nolan): amber shield + 全部自动同意已开启 on the left, the way back to 每次询问 on the right, nothing in
// between. What the mode does for this Agent (Codex: sandbox off, Claude: skips all permission checks …) is the left
// label's tooltip and its accessible description; the permission menu shows the same wording. Not dismissible.
import { useId } from "react";
import { Icon } from "./Icons";
import { autoApproveBannerDesc } from "../i18n/modes.js";
import { t } from "../i18n/index.js";
export function AutoApproveBanner({ providerId, onBack }: { providerId?: string; onBack?: () => void }) {
const desc = autoApproveBannerDesc(providerId);
const descId = useId();
return (
<div className="cp-auto-on" role="status" aria-live="polite" data-testid="auto-on">
<span className="cp-auto-t" title={desc} aria-describedby={descId} tabIndex={0}>
<span className="cp-auto-ic" aria-hidden><Icon name="shieldCheck" size={13} /></span>
<b>{t("composer.autoOn.title")}</b>
</span>
<span id={descId} className="sr-only">{desc}</span>
{onBack && (
<button type="button" className="cp-auto-back" onClick={onBack}>{t("composer.autoOn.back")}</button>
)}
</div>
);
}
@@ -0,0 +1,73 @@
// 1.3 全部自动同意 (#727 review): the approvals the daemon gave by itself, one quiet row per run of tool calls.
// Collapsed: "已自动同意 3 项 · npm test · git status …"; expanded: each request's title, command / file and the answer.
import { useState } from "react";
import type { DisplayItem } from "../timeline/reducer";
import { approvalChoice, approvalTarget } from "../timeline/autoApproved";
import { Icon } from "./Icons";
import { t, tf } from "../i18n/index.js";
import { ws } from "../main";
export function AutoApprovedItem({ it }: { it: Extract<DisplayItem, { kind: "autoperm" }> }) {
// Same flat one-line rows as the 1.3 tool steps: icon slot · text · right-edge meta; the shield keeps the amber of the
// 全部自动同意 chip so the row reads "approved for you", not "you approved"
const [open, setOpen] = useState(false);
const peek = it.items.map(approvalTarget).filter(Boolean).join(" · ");
return (
<div className={`apv${open ? " open" : ""}`} data-testid="auto-approved">
<button className="apv-head" aria-expanded={open} onClick={() => setOpen(!open)}
title={t("timeline.autoApproved.title")}>
<span className="apv-ic" aria-hidden><Icon name="shieldCheck" size={13} /></span>
<span className="apv-n">{tf("timeline.autoApproved.count", { n: it.items.length })}</span>
{!open && peek && <span className="apv-peek">{peek}</span>}
<span className={`caret${open ? " open" : ""}`} aria-hidden>›</span>
</button>
{open && (
<div className="apv-list">
{it.items.map((p) => {
const d = (p.detail ?? {}) as { command?: unknown; path?: unknown };
const choice = approvalChoice(p);
const cmd = typeof d.command === "string" && d.command.trim() ? d.command.trim() : "";
const path = !cmd && typeof d.path === "string" && d.path.trim() ? d.path.trim() : "";
const answer = p.status === "pending"
? t("timeline.autoApproved.pending")
: tf("timeline.autoApproved.answer", { opt: choice ?? t("timeline.permAllowed") });
return (
<div key={p.requestId} className="apv-row" title={[p.title, cmd || path, answer].filter(Boolean).join("\n")}>
<span className="ts-ic" aria-hidden><Icon name={p.status === "pending" ? "hourglass" : "check"} size={13} /></span>
{cmd ? <span className="apv-cmd">{cmd}</span>
: path ? <span className="apv-path">{path}</span>
: <span className="apv-title">{p.title}</span>}
<span className="apv-meta">{answer}</span>
</div>
);
})}
</div>
)}
</div>
);
}
/** 1.3 upgrade (#727 review 3): a 1.2 全部放行 that did nothing for this Agent was not turned into real auto-approval */
export const AUTO_UPGRADE_CODES = new Set(["auto_approve_upgrade", "auto_approve_migrated"]);
export function AutoUpgradeNotice({ it, threadId }: { it: Extract<DisplayItem, { kind: "notice" }>; threadId: string }) {
const [busy, setBusy] = useState(false);
const migrated = it.code === "auto_approve_migrated";
const turnOn = () => {
setBusy(true);
void ws.call("thread.setMode", { id: threadId, mode: "bypassPermissions" }).catch(() => {}).finally(() => setBusy(false));
};
return (
<div className="nt nt-auto" data-testid="auto-upgrade-notice" role="note">
<div className="nt-auto-h">
<span className="apv-ic"><Icon name="shieldCheck" size={14} /></span>
<b>{t("timeline.autoUpgrade.title")}</b>
</div>
<div>{t(migrated ? "timeline.autoUpgrade.migrated" : "timeline.autoUpgrade.body")}</div>
<div className="nt-actions">
<button type="button" className="btn" disabled={busy} onClick={turnOn}>{t("timeline.autoUpgrade.turnOn")}</button>
<button type="button" className="btn" onClick={() => window.dispatchEvent(new Event("open-settings"))}>{t("timeline.autoUpgrade.settings")}</button>
</div>
</div>
);
}
@@ -7,6 +7,7 @@ import { useData, pickDefaultProvider } from "../stores/data";
import { useTimeline } from "../stores/timeline";
import { TimelineRow } from "./Timeline";
import { foldTimeline, TOOL_COLLAPSE_AT } from "../timeline/fold";
import { collectAutoApproved } from "../timeline/autoApproved";
import { Composer } from "./Composer";
import { QuoteSelect } from "./QuoteSelect";
import { Icon } from "./Icons";
@@ -23,7 +24,8 @@ export function Chat() {
const prefs = useLiveSettings();
// 1.3: runs of tool calls (and short thinking between them) fold into one summary row
// (tl.items is a fresh array after every timeline change, so the memo follows the stream)
const items = useMemo(() => foldTimeline(tl.items, { showThinking: prefs.showThinking }), [tl.items, prefs.showThinking]);
// 1.3 全部自动同意: the daemon's own approvals become one quiet row after their run (collectAutoApproved)
const items = useMemo(() => foldTimeline(collectAutoApproved(tl.items), { showThinking: prefs.showThinking }), [tl.items, prefs.showThinking]);
const scrollRef = useRef<HTMLDivElement>(null);
const [stick, setStick] = useState(true);
const [hasNew, setHasNew] = useState(false);
@@ -19,6 +19,7 @@ import { composerModeOptions, effortLabel } from "../i18n/modes.js";
import { Logo } from "./Logo";
import { currentChecklist, todoProgress } from "../timeline/fold";
import { SelectMenu } from "./SelectMenu";
import { AutoApproveBanner } from "./AutoApproveBanner";
import { errMsg, t as tr, tf } from "../i18n/index.js";
import {
applySlashPick,
@@ -397,8 +398,12 @@ export function Composer() {
};
const setMode = (m: Mode) => {
if (thread) void ws.call("thread.setMode", { id: thread.id, mode: m });
if (!thread) return;
void ws.call("thread.setMode", { id: thread.id, mode: m }).catch((e) => toast(errMsg(e), true));
};
// 1.3 (#727 review 1): while the mode this Agent really uses is 全部自动同意, a persistent banner + warning-coloured chip
const autoOn = !!(modes.find((m) => m.id === mode) ?? modes[0])?.auto;
const canAsk = modes.some((m) => m.id === "default" && !m.auto);
const setEffort = (effort: string | null) => {
if (thread) void ws.call("thread.setEffort", { id: thread.id, effort });
};
@@ -469,10 +474,8 @@ export function Composer() {
))}
</div>
)}
{mode === "bypassPermissions" && (
<div className="cp-danger">{tr("composer.bypassWarn")}</div>
)}
<div className={`cp-card${waiting ? " waiting" : ""}${mode === "bypassPermissions" ? " danger" : ""}${dropHint ? " drop-on" : ""}`}>
{autoOn && <AutoApproveBanner providerId={thread?.provider} onBack={canAsk ? () => setMode("default") : undefined} />}
<div className={`cp-card${waiting ? " waiting" : ""}${autoOn ? " auto-on" : ""}${dropHint ? " drop-on" : ""}`}>
{dropHint && <div className="cp-drop-hint">{tr("mention.drop")}</div>}
{imagesByPath && attachments.some((a) => a.mime.startsWith("image/")) && (
<div className="att-note">{tf("composer.imagesByPath", { agent: provider?.name ?? "" })}</div>
@@ -728,13 +731,19 @@ export function Composer() {
<ChipCaret />
</SelectMenu>
)}
{/* permission mode: list only the modes this Agent really has; hidden when there is only one (e.g. Pi has no modes) */}
{/* permission mode: list only the modes this Agent really has; one mode only (Pi: always auto) = a plain label */}
{modes.length === 1 && (
<span className={`pill ipill mode-chip static${modes[0]!.auto ? " auto" : ""}`} title={modes[0]!.desc} data-mode={modes[0]!.id}>
<Icon name={modes[0]!.auto ? "shieldCheck" : "shield"} size={14} />
<span className="ip-l">{modes[0]!.label}</span>
</span>
)}
{modes.length > 1 && (() => {
// The mode stored on the conversation doesn't exist for this Agent → show the one it will actually use
const shown = modes.find((m) => m.id === mode) ?? modes[0]!;
return (
<SelectMenu
className={`pill ipill${shown.danger ? " danger" : ""}`}
className={`pill ipill mode-chip${shown.danger ? " danger" : ""}${shown.auto ? " auto" : ""}`}
title={shown.desc}
ariaLabel={tr("composer.modeTitle")}
prefer="up"
@@ -742,9 +751,9 @@ export function Composer() {
menuClassName="mode-menu"
value={shown.id}
onChange={(v) => setMode(v as Mode)}
options={modes.map((m) => ({ value: m.id, label: m.label, hint: m.desc, danger: m.danger }))}
options={modes.map((m) => ({ value: m.id, label: m.label, hint: m.desc, danger: m.danger, warn: m.auto, icon: m.auto ? "shieldCheck" : undefined }))}
>
<Icon name="shield" size={14} />
<Icon name={shown.auto ? "shieldCheck" : "shield"} size={14} />
<span className="ip-l">{shown.label}</span>
<ChipCaret />
</SelectMenu>
@@ -29,6 +29,7 @@ const PATHS: Record<string, string> = {
shield: "M12 3l8 3v6c0 5-3.5 9-8 11-4.5-2-8-6-8-11V6l8-3z",
quote: "M5 7h5v5H7c0 2 1 3 3 4M14 7h5v5h-3c0 2 1 3 3 4",
pencil: "M4 20h4L19 9a2.1 2.1 0 0 0-3-3L5 17v3zM14 7l3 3",
shieldCheck: "M12 3l8 3v6c0 5-3.5 9-8 11-4.5-2-8-6-8-11V6l8-3zM8.5 12.2l2.4 2.4 4.6-4.8",
zap: "M13 2L4 14h7l-1 8 9-12h-7l1-8z",
// 1.3 timeline rows / footer / code blocks
prompt: "M5 7l5 5-5 5M12 17h7",
@@ -3,6 +3,7 @@
// Enter/Space pick, Esc/Tab close (Esc returns focus to the trigger). Click outside closes. The menu is portaled to <body> with
// fixed positioning, opens below the trigger or flips above it when there's no room (the composer sits at the bottom), and is
// kept inside the window; no browser popup is involved, so it behaves the same inside Magpie's sandboxed iframe.
import { Icon } from "./Icons";
import { useCallback, useEffect, useId, useLayoutEffect, useRef, useState, type ReactNode } from "react";
import { createPortal } from "react-dom";
@@ -12,6 +13,10 @@ export type SelectOption<T extends string = string> = {
hint?: string;
disabled?: boolean;
danger?: boolean;
/** Warning colour (1.3: 全部自动同意, #727 review 1) */
warn?: boolean;
/** Small icon before the label (1.3: the 全部自动同意 shield) */
icon?: string;
};
const GAP = 4;
@@ -186,12 +191,12 @@ export function SelectMenu<T extends string>({
role="option"
aria-selected={o.value === value}
aria-disabled={o.disabled || undefined}
className={`mi sm-opt${i === active ? " on" : ""}${o.disabled ? " off" : ""}${o.danger ? " danger" : ""}${o.hint ? " has-hint" : ""}`}
className={`mi sm-opt${i === active ? " on" : ""}${o.disabled ? " off" : ""}${o.danger ? " danger" : ""}${o.warn ? " warn" : ""}${o.hint ? " has-hint" : ""}`}
onPointerMove={() => { if (!o.disabled && active !== i) setActive(i); }}
onClick={() => pick(i)}
>
<span className="sm-text">
<span className="sm-label">{o.label}</span>
<span className="sm-label">{o.icon && <Icon name={o.icon} size={13} />}{o.label}</span>
{o.hint && <span className="sm-hint">{o.hint}</span>}
</span>
<span className="sm-check" aria-hidden="true">{o.value === value ? (
@@ -225,10 +225,10 @@ export function SettingsDialog({ onClose, providers }: { onClose: () => void; pr
{row(t("settings.defaultMode"), (
<SelectMenu className="tinput sm-field" matchWidth ariaLabel={t("settings.defaultMode")}
value={s.defaultMode ?? "default"} onChange={(v) => void set({ defaultMode: v })}
options={modes.map((m) => ({ value: m.id, label: m.label, hint: m.desc }))}>
options={modes.map((m) => ({ value: m.id, label: m.label, hint: m.desc, icon: m.auto ? "shieldCheck" : undefined }))}>
<span className="sm-val">{(() => { const m = modes.find((x) => x.id === (s.defaultMode ?? "default")); return m ? `${m.label} — ${m.desc}` : ""; })()}</span>
</SelectMenu>
), t("settings.defaultModeHint"))}
), s.defaultMode === "bypassPermissions" ? `${t("settings.defaultModeHint")} ${t("composer.autoWarn")}` : t("settings.defaultModeHint"))}
{row(t("settings.theme"), (
<SelectMenu className="tinput sm-field" matchWidth ariaLabel={t("settings.theme")}
value={normalizeThemeSetting(s.theme)} onChange={(v) => void set({ theme: v })}
@@ -17,6 +17,7 @@ import { splitLocalLinks } from "../util/localLinks";
import { onChatLinkClick, openExternal } from "../preview/open";
import { splitQuotes } from "../composer/quotes";
import { localClientIds, useTimeline } from "../stores/timeline";
import { AUTO_UPGRADE_CODES, AutoApprovedItem, AutoUpgradeNotice } from "./AutoApproved";
export const GIT_FOR_WINDOWS_URL = "https://git-scm.com/download/win";
@@ -409,7 +410,8 @@ export function PermissionItem({ it, threadId }: { it: Extract<DisplayItem, { ki
const detail = it.detail as { command?: string; path?: string; plan?: string; hunks?: DiffHunk[]; diff?: { path?: string; hunks?: DiffHunk[] } } | undefined;
const hunks = detail?.hunks ?? detail?.diff?.hunks;
const label = it.status === "resolved"
? it.choice === "allow_always" || it.choice === "acceptForSession" ? t("timeline.permAllowSession")
? it.auto ? t("timeline.permAutoAllowed")
: it.choice === "allow_always" || it.choice === "acceptForSession" ? t("timeline.permAllowSession")
: it.choice === "deny" || it.choice === "reject" || it.choice === "decline" ? t("timeline.permDenied")
: it.choice === "implement" ? t("timeline.permAllowed") : t("timeline.permAllowed")
: t("timeline.permCancelled");
@@ -567,9 +569,11 @@ export function TimelineRow({ it, threadId, onEditResend, onRetryLast, replyText
case "plan": return <PlanItem it={it} />;
case "todo": return <TodoItem it={it} />;
case "permission": return <PermissionItem it={it} threadId={threadId} />;
case "autoperm": return <AutoApprovedItem it={it} />;
case "question": return <QuestionItem it={it} threadId={threadId} />;
case "notice":
if (it.code === "bash_missing") return <BashMissingNotice it={it} />;
if (it.code && AUTO_UPGRADE_CODES.has(it.code)) return <AutoUpgradeNotice it={it} threadId={threadId} />;
return <div className={`nt ${it.level}`}>{localizeDaemonMessage(it.message)}</div>;
case "turnend": return <TurnEndItem it={it} onRetry={onRetryLast} replyText={replyText} />;
case "gone": return null;