Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Skill removal and opt-outs fail closed; the native skill hint says what Codex does
Plateau Nguyen6328b1eae831
diff --git a/docs/feature-flags.md b/docs/feature-flags.mdindex 966cacfd68..cb2b71e167 100644--- a/docs/feature-flags.md+++ b/docs/feature-flags.md@@ -60,6 +60,13 @@ text and extra work can increase token usage.| `agentsToolBridge` | Off, except eligible local-model turns | Lists a smaller tool catalog with `find_tool` and `use_tool`. | Tool lookup can add model calls; smaller initial context is not a guaranteed saving. See [Agents tool bridge](agents-tool-bridge.md) for eligibility and measurements. || `savedSteps` | On | Allows saving and repeating computer tasks from their steps on a supported host. | Currently requires a Mac server. Enabling it does not add host support. |+With `skillsLibrary` on, the every-bot skills a bot was taken off live in+`<data>/skill-state/<bot id>/library-opt-out.json`. If that file is there but+can't be read or isn't a list of names, every library skill counts as off for+that bot (skills assigned to it explicitly still apply) and the server logs it+once. To recover, make the file readable and writable again (or delete it to+give the bot every every-bot skill), then switch skills back on for the bot.+### Ordinary server lending has three statesFor an ordinary self-hosted server that is not the bots' home,diff --git a/server/routes/bot-skills.test.ts b/server/routes/bot-skills.test.tsindex cf61c92e5c..dc73eb89b2 100644--- a/server/routes/bot-skills.test.ts+++ b/server/routes/bot-skills.test.ts@@ -1,10 +1,10 @@-import { existsSync, readFileSync } from "node:fs";+import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, symlinkSync, writeFileSync } from "node:fs";import { createServer, type Server } from "node:http";import type { AddressInfo } from "node:net";-import { join } from "node:path";+import { dirname, join } from "node:path";import { afterEach, describe, expect, it, vi } from "vitest";-import type { AppConfig } from "../config.ts";+import { DATA_DIR, type AppConfig } from "../config.ts";import { json, readBody } from "../harness/http.ts";import type { RequestAuth } from "../request-auth.ts";import { installLibrarySkill, readLibrarySkillFile, setLibrarySkillEveryBot } from "../skill-library.ts";@@ -165,4 +165,79 @@ describe("removing a skill from one bot", () => {expect(cleared.status).toBe(200);expect(resolveBotSkills(first, []).map((skill) => skill.name)).toContain(shared);});++ async function twinFixture(botId: string, name: string) {+ const bot = { id: botId, name: "Twin", assignedSkills: [name] as string[] | undefined };+ expect(installSkill(botId, "private:test", [{ path: "SKILL.md", content: learned(name) }])).toMatchObject({ name });+ expect(installLibrarySkill({ name, instructions: learned(name), source: "lib", reviewState: "approved" })).toMatchObject({ name });+ const store = {+ bot: (id: string) => (id === botId ? bot : undefined),+ get bots() { return [bot]; },+ patchBot(_id: string, patch: { assignedSkills?: string[] }) { return Object.assign(bot, patch); },+ } as unknown as Store;+ const routes = [createBotSkillsRoutes({+ store,+ cfg: { features: { skillsLibrary: true } } as AppConfig,+ listBotSkills: () => [],+ readBotSkillFile: () => null,+ stagedSkillListing: (staged) => staged,+ })];+ const server = createServer(async (req, res) => {+ const url = new URL(req.url ?? "/", "http://localhost");+ const auth = { kind: "loopback", scopes: ["admin"] } as unknown as RequestAuth;+ if (!await dispatchRoutes(routes, { req, res, url, path: url.pathname, method: req.method ?? "GET", auth, json, readBody })) json(res, 404, {});+ });+ servers.push(server);+ await new Promise<void>((ready) => server.listen(0, "127.0.0.1", ready));+ const remove = async () => {+ const response = await fetch(`http://127.0.0.1:${(server.address() as AddressInfo).port}/api/bots/${botId}/skills/${name}`, { method: "DELETE" });+ return { status: response.status, error: (await response.json() as { error?: string }).error };+ };+ return { bot, remove };+ }++ it("refuses a private skill it cannot remove instead of unassigning the shared skill of the same name", async () => {+ const { bot, remove } = await twinFixture("route-twin-unsafe-root", "twin-unsafe-root");+ const skillsRoot = join(workspaceDir(bot.id), "skills");+ renameSync(skillsRoot, `${skillsRoot}-real`);+ symlinkSync(`${skillsRoot}-real`, skillsRoot, process.platform === "win32" ? "junction" : "dir");++ expect(await remove()).toMatchObject({ status: 409, error: expect.stringMatching(/refusing to remove/) });+ expect(bot.assignedSkills).toEqual(["twin-unsafe-root"]);+ expect(listSkills(bot.id).map((skill) => skill.name)).toContain("twin-unsafe-root");+ });++ it("leaves the shared skill assigned when the bot's own skill list can't be read", async () => {+ const { bot, remove } = await twinFixture("route-twin-damaged-list", "twin-damaged-list");+ writeFileSync(join(DATA_DIR, "skill-state", bot.id, "skills.json"), "{\"twin-damaged-list\": {");++ expect(await remove()).toMatchObject({ status: 409, error: expect.stringMatching(/can't be read/) });+ expect(bot.assignedSkills).toEqual(["twin-damaged-list"]);+ });+});++describe("a bot's opt-outs from every-bot skills", () => {+ const optOutFile = (botId: string) => join(DATA_DIR, "skill-state", botId, "library-opt-out.json");++ it("keeps every-bot skills off for a bot whose opt-out list is damaged or can't be read", () => {+ const shared = "everyone-opt-out-check";+ expect(installLibrarySkill({ name: shared, instructions: learned(shared), source: "lib", reviewState: "approved" })).toMatchObject({ name: shared });+ expect(setLibrarySkillEveryBot(shared, true)).toMatchObject({ everyBot: true });+ mkdirSync(dirname(optOutFile("opt-out-damaged")), { recursive: true });+ writeFileSync(optOutFile("opt-out-damaged"), "[\"half-written");++ expect(resolveBotSkills("opt-out-none", []).map((skill) => skill.name)).toContain(shared);+ expect(resolveBotSkills("opt-out-damaged", []).map((skill) => skill.name)).not.toContain(shared);+ expect(resolveBotSkills("opt-out-damaged", [shared]).map((skill) => skill.name)).toContain(shared);++ if (process.platform === "win32" || process.getuid?.() === 0) return;+ mkdirSync(dirname(optOutFile("opt-out-unreadable")), { recursive: true });+ writeFileSync(optOutFile("opt-out-unreadable"), "[]");+ chmodSync(dirname(optOutFile("opt-out-unreadable")), 0o000);+ try {+ expect(resolveBotSkills("opt-out-unreadable", []).map((skill) => skill.name)).not.toContain(shared);+ } finally {+ chmodSync(dirname(optOutFile("opt-out-unreadable")), 0o700);+ }+ });});diff --git a/server/routes/bot-skills.ts b/server/routes/bot-skills.tsindex 99b09cc8b0..2ce59a0f26 100644--- a/server/routes/bot-skills.ts+++ b/server/routes/bot-skills.ts@@ -9,7 +9,7 @@ import { fetchSkillFromSource } from "../skill-fetch.ts";import { skillImportSummary } from "../skill-folder.ts";import { installLibrarySkill, librarySkillOptOuts, listLibrarySkills, readLibrarySkillFile, readSkillLibraryIndex, setLibrarySkillEveryBot, setLibrarySkillOptOut, setLibrarySkillReviewState, skillsLibraryEnabled, unassignLibrarySkill } from "../skill-library.ts";import {- installSkill, listBotSkillsWithOrigin, listStagedSkillWrites, parseSkillMd, removeSkill, scanSkillText, setSkillEnabled,+ installSkill, listBotSkillsWithOrigin, listStagedSkillWrites, ownsPrivateSkill, parseSkillMd, removeSkill, scanSkillText, setSkillEnabled,type SkillListing, type StagedSkillWrite,} from "../skills.ts";import type { BotRecord, Store } from "../store.ts";@@ -113,6 +113,9 @@ export function createBotSkillsRoutes(deps: BotSkillsRouteDeps): RouteHandler {const name = m[2]!;const removed = removeSkill(bot.id, name);if (!("error" in removed)) return json(res, 200, { ok: true });+ const owned = ownsPrivateSkill(bot.id, name);+ if (owned === null) return json(res, 409, { error: "this bot's own skill list can't be read, so nothing was removed" });+ if (owned) return json(res, 409, { error: removed.error });if (skillsLibraryEnabled(cfg)) {const unassigned = unassignLibrarySkill(bot.id, name, bot.assignedSkills);if ("unassigned" in unassigned) {diff --git a/server/skill-library.ts b/server/skill-library.tsindex 4d98dea611..4c47f56d31 100644--- a/server/skill-library.ts+++ b/server/skill-library.ts@@ -310,17 +310,35 @@ function libraryOptOutPath(botId: string): string | null {return join(DATA_DIR, "skill-state", botId, "library-opt-out.json");}-/** Names this bot has taken off its own list. An explicit assignment still wins; the shared copy stays. */+const unreadableOptOutsWarned = new Set<string>();++function everyLibrarySkillOff(path: string, why: string): ReadonlySet<string> {+ if (!unreadableOptOutsWarned.has(path)) {+ unreadableOptOutsWarned.add(path);+ console.warn(`Library opt-outs at ${path} can't be read (${why}); every library skill stays off for that bot until the file is readable again and one is switched back on.`);+ }+ return new Set(listLibrarySkills().map((skill) => skill.name));+}++/** Names this bot has taken off its own list. An explicit assignment still wins; the shared copy stays. A list that is+ * there but cannot be read counts as every library skill, so a damaged or unreadable file never puts an every-bot skill+ * back. */export function librarySkillOptOuts(botId: string): ReadonlySet<string> {const path = libraryOptOutPath(botId);- if (!path || !existsSync(path)) return new Set();+ if (!path) return new Set();+ let text: string;try {- const parsed = libraryOptOutSchema.safeParse(JSON.parse(readFileSync(path, "utf8")));- if (!parsed.success) return new Set();- return new Set(parsed.data.filter(isSkillName));- } catch {- return new Set();+ text = readFileSync(path, "utf8");+ } catch (error) {+ const code = (error as NodeJS.ErrnoException).code;+ if (code === "ENOENT") return new Set();+ return everyLibrarySkillOff(path, code ?? "read failed");}+ try {+ const parsed = libraryOptOutSchema.safeParse(JSON.parse(text));+ if (parsed.success) return new Set(parsed.data.filter(isSkillName));+ } catch {}+ return everyLibrarySkillOff(path, "not a list of skill names");}export function setLibrarySkillOptOut(botId: string, name: string, optedOut: boolean): void {diff --git a/server/skills.ts b/server/skills.tsindex 81bbc1addf..838bac48df 100644--- a/server/skills.ts+++ b/server/skills.ts@@ -239,6 +239,19 @@ function readManifest(botId: string): SkillManifest {return migrated;}+/** Whether this bot keeps a private skill of that name; null when its protected manifest is there but cannot be read,+ * so a caller never takes an unreadable list for an empty one. */+export function ownsPrivateSkill(botId: string, name: string): boolean | null {+ try {+ readFileSync(manifestPath(botId));+ } catch (error) {+ if ((error as NodeJS.ErrnoException).code !== "ENOENT") return null;+ return Object.hasOwn(readManifest(botId), name);+ }+ const manifest = manifestFromFile(manifestPath(botId));+ return manifest ? Object.hasOwn(manifest, name) : null;+}+function comparablePath(path: string): string {const normalized = resolve(path).replace(/^\\\\\?\\/, "");return process.platform === "win32" ? normalized.toLowerCase() : normalized;diff --git a/src/locales/en.json b/src/locales/en.jsonindex d29c2a987a..ae8185b5d4 100644--- a/src/locales/en.json+++ b/src/locales/en.json@@ -6189,7 +6189,7 @@"skills.origin.imported": "this computer","skills.origin.importedHint": "Brought in from this computer. Each bot lists the ones that fit its role and finds the rest when a task needs them. Switch it on to list it for this bot, or off to keep it from this bot.","skills.origin.native": "AI",- "skills.origin.nativeHint": "The bot's AI loads this from the folder under Source. Turn it off here for this bot only; the files stay where they are. On Codex, while any is off here, this bot's replies skip the skills.config list in ~/.codex/config.toml.",+ "skills.origin.nativeHint": "The bot's AI loads this from the folder under Source. Turn it off here for this bot only; the files stay where they are.","skills.write.title": "Write a command","skills.write.hint": "Give the bot a short command for something you ask often. Type /name in a chat to run it. Anything after the name fills in {input}.","skills.write.name": "Command name",diff --git a/src/locales/ja.json b/src/locales/ja.jsonindex b2d00c67f4..4dfef6d07b 100644--- a/src/locales/ja.json+++ b/src/locales/ja.json@@ -5727,7 +5727,7 @@"skills.learned.hintOff": "スキルの作成はオフですが、すでに有効にしたスキルは引き続きここで管理できます。","skills.origin.imported": "このコンピューター","skills.origin.native": "AI",- "skills.origin.nativeHint": "ボットの AI が、Source に表示されているフォルダーから読み込みます。ここでオフにすると、このボットでのみ無効になります。ファイルは元の場所に残ります。 Codex では、ここで 1 つでもオフにしている間、このボットの返信は ~/.codex/config.toml の skills.config を使いません。",+ "skills.origin.nativeHint": "ボットの AI が、Source に表示されているフォルダーから読み込みます。ここでオフにすると、このボットでのみ無効になります。ファイルは元の場所に残ります。","skills.write.title": "コマンドを作成","skills.write.hint": "よく頼む作業をボットの短いコマンドにできます。チャットで /name と入力すると実行できます。名前の後のテキストが {input} に入ります。","skills.write.name": "コマンド名",diff --git a/src/locales/ko.json b/src/locales/ko.jsonindex c2af1b0dfa..fa55dc2671 100644--- a/src/locales/ko.json+++ b/src/locales/ko.json@@ -5498,7 +5498,7 @@"skills.learned.hintOff": "스킬 작성은 꺼져 있지만, 이미 켠 스킬은 여기서 계속 관리할 수 있어요.","skills.origin.imported": "이 컴퓨터","skills.origin.native": "엔진",- "skills.origin.nativeHint": "봇의 AI가 소스 아래에 표시된 폴더에서 이 스킬을 불러와요. 여기서 끄면 이 봇에서만 비활성화돼요. 파일은 원래 위치에 그대로 남아요. Codex에서는 여기서 하나라도 꺼 두는 동안 이 봇의 답변은 ~/.codex/config.toml의 skills.config 목록을 사용하지 않아요.",+ "skills.origin.nativeHint": "봇의 AI가 소스 아래에 표시된 폴더에서 이 스킬을 불러와요. 여기서 끄면 이 봇에서만 비활성화돼요. 파일은 원래 위치에 그대로 남아요.","skills.write.title": "명령 만들기","skills.write.hint": "자주 요청하는 일을 짧은 명령으로 만들어 봇에게 주세요. 채팅에서 /이름을 입력하면 실행돼요. 이름 뒤에 쓴 내용은 {input}에 들어가요.","skills.write.name": "명령 이름",diff --git a/src/locales/pt-br.json b/src/locales/pt-br.jsonindex 450a691063..4f7c996dd7 100644--- a/src/locales/pt-br.json+++ b/src/locales/pt-br.json@@ -5875,7 +5875,7 @@"skills.origin.imported": "este computador","skills.origin.importedHint": "Trazida deste computador. Cada bot lista as que combinam com a função dele e encontra as outras quando uma tarefa precisa. Ative para listá-la neste bot, ou desative para mantê-la longe deste bot.","skills.origin.native": "IA",- "skills.origin.nativeHint": "A IA do bot carrega esta habilidade da pasta indicada em Origem. Desative aqui apenas para este bot; os arquivos ficam onde estão. No Codex, enquanto alguma estiver desativada aqui, as respostas deste bot ignoram a lista skills.config de ~/.codex/config.toml.",+ "skills.origin.nativeHint": "A IA do bot carrega esta habilidade da pasta indicada em Origem. Desative aqui apenas para este bot; os arquivos ficam onde estão.","skills.write.title": "Escrever um comando","skills.write.hint": "Dê ao bot um comando curto para algo que você pede com frequência. Digite /nome em uma conversa para executá-lo. O que vier depois do nome preenche {input}.","skills.write.name": "Nome do comando",diff --git a/src/locales/source-hashes.json b/src/locales/source-hashes.jsonindex e2c149b305..290bcce3ba 100644--- a/src/locales/source-hashes.json+++ b/src/locales/source-hashes.json@@ -23210,7 +23210,7 @@"remote.computerName.placeholder": "33d53fc415aeeb5128cb4c82cebe65e8fe3fbbbfae607ffee515ce72fafbbbd1","remote.computerName.error": "39431ac4903234c376d4ee65e3cc59c4b0ec58484bb02363a27e128bca8f37c0","skills.origin.native": "11fb682be0a0233d5fb899721ecfc1827d20f0d2ff2e093310efa61efca8af1c",- "skills.origin.nativeHint": "53bab467a186221ba1427720e9ba8dafe320ee791d2a0b091e3e7afc7bcbab72",+ "skills.origin.nativeHint": "bee2376a8f6c41590707e2f4360170f67410193554d75d55a51f9bbff9e30fde","skills.library.loadError": "4d57d005cf8bde449b67e1c1834d7e3a952a2df0cb8bf31f6b6ab811502157dd","settings.import.grokTitle": "c96cf4df1e00ae630e09a66849df3c258cca41adba11f7349f081b5b479b04e6","settings.import.grokSubtitle": "b947da44b989a085237c9dd40086b7eb57595fd8653affd57c68df71b2f6f95a",@@ -29392,7 +29392,7 @@"skills.origin.imported": "058bf37c9767891850a04e77e252c5bcd5036c4a1d0cec568d498dc4c8437379","skills.origin.importedHint": "1a0a4444bcb02305a59f0659abae2383385bf60c954dc84baade1d33d8b43ac1","skills.origin.native": "11fb682be0a0233d5fb899721ecfc1827d20f0d2ff2e093310efa61efca8af1c",- "skills.origin.nativeHint": "53bab467a186221ba1427720e9ba8dafe320ee791d2a0b091e3e7afc7bcbab72",+ "skills.origin.nativeHint": "bee2376a8f6c41590707e2f4360170f67410193554d75d55a51f9bbff9e30fde","skills.write.title": "247262706fab09d0262162ba8a4fe4493b9abf4cd9a4eb5236094437f661e344","skills.write.hint": "502d59dd98da355ebdd92770ec84323129cb4f8dd5156b6a3a06d0dd86c0f88e","skills.write.name": "5af23acc15079d189a6abaefdd7e13ece4ec7fc5ae94aaa3f665407ce8a61d61",@@ -40107,7 +40107,7 @@"skills.learned.hintOn": "ff18ab90b4f16073eead025c8ae9247beda43d6f0b63f857bcc25d43db568825","skills.origin.imported": "058bf37c9767891850a04e77e252c5bcd5036c4a1d0cec568d498dc4c8437379","skills.origin.native": "11fb682be0a0233d5fb899721ecfc1827d20f0d2ff2e093310efa61efca8af1c",- "skills.origin.nativeHint": "53bab467a186221ba1427720e9ba8dafe320ee791d2a0b091e3e7afc7bcbab72",+ "skills.origin.nativeHint": "bee2376a8f6c41590707e2f4360170f67410193554d75d55a51f9bbff9e30fde","skills.write.title": "247262706fab09d0262162ba8a4fe4493b9abf4cd9a4eb5236094437f661e344","skills.write.hint": "502d59dd98da355ebdd92770ec84323129cb4f8dd5156b6a3a06d0dd86c0f88e","skills.write.name": "5af23acc15079d189a6abaefdd7e13ece4ec7fc5ae94aaa3f665407ce8a61d61",@@ -48538,7 +48538,7 @@"botAccess.recordSteps.myChrome": "6fc8728673d3b750b3152d7375c4b426621ce5657e3b811cc717bb53ee9aca74","skills.origin.imported": "058bf37c9767891850a04e77e252c5bcd5036c4a1d0cec568d498dc4c8437379","skills.origin.native": "11fb682be0a0233d5fb899721ecfc1827d20f0d2ff2e093310efa61efca8af1c",- "skills.origin.nativeHint": "53bab467a186221ba1427720e9ba8dafe320ee791d2a0b091e3e7afc7bcbab72",+ "skills.origin.nativeHint": "bee2376a8f6c41590707e2f4360170f67410193554d75d55a51f9bbff9e30fde","skills.write.title": "247262706fab09d0262162ba8a4fe4493b9abf4cd9a4eb5236094437f661e344","skills.write.hint": "502d59dd98da355ebdd92770ec84323129cb4f8dd5156b6a3a06d0dd86c0f88e","skills.write.name": "5af23acc15079d189a6abaefdd7e13ece4ec7fc5ae94aaa3f665407ce8a61d61",@@ -92068,7 +92068,7 @@"skills.learned.hintOff": "f3477db333415d4fdb93b9f40229ca082915b4e47e1749acaac94588a5836ab7","skills.origin.imported": "058bf37c9767891850a04e77e252c5bcd5036c4a1d0cec568d498dc4c8437379","skills.origin.native": "11fb682be0a0233d5fb899721ecfc1827d20f0d2ff2e093310efa61efca8af1c",- "skills.origin.nativeHint": "53bab467a186221ba1427720e9ba8dafe320ee791d2a0b091e3e7afc7bcbab72",+ "skills.origin.nativeHint": "bee2376a8f6c41590707e2f4360170f67410193554d75d55a51f9bbff9e30fde","skills.write.title": "247262706fab09d0262162ba8a4fe4493b9abf4cd9a4eb5236094437f661e344","skills.write.hint": "502d59dd98da355ebdd92770ec84323129cb4f8dd5156b6a3a06d0dd86c0f88e","skills.write.name": "5af23acc15079d189a6abaefdd7e13ece4ec7fc5ae94aaa3f665407ce8a61d61",diff --git a/src/locales/zh-tw.json b/src/locales/zh-tw.jsonindex c5d6bce7c7..ac50992be9 100644--- a/src/locales/zh-tw.json+++ b/src/locales/zh-tw.json@@ -5921,7 +5921,7 @@"skills.learned.hintOff": "技能撰寫已關閉,但你已啟用的技能仍在此由你掌控。","skills.origin.imported": "這台電腦","skills.origin.native": "AI",- "skills.origin.nativeHint": "機器人的 AI 會從「來源」下的資料夾載入此技能。在這裡關閉,只會對這個機器人停用;檔案會留在原處。在 Codex 中,只要這裡關閉了任何一項,這個機器人的回覆就不會使用 ~/.codex/config.toml 中的 skills.config 清單。",+ "skills.origin.nativeHint": "機器人的 AI 會從「來源」下的資料夾載入此技能。在這裡關閉,只會對這個機器人停用;檔案會留在原處。","skills.write.title": "撰寫指令","skills.write.hint": "為你常要求的事情給機器人一個簡短指令。在聊天中輸入 /名稱 即可執行。名稱後面的任何內容會填入 {input}。","skills.write.name": "指令名稱",diff --git a/src/locales/zh.json b/src/locales/zh.jsonindex 8c3a2a6b30..814ba5bef9 100644--- a/src/locales/zh.json+++ b/src/locales/zh.json@@ -5706,7 +5706,7 @@"skills.learned.hintOff": "技能撰写已关闭,但你已激活的技能仍在此由你掌控。","skills.origin.imported": "这台电脑","skills.origin.native": "AI",- "skills.origin.nativeHint": "机器人的 AI 会从「来源」下的文件夹加载此技能。在这里关闭,仅对这个机器人停用;文件会保留在原处。在 Codex 中,只要这里关闭了任何一项,这个机器人的回复就不会使用 ~/.codex/config.toml 中的 skills.config 列表。",+ "skills.origin.nativeHint": "机器人的 AI 会从「来源」下的文件夹加载此技能。在这里关闭,仅对这个机器人停用;文件会保留在原处。","skills.write.title": "编写命令","skills.write.hint": "为经常提出的需求给机器人设置一条简短命令。在聊天中输入 /name 即可运行。名称后面的任何内容都会填入 {input}。","skills.write.name": "命令名称",