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) });
}
@@ -68,6 +68,13 @@ async function main(): Promise<void> {
} catch (e) {
log("error", "旧数据迁移失败", { err: String(e) });
}
// 1.3 (#727 review 3): a 1.2 "全部放行" never turns into real auto-approval silently for Cursor / OpenCode / dsh
try {
const { migrateAutoApprove13 } = await import("./migrate/autoApprove13.js");
await migrateAutoApprove13({ settings, threads });
} catch (e) {
log("error", "全部自动同意迁移失败", { err: String(e) });
}
const manager = new AgentManager(gateway, threads, projects, settings, attachments);
await manager.recoverOnStart();
const terminals = new TerminalService(gateway);
@@ -0,0 +1,81 @@
// 1.3 全部自动同意 upgrade safety (#727 review 3).
//
// In 1.2, "bypassPermissions" (全部放行) only did something for Agents with a native switch (Claude, Codex, Copilot,
// Devin). Cursor and OpenCode had no such mode, so a saved default of bypassPermissions was clamped to "default" for
// them, and dsh accepted the mode but still asked for every tool. In 1.3 the daemon answers those Agents' approvals
// itself, so the same saved setting would silently start approving everything for them.
//
// Choice: never escalate silently. On the first 1.3 start:
// - conversations of those Agents stored in bypassPermissions go back to "default" (每次询问), each with a notice;
// - a pre-1.3 default of bypassPermissions is remembered as "legacy": new conversations of those Agents start in
// "default" and the first one says once that the new mode exists (the user can switch it on there, explicitly).
// Choosing a default permission mode in Settings after the upgrade is a 1.3-era decision and ends the legacy state.
// Claude / Codex / Copilot / Devin keep bypassPermissions: for them 1.2 already meant the same thing.
import type { SettingsStore } from "../store/settings.js";
import type { ThreadsStore } from "../store/threads.js";
import type { Mode } from "../timeline/types.js";
import { FULL_AUTO } from "../providers/autoApprove.js";
import { tr } from "../util/i18n.js";
import { log } from "../log.js";
/** Agents for which 1.2's bypassPermissions did not auto-approve anything */
export const LEGACY_NO_AUTO = new Set(["cursor", "opencode", "dsh"]);
export const UPGRADE_NOTICE_CODE = "auto_approve_upgrade";
export const MIGRATED_NOTICE_CODE = "auto_approve_migrated";
/** Kept in settings.json; written only by the daemon (not in settingsPatchSchema, so the page cannot set it) */
export type AutoApproveUpgradeState = { done: true; legacyDefault: boolean; noticed: boolean };
const KEY = "autoApproveUpgrade";
function state(s: Record<string, unknown>): AutoApproveUpgradeState | null {
const v = s[KEY] as Partial<AutoApproveUpgradeState> | undefined;
return v && typeof v === "object" && v.done === true
? { done: true, legacyDefault: v.legacyDefault === true, noticed: v.noticed === true }
: null;
}
/** Runs once, on the first start of a build with this code (fresh installs: nothing to do, just marks it done) */
export async function migrateAutoApprove13(stores: { settings: SettingsStore; threads: ThreadsStore }): Promise<{ threads: string[]; legacyDefault: boolean; skipped: boolean }> {
const s = await stores.settings.get();
if (state(s)) return { threads: [], legacyDefault: false, skipped: true };
const moved: string[] = [];
for (const t of await stores.threads.list()) {
if (t.mode !== FULL_AUTO || !LEGACY_NO_AUTO.has(t.provider)) continue;
try {
await stores.threads.patch(t.id, { mode: "default" });
await stores.threads.appendEvent(t.id, { type: "notice", level: "warn", code: MIGRATED_NOTICE_CODE, message: tr("notice.autoApproveMigrated") });
moved.push(t.id);
} catch (e) {
log("warn", `全部自动同意迁移:对话 ${t.id} 失败:${String(e)}`);
}
}
const legacyDefault = s.defaultMode === FULL_AUTO;
await stores.settings.set({ [KEY]: { done: true, legacyDefault, noticed: false } satisfies AutoApproveUpgradeState });
if (moved.length || legacyDefault) log("info", `全部自动同意迁移:${moved.length} 个对话改回每次询问;旧的默认全部放行=${legacyDefault}`);
return { threads: moved, legacyDefault, skipped: false };
}
/**
* The mode a new (or re-pointed) conversation of this Agent really starts in. A pre-1.3 default of bypassPermissions
* does not turn into real auto-approval for Agents where it did nothing in 1.2; the first time, a notice says so.
*/
export async function guardLegacyMode(settings: SettingsStore, providerId: string, mode: Mode): Promise<{ mode: Mode; notice: boolean }> {
if (mode !== FULL_AUTO || !LEGACY_NO_AUTO.has(providerId)) return { mode, notice: false };
const s = await settings.get();
const st = state(s);
if (!st?.legacyDefault) return { mode, notice: false };
if (st.noticed) return { mode: "default", notice: false };
await settings.set({ [KEY]: { ...st, noticed: true } satisfies AutoApproveUpgradeState });
return { mode: "default", notice: true };
}
/** The user picked a default permission mode in Settings: their 1.3 choice from now on */
export async function endLegacyDefault(settings: SettingsStore): Promise<void> {
const st = state(await settings.get());
if (st?.legacyDefault) await settings.set({ [KEY]: { ...st, legacyDefault: false } satisfies AutoApproveUpgradeState });
}
/** The one-time notice appended to the conversation the guard kept in 每次询问 */
export function upgradeNotice(): { type: "notice"; level: "info"; code: string; message: string } {
return { type: "notice", level: "info", code: UPGRADE_NOTICE_CODE, message: tr("notice.autoApproveUpgrade") };
}
@@ -45,7 +45,9 @@ export const acpCapabilities: Capabilities = {
export const cursorAcpCapabilities: Capabilities = {
...acpCapabilities,
questions: true,
modes: ["default", "plan", "ask"],
// 1.3: bypassPermissions = 全部自动同意: Cursor's agent mode, every approval answered "allow once" by the daemon
// (Cursor's own --force only exists at spawn, and Auto-review is not applied over ACP)
modes: ["default", "bypassPermissions", "plan", "ask"],
};
function runVersion(r: ResolveResult & { ok: true }, args: string[], timeoutMs = 8000): Promise<string> {
@@ -79,7 +81,7 @@ async function resolveProviderBin(cfg: AcpProviderConfig) {
export function createAcpProvider(cfg: AcpProviderConfig): Provider {
const base = cfg.capabilities ?? acpCapabilities;
// With a mode table, expose only the modes the Agent really has (in our fixed order)
const ORDER: Mode[] = ["plan", "default", "acceptEdits", "bypassPermissions"];
const ORDER: Mode[] = ["plan", "default", "acceptEdits", "bypassPermissions", "ask"];
const caps: Capabilities = cfg.modeMap
? { ...base, modes: ORDER.filter((m) => cfg.modeMap![m] !== undefined), modeLabels: cfg.modeLabels }
: base;
@@ -268,7 +268,7 @@ export class AcpSession implements ProviderSession {
return hit?.id ?? want;
}
if (this.o.flavor === "cursor") {
const map: Partial<Record<Mode, string>> = { default: "agent", plan: "plan", ask: "ask" };
const map: Partial<Record<Mode, string>> = { default: "agent", bypassPermissions: "agent", plan: "plan", ask: "ask" };
const want = map[mode] ?? "agent";
const avail = this.active?.modes?.availableModes ?? [];
const hit = avail.find((m) => m.id === want || m.name.toLowerCase() === want);
@@ -49,8 +49,9 @@ export function acpConfigForEntry(entry: ProviderCatalogEntry, appVersion: strin
...base,
acpArgs: ["acp"],
fetchModels: acpProbeModels(["acp"], entry.id),
modeMap: { plan: "plan", default: "build" },
modeLabels: { plan: "Plan", default: "Build" },
// 1.3: 全部自动同意 = build + the daemon answers each approval "allow once" (OPENCODE_PERMISSION only applies at spawn)
modeMap: { plan: "plan", default: "build", bypassPermissions: "build" },
modeLabels: { plan: "Plan", default: "Build", bypassPermissions: "Build" },
};
case "copilot":
// As Paseo: Agent / Plan / Allow All. Allow All = agent mode + allow_all config on (autopilot is not used)
@@ -62,7 +63,9 @@ export function acpConfigForEntry(entry: ProviderCatalogEntry, appVersion: strin
modeLabels: { plan: "Plan", default: "Agent", bypassPermissions: "Allow All" },
};
case "pi":
// pi-acp has no mode options; thinking level thought_level (low…max)
// pi-acp has no mode options; thinking level thought_level (low…max). Pi never asks before its tools, so its one
// mode uses the neutral default id (shown read-only; nothing is sent), so switching Agents never carries
// bypassPermissions into an Agent the user did not choose. Pi extensions' own dialogs still reach the user.
return { ...base, acpArgs: [], fetchModels: acpProbeModels([], entry.id), modeMap: { default: "" } };
case "dsh":
// Started on the conversation's route (--patch), so its initialize advertises image input for that model (see dsh.ts)
@@ -0,0 +1,60 @@
// 1.3 "全部自动同意" (full auto-approve): the permission chip's bypassPermissions mode, for every Agent.
//
// Where the Agent has its own switch we use it (see FULL_AUTO); the daemon also answers every tool approval the Agent
// still asks for while the mode is on, so Agents that only ask over their protocol (Cursor / OpenCode / dsh over ACP)
// stop asking too, and a card already on screen is approved the moment the user turns the mode on.
//
// The answer is always the option that covers this one request ("Allow once" / accept), never "Allow always":
// an allow-always answer can make the Agent write a permanent rule into the user's own config (Cursor's allowlist,
// OpenCode's permission file), which would outlive the mode. Questions and plan approvals are never auto-answered.
import type { Mode } from "./types.js";
export const FULL_AUTO: Mode = "bypassPermissions";
export type ApprovalOption = { id: string; label?: string; kind?: string };
export type ApprovalRequest = { kind?: string; options: ApprovalOption[] };
/** How full-auto works for each Agent (also the source of the plan's table) */
export const FULL_AUTO_NATIVE: Record<string, { native: string; live: "live" | "nextTurn" | "none"; daemonAnswers: boolean }> = {
claude: { native: "--permission-mode bypassPermissions (+ --allow-dangerously-skip-permissions)", live: "nextTurn", daemonAnswers: true },
codex: { native: "approvalPolicy never + sandbox danger-full-access (turn/start)", live: "nextTurn", daemonAnswers: true },
cursor: { native: "none over ACP (--force is spawn-only); ACP mode agent", live: "live", daemonAnswers: true },
copilot: { native: "ACP config allow_all = on (agent mode)", live: "live", daemonAnswers: true },
opencode: { native: "none over ACP (OPENCODE_PERMISSION is spawn-only); ACP mode build", live: "live", daemonAnswers: true },
devin: { native: "ACP mode bypass", live: "live", daemonAnswers: true },
dsh: { native: "none known; ACP default mode", live: "live", daemonAnswers: true },
// pi never asks before its own tools; requestPermission only carries Pi extensions' own dialogs, which stay with the user
pi: { native: "always (Pi has no tool approvals)", live: "live", daemonAnswers: false },
mock: { native: "mock", live: "live", daemonAnswers: true },
};
const REJECT = /reject|deny|decline|cancel|never|拒绝/i;
const ALLOW = /allow|accept|approve|yes|允许|同意/i;
/**
* The option that allows just this request: kind allow_once, else an allow-looking id/label that is not "always" /
* "session". Never allow_always (that writes a lasting rule into the Agent's own config): when a request offers
* nothing narrower, null, and the card is left for the user.
*/
export function pickAllowOnce(options: ApprovalOption[]): ApprovalOption | null {
const once = options.find((o) => o.kind === "allow_once");
if (once) return once;
const plain = options.find((o) => {
const s = `${o.id} ${o.label ?? ""}`;
return !o.kind?.startsWith("reject") && !REJECT.test(s) && ALLOW.test(s) && !/always|session|总是|始终/i.test(s);
});
return plain ?? null;
}
/** The daemon answers this request itself: the mode is full-auto, the Agent lets us, it is a tool approval and something allows it */
export function autoApproveOption(
mode: Mode | null | undefined,
providerId: string,
req: ApprovalRequest,
): ApprovalOption | null {
if (mode !== FULL_AUTO) return null;
if (FULL_AUTO_NATIVE[providerId]?.daemonAnswers === false) return null;
// A plan ("implement this plan?") is a decision, not a tool permission
if (req.kind === "plan" || req.kind === "switch_mode") return null;
return pickAllowOnce(req.options);
}
@@ -17,8 +17,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 }
@@ -37,8 +37,8 @@ export type ProviderEvent =
| { type: "tool_call"; itemId: string; kind: string; title: string; status: "running" | "ok" | "failed"; input?: unknown; detail?: unknown; output?: string; exitCode?: number; durationMs?: number }
| { type: "plan"; itemId: string; markdown: string; entries?: { step: string; status: string }[] }
| { type: "todo"; items: { text: string; status: string }[] }
| { type: "permission_request"; requestId: string; title: string; kind: string; detail?: unknown; options: { id: string; label: string; kind: string }[] }
| { type: "permission_resolved"; requestId: string; optionId?: string; cancelled?: boolean }
| { type: "permission_request"; requestId: string; title: string; kind: string; detail?: unknown; options: { id: string; label: string; kind: string }[]; auto?: boolean }
| { type: "permission_resolved"; requestId: string; optionId?: string; cancelled?: boolean; auto?: boolean }
| { type: "question"; requestId: string; questions: unknown[] }
| { type: "question_answered"; requestId: string; answers: Record<string, string> }
| { type: "usage"; inputTokens: number; outputTokens: number; cacheReadTokens: number; costUsd: number; contextWindow?: number }
@@ -29,6 +29,8 @@ const dict: Record<AppLocale, Record<string, string>> = {
"notice.sessionStartFailed": "会话启动失败:{detail}",
"notice.sendFailed": "发送失败:{detail}",
"notice.bashMissing": "没有找到 Git Bash。这个 Agent 在 Windows 上要用 Git Bash 运行命令(C:\\Windows\\System32\\bash.exe 是 WSL 启动器,不能用)。请安装 Git for Windows:https://git-scm.com/download/win ,或在「设置 → Bash 路径」里手动指定 bash.exe。",
"notice.autoApproveUpgrade": "1.3 新增「全部自动同意」:现在对 Cursor、OpenCode、dsh 也会真正自动同意(1.2 的「全部放行」对它们不生效,仍会询问)。你之前把默认权限模式设成了它,为安全起见这个对话仍从「每次询问」开始;需要时请在下方权限菜单里手动开启,或在设置里重新选择默认权限模式。",
"notice.autoApproveMigrated": "这个对话在 1.2 里设成了「全部放行」,当时这个 Agent 实际仍会询问。1.3 起「全部自动同意」会真正自动同意,所以已改回「每次询问」;需要时请在下方权限菜单里手动开启。",
"notice.effortNextTurn": "思考强度已保存,将在下一轮生效",
"notice.effortResetOnModel": "当前模型不支持该思考强度,已恢复为 Default",
"turn.agentExit": "Agent 进程意外退出",
@@ -140,6 +142,8 @@ const dict: Record<AppLocale, Record<string, string>> = {
"notice.sessionStartFailed": "Session start failed: {detail}",
"notice.sendFailed": "Send failed: {detail}",
"notice.bashMissing": "Git Bash was not found. On Windows this agent runs its commands with Git Bash (C:\\Windows\\System32\\bash.exe is the WSL launcher and won't work). Install Git for Windows: https://git-scm.com/download/win , or set bash.exe under Settings → Bash path.",
"notice.autoApproveUpgrade": "New in 1.3: Auto-approve all now really auto-approves for Cursor, OpenCode and dsh too (1.2's bypass mode did nothing for them; they still asked). Your default permission mode was set to it, so to be safe this conversation starts in Always Ask; switch it on in the permission menu below if you want it, or pick the default permission mode again in Settings.",
"notice.autoApproveMigrated": "This conversation was set to bypass permissions in 1.2, where this agent still asked anyway. From 1.3 Auto-approve all really auto-approves, so it was put back to Always Ask; switch it on in the permission menu below if you want it.",
"notice.effortNextTurn": "Reasoning effort saved — takes effect on the next turn",
"notice.effortResetOnModel": "This model does not support that effort level; reset to Default",
"turn.agentExit": "Agent process exited unexpectedly",
@@ -23,6 +23,7 @@ import { clearBinCache } from "../util/bin.js";
import { cachedDetect, cachedModels, clearProviderCache } from "../providers/infoCache.js";
import { launchFromSettings } from "../providers/launch.js";
import { clampMode } from "../providers/modes.js";
import { endLegacyDefault, guardLegacyMode, upgradeNotice } from "../migrate/autoApprove13.js";
import { setAppLocale, tr, intlLocale } from "../util/i18n.js";
import { MAX_MENTIONS } from "../util/mentions.js";
import { openExternal } from "../util/openExternal.js";
@@ -153,6 +154,8 @@ export function registerMethods(gw: Gateway, svc: Services): void {
if (!checked.ok) throw new ApiError("bad_params", `Invalid setting: ${checked.error}`);
const before = await svc.settings.get();
const next = await svc.settings.set(checked.patch as Partial<Settings>);
// 1.3: a default permission mode picked after the upgrade is the user's 1.3 choice (ends the 1.2 全部放行 guard)
if ("defaultMode" in checked.patch) await endLegacyDefault(svc.settings);
// 1.3: Settings → Bash path (Windows) re-runs Git Bash detection for the next agent start
if ("bashPath" in checked.patch && (before.bashPath ?? "") !== (next.bashPath ?? "")) {
await refreshAgentShell(typeof next.bashPath === "string" ? next.bashPath : "");
@@ -329,8 +332,11 @@ export function registerMethods(gw: Gateway, svc: Services): void {
}
// B8: the default permission mode is mapped onto this Agent's own modes (same rule as thread.setProvider)
const provider = getProvider(p.provider);
const mode = clampMode(provider?.capabilities.modes ?? [], p.mode);
// 1.3 (#727 review 3): a pre-1.3 default of 全部放行 stays 每次询问 for Agents it did nothing for in 1.2 (told once)
const guard = await guardLegacyMode(svc.settings, p.provider, clampMode(provider?.capabilities.modes ?? [], p.mode));
const mode = guard.mode;
const meta = await svc.threads.create({ ...p, mode });
if (guard.notice) await svc.threads.appendEvent(meta.id, upgradeNotice());
gw.publish("sidebar", { type: "thread.upsert", thread: meta });
return meta;
}