Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(approvals): a thread a bot opens from a chat takes that chat's level (#6846)

Milind Soni72abd6094513
diff --git a/docs/approval-levels.md b/docs/approval-levels.md
index 2da0e3a59e..33d37001c1 100644
--- a/docs/approval-levels.md
+++ b/docs/approval-levels.md
@@ -30,18 +30,53 @@ library. A level a person picks stays until someone changes it. On a hosted
company workspace the default stays Ask, because Full access there comes only
from the operator's dedicated policy.
-A thread a bot opens (its own `start_thread`, a hand-off, a burst, a routine
-run) starts at its bot's level. A level change the desktop is still confirming
-does not leak into it: a composer change belongs to that one conversation, and
-while a bot-wide change is unconfirmed the new thread follows the bot, so it
-gets the new level once confirmed and Ask if it rolls back.
+**A thread a bot opens from a conversation takes that conversation's level**
+when the conversation has one of its own that differs from the bot's: its own
+`start_thread` (with `report_back` too), a burst's parts, and a teammate's new
+thread or work thread opened by a hand-off (`coordinate_bots`, `start_thread`
+on a teammate). It works both ways: a chat set to Full access in its composer
+opens Full access threads even on a bot saved at Ask, and a chat at Ask opens
+Ask threads even on a bot at Full access, so nothing a bot opens runs above
+what the person chose in that chat. The level is saved on the new thread, which
+keeps it like any thread's own level; the bots' own defaults do not move.
+The resolver is `server/host/spawn-level.ts`.
+
+The floors stay:
+
+- **No level a person chose.** What a conversation without a level of its
+ own opens starts at the bot's level as before, and so does what a routine
+ run's conversation opens (it only copies its bot's level), a room job's
+ thread (a room keeps no level: room jobs open only from inside a room), a
+ consultation's thread (`consult: true` acts on nothing), and a thread an
+ external runtime's hand-off opens.
+- **Being confirmed.** A level change the desktop is still confirming never
+ travels: a composer change in progress leaves the new thread at its bot's
+ level, and while a bot-wide change is unconfirmed the new thread follows the
+ bot, so it gets the new level once confirmed and Ask if it rolls back.
+- **Engines.** The level is capped by the engine the new thread runs on, as
+ an engine switch would: Auto-accept edits opens a Codex thread at Ask.
+ Custom is never copied: a thread opened from a Custom chat starts at Ask,
+ unless it is the same bot, itself on Custom. A bot on Custom keeps Custom
+ in the threads opened on it, whatever the chat handing it work is set to.
+- **A turn held at Ask opens Ask threads.** A guest's turn on a Cloud, a Bot
+ API key's thread, a fenced proactive turn, or an engine that cannot run the
+ level opens its threads at Ask. A Bot API thread itself stays at Ask.
+- **No raise without the right to set it.** Only someone who may set a level
+ there can carry one above the bot's: on a Cloud only its owner, never work
+ from outside (a webhook, an app event), and on a hosted company workspace
+ only under the operator's Full access policy. Anyone else's chat still lowers
+ what it opens, never raises it.
+
+The guards Full access cannot skip (the [safety floor](verification/safety-floor.md),
+guarded sends, a Cloud guest's or webhook's confinement) apply in the new
+thread exactly as in any other.
| Level | Behavior |
| --- | --- |
| **Ask for approval** | Requests approval for commands and file changes, the way the provider's supervised mode does. |
| **Auto-accept edits** | Approves file edits automatically; other actions can still require approval. Offered where the provider has such a mode (Claude, Grok, Antigravity). |
| **Approve for me** | Uses the provider's automatic review on Codex, Claude, Cursor, and Grok to approve routine actions and ask about others. Providers without an equivalent fall back to asking. |
-| **Full access** | Enables the provider's permissive mode for commands, edits, and selected-computer actions, including potentially destructive or sensitive work. Residual native permission prompts are answered for you. OMB profile changes, routine actions, team setup, bot deletion, and enabled skill authoring apply without a second approval. Peer-review prompts are skipped within the bot's authorized scope. Sends through connected apps (email, messages, posts, payments) follow the bot's Sending on your behalf setting: Ask every time requires consent, and Send without asking, or no setting at all, sends with no daily limit. Apps outside the bot's connected-app scope are still refused. Work handed on with `coordinate_bots` uses the receiving bot's setting, never the sender's — except from a Chief of Staff, whose level flows down (below). Actual questions and missing credentials still need your input. |
+| **Full access** | Enables the provider's permissive mode for commands, edits, and selected-computer actions, including potentially destructive or sensitive work. Residual native permission prompts are answered for you. OMB profile changes, routine actions, team setup, bot deletion, and enabled skill authoring apply without a second approval. Peer-review prompts are skipped within the bot's authorized scope. Sends through connected apps (email, messages, posts, payments) follow the bot's Sending on your behalf setting: Ask every time requires consent, and Send without asking, or no setting at all, sends with no daily limit. Apps outside the bot's connected-app scope are still refused. Work handed on with `coordinate_bots` runs at the level of the receiving bot's thread: a new thread or work thread it opens takes the sending conversation's own level (above), and a Chief of Staff's level flows down (below). Actual questions and missing credentials still need your input. |
| **Custom (`config.toml`)** | Codex only. OpenMausBot reads and reapplies the effective approval and sandbox settings from your Codex configuration. |
Full access applies the moment you pick it: no confirmation dialog, no second
@@ -114,6 +149,15 @@ set a level on follows the default, and so does each of its threads without a
level of its own. Bots and threads that saved Ask before Full access became
the default keep it: choose Full access in the bot's settings, or **Set for
all bots in this team…**, to move a bot and every one of its threads at once.
+The one exception is a teammate's standing work thread (the "@Sender · work"
+thread every hand-off from one conversation reuses), which nobody chose a
+level for: once, on the first start of a build with this change, such a thread
+created before 2026-10-14 and still saved at Ask drops that saved level and
+follows its bot's from then on (`server/legacy-work-threads.ts`; a marker file
+in the data folder records that it ran). Conversations a person opened, new
+threads a hand-off opened, room jobs, and work threads made on or after that
+day keep their level, and a bot whose level change was still being confirmed
+at shutdown is left to that change's own recovery.
OpenMausBot adds no review card of its own at any level: a bot's profile,
working folder, model, skill, team setup and team memory changes apply at
once and leave a one-line receipt with Undo, so the bot continues in the same
@@ -186,13 +230,19 @@ nearest Chief conversation (`server/host/delegated-level.ts`). The level is
computed once when the assignment is written and recorded on it
(docs/runtime-contract.md §3); the turn runs with exactly that level.
-It only ever raises: a teammate already on a higher level keeps it, a teammate
-on Custom keeps its own configuration, and a Chief handing work out from an
-Ask conversation passes nothing on. Every engine runs Full access, so only
+The flow-down only ever raises: a thread already on a higher level keeps it, a
+teammate on Custom keeps its own configuration, and a Chief handing work out
+from an Ask conversation passes nothing on this way. A new thread the hand-off
+opens is different: it starts at the Chief conversation's own level, like a
+thread any conversation opens (above), so a Chief chat on Approve for me opens
+a teammate's new thread at Approve for me even when that teammate is saved at
+Full access, and one on Ask opens it at Ask. Every engine runs Full access, so only
Auto-accept edits can be capped: a teammate on an engine without it (Codex,
whose Ask already writes the workspace) stays on its own level. The teammate's
-own default and its other conversations do not change, and an ordinary bot's
-hand-off, with no Chief up its chain, still uses the recipient's setting. A consultation (`consult: true`)
+own default and its other conversations do not change. An ordinary bot's
+hand-off, with no Chief up its chain, uses the level of the recipient's thread:
+the sending conversation's own when the hand-off opens that thread (above), and
+the thread's own when it reuses one. A consultation (`consult: true`)
answers from what the teammate knows and acts on nothing, so no level travels
with it. Questions and missing credentials still reach you.
diff --git a/docs/runtime-contract.md b/docs/runtime-contract.md
index 02a33db121..82d6d6b3f8 100644
--- a/docs/runtime-contract.md
+++ b/docs/runtime-contract.md
@@ -52,7 +52,7 @@ queued ──admit──> running ──turn ends──> completed | failed | ca
`level = max(own, inherited)` in the order `ask < edits < auto < full`. `custom` never travels.
-`inherited` is the Chief conversation's level only when the origin is `person` or `routine` **and** the requester is a Chief, or a Chief is an ancestor in the same root. Outside lineage inherits nothing: a thread a hand-off opens keeps its own level, and no level lands on it (`server/host/delegated-level.ts` asks `handsNoLevel`, the conversation's own record, so this holds after the run ends and after a restart).
+`inherited` is the Chief conversation's level only when the origin is `person` or `routine` **and** the requester is a Chief, or a Chief is an ancestor in the same root. Outside lineage inherits nothing: a thread a hand-off opens keeps the level it was opened at (the sending conversation's own, `server/host/spawn-level.ts`, never raised from outside lineage), and no level lands on it (`server/host/delegated-level.ts` asks `handsNoLevel`, the conversation's own record, so this holds after the run ends and after a restart).
The inherited level is capped by what the assignee's engine really does (`shared/approval-mode.ts`): `full` passes on every engine (`supportsApprovalMode(kind, "full")` is always true, Full being the default level); `auto` only if `hasNativeAutoReview(kind)`, otherwise `edits` if supported, otherwise `own`. `levelSource` says which rule won. The permission mode a turn runs with must equal the level on its record (invariant I6).
diff --git a/server/auto-approve.ts b/server/auto-approve.ts
index 494979c845..a03773a24f 100644
--- a/server/auto-approve.ts
+++ b/server/auto-approve.ts
@@ -26,8 +26,9 @@ export async function deliverFullAccessApproval(
}
}
-/** Full access is the person's grant to this receiving bot: never inherited from a sender (delegatedApprovalMode aside), and
- * peer-started Custom turns run as Auto. */
+/** Full access is the person's grant to this receiving bot: a turn never inherits it from a sender (delegatedApprovalMode
+ * aside; a thread a hand-off opens is saved at the sending conversation's own level, spawn-level.ts), and peer-started
+ * Custom turns run as Auto. */
export function approvalModeForOrigin(mode: ApprovalMode, origin: { peerInitiated: boolean }): ApprovalMode {
if (mode === "custom" && origin.peerInitiated) return "auto";
return mode;
diff --git a/server/bot-api.e2e.test.ts b/server/bot-api.e2e.test.ts
index 7e76025637..5790ecd627 100644
--- a/server/bot-api.e2e.test.ts
+++ b/server/bot-api.e2e.test.ts
@@ -68,7 +68,8 @@ it("answers the card's own curl with the bot's reply, and refuses a wrong key, a
// The app shows the thread as the API's, with what the caller asked and what the bot said.
const bots = (await api("GET", "/api/bots")).bots as any[];
const task = bots.find((candidate) => candidate.id === bot.id).tasks.find((candidate: any) => candidate.threadId === answered.thread);
- expect(task).toMatchObject({ botApi: true, title: "Hello! What can you do?" });
+ // At Ask, though the bot is at the default Full access: an API thread never takes a level from anywhere.
+ expect(task).toMatchObject({ botApi: true, title: "Hello! What can you do?", approvalMode: "ask" });
const lines = (await api("GET", `/api/threads/${answered.thread}/messages`)).messages as any[];
expect(lines.find((line) => line.role === "user")).toMatchObject({ text: "Hello! What can you do?", via: "api" });
expect(lines.filter((line) => line.role === "bot" && line.kind === "text").map((line) => line.text)).toEqual(["hello from fake claude"]);
diff --git a/server/chief-level-every-hop.e2e.test.ts b/server/chief-level-every-hop.e2e.test.ts
index 9bd4477cd1..14e300d674 100644
--- a/server/chief-level-every-hop.e2e.test.ts
+++ b/server/chief-level-every-hop.e2e.test.ts
@@ -7,7 +7,7 @@ import { handleToolCall, request } from "../scripts/mcp-server.ts";
// A Chief's level reached the teammate it handed work to and stopped there: Clive on Approve for me, Ada ran at auto,
// and the work Ada handed Bea ran at Ask ("default").
-it("carries a Chief's level down every hop it hands out, in threads and in a room, and never an ordinary bot's", async () => {
+it("carries a Chief's level down every hop it hands out, in threads and in a room; an ordinary bot's only opens a thread at its conversation's level", async () => {
const fixture = await launchVerificationServer({}, undefined, undefined, undefined, undefined, { scripted: true });
const { url, dataDir, logPath } = fixture.info;
const planPath = join(dataDir, "room-plan.json");
@@ -69,7 +69,8 @@ it("carries a Chief's level down every hop it hands out, in threads and in a roo
expect(await chips(adaTurn.threadId)).toEqual(["Approve for me — handed on by Clive, a Chief of Staff on Approve for me"]);
expect(await chips(beaTurn.threadId)).toEqual(["Approve for me — handed on by Ada, from Clive, a Chief of Staff on Approve for me"]);
- // Ola's own Approve for me came from the person, not a Chief: the work she hands Bea stays on Bea's level.
+ // Ola's own Approve for me came from the person, not a Chief: no Chief's level comes down with it, but the work thread it
+ // opens on Bea takes the level of Ola's conversation, as any thread a conversation opens does (spawn-level.ts).
plan(ola.id,
{ steps: [coordinate(bea.id, "ordinary-bea", "Run the check and report the result.")], reply: "Handed to Bea." },
{ reply: "Bea ran the check." });
@@ -79,7 +80,7 @@ it("carries a Chief's level down every hop it hands out, in threads and in a roo
expect((await cli("wait", "--bot", ola.id, "--task", ola.activeTaskId, "--timeout", "25")).status).toBe("settled");
const ordinaryTurn = turnOf(bea.id, 1);
expect(ordinaryTurn.threadId).not.toBe(beaTurn.threadId);
- expect(ordinaryTurn.permissionMode).toBe("default");
+ expect(ordinaryTurn.permissionMode).toBe("auto");
expect(await chips(ordinaryTurn.threadId)).toEqual([]);
// The same chain inside a room. The room thread is shared, so nothing is patched onto it: each turn's level rides
diff --git a/server/cloud-lending-memory.e2e.test.ts b/server/cloud-lending-memory.e2e.test.ts
index b3fd650d65..511308d5da 100644
--- a/server/cloud-lending-memory.e2e.test.ts
+++ b/server/cloud-lending-memory.e2e.test.ts
@@ -560,6 +560,30 @@ it("a turn that may use the Mac finds only the owner's own conversations with th
expect(threads).not.toContain("Guest kumquat notes");
}, 60_000);
+it("a thread opened from a conversation a guest left behind starts at Ask, whatever that chat and its bot are set to; the owner's own chat raises", async () => {
+ const bot = await newBot("Opens threads", "held");
+ const guests = await guestThread(bot, "Guest's job");
+ const mine = await newThread(bot);
+ // The owner put both conversations on Full access in their composers.
+ for (const thread of [guests, mine]) {
+ const set = await api("PATCH", `/api/bots/${bot.id}/tasks/${thread}`, { token: owner, body: { approvalMode: "full" } });
+ expect(set.status, JSON.stringify(set.body)).toBe(200);
+ }
+ const opened = async (from: string, title: string) => {
+ const tools = await toolsFor(() => say(owner, bot, "Open a job for this.", from));
+ expect((await tools("start_thread", { title, message: "Do the job." })).isError).toBeFalsy();
+ await stopRunningTurns();
+ const tasks = (await api("GET", "/api/bots", { token: owner })).body.bots.find((candidate: any) => candidate.id === bot.id).tasks as any[];
+ return tasks.find((task) => task.title === title)?.approvalMode;
+ };
+ // The bot is at Full access too, yet a turn there runs at Ask, and so does what it opens.
+ expect(await opened(guests, "Guest's, bot at Full")).toBe("ask");
+ // Saved at Ask, the bot's threads open at the level of the owner's chat, never of the guest's.
+ expect((await api("PATCH", `/api/bots/${bot.id}`, { token: owner, body: { approvalMode: "ask" } })).status).toBe(200);
+ expect(await opened(guests, "Guest's, bot at Ask")).toBe("ask");
+ expect(await opened(mine, "Mine, bot at Ask")).toBe("full");
+}, 120_000);
+
it("only the owner changes how a bot asks for approval in a conversation a guest left behind, not a process on the Cloud", async () => {
const bot = await newBot("Approvals", "held");
const guests = await guestThread(bot);
@@ -1103,7 +1127,7 @@ it("an answer from a turn that can't use the Mac ends it for parked handed-on wo
expect((await parkedThenAnswered(sender, receiver, () => toolsFor(() => say(owner, locked, "Go.", locked.threadId)))).computers).toHaveLength(0);
await stopRunningTurns(true);
}, 90_000);
-it("a conversation set to Ask on a Full bot can't hand the Mac to a Full teammate; the same bot on Full can", async () => {
+it("a conversation set to Ask on a Full bot never hands the Mac to work running above Ask; the same bot on Full can", async () => {
const sender = await newBot("Thread at Ask", "held");
const receiver = await newBot("Stays at Full", "held");
await review(receiver);
@@ -1114,10 +1138,20 @@ it("a conversation set to Ask on a Full bot can't hand the Mac to a Full teammat
const mine = await newThread(sender);
const set = await api("PATCH", `/api/bots/${sender.id}/tasks/${mine}`, { token: owner, body: { approvalMode: "ask" } });
expect(set.status, JSON.stringify(set.body)).toBe(200);
+ // The work thread it opens on the Full teammate takes the conversation's Ask, so that work runs at Ask, Mac and all.
const atAsk = await handedThread({ id: sender.id, threadId: mine }, receiver);
- expect((await sees(atAsk.tools)).computers).toHaveLength(0);
+ const levelOf = async (threadId: string) => ((await api("GET", "/api/bots", { token: owner })).body.bots.find((bot: any) => bot.id === receiver.id)
+ .tasks as any[]).find((task) => task.threadId === threadId)?.approvalMode;
+ expect(await levelOf(atAsk.thread)).toBe("ask");
+ expect((await sees(atAsk.tools)).computers).toHaveLength(1);
await stopRunningTurns();
-}, 90_000);
+ // Raised to Full access, that thread runs above the conversation handing it more work: the Mac stays out of reach.
+ expect((await api("PATCH", `/api/bots/${receiver.id}/tasks/${atAsk.thread}`, { token: owner, body: { approvalMode: "full" } })).status).toBe(200);
+ const above = await handedThread({ id: sender.id, threadId: mine }, receiver);
+ expect(above.thread).toBe(atAsk.thread);
+ expect((await sees(above.tools)).computers).toHaveLength(0);
+ await stopRunningTurns();
+}, 120_000);
it("work handed on with nothing coming back doesn't keep the Mac, since Stop on the sender doesn't reach it", async () => {
const sender = await newBot("Notifies", "held");
const receiver = await newBot("Gets a notice", "held");
diff --git a/server/coordinator.ts b/server/coordinator.ts
index c0d4fc0175..b9d6bc593d 100644
--- a/server/coordinator.ts
+++ b/server/coordinator.ts
@@ -4,6 +4,7 @@ import type { LegacyThreadResolver } from "./runtime/import-legacy.ts";
import type { Answerer, Assignment, EnvelopeNames, Level, Limits, Mode, Origin, Outcome, Owner, Reply, Requester, StatusView, TurnEvidence } from "./runtime/types.ts";
import type { ModelSelection } from "../shared/wire.ts";
import type { PassedFile } from "./host/handoff-files.ts";
+import type { NewThreadLevel } from "./task-record.ts";
/** One coordinate_bots call, as the internal route hands it to the server. */
export type CoordinateBotsCall = {
@@ -26,7 +27,7 @@ export type CoordinateBotsCall = {
/** Files that travel with the work, already in the attachment store (server/host/handoff-files.ts). */
files?: readonly PassedFile[];
/** start_thread's report_back: the one target is the sender's own new thread, run on this model. */
- ownThread?: { modelSelection?: ModelSelection; approvalMode?: "ask" };
+ ownThread?: { modelSelection?: ModelSelection; approvalMode?: NewThreadLevel };
/** post_to_thread: one message into this existing thread; wake starts a run there, else it waits for the next one. */
post?: { deliveryId: string; wake: boolean };
};
diff --git a/server/host/burst-host.ts b/server/host/burst-host.ts
index 9e39013615..037268cf4e 100644
--- a/server/host/burst-host.ts
+++ b/server/host/burst-host.ts
@@ -15,6 +15,7 @@ import type { HostTurnResult } from "../coordinator.ts";
import type { WorkOrigin } from "../peer-provenance.ts";
import { serverLine, type ServerLineKey } from "../server-lines.ts";
import type { BotRecord, Message, Store } from "../store.ts";
+import type { NewThreadLevel } from "../task-record.ts";
const INBOX_TEXT_MAX = 2_000;
const CARD_LINE: Record<BurstPhase, ServerLineKey> = {
@@ -52,7 +53,8 @@ export interface BurstHostDeps {
opened(threadId: string, parentThreadId: string): void;
/** Whom this request came from, in the record's words, for what a turn may reach. */
origin(burst: BurstRecord): WorkOrigin;
- approval(bot: BotRecord, selection: ModelSelection): "ask" | undefined;
+ /** The level a child opened from `fromThreadId` on `selection` starts at (spawn-level.ts). */
+ approval(bot: BotRecord, selection: ModelSelection, fromThreadId: string): NewThreadLevel | undefined;
/** The model a burst defaults to: the bot's own engine's fast model, or the model of the chat that asked. */
defaultModel(bot: BotRecord, threadId: string): ModelSelection;
modelName(selection: ModelSelection): string;
@@ -81,7 +83,7 @@ export function createBurstHost(deps: BurstHostDeps): BurstManager & { model(bot
const bot = store.bot(burst.botId);
if (!bot) return null;
const task = store.createTask(bot.id, child.title, false, undefined,
- { botId: bot.id, name: bot.name, threadId: burst.threadId, burstId: burst.id, at: Date.now() }, deps.approval(bot, burst.model), burst.model);
+ { botId: bot.id, name: bot.name, threadId: burst.threadId, burstId: burst.id, at: Date.now() }, deps.approval(bot, burst.model, burst.threadId), burst.model);
if (!task) return null;
deps.opened(task.threadId, burst.threadId);
return task.threadId;
diff --git a/server/host/delegated-level.test.ts b/server/host/delegated-level.test.ts
index c640e35378..8e705f31f8 100644
--- a/server/host/delegated-level.test.ts
+++ b/server/host/delegated-level.test.ts
@@ -5,7 +5,8 @@ import type { BotRecord } from "../store.ts";
import { createDelegatedLevel, type DelegatedLevelDeps, type Hop } from "./delegated-level.ts";
// Clive (a Chief) handed work to Ada, and Ada's turn hands work on: the chain is the hand-off nodes' parents.
-function world(levels: Record<string, ApprovalMode>, nodes: Record<string, Hop>, guest = new Set<string>(), outside = new Set<string>()) {
+function world(levels: Record<string, ApprovalMode>, nodes: Record<string, Hop>, guest = new Set<string>(), outside = new Set<string>(),
+ saved: Record<string, ApprovalMode> = {}) {
const bots: Record<string, Partial<BotRecord>> = {
clive: { id: "clive", name: "Clive", chiefOfStaff: true }, ada: { id: "ada", name: "Ada" }, bea: { id: "bea", name: "Bea" }, ola: { id: "ola", name: "Ola" },
};
@@ -14,7 +15,7 @@ function world(levels: Record<string, ApprovalMode>, nodes: Record<string, Hop>,
const store = {
bot: (id: string) => bots[id],
projectBotForTask: () => undefined,
- taskByThread: () => undefined,
+ taskByThread: (_botId: string, threadId: string) => saved[threadId] ? { approvalMode: saved[threadId] } : undefined,
patchTask: (botId: string, threadId: string, patch: { approvalMode?: ApprovalMode }) => { patched.push({ botId, threadId, ...patch }); },
appendMessage: (_threadId: string, message: { tool?: { name: string } }) => { lines.push(message.tool!.name); },
} as unknown as DelegatedLevelDeps["store"];
@@ -77,6 +78,19 @@ describe("a Chief's level, every hop down", () => {
]);
});
+ it("raises a thread a hand-off just opened from its bot's own level, announces it, and never lowers what it opened at", () => {
+ // Ada is saved at Ask; each new thread already took the level of the conversation that opened it (spawn-level.ts).
+ const opened = (at: ApprovalMode) => {
+ const w = world({ "clive:clive-chat": "auto" }, chain, new Set(), new Set(), { "ada-new": at });
+ w.apply(w.bot("clive"), "clive-chat", "root", w.bot("ada"), "ada-new", true);
+ return { patched: w.patched.map((patch) => patch.approvalMode), lines: w.lines };
+ };
+ const said = ["Approve for me — handed on by Clive, a Chief of Staff on Approve for me"];
+ expect(opened("auto")).toEqual({ patched: ["auto"], lines: said });
+ expect(opened("edits")).toEqual({ patched: ["auto"], lines: said });
+ expect(opened("full")).toEqual({ patched: [], lines: [] });
+ });
+
it("brings nothing down from work that came in from outside: the teammate keeps its own level", () => {
const w = world({ "clive:clive-chat": "full" }, chain, new Set(), new Set(["clive-chat"]));
w.apply(w.bot("clive"), "clive-chat", "root", w.bot("ada"), "ada-work");
diff --git a/server/host/delegated-level.ts b/server/host/delegated-level.ts
index 3667108ff4..6d0e0c07f8 100644
--- a/server/host/delegated-level.ts
+++ b/server/host/delegated-level.ts
@@ -1,6 +1,6 @@
// A Chief of Staff's level flows down every hop of the work it hands out, a teammate's teammate too, in threads and in
// rooms alike: each hand-off resolves the nearest Chief conversation up its chain (docs/approval-levels.md).
-import type { ApprovalMode } from "../../shared/approval-mode.ts";
+import { approvalModeWidens, type ApprovalMode } from "../../shared/approval-mode.ts";
import { delegatedApprovalMode } from "../auto-approve.ts";
import { chiefLevel } from "../chief-level.ts";
import type { HandoffView, RoomAddress } from "../coordinator.ts";
@@ -52,12 +52,15 @@ export function createDelegatedLevel(deps: DelegatedLevelDeps) {
return level ? { level, chief: above.chief, chiefMode } : null;
}
- /** The teammate's thread switches to the level the work came down with, keeps it, and says so once. */
- function apply(from: BotRecord, fromThreadId: string, fromNodeId: string | undefined, target: BotRecord, threadId: string): void {
+ /** The teammate's thread switches to the level the work came down with, keeps it, and says so once. A thread this hand-off
+ * just `opened` already took the sending conversation's level (spawn-level.ts): the Chief's is measured against the
+ * teammate's own, replaces it unless that is higher, and says so. */
+ function apply(from: BotRecord, fromThreadId: string, fromNodeId: string | undefined, target: BotRecord, threadId: string, opened = false): void {
const parentId = fromNodeId ? deps.node(fromNodeId)?.parentId : undefined;
- const own = deps.turnLevel(store.projectBotForTask(target.id, threadId) ?? target, false, threadId);
+ const own = deps.turnLevel(opened ? target : store.projectBotForTask(target.id, threadId) ?? target, false, threadId);
const passed = handedDown({ botId: from.id, threadId: fromThreadId, ...(parentId ? { parentId } : {}) }, target, own);
- if (!passed || store.taskByThread(target.id, threadId)?.approvalMode === passed.level) return;
+ const saved = store.taskByThread(target.id, threadId)?.approvalMode;
+ if (!passed || (opened ? approvalModeWidens(passed.level, saved ?? own) : saved === passed.level)) return;
store.patchTask(target.id, threadId, { approvalMode: passed.level, autoApprove: false, alwaysAllow: [] });
const name = NAMES[passed.level] ?? passed.level;
const via = passed.chief.id === from.id ? "" : `from ${passed.chief.name}, `;
diff --git a/server/host/own-threads.ts b/server/host/own-threads.ts
index 5bc7853b64..ae8b2516c4 100644
--- a/server/host/own-threads.ts
+++ b/server/host/own-threads.ts
@@ -1,19 +1,17 @@
// A bot's own threads: list_models, start_thread and the thread's turn start share one check, so a model the list offers
// always opens, and a second opinion never quietly comes from the opener's own model.
-import { approvalModeFor, modelSwitchNeedsAsk } from "../../shared/approval-mode.ts";
import type { ModelSelection } from "../../shared/wire.ts";
import { modelMenu, type MenuEngine, type ModelMenu } from "../routes/internal-models.ts";
import type { BotRecord, Store } from "../store.ts";
+import type { NewThreadLevel } from "../task-record.ts";
import type { ThreadModelFallback } from "../thread-model.ts";
-
-/** The level a new thread of the bot's starts at (task-record.ts), never a pending grant's Ask mask. */
-const savedLevel = (bot: BotRecord) => approvalModeFor({ ...bot, approvalGrant: undefined });
+import { createSpawnLevel, type SpawnLevelDeps } from "./spawn-level.ts";
type Placed = { botId: string; threadId: string; groupId?: string };
type Node = Omit<Placed, "threadId"> & { parentId?: string };
-export function createOwnThreads(deps: {
- store: Pick<Store, "bot" | "taskByThread">;
+export function createOwnThreads(deps: Pick<SpawnLevelDeps, "sourceLevel" | "mayRaise"> & {
+ store: Pick<Store, "bot" | "taskByThread" | "projectBotForTask">;
registry: { instances(): readonly MenuEngine[]; cliTarget(instanceId: string): { driverKind: string } | null | undefined };
node(id: string): Node | undefined;
current(botId: string, threadId: string): ModelSelection | undefined;
@@ -24,6 +22,8 @@ export function createOwnThreads(deps: {
modelName(selection: ModelSelection): string;
}) {
const { store } = deps;
+ /** The level a new thread opened from a conversation starts at (spawn-level.ts). */
+ const levelFor = createSpawnLevel({ ...deps, driverKind: (instanceId) => deps.registry.cliTarget(instanceId)?.driverKind });
const own = (requester: Omit<Placed, "threadId">, child: Omit<Placed, "threadId">) =>
requester.botId === child.botId && !requester.groupId && !child.groupId;
const cannotRun = (selection: ModelSelection, bot: BotRecord): string | null => {
@@ -51,18 +51,18 @@ export function createOwnThreads(deps: {
const requester = asked?.parentId === undefined ? undefined : deps.node(asked.parentId);
return Boolean(asked && requester && requester.botId === botId && own(requester, asked));
},
- /** "ask" when running on `selection` crosses to an engine where this bot's permission level does not carry over. */
- approvalFor(bot: BotRecord, selection: ModelSelection): "ask" | undefined {
- return modelSwitchNeedsAsk(savedLevel(bot), deps.registry.cliTarget(bot.modelSelection.instanceId)?.driverKind, deps.registry.cliTarget(selection.instanceId)?.driverKind) ? "ask" : undefined;
+ levelFor,
+ /** A burst child's level: the conversation it was opened from, on `selection`; "ask" where that level does not carry over. */
+ approvalFor(bot: BotRecord, selection: ModelSelection, fromThreadId?: string): NewThreadLevel | undefined {
+ return levelFor(bot, selection, fromThreadId === undefined ? undefined : { botId: bot.id, threadId: fromThreadId });
},
- inherited(botId: string, parentThreadId: string): { modelSelection?: ModelSelection; approvalMode?: "ask" } {
+ /** A thread the bot opens on itself from `parentThreadId`: on `picked`, else that conversation's model, at its level. */
+ inherited(botId: string, parentThreadId: string, picked?: ModelSelection): { modelSelection?: ModelSelection; approvalMode?: NewThreadLevel } {
const bot = store.bot(botId);
- const modelSelection = bot && store.taskByThread(bot.id, parentThreadId)?.modelSelection;
- if (!bot || !modelSelection) return {};
- const needsAsk = modelSwitchNeedsAsk(savedLevel(bot),
- deps.registry.cliTarget(bot.modelSelection.instanceId)?.driverKind,
- deps.registry.cliTarget(modelSelection.instanceId)?.driverKind);
- return { modelSelection, ...(needsAsk ? { approvalMode: "ask" as const } : {}) };
+ if (!bot) return {};
+ const modelSelection = picked ?? store.taskByThread(bot.id, parentThreadId)?.modelSelection;
+ const approvalMode = levelFor(bot, modelSelection, { botId, threadId: parentThreadId });
+ return { ...(modelSelection ? { modelSelection } : {}), ...(approvalMode ? { approvalMode } : {}) };
},
name(requester: Omit<Placed, "threadId">, child: Placed): string | undefined {
return own(requester, child) ? `#${store.taskByThread(child.botId, child.threadId)?.title ?? "Thread"}` : undefined;
diff --git a/server/host/spawn-level.test.ts b/server/host/spawn-level.test.ts
new file mode 100644
index 0000000000..4d6d18cac4
--- /dev/null
+++ b/server/host/spawn-level.test.ts
@@ -0,0 +1,194 @@
+import { rmSync } from "node:fs";
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { approvalModeFor, type ApprovalMode } from "../../shared/approval-mode.ts";
+import { DATA_DIR } from "../config.ts";
+import type { ModelSelection } from "../contracts.ts";
+import { Store, type BotRecord } from "../store.ts";
+import { createOwnThreads } from "./own-threads.ts";
+
+const claude = (): ModelSelection => ({ instanceId: "claude", model: "claude-sonnet-5" });
+const codex: ModelSelection = { instanceId: "codex", model: "gpt-5" };
+const drivers: Record<string, string> = { claude: "claudeAgent", codex: "codex" };
+const REQUEST = "123e4567-e89b-42d3-a456-426614174000";
+
+/** The host's wiring (index.ts): a turn's level has its floors applied, and only the owner may raise one. */
+function host(options: { floored?: Set<string>; owner?: boolean } = {}) {
+ const store = new Store(claude);
+ const own = createOwnThreads({
+ store, registry: { instances: () => [], cliTarget: (id) => ({ driverKind: drivers[id]! }) }, node: () => undefined,
+ current: () => undefined, proposalRefusal: () => null, givesWay: () => null, modelName: (one) => one.model,
+ // sourceApprovalMode: a guest's or a fenced turn (`floored`) and a Bot API thread run at Ask, whatever the thread says.
+ sourceLevel: (botId, threadId) => options.floored?.has(threadId) || store.taskByThread(botId, threadId)?.botApi
+ ? "ask" : approvalModeFor(store.projectBotForTask(botId, threadId)!),
+ mayRaise: () => options.owner ?? true,
+ });
+ return { store, own };
+}
+
+type Host = ReturnType<typeof host>;
+const levelOf = (store: Store, botId: string, threadId: string) => approvalModeFor(store.projectBotForTask(botId, threadId)!);
+
+function botAt(store: Store, mode: ApprovalMode, name = "Opener"): BotRecord {
+ const bot = store.createBot();
+ store.patchBot(bot.id, { name, approvalMode: mode, autoApprove: mode === "auto", alwaysAllow: ["mcp__docs__read"] });
+ return store.bot(bot.id)!;
+}
+
+/** A conversation of the bot's with its own level, picked in its composer. */
+function chatAt(store: Store, bot: BotRecord, mode: ApprovalMode): string {
+ const chat = store.createTask(bot.id, "Chat", false)!.threadId;
+ store.patchTask(bot.id, chat, { approvalMode: mode, autoApprove: mode === "auto" });
+ return chat;
+}
+
+/** Every thread the bot opens from `chat`, the way index.ts and burst-host.ts open them. */
+function spawnAll({ store, own }: Host, opener: BotRecord, chat: string, teammate: BotRecord) {
+ const at = Date.now();
+ const inherited = own.inherited(opener.id, chat);
+ const startThread = store.createTask(opener.id, "Research", false, undefined, { botId: opener.id, name: opener.name, at }, inherited.approvalMode, inherited.modelSelection)!;
+ const reportBack = own.inherited(opener.id, chat);
+ const reported = store.createTask(opener.id, "Report back", false, undefined, { botId: opener.id, name: opener.name, threadId: chat, at }, reportBack.approvalMode, reportBack.modelSelection)!;
+ const burstChild = store.createTask(opener.id, "Part 1", false, undefined, { botId: opener.id, name: opener.name, threadId: chat, burstId: "b1", at },
+ own.approvalFor(store.bot(opener.id)!, claude(), chat), claude())!;
+ const handedNew = store.createTask(teammate.id, "Handed on", false, undefined, { botId: opener.id, name: opener.name, threadId: chat, at },
+ own.levelFor(store.bot(teammate.id)!, undefined, { botId: opener.id, threadId: chat }))!;
+ const handedWork = store.createTask(teammate.id, `@${opener.name} · work`, false, undefined, { botId: opener.id, name: opener.name, threadId: chat, kind: "work", at },
+ own.levelFor(store.bot(teammate.id)!, undefined, { botId: opener.id, threadId: chat }))!;
+ return {
+ own: [startThread, reported, burstChild].map((task) => levelOf(store, opener.id, task.threadId)),
+ teammate: [handedNew, handedWork].map((task) => levelOf(store, teammate.id, task.threadId)),
+ threads: { startThread, handedNew },
+ };
+}
+
+describe("a thread a bot opens from a conversation takes that conversation's level", () => {
+ beforeEach(() => {
+ rmSync(DATA_DIR, { recursive: true, force: true });
+ });
+
+ it("opens Full access threads from a chat at Full access, though the bot and its teammate are saved at Ask", () => {
+ const h = host();
+ const opener = botAt(h.store, "ask");
+ const teammate = botAt(h.store, "ask", "Helper");
+ const chat = chatAt(h.store, opener, "full");
+
+ const spawned = spawnAll(h, opener, chat, teammate);
+
+ expect(spawned.own).toEqual(["full", "full", "full"]);
+ expect(spawned.teammate).toEqual(["full", "full"]);
+ // Saved on the thread, so it outlives a restart, and the teammate's own default does not move.
+ expect(levelOf(new Store(claude), teammate.id, spawned.threads.handedNew.threadId)).toBe("full");
+ expect(approvalModeFor(h.store.bot(teammate.id)!)).toBe("ask");
+ expect(approvalModeFor(h.store.bot(opener.id)!)).toBe("ask");
+ });
+
+ it("opens Ask threads from a chat at Ask, though the bot and its teammate are at Full access, keeping each bot's own grants", () => {
+ const h = host();
+ const opener = botAt(h.store, "full");
+ const teammate = botAt(h.store, "full", "Helper");
+ const chat = chatAt(h.store, opener, "ask");
+
+ const spawned = spawnAll(h, opener, chat, teammate);
+
+ expect(spawned.own).toEqual(["ask", "ask", "ask"]);
+ expect(spawned.teammate).toEqual(["ask", "ask"]);
+ expect(h.store.taskByThread(teammate.id, spawned.threads.handedNew.threadId)).toMatchObject({ approvalMode: "ask", autoApprove: false, alwaysAllow: ["mcp__docs__read"] });
+ });
+
+ it("carries Approve for me and Auto-accept edits, and caps a level at what the thread's engine runs", () => {
+ const h = host();
+ const opener = botAt(h.store, "ask");
+ const onCodex = h.store.createBot();
+ h.store.patchBot(onCodex.id, { name: "Coder", modelSelection: codex, approvalMode: "full" });
+ const auto = chatAt(h.store, opener, "auto");
+ expect(h.store.taskByThread(opener.id, h.store.createTask(opener.id, "Auto", false, undefined, undefined, h.own.inherited(opener.id, auto).approvalMode)!.threadId))
+ .toMatchObject({ approvalMode: "auto", autoApprove: true });
+
+ // Auto-accept edits does not exist on Codex: the teammate's new thread there starts at Ask, as an engine switch would.
+ const edits = chatAt(h.store, opener, "edits");
+ expect(h.own.levelFor(h.store.bot(onCodex.id)!, undefined, { botId: opener.id, threadId: edits })).toBe("ask");
+ expect(h.own.approvalFor(h.store.bot(opener.id)!, codex, edits)).toBe("ask");
+ expect(h.own.approvalFor(h.store.bot(opener.id)!, claude(), edits)).toEqual({ from: "edits" });
+ });
+
+ it("keeps the bot's level when the chat has none of its own, the same, a routine run's, or one still being confirmed", () => {
+ const h = host();
+ const opener = botAt(h.store, "ask");
+ const teammate = botAt(h.store, "edits", "Helper");
+ const chat = h.store.createTask(opener.id, "No level", false)!.threadId;
+ const record = h.store.taskByThread(opener.id, chat)!;
+ delete record.approvalMode;
+ delete record.autoApprove;
+ const from = { botId: opener.id, threadId: chat };
+ expect(h.own.levelFor(h.store.bot(teammate.id)!, undefined, from)).toBeUndefined();
+ expect(h.own.inherited(opener.id, chat)).toEqual({});
+
+ const same = chatAt(h.store, opener, "ask");
+ expect(h.own.inherited(opener.id, same)).toEqual({});
+
+ // A routine run's conversation saves its bot's level when the run opens it: nobody chose it there.
+ const run = chatAt(h.store, opener, "full");
+ h.store.patchTask(opener.id, run, { routineRunId: "run-1" });
+ expect(h.own.levelFor(h.store.bot(teammate.id)!, undefined, { botId: opener.id, threadId: run })).toBeUndefined();
+
+ // The person picks Full access in that chat; the desktop is still confirming it: no Ask mask, no unconfirmed Full.
+ const confirming = chatAt(h.store, opener, "full");
+ h.store.patchBot(opener.id, { approvalGrant: { requestId: REQUEST, mode: "full", phase: "prepared", threadId: confirming, threadOnly: true } });
+ expect(h.own.levelFor(h.store.bot(teammate.id)!, undefined, { botId: opener.id, threadId: confirming })).toBeUndefined();
+ });
+
+ it("never copies Custom, and never replaces it: a Custom chat opens Ask threads, a Custom bot's threads keep Custom", () => {
+ const h = host();
+ const opener = h.store.createBot();
+ h.store.patchBot(opener.id, { name: "Codex bot", modelSelection: codex, approvalMode: "full" });
+ const custom = chatAt(h.store, h.store.bot(opener.id)!, "custom");
+ expect(h.own.inherited(opener.id, custom).approvalMode).toEqual({ from: "ask" });
+ h.store.patchBot(opener.id, { approvalMode: "custom" });
+ expect(h.own.inherited(opener.id, custom).approvalMode).toBeUndefined();
+
+ // A teammate on Custom keeps its own configuration whatever the chat handing it work is set to.
+ const sender = botAt(h.store, "ask", "Sender");
+ for (const mode of ["full", "auto", "ask"] as const) {
+ expect(h.own.levelFor(h.store.bot(opener.id)!, undefined, { botId: sender.id, threadId: chatAt(h.store, sender, mode) })).toBeUndefined();
+ }
+ });
+
+ it("lets no guest or non-owner raise a level: a guest-driven chat opens Ask threads, and anyone else's at most the bot's", () => {
+ const floored = new Set<string>();
+ const guest = host({ floored, owner: false });
+ const opener = botAt(guest.store, "full");
+ const teammate = botAt(guest.store, "full", "Helper");
+ const chat = chatAt(guest.store, opener, "full");
+ // A guest drives this chat: its turn runs at Ask whatever the chat says, and so does everything it opens.
+ floored.add(chat);
+ const spawned = spawnAll(guest, opener, chat, teammate);
+ expect(spawned.own).toEqual(["ask", "ask", "ask"]);
+ expect(spawned.teammate).toEqual(["ask", "ask"]);
+ expect(guest.store.taskByThread(opener.id, spawned.threads.startThread.threadId)?.alwaysAllow).toEqual([]);
+
+ // Someone who may not set a level (a member, work from outside): a Full chat does not lift a bot saved at Ask...
+ const member = host({ owner: false });
+ const askBot = botAt(member.store, "ask");
+ const askMate = botAt(member.store, "ask", "Helper");
+ expect(spawnAll(member, askBot, chatAt(member.store, askBot, "full"), askMate)).toMatchObject({ own: ["ask", "ask", "ask"], teammate: ["ask", "ask"] });
+ // ...while an Ask chat still lowers what it opens.
+ const fullBot = botAt(member.store, "full", "Full");
+ const fullMate = botAt(member.store, "full", "Full helper");
+ expect(spawnAll(member, fullBot, chatAt(member.store, fullBot, "ask"), fullMate)).toMatchObject({ own: ["ask", "ask", "ask"], teammate: ["ask", "ask"] });
+ });
+
+ it("keeps Bot API threads at Ask, and what one opens at Ask too", () => {
+ const h = host();
+ const bot = botAt(h.store, "full");
+ const teammate = botAt(h.store, "full", "Helper");
+ // bot-api-host.ts: a key that does not act as the owner opens its thread at an explicit Ask.
+ const api = h.store.createTask(bot.id, "From the API", false, undefined, undefined, "ask")!;
+ h.store.patchTask(bot.id, api.threadId, { botApi: true });
+ expect(h.store.taskByThread(bot.id, api.threadId)).toMatchObject({ approvalMode: "ask", autoApprove: false, alwaysAllow: [] });
+
+ const spawned = spawnAll(h, bot, api.threadId, teammate);
+ expect(spawned.own).toEqual(["ask", "ask", "ask"]);
+ expect(spawned.teammate).toEqual(["ask", "ask"]);
+ });
+});
diff --git a/server/host/spawn-level.ts b/server/host/spawn-level.ts
new file mode 100644
index 0000000000..9aa0f29a06
--- /dev/null
+++ b/server/host/spawn-level.ts
@@ -0,0 +1,50 @@
+// A thread a bot opens from a conversation (its own start_thread and report_back, a burst child, a teammate's new or work
+// thread from a hand-off) starts at the level the person chose in that conversation, both ways: a chat at Full access opens
+// Full access threads and a chat at Ask opens Ask ones, whatever the bot's own saved level (docs/approval-levels.md).
+import { approvalModeFor, levelWithin, modelSwitchNeedsAsk, type ApprovalMode } from "../../shared/approval-mode.ts";
+import type { ModelSelection } from "../../shared/wire.ts";
+import type { BotRecord, Store } from "../store.ts";
+import type { NewThreadLevel } from "../task-record.ts";
+
+export interface SpawnLevelDeps {
+ store: Pick<Store, "taskByThread" | "projectBotForTask">;
+ driverKind(instanceId: string): string | undefined;
+ /** The level a turn in that conversation runs at, its floors applied: a guest's, a Bot API key's or a fenced turn runs at Ask. */
+ sourceLevel(botId: string, threadId: string): ApprovalMode;
+ /** Whoever drives that conversation may set a level there: not work from outside, nor a guest or anyone but the owner on a
+ * Cloud, nor a hosted workspace without its operator's policy. Lowering needs no one. */
+ mayRaise(threadId: string): boolean;
+}
+
+/** The conversation a thread is opened from. A room's thread is never one: a room keeps no level of its own. */
+export type Opener = { botId: string; threadId: string };
+
+export function createSpawnLevel(deps: SpawnLevelDeps) {
+ const { store } = deps;
+ const needsAsk = (mode: ApprovalMode, from: ModelSelection, to: ModelSelection) =>
+ modelSwitchNeedsAsk(mode, deps.driverKind(from.instanceId), deps.driverKind(to.instanceId));
+
+ /** What a new thread of `target` on `selection` saves: `from`'s level when that conversation has a settled one of its own and
+ * it differs from `target`'s, capped by the engine the thread runs on; undefined starts it at `target`'s own (task-record.ts). */
+ return function levelFor(target: BotRecord, selection: ModelSelection = target.modelSelection, from?: Opener): NewThreadLevel | undefined {
+ const own = approvalModeFor({ ...target, approvalGrant: undefined });
+ const ownCarries = needsAsk(own, target.modelSelection, selection) ? "ask" as const : undefined;
+ const task = from && store.taskByThread(from.botId, from.threadId);
+ const view = from && store.projectBotForTask(from.botId, from.threadId);
+ // No level of its own, or none a person chose (a routine run's conversation copies its bot's), or one the desktop is still
+ // confirming (never its Ask mask, never an unconfirmed Full), or the target's own bot-wide change pending, under which a
+ // new thread follows its bot: as before.
+ if (!from || !task || !view || view.approvalGrant || task.routineRunId || (task.approvalMode === undefined && task.autoApprove === undefined) ||
+ (target.approvalGrant && !target.approvalGrant.threadOnly)) return ownCarries;
+ const chosen = approvalModeFor(view);
+ const runs = deps.sourceLevel(from.botId, from.threadId);
+ // A floor held that conversation at Ask (a guest, a Bot API key, the fence, its engine): so does what it opens.
+ if (runs !== chosen) return "ask";
+ // Custom is one Codex configuration the desktop alone may grant: never copied, and nothing above it comes in its place.
+ const level: ApprovalMode = chosen === "custom" && (own !== "custom" || from.botId !== target.id) ? "ask" : chosen;
+ // A thread of a bot on Custom keeps the configuration the person wrote, as a Chief's level leaves it (delegated-level.ts).
+ if (level === own || own === "custom") return ownCarries;
+ if (!levelWithin(level, own) && !deps.mayRaise(from.threadId)) return ownCarries;
+ return needsAsk(level, view.modelSelection, selection) ? "ask" : { from: level };
+ };
+}
diff --git a/server/independent-threads-api.test.ts b/server/independent-threads-api.test.ts
index 04b363de99..d0168b3d45 100644
--- a/server/independent-threads-api.test.ts
+++ b/server/independent-threads-api.test.ts
@@ -257,6 +257,8 @@ describe("independent bot tasks through the isolated control surface", () => {
it.each(["finish", "fail"] as const)("tells a delegating bot that its teammate's approval went unanswered, so the step did not run (turn ends: %s)", async (ending) => {
const chief = (await tool("create_bot", { name: "Delegating Chief", instance_id: "claude", model: models[0] })).bot;
const peer = (await tool("create_bot", { name: "Delegated Peer", instance_id: "claude", model: models[1] })).bot;
+ // The Chief stays at the default Full access: a routine run's conversation hands the peer's new work thread no level, as
+ // nobody chose one there, so the peer's own Ask holds.
expect((await api("PATCH", `/api/bots/${peer.id}`, { approvalMode: "ask" })).status).toBe(200);
const routine = await api("POST", "/api/routines", {
name: "Release checks", prompt: "Delegate the release checks to the reviewer.", botId: chief.id, enabled: false,
diff --git a/server/index.ts b/server/index.ts
index 2785c558d7..83ddcaef94 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -9102,7 +9102,7 @@ const validateModelProposal = (selection: ModelSelection, current?: BotRecord):
}
return null;
};
-const ownThreads = createOwnThreads({ store, registry, node: (id) => coordinator.node(id), current: turnSelection, proposalRefusal: validateModelProposal, givesWay: modelGivesWay, modelName }); const burst = createBurstHost({ dataDir: DATA_DIR, cloudHome: Boolean(CLOUD_HOME), tier: () => cloudPlanTier.tier(), maxParallel: () => cfg.burst?.maxParallel, hasRoom: () => engineMemory.laneHasRoom(), store, language: (threadId) => threadLanguage(threadId), startTurn: (botId, text, opts) => startTurn(botId, text, opts), stop: (botId, threadId, cause) => { void interruptDirectThread(botId, threadId, cause).catch(() => {}); }, threadBusy, opened: (threadId, parent) => threadStarters.set(threadId, openerFrom(parent)), origin: (run) => withPerson({ kind: "user", request: quoteInNote(run.task, 400) }, threadPersonKey(run.threadId)), approval: (bot, selection) => ownThreads.approvalFor(bot, selection), defaultModel: (bot, threadId) => burstDefaultModel({ own: store.taskByThread(bot.id, threadId)?.modelSelection ?? bot.modelSelection, catalog: (id) => registry.get(id)?.models, refused: (id) => quickFallback.refused(id), usable: (selection) => ownThreads.refusal(selection, bot) === null }), modelName, route: (notification) => teamMessages.route(notification, { routine: true }), announce: (notification) => { broadcast({ kind: "notify", notification: logNotification(notification) }); } });
+const ownThreads = createOwnThreads({ store, registry, node: (id) => coordinator.node(id), current: turnSelection, proposalRefusal: validateModelProposal, givesWay: modelGivesWay, modelName, sourceLevel: sourceApprovalMode, mayRaise: (threadId) => !outsideLineage.handsNoLevel(threadId) && (!CLOUD_HOME || cloudOwnerPerson(threadPersonKey(threadId))) && (!HOSTED_WORKSPACE || sharedWorkspaceFullAccessEnabled()) }); const burst = createBurstHost({ dataDir: DATA_DIR, cloudHome: Boolean(CLOUD_HOME), tier: () => cloudPlanTier.tier(), maxParallel: () => cfg.burst?.maxParallel, hasRoom: () => engineMemory.laneHasRoom(), store, language: (threadId) => threadLanguage(threadId), startTurn: (botId, text, opts) => startTurn(botId, text, opts), stop: (botId, threadId, cause) => { void interruptDirectThread(botId, threadId, cause).catch(() => {}); }, threadBusy, opened: (threadId, parent) => threadStarters.set(threadId, openerFrom(parent)), origin: (run) => withPerson({ kind: "user", request: quoteInNote(run.task, 400) }, threadPersonKey(run.threadId)), approval: ownThreads.approvalFor, defaultModel: (bot, threadId) => burstDefaultModel({ own: store.taskByThread(bot.id, threadId)?.modelSelection ?? bot.modelSelection, catalog: (id) => registry.get(id)?.models, refused: (id) => quickFallback.refused(id), usable: (selection) => ownThreads.refusal(selection, bot) === null }), modelName, route: (notification) => teamMessages.route(notification, { routine: true }), announce: (notification) => { broadcast({ kind: "notify", notification: logNotification(notification) }); } });
const teamMemory = new TeamMemory(join(DATA_DIR, "team-memory.json"));
const teamMemoryRequests = createTeamMemoryRequests({ teamMemory, store, sectionKey: sectionContextKey, decide: (row) => appendDecision(DATA_DIR, row) });
const outsideWrites = createOutsideWrites({ store, notify, language: (threadId) => threadLanguage(threadId), decide: (row) => appendDecision(DATA_DIR, row),
@@ -13604,14 +13604,14 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
if (lane?.created) createdThread = lane.threadId;
if (lane) delegatedLevel.apply(internalSender, internalCapability.threadId, internalCapability.roomHandoffId ?? generation, recipient, lane.threadId);
if (!room) {
- const opened = { botId: internalSender.id, name: internalSender.name, threadId: address.threadId, at: Date.now(), ...(lends ? { forOwner: true as const } : {}) }, startedFor = (created: { threadId: string }) => threadStarters.set(created.threadId, opener);
+ const opened = { botId: internalSender.id, name: internalSender.name, threadId: address.threadId, at: Date.now(), ...(lends ? { forOwner: true as const } : {}) }, startedFor = (created: { threadId: string }) => threadStarters.set(created.threadId, opener), level = call.ownThread ? call.ownThread.approvalMode : EXTERNAL || mode === "consult" ? undefined : ownThreads.levelFor(recipient, undefined, address);
const task = continued ?? (fresh
- ? store.createTask(target.botId, call.title ?? (call.message.replace(/\s+/g, " ").trim().slice(0, 60) || `From ${internalSender.name}`), false, call.projectId, opened, call.ownThread?.approvalMode, call.ownThread?.modelSelection, folder.cwd, startedFor)
- : store.createTask(target.botId, `@${internalSender.name} · work`, false, undefined, { ...opened, kind: "work" }, undefined, undefined, folder.cwd, startedFor));
+ ? store.createTask(target.botId, call.title ?? (call.message.replace(/\s+/g, " ").trim().slice(0, 60) || `From ${internalSender.name}`), false, call.projectId, opened, level, call.ownThread?.modelSelection, folder.cwd, startedFor)
+ : store.createTask(target.botId, `@${internalSender.name} · work`, false, undefined, { ...opened, kind: "work" }, level, undefined, folder.cwd, startedFor));
if (!task) throw new Error("The recipient no longer exists");
target.threadId = task.threadId;
if (!continued) createdThread = task.threadId;
- delegatedLevel.apply(internalSender, internalCapability.threadId, internalCapability.roomHandoffId ?? generation, recipient, target.threadId); if (lends && !levelWithin(approvalModeForTurn(store.projectBotForTask(recipient.id, target.threadId) ?? recipient, true, target.threadId), approvalModeForTurn(store.projectBotForTask(internalSender.id, address.threadId) ?? internalSender, internalCapability.depth > 0, address.threadId))) { lends = false; handedInUnproven(target.threadId); }
+ delegatedLevel.apply(internalSender, internalCapability.threadId, internalCapability.roomHandoffId ?? generation, recipient, target.threadId, !continued); if (lends && !levelWithin(approvalModeForTurn(store.projectBotForTask(recipient.id, target.threadId) ?? recipient, true, target.threadId), approvalModeForTurn(store.projectBotForTask(internalSender.id, address.threadId) ?? internalSender, internalCapability.depth > 0, address.threadId))) { lends = false; handedInUnproven(target.threadId); }
}
const routed = lane ? { botId: target.botId, threadId: lane.threadId } : target;
outsideLineage.carry(address.threadId, routed.threadId);
@@ -13926,7 +13926,7 @@ const handleRequest = async (req: IncomingMessage, res: ServerResponse) => {
const sourceTitle = owner.group ? owner.group.name : (store.taskByThread(from.id, fromThreadId)?.title ?? "");
const picked = body.modelSelection === undefined ? null : checkedModelSelection(body.modelSelection, undefined, true); const refused = !picked ? null : target.id !== from.id ? "model_selection is only for threads on yourself" : !picked.ok ? picked.error : ownThreads.refusal(picked.selection, from); if (refused) return json(res, 400, { error: refused });
if (target.id === from.id) { const selfRefused = selfThreadRefusal({ handoff: Boolean(internalCapability.roomHandoffId), requestLine: store.activePath(fromThreadId).findLast((line) => line.role === "user" && line.kind === "text") }); if (selfRefused) return json(res, 409, { error: selfRefused });
- const inherited = picked?.ok ? { modelSelection: picked.selection, approvalMode: undefined } : ownThreads.inherited(from.id, fromThreadId);
+ const inherited = ownThreads.inherited(from.id, fromThreadId, picked?.ok ? picked.selection : undefined);
if (body.reportBack === true) { if (owner.group) return json(res, 400, { error: "report_back works only from your own conversation, not a room. Leave it out; the thread's result then stays in that thread." });
const result = await coordinateBots({ botIds: [from.id], message, rework: false, thread: "new", reply: "resume", consult: false, title, projectId, ownThread: inherited }), receipt = (result.body.receipts as PeerDeliveryReceipt[] | undefined)?.[0];
return json(res, result.status === 200 ? 201 : result.status, { ...result.body, self: true, reportBack: true, title, botId: from.id, botName: from.name, threadId: receipt?.threadId, requestId: receipt?.requestId }); }
diff --git a/server/legacy-work-threads.test.ts b/server/legacy-work-threads.test.ts
new file mode 100644
index 0000000000..f298f721a7
--- /dev/null
+++ b/server/legacy-work-threads.test.ts
@@ -0,0 +1,83 @@
+import { existsSync, rmSync } from "node:fs";
+import { join } from "node:path";
+import { beforeEach, describe, expect, it } from "vitest";
+
+import { approvalModeFor, type ApprovalMode } from "../shared/approval-mode.ts";
+import type { TaskOpenedBy } from "../shared/wire.ts";
+import { DATA_DIR } from "./config.ts";
+import type { ModelSelection } from "./contracts.ts";
+import { Store } from "./store.ts";
+
+const selection = (): ModelSelection => ({ instanceId: "claude", model: "claude-sonnet-5" });
+const OCT_1 = Date.UTC(2026, 9, 1);
+const OCT_20 = Date.UTC(2026, 9, 20);
+const MARKER = join(DATA_DIR, "legacy-work-threads-follow-bot");
+/** The next start runs this build for the first time: an older one left no marker. */
+const upgraded = () => { rmSync(MARKER, { force: true }); return new Store(selection); };
+const levelOf = (store: Store, botId: string, threadId: string) => approvalModeFor(store.projectBotForTask(botId, threadId)!);
+
+/** A thread as an older build saved it: made at `createdAt`, saved at `mode`. */
+function saved(store: Store, botId: string, title: string, createdAt: number, mode: ApprovalMode, openedBy?: Omit<TaskOpenedBy, "at">): string {
+ const task = store.createTask(botId, title, false, undefined, openedBy && { ...openedBy, at: createdAt })!;
+ Object.assign(store.taskByThread(botId, task.threadId)!, { createdAt, approvalMode: mode, autoApprove: false, alwaysAllow: [] });
+ store.patchTask(botId, task.threadId, { title });
+ return task.threadId;
+}
+
+describe("work threads saved at Ask before Full access was the default", () => {
+ beforeEach(() => {
+ rmSync(DATA_DIR, { recursive: true, force: true });
+ });
+
+ it("follow their bot once, and only the hand-off's standing work thread does", () => {
+ const first = new Store(selection);
+ const sender = first.createBot();
+ const bot = first.createBot(); // nobody set its level: it reads the default, Full access
+ const work = { botId: sender.id, name: "Sender", threadId: sender.threadId, kind: "work" as const };
+ const legacy = saved(first, bot.id, "@Sender · work", OCT_1, "ask", work);
+ const personal = saved(first, bot.id, "My own chat", OCT_1, "ask");
+ const handedNew = saved(first, bot.id, "A new thread handed on", OCT_1, "ask", { botId: sender.id, name: "Sender", threadId: sender.threadId });
+ const roomJob = saved(first, bot.id, "Room · job", OCT_1, "ask", { ...work, roomLane: true });
+ const later = saved(first, bot.id, "@Other · work", OCT_20, "ask", { ...work, threadId: "another-chat" });
+ const edits = saved(first, bot.id, "@Third · work", OCT_1, "edits", { ...work, threadId: "third-chat" });
+ expect(levelOf(first, bot.id, legacy)).toBe("ask");
+
+ const loaded = upgraded();
+
+ expect(loaded.taskByThread(bot.id, legacy)).not.toHaveProperty("approvalMode");
+ expect(loaded.taskByThread(bot.id, legacy)).not.toHaveProperty("autoApprove");
+ expect(levelOf(loaded, bot.id, legacy)).toBe("full");
+ for (const kept of [personal, handedNew, roomJob, later]) expect(levelOf(loaded, bot.id, kept)).toBe("ask");
+ expect(levelOf(loaded, bot.id, edits)).toBe("edits");
+ expect(existsSync(MARKER)).toBe(true);
+
+ // Done once: the person later picks Ask on that thread, and it stays Ask through every later load.
+ loaded.patchTask(bot.id, legacy, { approvalMode: "ask", autoApprove: false });
+ expect(levelOf(new Store(selection), bot.id, legacy)).toBe("ask");
+ });
+
+ it("follows a bot saved at Ask to Ask, and later to whatever its bot is set to", () => {
+ const first = new Store(selection);
+ const sender = first.createBot();
+ const bot = first.createBot();
+ first.patchBot(bot.id, { approvalMode: "ask", autoApprove: false });
+ const legacy = saved(first, bot.id, "@Sender · work", OCT_1, "ask", { botId: sender.id, name: "Sender", threadId: sender.threadId, kind: "work" });
+
+ const loaded = upgraded();
+ expect(levelOf(loaded, bot.id, legacy)).toBe("ask");
+ loaded.patchBot(bot.id, { approvalMode: "auto", autoApprove: true });
+ expect(levelOf(loaded, bot.id, legacy)).toBe("auto");
+ });
+
+ it("leaves a bot whose level change was pending at shutdown to the grant's own recovery", () => {
+ const first = new Store(selection);
+ const sender = first.createBot();
+ const bot = first.createBot();
+ const legacy = saved(first, bot.id, "@Sender · work", OCT_1, "ask", { botId: sender.id, name: "Sender", threadId: sender.threadId, kind: "work" });
+ first.patchBot(bot.id, { approvalMode: "full", approvalGrant: { requestId: "123e4567-e89b-42d3-a456-426614174000", mode: "full", phase: "prepared" } });
+
+ const loaded = upgraded();
+ expect(loaded.bot(bot.id)?.approvalMode).toBe("ask");
+ expect(loaded.taskByThread(bot.id, legacy)?.approvalMode).toBe("ask");
+ });
+});
diff --git a/server/legacy-work-threads.ts b/server/legacy-work-threads.ts
new file mode 100644
index 0000000000..b90eef296d
--- /dev/null
+++ b/server/legacy-work-threads.ts
@@ -0,0 +1,41 @@
+// Before Full access became the default (2026-10-14), a work thread a teammate's hand-off opened ("@Sender · work", reused by
+// every later hand-off from that conversation) saved the default of the day, Ask, though nobody picked it. Its bot now reads
+// Full access, yet that thread still asked for everything. Once per data folder, on load, such a thread drops the Ask it
+// saved and follows its bot's level from then on. A conversation a person opened is never one of these.
+import { existsSync } from "node:fs";
+import { join } from "node:path";
+
+import { writeFileAtomic } from "./atomic.ts";
+import type { BotRecord, TaskRecord } from "./store.ts";
+
+/** The day Full access became the level a new bot and thread start at. */
+export const FULL_ACCESS_DEFAULT_SINCE = Date.UTC(2026, 9, 14);
+
+const MARKER = "legacy-work-threads-follow-bot";
+
+/** A hand-off's standing work thread (not a room job's), made before that day, that still saves Ask. Its creation time comes
+ * from the record; the opener's timestamp, written in the same moment, stands in only where that is missing. */
+export function legacyAskWorkThread(task: TaskRecord): boolean {
+ const opened = task.openedBy;
+ if (opened?.kind !== "work" || opened.roomLane || task.botApi || task.approvalMode !== "ask") return false;
+ const at = Number.isFinite(task.createdAt) ? task.createdAt : opened.at;
+ return Number.isFinite(at) && at < FULL_ACCESS_DEFAULT_SINCE;
+}
+
+/** Runs once: null when it ran already, or when bots.json could not be read (`readable` false), so a later load still can.
+ * A bot whose level change was pending at shutdown is left alone: the grant's own recovery decides its threads. Call `done`
+ * once the repaired bots are saved. */
+export function repairLegacyWorkThreads(dataDir: string, bots: readonly BotRecord[], readable: boolean): { changed: boolean; done(): void } | null {
+ const marker = join(dataDir, MARKER);
+ if (!readable || existsSync(marker)) return null;
+ let changed = false;
+ for (const task of bots.flatMap((bot) => bot.approvalGrant ? [] : bot.tasks ?? [])) {
+ if (!legacyAskWorkThread(task)) continue;
+ // All three go: a thread keeping any of them would not follow its bot (threadApproval).
+ delete task.approvalMode;
+ delete task.autoApprove;
+ delete task.alwaysAllow;
+ changed = true;
+ }
+ return { changed, done: () => writeFileAtomic(marker, "Work threads saved at Ask before Full access was the default follow their bot.\n", { mode: 0o600 }) };
+}
diff --git a/server/store.ts b/server/store.ts
index 3604c07b3e..5d222d8554 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -42,7 +42,8 @@ import { appsFromCreator } from "./inherited-apps.ts"; import { newBotOwner, sha
import { ThreadCache, type ThreadState } from "./thread-cache.ts";
import { lastMessageId, messagesBefore } from "./thread-history.ts";
import { titleFromMessage, UNTITLED_TASK } from "./thread-title.ts";
-import { buildTask, threadTitleFrom, UNTITLED_THREAD } from "./task-record.ts";
+import { buildTask, threadTitleFrom, UNTITLED_THREAD, type NewThreadLevel } from "./task-record.ts";
+import { repairLegacyWorkThreads } from "./legacy-work-threads.ts";
import { createBotFork, createGroupFork } from "./store-forks.ts";
import { createThreadBotIndex } from "./thread-bot-index.ts";
import { activeGroupTask, groupTaskByThread, groupTasks, migrateGroupTaskRead, mirrorActiveGroupTask, refreshGroupUnread, setGroupTaskRead, syncGroupReadPatch } from "./group-task-state.ts";
@@ -304,7 +305,8 @@ export class Store {
this.groups = [];
}
this.rememberSections([...this.bots, ...this.groups].map((record) => record.section));
- let botsMigrated = false;
+ // Before the grant recovery below sets a thread to Ask: that Ask is not the legacy default's.
+ const legacyWork = repairLegacyWorkThreads(DATA_DIR, this.bots, botsLoaded || !existsSync(BOTS_FILE)); let botsMigrated = Boolean(legacyWork?.changed);
const browserProfileAliases = loadBrowserProfileIdAliases();
const chiefSectionsSeen = new Set<string>();
let groupsMigrated = false;
@@ -475,16 +477,7 @@ export class Store {
b.projects = b.projects.map(({ id, name, emoji }) => ({ id, name, ...(isProjectEmoji(emoji) ? { emoji } : {}) }));
botsMigrated = true;
}
- if (!b.tasks?.length) {
- b.tasks = [{
- threadId: b.threadId,
- title: this.firstUserLine(b.threadId) ?? UNTITLED_TASK,
- createdAt: b.createdAt,
- updatedAt: b.createdAt,
- resumeCursors: b.resumeCursors ?? {},
- }];
- botsMigrated = true;
- }
+ b.tasks ??= [];
let active = b.tasks.find((task) => task.threadId === b.threadId);
if (!active) {
active = {
@@ -537,6 +530,7 @@ export class Store {
b.unread = b.tasks.some(taskCountsAsBotUnread);
}
if (botsMigrated) this.saveBots();
+ legacyWork?.done();
if (clearModelCopies) writeFileAtomic(THREAD_MODEL_COPIES_CLEARED, "Threads follow their bot's model; the copies older builds made are cleared.\n", { mode: 0o600 });
const knownThreads = new Set([
...this.bots.flatMap((b) => [b.threadId, ...(b.tasks ?? []).map((task) => task.threadId)]),
@@ -2139,7 +2133,7 @@ export class Store {
bot.pinnedMessageId = task.pinnedMessageId;
}
- createTask(botId: string, title?: string, activate = true, projectId?: string, openedBy?: TaskOpenedBy, approvalMode?: "ask" | "full",
+ createTask(botId: string, title?: string, activate = true, projectId?: string, openedBy?: TaskOpenedBy, approvalMode?: NewThreadLevel,
modelSelection?: ModelSelection, cwd?: string, beforeShown?: (task: TaskRecord) => void): TaskRecord | null {
const bot = this.own(botId);
if (!bot) return null;
diff --git a/server/task-record.test.ts b/server/task-record.test.ts
index d15095e9cc..af44d6f1c5 100644
--- a/server/task-record.test.ts
+++ b/server/task-record.test.ts
@@ -103,7 +103,8 @@ describe("a thread a bot opens while a level change is being confirmed", () => {
store.patchBot(bot.id, { approvalGrant: { requestId: REQUEST, mode: "full", phase: "prepared", threadId: bot.threadId, threadOnly: true } });
const drivers: Record<string, string> = { claude: "claudeAgent", codex: "codex" };
const own = createOwnThreads({ store, registry: { instances: () => [], cliTarget: (id) => ({ driverKind: drivers[id]! }) }, node: () => undefined,
- current: () => undefined, proposalRefusal: () => null, givesWay: () => null, modelName: (one) => one.model });
+ current: () => undefined, proposalRefusal: () => null, givesWay: () => null, modelName: (one) => one.model,
+ sourceLevel: (botId, threadId) => approvalModeFor(store.projectBotForTask(botId, threadId)!), mayRaise: () => true });
// Auto-accept edits does not exist on Codex, so a burst child or an own thread there starts at Ask, as without a grant.
expect(own.approvalFor(store.bot(bot.id)!, codex)).toBe("ask");
diff --git a/server/task-record.ts b/server/task-record.ts
index 658e35917b..3f5f6f0d7b 100644
--- a/server/task-record.ts
+++ b/server/task-record.ts
@@ -1,4 +1,4 @@
-import { approvalModeFor } from "../shared/approval-mode.ts";
+import { approvalModeFor, type ApprovalMode } from "../shared/approval-mode.ts";
import { sameModelSelection } from "../shared/thread-model.ts";
import type { TaskOpenedBy } from "../shared/wire.ts";
import { newId, type ModelSelection } from "./contracts.ts";
@@ -19,8 +19,15 @@ function botLevel(bot: BotRecord): Pick<TaskRecord, "approvalMode" | "autoApprov
return { approvalMode: approvalModeFor({ ...bot, approvalGrant: undefined }), autoApprove: Boolean(bot.autoApprove), alwaysAllow: [...(bot.alwaysAllow ?? [])] };
}
+/** The level a new thread opens at, when not its bot's: exactly "ask" or "full" with no saved grants (a Bot API thread, an
+ * engine its bot's level does not carry to, a level picked for it), or `from` the conversation that opened it, with the bot's
+ * own saved grants (spawn-level.ts). */
+export type NewThreadLevel = "ask" | "full" | { from: ApprovalMode };
+
+const levelFrom = (bot: BotRecord, mode: ApprovalMode) => ({ approvalMode: mode, autoApprove: mode === "auto", alwaysAllow: [...(bot.alwaysAllow ?? [])] });
+
export function buildTask(bot: BotRecord, title?: string, projectId?: string, openedBy?: TaskOpenedBy,
- approvalMode?: "ask" | "full", modelSelection?: ModelSelection, cwd?: string | null): TaskRecord {
+ approvalMode?: NewThreadLevel, modelSelection?: ModelSelection, cwd?: string | null): TaskRecord {
const createdAt = Date.now();
return {
threadId: newId(),
@@ -32,7 +39,7 @@ export function buildTask(bot: BotRecord, title?: string, projectId?: string, op
...(openedBy ? { openedBy: structuredClone(openedBy) } : {}),
resumeCursors: {},
...(modelSelection && !sameModelSelection(modelSelection, bot.modelSelection) ? { modelSelection: structuredClone(modelSelection) } : {}),
- ...(approvalMode ? { approvalMode, autoApprove: false, alwaysAllow: [] } : botLevel(bot)),
+ ...(typeof approvalMode === "string" ? { approvalMode, autoApprove: false, alwaysAllow: [] } : approvalMode ? levelFrom(bot, approvalMode.from) : botLevel(bot)),
unread: false,
activity: "idle",
busy: false,