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,56 @@
// 1.3 全部自动同意 (#727 review): every approval the daemon answers by itself is in the timeline (permission_request +
// permission_resolved, both marked auto), so the user can always look up what was approved. Shown quietly: the auto
// approvals of one run of tool calls become one foldable row ("已自动同意 3 项") placed after that run, so they neither
// break the folded tool summary nor show up as cards with buttons. Pure: the reducer's items are not changed.
import type { DisplayItem } from "./reducer.js";
import { isShortThinking } from "./fold.js";
type Perm = Extract<DisplayItem, { kind: "permission" }>;
type AutoPerm = Extract<DisplayItem, { kind: "autoperm" }>;
export function isAutoApproved(it: DisplayItem): it is Perm {
return it.kind === "permission" && !!it.auto && it.status !== "cancelled";
}
/** Items a tool run is made of (what foldTimeline merges); anything else ends the run */
function inRun(it: DisplayItem): boolean {
return it.kind === "toolgroup" || it.kind === "gone" || isShortThinking(it);
}
/** Run before foldTimeline: pull auto-approved permissions out and put one "autoperm" row at the end of their run */
export function collectAutoApproved(items: DisplayItem[]): DisplayItem[] {
if (!items.some(isAutoApproved)) return items;
const out: DisplayItem[] = [];
let bucket: AutoPerm | null = null;
const flush = () => {
if (bucket) out.push(bucket);
bucket = null;
};
for (const it of items) {
if (isAutoApproved(it)) {
if (!bucket) bucket = { kind: "autoperm", key: `autoperm:${it.requestId}`, items: [] };
bucket.items.push(it);
continue;
}
if (bucket && !inRun(it)) flush();
out.push(it);
}
flush();
return out;
}
/** What one approval was for, on one line: the command, else the file, else the Agent's title */
export function approvalTarget(p: Perm): string {
const d = (p.detail ?? {}) as { command?: unknown; path?: unknown; diff?: { path?: unknown } };
const s = typeof d.command === "string" && d.command.trim() ? d.command
: typeof d.path === "string" && d.path.trim() ? d.path
: typeof d.diff?.path === "string" && d.diff.path.trim() ? d.diff.path
: p.title;
return s.replace(/\s+/g, " ").trim();
}
/** The label of the option the daemon picked ("Allow once" …), or its id */
export function approvalChoice(p: Perm): string | null {
if (!p.choice) return null;
return p.options.find((o) => o.id === p.choice)?.label ?? p.choice;
}
@@ -25,9 +25,11 @@ export type DisplayItem =
| { kind: "toolgroup"; key: string; steps: ToolStep[] }
| { kind: "plan"; key: string; itemId: string; markdown: string }
| { kind: "todo"; key: string; items: { text: string; status: string }[] }
| { kind: "permission"; key: string; requestId: string; title: string; kindStr: string; detail?: unknown; options: { id: string; label: string; kind: string }[]; status: "pending" | "resolved" | "cancelled"; choice?: string }
| { kind: "permission"; key: string; requestId: string; title: string; kindStr: string; detail?: unknown; options: { id: string; label: string; kind: string }[]; status: "pending" | "resolved" | "cancelled"; choice?: string; auto?: boolean }
| { kind: "question"; key: string; requestId: string; questions: unknown[]; answers?: Record<string, string>; status: "pending" | "answered" | "cancelled" }
| { kind: "notice"; key: string; level: string; message: string; code?: string }
/** 1.3 全部自动同意: the approvals the daemon gave in one run of tool calls, as one quiet foldable row (autoApproved.ts) */
| { kind: "autoperm"; key: string; items: Extract<DisplayItem, { kind: "permission" }>[] }
| { kind: "gone"; key: string } // placeholder: duplicate delta items cleared by sweepSiblings; skipped when rendering
| { kind: "turnend"; key: string; status: string; durationMs?: number; error?: string; filesChanged?: number; usage?: TurnUsage;
/** 1.3: the model the turn ran on (turn_started; null = the Agent's default) and when it ended, for the reply footer */
@@ -224,6 +226,8 @@ export function applyEvent(st: State, ev: TimelineEvent): void {
st.items.push({
kind: "permission", key: `perm:${ev.requestId}`, requestId: ev.requestId,
title: ev.title, kindStr: ev.kind, detail: ev.detail, options: ev.options, status: "pending",
// 1.3 全部自动同意: the daemon answered it itself (never a card with buttons; see timeline/autoApproved.ts)
...(ev.auto ? { auto: true } : {}),
});
return;
case "permission_resolved": {
@@ -232,6 +236,7 @@ export function applyEvent(st: State, ev: TimelineEvent): void {
if (it?.kind === "permission") {
it.status = ev.cancelled ? "cancelled" : "resolved";
it.choice = ev.optionId;
if (ev.auto) it.auto = true;
}
return;
}
@@ -16,8 +16,8 @@ export type TimelineEvent =
| { seq: number; ts: number; threadId: string; turnId?: string; type: "tool_call"; itemId: string; kind: ToolKind; title: string; status: "running" | "ok" | "failed"; input?: unknown; detail?: unknown; output?: string; exitCode?: number; durationMs?: number }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "plan"; itemId: string; markdown: string; entries?: { step: string; status: string }[] }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "todo"; items: { text: string; status: string }[] }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "permission_request"; requestId: string; title: string; kind: string; detail?: unknown; options: { id: string; label: string; kind: string }[] }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "permission_resolved"; requestId: string; optionId?: string; cancelled?: boolean }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "permission_request"; requestId: string; title: string; kind: string; detail?: unknown; options: { id: string; label: string; kind: string }[]; auto?: boolean }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "permission_resolved"; requestId: string; optionId?: string; cancelled?: boolean; auto?: boolean }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "question"; requestId: string; questions: unknown[] }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "question_answered"; requestId: string; answers: Record<string, string> }
| { seq: number; ts: number; threadId: string; turnId?: string; type: "usage"; inputTokens: number; outputTokens: number; cacheReadTokens: number; costUsd: number; contextWindow?: number }