Skip to content

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

fix(moves): a later Chief-only pass doesn't crown the arriving MausBot

AdityaUmalea9b35b8b7c05
diff --git a/electron/cloud-send-kinds.mjs b/electron/cloud-send-kinds.mjs
index f7e0ad9939..842a4758be 100644
--- a/electron/cloud-send-kinds.mjs
+++ b/electron/cloud-send-kinds.mjs
@@ -121,7 +121,7 @@ export function createMoveKinds({ localJson, localBytes, localSend, entry, persi
const held = await localJson(`/api/cloud-send/kind?key=${encodeURIComponent(`bot:${botId}`)}`);
const fields = Object.fromEntries(names.map((name) => [name, record(held?.record) && held.record[name] !== undefined ? held.record[name] : null]));
const answer = await ctx.session.call("PUT", "/api/cloud-send/kind", { v: 1, key: `bot:${botId}`, dataDir: held?.dataDir ?? "-", record: fields,
- ...(typeof held?.computer === "string" && held.computer ? { computer: held.computer } : {}) });
+ ...(typeof held?.computer === "string" && held.computer ? { computer: held.computer } : {}), ...(record(held?.record) && held.record.defaultBot ? { sourceDefault: true } : {}) });
return answer.ok ? {} : Object.fromEntries(parts.filter((part) => MOVE_BOT_PARTS[part]).map((part) => [part, refusal(answer, "My Cloud refused this setting.")]));
}
diff --git a/server/cloud-send-kinds.ts b/server/cloud-send-kinds.ts
index 4a4071f572..cc947dcd45 100644
--- a/server/cloud-send-kinds.ts
+++ b/server/cloud-send-kinds.ts
@@ -266,7 +266,7 @@ const librarySkillSchema = z.object({ text: z.string().max(512 * 1024), entry: z
/** My Cloud sets a bot's move-only fields as they are on this computer: absent ones it clears, its own projects it keeps
* beside the ones that arrive, and an engine, team or library skill it lacks it leaves out. */
-function applyBotFields(deps: MoveKindsDeps, id: string, raw: unknown, computer?: string): void {
+function applyBotFields(deps: MoveKindsDeps, id: string, raw: unknown, source: ArrivingSource = {}): void {
const bot = deps.store.bot(id) ?? refuse(409, "This bot is not on My Cloud yet.");
const parsed = botFieldsSchema.safeParse(raw);
if (!parsed.success) refuse(400, "send the bot's fields as this computer holds them");
@@ -293,12 +293,13 @@ function applyBotFields(deps: MoveKindsDeps, id: string, raw: unknown, computer?
if (Object.hasOwn(fields, "chiefOfStaff") && fields.chiefOfStaff !== true) patch.chiefOfStaff = fields.chiefOfStaff ?? undefined;
if (fields.chiefOfStaff === true) delete patch.hidden;
deps.store.patchBot(id, patch);
- // A MausBot arriving where the person's own MausBot stays (takeArrivingDefaultBot) doesn't take that one's crown.
- if (fields.chiefOfStaff === true && !(fields.defaultBot && keptDefaultBot(deps.store, id)?.chiefOfStaff)) {
+ // A MausBot arriving where the person's own MausBot stays (takeArrivingDefaultBot) doesn't take that one's crown, also
+ // when a later pass sends its Chief fields without its MausBot mark (`source.defaultBot`).
+ if (fields.chiefOfStaff === true && !((fields.defaultBot || source.defaultBot) && keptDefaultBot(deps.store, id)?.chiefOfStaff)) {
deps.store.setChiefOfStaff(id);
if (patch.managedSections) deps.store.patchBot(id, { managedSections: patch.managedSections });
}
- if (fields.defaultBot) takeArrivingDefaultBot(deps.store, id, computer);
+ if (fields.defaultBot) takeArrivingDefaultBot(deps.store, id, source.computer);
retireUnusedStarter(deps.store, deps.dataDir);
}
@@ -328,10 +329,10 @@ function adoptRoutine(deps: MoveKindsDeps, raw: unknown, runs: unknown, from: st
deps.arrived?.();
}
-async function adopt(deps: MoveKindsDeps, kind: Kind, id: string, raw: unknown, runs: unknown, from: string, owner: CloudOwner, computer?: string): Promise<void> {
+async function adopt(deps: MoveKindsDeps, kind: Kind, id: string, raw: unknown, runs: unknown, from: string, owner: CloudOwner, source: ArrivingSource = {}): Promise<void> {
if (!record(raw) && kind !== "bot") refuse(400, "send the item's record");
const same = (value: unknown) => record(value) && (value.id === undefined || value.id === id);
- if (kind === "bot") return applyBotFields(deps, id, raw, computer);
+ if (kind === "bot") return applyBotFields(deps, id, raw, source);
if (kind === "routine") return adoptRoutine(deps, raw, runs, from, owner);
if (!same(raw) && kind !== "imported-skill" && kind !== "library-skill") refuse(400, "the record names another item");
if (kind === "call") {
@@ -379,7 +380,10 @@ async function adopt(deps: MoveKindsDeps, kind: Kind, id: string, raw: unknown,
}
const putSchema = z.object({ v: z.literal(1), key: z.string().max(200), dataDir: z.string().min(1).max(4096), record: z.unknown(), runs: z.array(z.unknown()).max(2_000).optional(),
- computer: z.string().max(120).optional() });
+ computer: z.string().max(120).optional(), sourceDefault: z.boolean().optional() });
+
+/** What the computer a bot comes from says of it: its name, and whether the bot is the MausBot there. */
+type ArrivingSource = { computer?: string; defaultBot?: boolean };
/** This computer's name as a person knows it, which a MausBot that moves away is named for when the place it goes keeps its own. */
function thisComputerName(): string {
@@ -404,7 +408,7 @@ export async function moveKindsRoute(deps: MoveKindsDeps, { req, res, path, meth
const body = putSchema.safeParse(await readBody(req, KIND_BODY_MAX));
const key = body.success ? parseKey(body.data.key) : null;
if (!body.success || !key) { json(res, 400, { error: "send { v: 1, key, dataDir, record }" }); return true; }
- await adopt(deps, key.kind, key.id, body.data.record, body.data.runs, body.data.dataDir, owner, body.data.computer);
+ await adopt(deps, key.kind, key.id, body.data.record, body.data.runs, body.data.dataDir, owner, { computer: body.data.computer, defaultBot: body.data.sourceDefault });
json(res, 200, { v: 1, ok: true });
return true;
}
diff --git a/server/default-bot.test.ts b/server/default-bot.test.ts
index 2aeb25837e..256ff7491a 100644
--- a/server/default-bot.test.ts
+++ b/server/default-bot.test.ts
@@ -254,11 +254,11 @@ describe("MausBot, every person's helper", () => {
const OWNER = { person: "p_owner0000000000000000", name: "Amit" };
const deps = (store: Store): MoveKindsDeps => ({ dataDir: DATA_DIR, store, routines: () => null, calls: () => null, webhooks: () => null, appEvents: () => null,
claudeCodeSkills: () => [], instanceExists: () => true, owner: () => OWNER, ownRoutine: () => {} } as unknown as MoveKindsDeps);
- async function arrive(store: Store, id: string, record: Record<string, unknown>, computer?: string) {
+ async function arrive(store: Store, id: string, record: Record<string, unknown>, computer?: string, extra: Record<string, unknown> = {}) {
let status = 0;
await moveKindsRoute(deps(store), { path: "/api/cloud-send/kind", method: "PUT", url: new URL("http://127.0.0.1/api/cloud-send/kind"), auth: {} as never, req: {} as never,
res: { setHeader() {} } as never, json: ((_res: unknown, code: number) => { status = code; }) as never,
- readBody: (async () => ({ v: 1, key: `bot:${id}`, dataDir: "/Users/amit/.openmausbot", record, ...(computer ? { computer } : {}) })) as never });
+ readBody: (async () => ({ v: 1, key: `bot:${id}`, dataDir: "/Users/amit/.openmausbot", record, ...(computer ? { computer } : {}), ...extra })) as never });
return status;
}
const fields = (bot: Record<string, unknown>) => Object.fromEntries(MOVE_BOT_FIELDS.map((name) => [name, bot[name] ?? null]));
@@ -315,7 +315,14 @@ describe("MausBot, every person's helper", () => {
const chief = cloud.createBot({ name: "MausBot" }, { id: "desk-maus-000006", seedMessages: false });
expect(await arrive(cloud, chief.id, fields({ defaultBot: {}, chiefOfStaff: true }), "Amit's MacBook")).toBe(200);
expect(cloud.bots.filter((bot) => bot.chiefOfStaff).map((bot) => bot.id)).toEqual([theirs.id]);
+ // Nor on a later pass that sends only its Chief fields: the computer it comes from says it is the MausBot there.
+ expect(await arrive(cloud, chief.id, { chiefOfStaff: true, managedSections: ["General"] }, "Amit's MacBook", { sourceDefault: true })).toBe(200);
+ expect(cloud.bots.filter((bot) => bot.chiefOfStaff).map((bot) => bot.id)).toEqual([theirs.id]);
expect(placeMausBots(cloud).map((bot) => bot.id)).toEqual([theirs.id]);
+ // A Chief that is not a MausBot still takes the crown, as before.
+ const ada = cloud.createBot({ name: "Ada" }, { id: "desk-ada-000007", seedMessages: false });
+ expect(await arrive(cloud, ada.id, { chiefOfStaff: true }, "Amit's MacBook")).toBe(200);
+ expect(cloud.bots.filter((bot) => bot.chiefOfStaff).map((bot) => bot.id)).toEqual([ada.id]);
});
it("keeps a used MausBot here and leaves a renamed arriving one its own name, or names an unknown computer plainly", async () => {