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.
57 lines
2.4 KiB
TypeScript
57 lines
2.4 KiB
TypeScript
// 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;
|
|
}
|