Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Skills at the start of text run only from the person's own line or the owner's routine
milind-sonife9b7310635f
diff --git a/electron/diagnostics.mjs b/electron/diagnostics.mjsindex 6773ba2adc..69b6729d92 100644--- a/electron/diagnostics.mjs+++ b/electron/diagnostics.mjs@@ -23,6 +23,7 @@ export const CREDENTIAL_ENV_NAMES = ["OPENCODE_API_KEY","OMB_TTS_KEY","OMB_FISH_AUDIO_API_KEY",+ "OMB_GEMINI_API_KEY","OMB_JEV_API_KEY","OMB_OPENROUTER_DECIDER_KEY","OMB_WORKERS_AI_TOKEN",diff --git a/server/host/skills-library.ts b/server/host/skills-library.tsindex 89646b08f1..d1f052cab2 100644--- a/server/host/skills-library.ts+++ b/server/host/skills-library.ts@@ -257,9 +257,9 @@ export function createSkillsLibraryHost(deps: SkillsLibraryHostDeps) {/** Each `/name` called for one of the bot's own, library or imported skills, or one its engine loads by itself. `lines`* are the turn's own lines when it is a person's turn: only words they typed can call a skill past the start of the text. */- expandSkillCommand(bot: BotRecord, threadId: string, text: string, instance?: TurnInstance, lines: ReadonlyArray<{ sendId?: string; text?: string }> = []): string {+ expandSkillCommand(bot: BotRecord, threadId: string, text: string, instance?: TurnInstance, lines: ReadonlyArray<{ sendId?: string; text?: string }> = [], ownStart = false): string {const typed = typedWords(threadId, lines);- const mentioned = skillCalls(text, typed);+ const mentioned = skillCalls(text, typed, ownStart);if (!mentioned.length) return text;const assigned = skillsLibraryEnabled(cfg) ? liveAssigned(bot) : undefined;const files = enabledSkillFiles(bot.id, mentioned, assigned);@@ -273,7 +273,7 @@ export function createSkillsLibraryHost(deps: SkillsLibraryHostDeps) {.filter((skill) => !skill.enabled).map((skill) => skill.name));add(nativesFor(bot, threadId, instance).filter((skill) => !switched.has(skill.name)));}- return skillCommandTurnText(text, files, typed);+ return skillCommandTurnText(text, files, typed, ownStart);},shareNote(bot: BotRecord, threadId: string, enabled: boolean): TurnShareNote {diff --git a/server/imported-skills.test.ts b/server/imported-skills.test.tsindex 80df17c6d7..ad7e7561eb 100644--- a/server/imported-skills.test.ts+++ b/server/imported-skills.test.ts@@ -61,7 +61,7 @@ describe("skills brought in from this computer", () => {expect(prompt).toContain("Skills from this computer:");expect(prompt).toContain(`- pdf: Works with pdf. Read ${JSON.stringify(join(IMPORTED_SKILLS_DIR, "pdf", "SKILL.md"))}.`);const files = new Map(skills.map((skill) => [skill.name, skill.file]));- expect(skillCommandTurnText("/review the diff", files)).toContain(`Read ${JSON.stringify(join(IMPORTED_SKILLS_DIR, "review", "SKILL.md"))}`);+ expect(skillCommandTurnText("/review the diff", files, "", true)).toContain(`Read ${JSON.stringify(join(IMPORTED_SKILLS_DIR, "review", "SKILL.md"))}`);expect(skillCommandTurnText("/other thing", files)).toBe("/other thing");const folder = ensureTaskWorkspaceWithSkills(bot, "thread-1", skills);for (const family of [".claude", ".agents", ".grok"]) {@@ -186,8 +186,8 @@ describe("skills brought in from this computer", () => {// The same set: listed in Bot Settings, readable, and run by /name.expect(host.listBotSkills(record).map((skill) => skill.name)).toEqual(["zeta-own", ...many.map((one) => one.name)]);expect(host.readBotSkillFile(record, "skill-03")).toBe(skillMd("skill-03"));- expect(host.expandSkillCommand(record, "thread", "/skill-03 go", { instanceId: "claude", driverKind: "claudeAgent" })).toContain(`Read ${JSON.stringify(join(IMPORTED_SKILLS_DIR, "skill-03", "SKILL.md"))}`);- expect(host.expandSkillCommand(record, "thread", "/zeta-own go")).toContain(JSON.stringify(join("workspaces", bot, "skills", "zeta-own", "SKILL.md")).slice(1, -1));+ expect(host.expandSkillCommand(record, "thread", "/skill-03 go", { instanceId: "claude", driverKind: "claudeAgent" }, [], true)).toContain(`Read ${JSON.stringify(join(IMPORTED_SKILLS_DIR, "skill-03", "SKILL.md"))}`);+ expect(host.expandSkillCommand(record, "thread", "/zeta-own go", undefined, [], true)).toContain(JSON.stringify(join("workspaces", bot, "skills", "zeta-own", "SKILL.md")).slice(1, -1));// One message reaches both kinds, whichever comes first.const sendId = randomUUID();const typed = "Two things: /skill-03 the diff, /zeta-own after it";diff --git a/server/index.ts b/server/index.tsindex f01af72454..8d66da0e6f 100644--- a/server/index.ts+++ b/server/index.ts@@ -3819,7 +3819,7 @@ const threadReadableFrom = (threadId: string) => (other: string): boolean => !prconst queuedStatus = createQueuedReason({ botName: (id) => store.bot(id)?.name, threadBusy, groupTurn: (id) => Boolean(activeGroupTurnForBot(id)), behindPerson: queuedBehindPerson,waitsForComputer: (node) => { const seat = parkedSeats.get(node.id); return Boolean(seat && !turnResources.free(seat)); },slots: (id) => ({ busy: store.tasks(id).filter((task) => threadBusy(id, task.threadId)).map(({ threadId, title }) => ({ threadId, title })), limit: maxConcurrentChildThreads(cfg, botThreadsHost(cloudPlanTier.starter())) }) });-const teammatePrompts = createTeammatePrompts({ store, outstandingDirect: (threadId) => coordinator.outstandingDirect(threadId), openPersonCard, queuedStatus, isUnattended, fullAccess: fullAccessForSource, startedOutside: (threadId) => directRequestOwners.get(threadId)?.origin?.kind === "outside" || coordinator.active().some((node) => node.threadId === threadId && node.origin?.kind === "outside"), guestDriven: cloudGuestDriven, confined: (threadId) => proactive.fence.confines(threadId), readableFrom: threadReadableFrom, waitingForPerson: (chief, teammates, readable) => questionRouting.waitingForPerson(chief, teammates, readable) });+const teammatePrompts = createTeammatePrompts({ store, outstandingDirect: (threadId) => coordinator.outstandingDirect(threadId), openPersonCard, queuedStatus, isUnattended, fullAccess: fullAccessForSource, startedOutside, guestDriven: cloudGuestDriven, confined: (threadId) => proactive.fence.confines(threadId), readableFrom: threadReadableFrom, waitingForPerson: (chief, teammates, readable) => questionRouting.waitingForPerson(chief, teammates, readable) });function queuedBehindPerson(node: HandoffView): { threadId: string; kind: "approval" | "question" | "review"; title: string } | undefined {if (node.groupId || node.status !== "queued" || threadBusy(node.botId, node.threadId) || !botAtThreadCapacity(node.botId, undefined, true)) return undefined;@@ -5618,6 +5618,8 @@ function markUnattended(botId: string, threadId: string) {function clearUnattended(threadId: string) {unattendedThreads.delete(threadId);}+/** Work an outside event started (a webhook, an app, another bot): it never uses the person's own computer unasked. */+function startedOutside(threadId: string): boolean { return directRequestOwners.get(threadId)?.origin?.kind === "outside" || coordinator.active().some((node) => node.threadId === threadId && node.origin?.kind === "outside"); }function isUnattended(botId?: string | null, threadId?: string): boolean {if (!botId) return false;if (!threadId) return [...unattendedThreads].some(([id, mark]) => mark.botId === botId && isUnattended(botId, id));@@ -7952,7 +7954,7 @@ async function beginTurn(const plannedConfig = sessionConfig(bot.soul);const skillAuthoring = skillAuthoringEnabled(cfg) && agentsMounted;const skillCommandText = supportsWorkspaceFiles(instance.driverKind)- ? skillsHost.expandSkillCommand(bot, threadId, providerText, instance, personLine ? activeMessages.filter((line) => skipTranscript.has(line.id)) : [])+ ? skillsHost.expandSkillCommand(bot, threadId, providerText, instance, personLine ? activeMessages.filter((line) => skipTranscript.has(line.id)) : [], (personLine && !userMessage.relayed && !startedOutside(threadId)) || ["schedule", "manual", "startup"].includes(opts?.automationSource ?? "")): providerText;const setupText = agentsMounted ? expandSetupTurnText(skillCommandText) : skillCommandText;const userTurnText = (opts?.app?.context ?? "") + (opts?.cardContinuation ? "" : routineRunNote(threadId, opts?.automationSource)) + labelledLine(personLine && !opts?.excludeMessageIds ? userMessage : {}, withReactionNotes(promptWithReply(diff --git a/server/native-skills.test.ts b/server/native-skills.test.tsindex 3e61a8f762..1ff197593f 100644--- a/server/native-skills.test.ts+++ b/server/native-skills.test.ts@@ -65,9 +65,9 @@ describe("skills the engine loads by itself", () => {expect(host.listBotSkills(bot).find((skill) => skill.name === "no-frontmatter")?.description).toBe("Just do the thing.");expect(host.listBotSkills(bot).find((skill) => skill.name === "bot-notes")).toMatchObject({ enabled: true, editable: false });expect(host.readBotSkillFile(bot, "growth-data-expert")).toBe(skillMd("growth-data-expert"));- expect(host.expandSkillCommand(bot, "main", "/growth-data-expert find churn")).toContain(`Read ${JSON.stringify(shared)}`);- expect(host.expandSkillCommand(bot, "main", "/bot-notes")).toContain(`Read ${JSON.stringify(own)}`);- expect(host.expandSkillCommand(bot, "main", "/mine go")).toContain(JSON.stringify(join("workspaces", bot.id, "skills", "mine")).slice(1, -1));+ expect(host.expandSkillCommand(bot, "main", "/growth-data-expert find churn", undefined, [], true)).toContain(`Read ${JSON.stringify(shared)}`);+ expect(host.expandSkillCommand(bot, "main", "/bot-notes", undefined, [], true)).toContain(`Read ${JSON.stringify(own)}`);+ expect(host.expandSkillCommand(bot, "main", "/mine go", undefined, [], true)).toContain(JSON.stringify(join("workspaces", bot.id, "skills", "mine")).slice(1, -1));});it("run mid-message from what a person typed, alongside the bot's own, and stay off when switched off", () => {@@ -85,7 +85,7 @@ describe("skills the engine loads by itself", () => {const both = typed("find churn with /growth-data-expert, then /mine");expect(both).toContain("ran 2 of your skills with /growth-data-expert, /mine");expect(both).toContain(`${JSON.stringify(shared)} for /growth-data-expert`);- expect(both).toMatch(new RegExp(`workspaces.${bot.id}.skills.mine.SKILL\\.md" for /mine`));+ expect(both).toMatch(new RegExp(`workspaces[\\\\/]+${bot.id}[\\\\/]+skills[\\\\/]+mine[\\\\/]+SKILL\\.md" for /mine`));expect(both).toContain("Request: find churn with /growth-data-expert, then /mine");expect(typed("Skip it, /mine-off")).toBe("Skip it, /mine-off");expect(host.expandSkillCommand(bot, "main", "find churn with /growth-data-expert")).toBe("find churn with /growth-data-expert");@@ -108,7 +108,7 @@ describe("skills the engine loads by itself", () => {plant(SHARED, "mine");installSkill(bot.id, "local", [{ path: "SKILL.md", content: skillMd("mine") }]);expect(listed(host.listBotSkills(bot))).toEqual(["mine:own"]);- expect(host.expandSkillCommand(bot, "main", "/mine go")).toBe("/mine go");+ expect(host.expandSkillCommand(bot, "main", "/mine go", undefined, [], true)).toBe("/mine go");});it("come from the folder a thread really works in, up to its git root", () => {@@ -122,12 +122,12 @@ describe("skills the engine loads by itself", () => {const project = hostFor("claudeAgent", { cwd: join(repo, "app") });expect(listed(project.host.listBotSkills(project.bot))).toEqual(["repo-skill:native"]);const pinned = hostFor("claudeAgent", { threadCwd: repo });- expect(pinned.host.expandSkillCommand(pinned.bot, "pinned", "/repo-skill")).toContain("repo-skill");+ expect(pinned.host.expandSkillCommand(pinned.bot, "pinned", "/repo-skill", undefined, [], true)).toContain("repo-skill");expect(listed(pinned.host.listBotSkills(pinned.bot, "pinned"))).toEqual(["repo-skill:native"]);expect(listed(pinned.host.listBotSkills(pinned.bot))).toEqual(["task-folder-skill:native"]);- expect(pinned.host.expandSkillCommand(pinned.bot, "main", "/repo-skill")).toBe("/repo-skill");+ expect(pinned.host.expandSkillCommand(pinned.bot, "main", "/repo-skill", undefined, [], true)).toBe("/repo-skill");const none = hostFor("claudeAgent", { threadCwd: null });- expect(none.host.expandSkillCommand(none.bot, "pinned", "/task-folder-skill")).toBe("/task-folder-skill");+ expect(none.host.expandSkillCommand(none.bot, "pinned", "/task-folder-skill", undefined, [], true)).toBe("/task-folder-skill");});it.skipIf(process.platform === "win32")("never read a SKILL.md that is itself a link", () => {@@ -136,7 +136,7 @@ describe("skills the engine loads by itself", () => {symlinkSync(plant(join(DATA_DIR, "elsewhere"), "secret"), join(SHARED, "linked", "SKILL.md"));expect(host.listBotSkills(bot)).toEqual([]);expect(host.readBotSkillFile(bot, "linked")).toBeNull();- expect(host.expandSkillCommand(bot, "main", "/linked go")).toBe("/linked go");+ expect(host.expandSkillCommand(bot, "main", "/linked go", undefined, [], true)).toBe("/linked go");});it("include ~/.claude/skills only with \"Also use my Claude Code skills\", and no task folders for other engines", () => {@@ -148,9 +148,9 @@ describe("skills the engine loads by itself", () => {expect(listed(off.host.listBotSkills(off.bot))).toEqual(["both:native", "shared-one:native"]);const on = hostFor("claudeAgent", { cfg: { features: { claudeUserSkills: true } } as AppConfig });expect(listed(on.host.listBotSkills(on.bot))).toEqual(["both:native", "personal-one:native", "shared-one:native"]);- expect(on.host.expandSkillCommand(on.bot, "main", "/both")).toContain(`Read ${JSON.stringify(personal)}`);+ expect(on.host.expandSkillCommand(on.bot, "main", "/both", undefined, [], true)).toContain(`Read ${JSON.stringify(personal)}`);const other = hostFor("geminiAgent", { cfg: { features: { claudeUserSkills: true } } as AppConfig });expect(listed(other.host.listBotSkills(other.bot))).toEqual([]);- expect(other.host.expandSkillCommand(other.bot, "main", "/shared-one")).toBe("/shared-one");+ expect(other.host.expandSkillCommand(other.bot, "main", "/shared-one", undefined, [], true)).toBe("/shared-one");});});diff --git a/server/skill-command.test.ts b/server/skill-command.test.tsindex f40aea8a6d..9d09cb95ad 100644--- a/server/skill-command.test.ts+++ b/server/skill-command.test.ts@@ -19,7 +19,7 @@ const host = createSkillsLibraryHost({appendSkillRequestCard: () => ({ requestId: "", summary: "" }),});type Line = { sendId?: string; text?: string };-const expand = (bot: string, text: string, lines?: Line[]) => host.expandSkillCommand({ id: bot } as BotRecord, "thread", text, undefined, lines);+const expand = (bot: string, text: string, lines?: Line[], ownStart = false) => host.expandSkillCommand({ id: bot } as BotRecord, "thread", text, undefined, lines, ownStart);function typedLine(text: string, threadId = "thread"): Line {const sendId = randomUUID();noteTypedSend(threadId, sendId, text);@@ -122,13 +122,19 @@ describe("skills in text no person typed", () => {expect(expand(bot, words, [{ sendId: randomUUID(), text: words }])).toBe(words);});- it("run only the one at the very start, as they always have", () => {+ it("run only the one at the very start, and only when that start is the person's own line or the owner's routine", () => {const bot = botWith("review", true, botWith("standup"));- const text = expand(bot, "/standup the work, then /review it");+ const text = expand(bot, "/standup the work, then /review it", undefined, true);expect(text).toContain("The user ran your standup skill with /standup.");expect(text).toContain("Request: the work, then /review it");- expect(skillCalls("/standup the work, then /review it", "")).toEqual(["standup"]);- expect(skillCalls("[A note]\n/standup the work", "")).toEqual([]);+ expect(skillCalls("/standup the work, then /review it", "", true)).toEqual(["standup"]);+ expect(skillCalls("[A note]\n/standup the work", "", true)).toEqual([]);+ });++ it("stay plain words at the very start of a webhook's, a relay's or another bot's text", () => {+ const bot = botWith("standup");+ expect(expand(bot, "/standup the work")).toBe("/standup the work");+ expect(skillCalls("/standup the work", "")).toEqual([]);});it("cannot borrow a person's send for other words or another conversation", () => {diff --git a/server/skills-library.test.ts b/server/skills-library.test.tsindex 946ed71179..7f14f401e4 100644--- a/server/skills-library.test.ts+++ b/server/skills-library.test.ts@@ -142,10 +142,10 @@ describe("skills library store", () => {const on = hostWith({ features: { skillsLibrary: true } } as AppConfig);expect(on.skillsIndex(record, "main")).toContain(name);expect(on.skillsIndex(record, undefined)).toContain(name);- expect(on.expandSkillCommand(record, "main", `/${name}`)).toContain(`ran your ${name} skill`);+ expect(on.expandSkillCommand(record, "main", `/${name}`, undefined, [], true)).toContain(`ran your ${name} skill`);const off = hostWith({} as AppConfig);expect(off.skillsIndex(record, "main")).not.toContain(name);- expect(off.expandSkillCommand(record, "main", `/${name}`)).toBe(`/${name}`);+ expect(off.expandSkillCommand(record, "main", `/${name}`, undefined, [], true)).toBe(`/${name}`);} finally {library.setLibrarySkillEveryBot(name, false);}diff --git a/shared/skill-command.ts b/shared/skill-command.tsindex e682820789..d96862a04f 100644--- a/shared/skill-command.ts+++ b/shared/skill-command.ts@@ -98,17 +98,18 @@ export function skillMentions(text: string): string[] {/*** The skills a turn calls. Security invariant: `typed` holds only words a person wrote themselves, and it is the one place* past the very start of the text that can call a skill. A webhook's payload and another bot's message reach the engine- * after a note saying who they are from, so the start of `text` is never theirs.+ * after a note saying who they are from. `ownStart`: whether the start of `text` is the person's own line or the owner's+ * routine; a relayed, outside or bot-written start names no skill.*/-export function skillCalls(text: string, typed: string): string[] {- const leading = LEADING_COMMAND.exec(text.trimStart())?.[1];+export function skillCalls(text: string, typed: string, ownStart = false): string[] {+ const leading = ownStart ? LEADING_COMMAND.exec(text.trimStart())?.[1] : undefined;return [...new Set([...(leading && offersSkillCommand(leading) ? [leading] : []), ...skillMentions(typed)])];}/** What the engine reads for a message that ran skills with `/name`: which SKILL.md to read and follow, then the* request. `files` maps each skill the bot has to its SKILL.md; any other `/word` stays plain text. */-export function skillCommandTurnText(text: string, files: ReadonlyMap<string, string>, typed = ""): string {- const names = skillCalls(text, typed).filter((name) => files.has(name));+export function skillCommandTurnText(text: string, files: ReadonlyMap<string, string>, typed = "", ownStart = false): string {+ const names = skillCalls(text, typed, ownStart).filter((name) => files.has(name));if (!names.length) return text;const read = (name: string) => JSON.stringify(files.get(name));const lead = names.length === 1