Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
share: leave switched-off skills out of bot and department templates
AdityaUmale35291b02c4ac
diff --git a/docs/team-sharing.md b/docs/team-sharing.mdindex d0d7e2476b..d9429a1612 100644--- a/docs/team-sharing.md+++ b/docs/team-sharing.md@@ -16,7 +16,7 @@ A bot or a whole department can be shared as a **template**: a small folder anyo```<name>/bot.md or team.md the bots, their instructions, group chats, the Chief, routines and apps by name- skills/<name>/SKILL.md every skill, as standard Agent Skills+ skills/<name>/SKILL.md every switched-on skill, as standard Agent Skillsskills/<name>/<path> the scripts and other text files beside a skill, named in bot.md's skillFilesavatars/<key>.webp pictures, at most 64 KB each```@@ -26,8 +26,9 @@ agent can follow when the file is pasted in. Older files (BotMRR v1 Markdown, `timport.Never in a template: chats, memory, keys, passwords, tokens, connection addresses, models, approval levels, folders,-computers or who may see a bot. Every text is checked for key- and password-shaped values, which are replaced; the card-says how many. Routines always arrive paused, and each app is connected with the new owner's own account.+computers or who may see a bot. A switched-off skill stays on its bot, named on the card under "Left out". Every text+is checked for key- and password-shaped values, which are replaced; the card says how many. Routines always arrive+paused, and each app is connected with the new owner's own account.**A skill's scripts travel with it** (`shared/skill-files.ts`): the files that came in with the skill, only those itsrecord lists and only while they are unchanged, never anything a run left beside it. Text files only, at most 30 perdiff --git a/server/package-export.ts b/server/package-export.tsindex 73c412c2dd..1b5c0a0f65 100644--- a/server/package-export.ts+++ b/server/package-export.ts@@ -277,6 +277,7 @@ export type TeamExportSkipReason =| "skill_conflict"| "bot_skill_limit"| "team_skill_limit"+ | "skill_off"| "preset_empty"| "preset_skill_conflict";diff --git a/server/share.e2e.test.ts b/server/share.e2e.test.tsindex 7eee0eb2c3..d1fbd41196 100644--- a/server/share.e2e.test.ts+++ b/server/share.e2e.test.ts@@ -84,6 +84,8 @@ describe("templates on a throwaway server", () => {});expect(seeded.status, JSON.stringify(seeded.body)).toBe(201);const bot = seeded.body.bots[0];+ // Skills from a template arrive switched off, and a template carries only switched-on ones.+ expect((await api("PATCH", `/api/bots/${bot.id}/skills/pricing`, { enabled: true })).status).toBe(200);expect((await api("PATCH", `/api/bots/${bot.id}`, { soul: `Quote from the list. The billing key is ${KEY}.\n${PRIVATE_LINE}\n` })).status).toBe(200);expect((await api("PUT", `/api/bots/${bot.id}/memory`, { text: `# Memory\n- ${MEMORY_MARKER}\n` })).status).toBe(200);const mcp = await api("POST", "/api/mcp/servers", { name: "crm", type: "http", url: `https://crm.example.com/mcp/${MCP_TOKEN}` });diff --git a/server/share.test.ts b/server/share.test.tsindex c4395e2156..c20a791a14 100644--- a/server/share.test.ts+++ b/server/share.test.ts@@ -12,6 +12,7 @@ import { createShareToolRoute, importSource, type ShareToolContext } from "./rouimport { GithubTemplateError } from "./share-github.ts";import { createCommunityPublisher, type CommunityResult } from "./share-publish.ts";import { pagesHomeSignature } from "./pages/access.ts";+import type { ExportablePackageSkill } from "./package-export.ts";import { createShareHost, creditName, readFolderFromDisk } from "./share.ts";import type { Routine } from "./routines.ts";import type { BotRecord } from "./store.ts";@@ -42,14 +43,15 @@ const routine = { id: "r1", name: "Morning sweep", botId: "bot-1", prompt: "Sweeconst clean = (overrides: Partial<BotRecord> = {}) => bot({ soul: "Be brief.", ...overrides });function host(options: { submit?: (submission: unknown) => Promise<CommunityResult>; signedIn?: boolean; bots?: BotRecord[]; picture?: (bot: BotRecord) => string | undefined; brief?: string;- personNames?: Array<string | undefined>; suggestedCredit?: string } = {}) {+ personNames?: Array<string | undefined>; suggestedCredit?: string; skills?: ExportablePackageSkill[] } = {}) {const dataDir = scratch(), botFolder = scratch();const patches: Array<{ messageId: string; card: TemplateCard }> = [];const bots = options.bots ?? [bot()];const publisher = createCommunityPublisher({ access: () => options.signedIn === false ? null : { kind: "desktop", url: "https://admin.example.com/api/cloud/pages/token", token: "t" } });const share = createShareHost({dataDir, bots: () => bots, groups: () => [], routines: () => [routine], brief: () => options.brief,- collectTeamSkills: (list) => ({ ok: true, skipped: [], skillsByBot: new Map(list.map((each) => [each.id, [{ name: "triage", description: "Sort the inbox.", instructions: skillText, enabled: true }]])) }),+ collectTeamSkills: (list) => ({ ok: true, skipped: [], skillsByBot: new Map(list.map((each) => [each.id,+ (options.skills ?? [{ name: "triage", description: "Sort the inbox.", instructions: skillText, enabled: true }]).map((skill) => ({ ...skill }))])) }),picture: options.picture ?? (() => undefined), botFolder: (id) => join(botFolder, id),publisher: options.submit ? { ...publisher, submit: options.submit } : publisher,patch: (_threadId, messageId, _text, card) => patches.push({ messageId, card }),@@ -96,6 +98,34 @@ describe("making a template", () => {expect(share.get(titled.card.id).details.summary).toBe("Keeps the inbox tidy.");});+ it("leaves a switched-off skill out of a bot's and a department's template and names it under Left out", () => {+ const off = "---\nname: drafts\ndescription: Old drafts.\n---\n\n# Drafts\n\nRead C:/Users/janedoe/Documents/drafts first.\n";+ const skills = [+ { name: "triage", description: "Sort the inbox.", instructions: skillText, enabled: true },+ { name: "drafts", description: "Old drafts.", instructions: off, enabled: false },+ ];+ const { share } = host({ skills });+ for (const [target, part] of [[{ scope: "bot" as const, bot: bot() }, "skills[drafts]"], [{ scope: "department" as const, section: "Ops", bots: [bot()] }, "Helper: skills[drafts]"]] as const) {+ const made = share.export(target, []);+ expect(made.card.counts.skills).toBe(1);+ expect(made.card.skipped).toContain(`skills switched off on the bot (${part})`);+ expect(existsSync(join(made.dir, "skills", "triage", "SKILL.md"))).toBe(true);+ expect(existsSync(join(made.dir, "skills", "drafts"))).toBe(false);+ expect(JSON.stringify(share.get(made.card.id).details)).not.toMatch(/drafts|janedoe/);+ }+ });++ it("keeps every switched-on skill, and a skill with no switch, in the template", () => {+ const { share } = host({ skills: [+ { name: "triage", description: "Sort the inbox.", instructions: skillText, enabled: true },+ { name: "notes", description: "Keep notes.", instructions: "---\nname: notes\ndescription: Keep notes.\n---\n\nWrite to C:/Users/janedoe/notes.md.\n" },+ ] });+ const made = share.export({ scope: "bot", bot: bot() }, []);+ expect(made.card.counts.skills).toBe(2);+ expect(made.card.skipped).not.toEqual(expect.arrayContaining([expect.stringContaining("switched off")]));+ expect(readFileSync(join(made.dir, "skills", "notes", "SKILL.md"), "utf8")).toContain("Write to ~/notes.md.");+ });+it("makes the same template again in the same folder and keeps its card", () => {const { share } = host();const first = share.export({ scope: "bot", bot: bot() }, [routine]);diff --git a/server/share.ts b/server/share.tsindex 6df7410139..75b6d298fa 100644--- a/server/share.ts+++ b/server/share.ts@@ -99,6 +99,7 @@ const SKIP_WORDS: Record<string, string> = {picture_too_large: "a picture over 64 KB", picture_invalid: "a picture that couldn't be read", files_not_shared: "files attached to a routine",lead_not_in_group_chat: "a group chat goal whose lead isn't in the chat", skill_changed: "a skill that changed while it was being shared",skill_conflict: "a skill two bots have in different versions", bot_skill_limit: "skills past a bot's limit", team_skill_limit: "skills past the department's limit",+ skill_off: "skills switched off on the bot",};/** The line a template gets when its bot or department has no words of its own; a card leaves it out. */const plainTagline = (scope: TemplateScope) => `A ${scope === "bot" ? "bot" : "department"} shared from ${productName()}.`;@@ -363,6 +364,13 @@ export function createShareHost(deps: ShareHostDeps) {if (!bots.length) throw new ShareError("This department has no bots to share.");const skills = deps.collectTeamSkills(bots, "all");if (!skills.ok) throw new ShareError(skills.error);+ const skipped = [...skills.skipped];+ for (const bot of bots) {+ const list = skills.skillsByBot.get(bot.id) ?? [];+ const where = target.scope === "bot" ? "" : `${bot.name}: `;+ for (const skill of list) if (skill.enabled === false) skipped.push({ part: `${where}skills[${skill.name}]`, reason: "skill_off" });+ skills.skillsByBot.set(bot.id, list.filter((skill) => skill.enabled !== false));+ }const fileSkips = new Set<string>();for (const bot of bots) {for (const skill of skills.skillsByBot.get(bot.id) ?? []) {@@ -401,7 +409,7 @@ export function createShareHost(deps: ShareHostDeps) {skillSelection: "all",avatars,mcpServers: {},- skipped: skills.skipped,+ skipped,// Connections never travel in a template, so a key in one doesn't keep it from being published.beforeRedaction: (definition) => { credential = scrubTree({ ...definition, connections: undefined }).counts.secrets > 0; },});