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
@@ -7,6 +7,8 @@ import type { AttachmentStore } from "../store/attachments.js";
import type { Provider, ProviderSession, SendInput, RespondAnswer, Mode, SlashCommand } from "../providers/types.js";
import { launchFromSettings } from "../providers/launch.js";
import { clampMode } from "../providers/modes.js";
import { guardLegacyMode, upgradeNotice } from "../migrate/autoApprove13.js";
import { autoApproveOption, FULL_AUTO } from "../providers/autoApprove.js";
import { resolveAttachmentRefs } from "../util/attachmentRefs.js";
import { getProvider } from "../providers/registry.js";
import { catalogById, providerCreatable } from "../providers/catalog.js";
@@ -450,10 +452,25 @@ export class AgentManager {
resolve: () => {},
event: ev,
};
// allowAlways hit → approve directly
if (ev.type === "permission_request") {
// 1.3 全部自动同意: the daemon answers "allow once" itself; no card (the tool call still shows in the timeline)
const meta = await this.threads.get(threadId);
const auto = meta ? autoApproveOption(meta.mode, meta.provider, ev) : null;
if (auto) {
// #727 review: every auto-approval leaves a trace. The request (title, command / path / diff, options) and its
// answer are persisted like a card the user answered, both marked auto, before the Agent is told to go on.
log("info", `thread ${threadId} 自动同意 ${ev.title.slice(0, 80)} → ${auto.id}`);
await this.appendRaw(threadId, { ...ev, auto: true });
await this.appendRaw(threadId, { type: "permission_resolved", requestId: ev.requestId, optionId: auto.id, auto: true });
rt.session?.respond(ev.requestId, { optionId: auto.id });
return;
}
}
// allowAlways hit → approve directly (with this request's own allow option, not a guessed id)
const toolName = (ev as { detail?: { toolName?: string } }).detail?.toolName;
if (toolName && rt.allowAlways.has(toolName)) {
rt.session?.respond(ev.requestId, { optionId: "accept" });
const allow = options.find((o) => o.kind === "allow_once") ?? options.find((o) => o.kind === "allow_always");
rt.session?.respond(ev.requestId, { optionId: allow?.id ?? "accept" });
return;
}
rt.pending.set(ev.requestId, pending);
@@ -544,6 +561,23 @@ export class AgentManager {
rt.session?.respond(requestId, answer);
}
/** Answer every waiting tool approval with its allow-once option (full-auto just turned on). Returns how many. */
private async autoApprovePending(threadId: string, providerId: string, mode: Mode): Promise<number> {
const rt = this.rt(threadId);
let n = 0;
for (const p of [...rt.pending.values()]) {
if (p.kind !== "permission") continue;
const ev = p.event as { kind?: string };
const opt = autoApproveOption(mode, providerId, { kind: ev.kind, options: p.options });
if (!opt) continue;
rt.pending.delete(p.requestId);
await this.appendRaw(threadId, { type: "permission_resolved", requestId: p.requestId, optionId: opt.id, auto: true });
rt.session?.respond(p.requestId, { optionId: opt.id });
n++;
}
return n;
}
// ---- interrupt ----
async interrupt(threadId: string): Promise<void> {
const rt = this.rt(threadId);
@@ -592,8 +626,10 @@ export class AgentManager {
this.gw.publish("sidebar", { type: "thread.upsert", thread: await this.threads.get(threadId) });
}
async setMode(threadId: string, mode: Mode): Promise<void> {
await this.threads.patch(threadId, { mode });
const meta = await this.threads.patch(threadId, { mode });
const rt = this.rt(threadId);
// 1.3: turning 全部自动同意 on also approves the cards already waiting (the user was stuck exactly there)
if (mode === FULL_AUTO) await this.autoApprovePending(threadId, meta.provider, mode);
if (rt.session) await rt.session.setMode(mode);
this.gw.publish("sidebar", { type: "thread.upsert", thread: await this.threads.get(threadId) });
}
@@ -652,14 +688,17 @@ export class AgentManager {
rt.commands = [];
}
rt.status = "idle";
// 1.3 (#727 review 3): same guard as threads.create for a pre-1.3 default of 全部放行
const guard = await guardLegacyMode(this.settings, providerId, clampMode(p.capabilities.modes, meta.mode));
await this.threads.patch(threadId, {
provider: providerId,
model: null,
mode: clampMode(p.capabilities.modes, meta.mode),
mode: guard.mode,
effort: null,
providerSessionId: null,
status: "idle",
});
if (guard.notice) await this.appendRaw(threadId, upgradeNotice());
this.gw.publish("sidebar", { type: "thread.upsert", thread: await this.threads.get(threadId) });
}