Skip to content

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

fix(team-setup): start bots a Chief's team setup creates at the saved New bot approval level

AdityaUmaleb98dc92e6a48
diff --git a/server/index.ts b/server/index.ts
index 9152332cc5..6bf5d15baf 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -391,7 +391,7 @@ import { skillReferencesSha256 } from "./skill-storage.ts";
import { createSkillsLibraryHost } from "./host/skills-library.ts";
import { skillExport } from "./skill-export.ts";
import { pickBotName } from "./names.ts";
-import { botSkillTemplateSchema, newBotDefaultsSchema } from "./new-bot-defaults.ts";
+import { botSkillTemplateSchema, newBotApproval, newBotDefaultsSchema } from "./new-bot-defaults.ts";
import { expandLearnTurnText, learnSource } from "./skill-learn.ts";
import { connectedAppsForSetup, expandSetupTurnText, setupModeActive, setupSystemPrompt, type SetupConnectedApps } from "./setup-mode.ts"; import { forgetSetupPresser, setupPresser, setupTurnText, takeSetupRequest } from "./setup-request.ts"; import { setupSuggestionsFor } from "./setup-suggestions.ts"; import { createSetupRequestRoutes } from "./routes/setup-request.ts";
import { isSkillSwitchAction, type SkillRequestCardData } from "../shared/skill-request.ts"; import { createSkillSwitchHost } from "./host/skill-switch-host.ts";
@@ -9192,7 +9192,7 @@ const modelRequests = new ModelRequestService({
const teamSetupTeams = () => [...new Set(["", ...readSections(), ...store.bots.map((bot) => sectionKey(bot.section)), ...store.groups.map((group) => sectionKey(group.section))])];
const teamSetupRequests = new TeamSetupRequestService({
store, teams: teamSetupTeams, hasTeamAuthority, canPersist: proposalPersistence, maxBots: MAX_WORKSPACE_BOTS,
- autoApply: appliesDirectly,
+ autoApply: appliesDirectly, newBotApproval: () => newBotApproval(cfg.newBotDefaults, HOSTED_WORKSPACE),
validateChange: (before, fields) => assertTeamComputerChangeIdle(before, { ...before, ...fields }),
mcpServerProblem: (name, botId) => mcpServerProblemFor(cfg.mcpServers, name, botId), ownsThread: (botId, threadId) => Boolean(connectorThread(botId, threadId)),
targetBusy: (botId, sourceThreadId) => {
diff --git a/server/new-bot-defaults.test.ts b/server/new-bot-defaults.test.ts
index d6953606d0..9695f95449 100644
--- a/server/new-bot-defaults.test.ts
+++ b/server/new-bot-defaults.test.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { newBotDefaultsSchema, resolveBotCreationDefaults } from "./new-bot-defaults.ts";
+import { newBotApproval, newBotDefaultsSchema, resolveBotCreationDefaults } from "./new-bot-defaults.ts";
import { parseConfigPatch } from "./config.ts";
describe("new-bot templates", () => {
@@ -79,3 +79,18 @@ describe("new-bot templates", () => {
expect(newBotDefaultsSchema.safeParse({ memory }).success).toBe(false);
});
});
+
+describe("the saved level a bot made outside New bot starts at", () => {
+ const saved = (approvalMode?: "ask" | "auto" | "full" | "custom") => newBotDefaultsSchema.parse({ profile: approvalMode ? { approvalMode } : {} });
+ it("is the template's level, and none when the template sets none", () => {
+ expect(newBotApproval(saved("auto"), false)).toBe("auto");
+ expect(newBotApproval(saved("ask"), true)).toBe("ask");
+ expect(newBotApproval(saved("full"), false)).toBe("full");
+ expect(newBotApproval(saved(), false)).toBeUndefined();
+ expect(newBotApproval(undefined, false)).toBeUndefined();
+ });
+ it("leaves Custom and a hosted workspace's Full access to the workspace default", () => {
+ expect(newBotApproval(saved("custom"), false)).toBeUndefined();
+ expect(newBotApproval(saved("full"), true)).toBeUndefined();
+ });
+});
diff --git a/server/new-bot-defaults.ts b/server/new-bot-defaults.ts
index acf85c70f2..479c94bea2 100644
--- a/server/new-bot-defaults.ts
+++ b/server/new-bot-defaults.ts
@@ -128,6 +128,15 @@ function settingsError(error: z.ZodError): Error {
return new Error(field && issue.message.startsWith(String(issue.path[0])) ? issue.message : `${field || "the bot"} is not valid`);
}
+export type NewBotApproval = "ask" | "auto" | "full";
+
+/** The saved level a bot made without the New bot dialog starts at. Custom needs the desktop permission flow and a
+ * hosted workspace starts no bot at Full access, so those keep the workspace default. */
+export function newBotApproval(saved: NewBotDefaults | undefined, hosted: boolean): NewBotApproval | undefined {
+ const mode = saved?.profile.approvalMode;
+ return mode === "custom" || (mode === "full" && hosted) ? undefined : mode;
+}
+
export function resolveBotCreationDefaults(saved: NewBotDefaults | undefined, body: Record<string, unknown>) {
if (body.useDefaults !== undefined && typeof body.useDefaults !== "boolean") {
throw Object.assign(new Error("useDefaults must be true or false"), { status: 400 });
diff --git a/server/store.test.ts b/server/store.test.ts
index 1d95457d7d..5ac8fbc8a1 100644
--- a/server/store.test.ts
+++ b/server/store.test.ts
@@ -25,6 +25,7 @@ import type { TeamSetupRequest } from "../shared/team-setup.ts";
import { SECTION_CONTEXTS_FILE, readSectionContext, writeSectionContext } from "./section-context.ts";
import { TeamComputers } from "./team-computers.ts";
import { allowsTool } from "../shared/tool-scope.ts";
+import { approvalModeFor } from "../shared/approval-mode.ts";
import { readRegistry, writeRegistry } from "./testing/registry.ts";
const selection = (): ModelSelection => ({ instanceId: "claude", model: "claude-sonnet-5" });
@@ -1344,6 +1345,24 @@ describe("Store", () => {
}
});
+ it("starts a bot a team setup creates at the saved New bot level, and at the default without one", () => {
+ const store = new Store(selection);
+ const chief = store.createBot({ name: "Chief", section: "Ops" });
+ store.patchBot(chief.id, { chiefOfStaff: true });
+ const setup = (requestId: string, botId: string, approval?: "ask" | "auto" | "full") => store.applyTeamSetup({ version: 1, requestId, botId: chief.id,
+ threadId: chief.threadId, reason: "Requested", createdAt: 1, requesterRevision: "fixture", newTeams: [], operations: [
+ { action: "create", botId, threadId: `${botId}-thread`, fields: { name: botId, section: "Ops", modelSelection: selection() } },
+ ] }, approval);
+ setup("setup-auto", "templated", "auto");
+ setup("setup-plain", "plain");
+ const reloaded = new Store(selection);
+ expect(approvalModeFor(reloaded.bot("templated")!)).toBe("auto");
+ expect(reloaded.bot("templated")?.autoApprove).toBe(true);
+ expect(approvalModeFor(reloaded.projectBotForTask("templated", "templated-thread")!)).toBe("auto");
+ expect(reloaded.bot("plain")?.approvalMode).toBeUndefined();
+ expect(reloaded.bot("plain")?.autoApprove).toBe(false);
+ });
+
it("gives a new department to a Chief in charge of every department once the write that made it is saved", async () => {
const store = new Store(selection);
const lead = store.createBot({ name: "Lead", section: "Ops" });
diff --git a/server/store.ts b/server/store.ts
index eb5bcc17fe..2d232fabab 100644
--- a/server/store.ts
+++ b/server/store.ts
@@ -1333,7 +1333,7 @@ export class Store {
return bot;
}
- applyTeamSetup(request: TeamSetupRequest): TeamSetupResult {
+ applyTeamSetup(request: TeamSetupRequest, newBotApproval?: Exclude<ApprovalMode, "custom">): TeamSetupResult {
const chief = this.own(request.botId);
if (!chief) throw new Error("The requesting Chief no longer exists");
if (chief.lastTeamSetupReceipt?.requestId === request.requestId) return chief.lastTeamSetupReceipt.result;
@@ -1352,7 +1352,7 @@ export class Store {
next = { id: operation.botId, threadId: operation.threadId, name: operation.fields.name,
title: "", description: "", soul: "", notifications: true, color: rotationColor(nextBots.length), unread: false,
resumeCursors: {}, createdAt, ...operation.fields, modelSelection,
- autoApprove: false,
+ ...(newBotApproval ? { approvalMode: newBotApproval } : {}), autoApprove: newBotApproval === "auto",
...sharedAsMaker(chief),
// A Chief's new specialist reports to the Chief's own person.
...(botOwner(chief) ? { createdBy: botOwner(chief)! } : {}),
diff --git a/server/team-setup-requests.test.ts b/server/team-setup-requests.test.ts
index d2b445b049..65374acac5 100644
--- a/server/team-setup-requests.test.ts
+++ b/server/team-setup-requests.test.ts
@@ -11,7 +11,7 @@ import type { BotRecord, OptionCardData } from "./store.ts";
import type { TeamSetupRequest, TeamSetupResult } from "../shared/team-setup.ts";
import type { DirectApply } from "./direct-apply.ts";
-function harness(caps?: Record<string, { driverKind: string; agentsMcp: boolean }>) {
+function harness(caps?: Record<string, { driverKind: string; agentsMcp: boolean }>, newBotApproval?: () => "ask" | "auto" | "full" | undefined) {
const bots: BotRecord[] = [];
const messages: Array<{ id: string; role?: string; card?: OptionCardData }> = [];
const teams = ["", "Work", "Engineering", "Private"];
@@ -23,7 +23,7 @@ function harness(caps?: Record<string, { driverKind: string; agentsMcp: boolean
};
const chief = bot("Clive", { chiefOfStaff: true, managedSections: ["Engineering"] });
const peer = bot("Ada");
- const apply = vi.fn((request: TeamSetupRequest): TeamSetupResult => {
+ const apply = vi.fn((request: TeamSetupRequest, _approval?: string): TeamSetupResult => {
const result: TeamSetupResult = { state: "applied", newTeams: request.newTeams, bots: request.operations.map((op) => {
const target = bots.find((item) => item.id === op.botId) ?? bot(op.botId);
Object.assign(target, op.fields);
@@ -63,7 +63,7 @@ function harness(caps?: Record<string, { driverKind: string; agentsMcp: boolean
if (!({ claude: ["sonnet", "opus"], codex: ["gpt-fixture"] }[selection.instanceId]?.includes(selection.model))) return "Model is not in the current catalog";
return current?.approvalMode === "full" && selection.instanceId !== current.modelSelection.instanceId ? "Existing permissions are incompatible" : null;
},
- ...(caps ? { driverCapabilities: (instanceId: string) => caps[instanceId] } : {}),
+ ...(caps ? { driverCapabilities: (instanceId: string) => caps[instanceId] } : {}), ...(newBotApproval ? { newBotApproval } : {}),
});
const propose = (operations: unknown[], newTeams: string[] = []) => service.propose({ botId: chief.id, threadId: chief.threadId, plan: { reason: "Requested specialist setup", operations, newTeams } });
const submit = (operations: unknown[], newTeams: string[] = []) => service.submit({ botId: chief.id, threadId: chief.threadId, plan: { reason: "Requested specialist setup", operations, newTeams } });
@@ -74,6 +74,13 @@ const specialist = (key: string, section: string, modelSelection = { instanceId:
fields: { name: key, title: "Specialist", soul: "Finish the assigned work.", section, modelSelection } });
describe("reviewed Chief team setup", () => {
+ it("applies a reviewed setup with the saved New bot level for the bots it creates", async () => {
+ const h = harness(undefined, () => "auto");
+ const request = h.propose([specialist("Analyst", "Engineering")]);
+ expect((await h.resolve(request.requestId))?.result.state).toBe("applied");
+ expect(h.apply).toHaveBeenCalledWith(expect.objectContaining({ requestId: request.requestId }), "auto");
+ });
+
it("reviews promotion in an authorized team without changing anything on denial", async () => {
const h = harness(); h.peer.section = "Engineering";
const before = structuredClone(h.store.bots);
diff --git a/server/team-setup-requests.ts b/server/team-setup-requests.ts
index 031eb89f38..91866e1c81 100644
--- a/server/team-setup-requests.ts
+++ b/server/team-setup-requests.ts
@@ -8,6 +8,7 @@ import { profileSnapshot } from "./profile-revision.ts";
import { recordProfileChange, type HistoryActor } from "./profile-versions.ts";
import { validateBotCwd } from "./bot-cwd.ts";
import { UNDO_STALE, type DirectApply } from "./direct-apply.ts";
+import type { NewBotApproval } from "./new-bot-defaults.ts";
import { harnessCapabilityLines, type DriverCapabilities } from "./harness-capabilities.ts";
import { MAX_MCP_SERVERS, mcpServerNameError } from "./mcp-registry.ts";
import { redactSecretsInText } from "./redact.ts"; import { chiefLevel } from "./chief-level.ts"; import { defaultBotRefusal } from "./default-bot.ts";
@@ -91,7 +92,7 @@ interface SetupStore {
messagesFor(threadId: string): Array<{ id: string; role?: string; card?: OptionCardData }>;
appendMessage(threadId: string, message: { role: "bot"; kind: "options"; card: OptionCardData; from?: { botId: string; name: string; color: string } }): { id: string };
patchMessage(threadId: string, messageId: string, patch: { card: OptionCardData }): unknown;
- applyTeamSetup(request: TeamSetupRequest): TeamSetupResult;
+ applyTeamSetup(request: TeamSetupRequest, approval?: NewBotApproval): TeamSetupResult;
patchBot(id: string, patch: Partial<BotRecord>): unknown;
}
@@ -102,6 +103,8 @@ interface Options {
canPersist(botId: string, threadId: string): { ok: true } | { ok: false; status: number; error: string };
validateModel(selection: ModelSelection, current?: BotRecord): string | null;
targetBusy(botId: string, sourceThreadId?: string): boolean;
+ /** The approval level the saved New bot defaults give a new bot, if they set one this setup may use. */
+ newBotApproval?(): NewBotApproval | undefined;
/** Null only where the owner confirms on a card (direct-apply.ts). */
autoApply?(botId: string, threadId: string): DirectApply | null;
driverCapabilities?(instanceId: string): DriverCapabilities | undefined;
@@ -370,7 +373,7 @@ export class TeamSetupRequestService {
const bot = operation.action === "update" ? this.options.store.bot(operation.botId) : undefined;
return bot ? [{ id: bot.id, profile: profileSnapshot(bot) }] : [];
});
- const result = this.options.store.applyTeamSetup(request);
+ const result = this.options.store.applyTeamSetup(request, this.options.newBotApproval?.());
for (const { id, profile } of before) {
const bot = this.options.store.bot(id);
if (bot) recordProfileChange(id, actor, via, profile, profileSnapshot(bot));