Skip to content

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

fix(skills): a project skill wins over the person's skill of the same name

Gökhan Kösec69dd50ca5f3
diff --git a/server/host/skills-library.ts b/server/host/skills-library.ts
index 9e0e6b5d48..e027e651d5 100644
--- a/server/host/skills-library.ts
+++ b/server/host/skills-library.ts
@@ -320,9 +320,10 @@ export function createSkillsLibraryHost(deps: SkillsLibraryHostDeps) {
turnSkillFiles,
- turnSettings(bot: BotRecord, threadId: string, instance: TurnInstance, restrictsMcp: boolean) {
+ /** `cwd`: the turn's folder, whose project skills win over the person's own of the same name. */
+ turnSettings(bot: BotRecord, threadId: string, instance: TurnInstance, restrictsMcp: boolean, cwd?: string) {
return {
- ...settingsTurnFields(cfg, DATA_DIR, restrictsMcp),
+ ...settingsTurnFields(cfg, DATA_DIR, restrictsMcp, undefined, cwd),
...(instance.driverKind === "antigravityAgent" ? { skillFiles: turnSkillFiles(bot, threadId, instance) } : {}),
};
},
diff --git a/server/index.ts b/server/index.ts
index 2785c558d7..6e1d260ff7 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -8361,7 +8361,7 @@ async function beginTurn(
mentionTurn: tagged.length > 0,
integrations,
...(integrations.browser && browserIsThePlace(turnSurfacePlan(bot, undefined, threadId, true)) ? { preloadBrowserTools: true } : {}),
- ...skillsHost.turnSettings(bot, threadId, instance, managedPolicy.restrictsMcp()),
+ ...skillsHost.turnSettings(bot, threadId, instance, managedPolicy.restrictsMcp(), cwd),
cwd, ...(worksInWorkspace || guestConfined || cloudGuestOpened(threadId) ? {} : { toolResultFolder: messageFileRootsForThread(bot.id, threadId).find((root) => root !== ATTACHMENTS_DIR) }),
botSettingsFile: botSettingsFile(bot),
}, (input) => quickFallback.sendTurn(instance, enginePrestart.note(instance.instanceId, input, personLine && !automated), route.quickModel ? { model, own: bot.modelSelection, onFallback: () => store.patchMessage(threadId, userMessage.id, { quickModel: undefined }) } : undefined))), () => companyShutdown || !directTurnClaimExists(bot.id, dispatchClaimId, threadId), async () => {
@@ -10224,7 +10224,7 @@ async function runClaimedGroupMemberTurn(
cwd, ...(worksInWorkspace || roomGuestConfined || cloudGuestOpened(threadId) ? {} : { toolResultFolder: messageFileRootsForThread(readyBot.id, threadId).find((root) => root !== ATTACHMENTS_DIR) }),
integrations,
...(integrations.browser && browserIsThePlace(roomPlan) ? { preloadBrowserTools: true } : {}),
- ...skillsHost.turnSettings(readyBot, threadId, instance, managedPolicy.restrictsMcp()),
+ ...skillsHost.turnSettings(readyBot, threadId, instance, managedPolicy.restrictsMcp(), cwd),
botSettingsFile: botSettingsFile(readyBot),
...(instance.instanceId === roomSelection.instanceId
? memberTurnSelection(roomSelection)
diff --git a/server/turn-settings.test.ts b/server/turn-settings.test.ts
index 7053832c81..39dc649522 100644
--- a/server/turn-settings.test.ts
+++ b/server/turn-settings.test.ts
@@ -30,6 +30,24 @@ describe("the person's own Claude Code skills", () => {
expect(claudeUserSkillsDir(data, home)).toBe(root);
});
+ it("leaves out the personal skills a bot's project ships itself, so the project's version wins", () => {
+ const home = temp(), data = temp(), cwd = temp();
+ for (const name of ["deploy", "crm"]) {
+ mkdirSync(join(home, ".claude", "skills", name), { recursive: true });
+ writeFileSync(join(home, ".claude", "skills", name, "SKILL.md"), `personal ${name}`);
+ }
+ mkdirSync(join(cwd, ".claude", "skills", "deploy"), { recursive: true });
+ writeFileSync(join(cwd, ".claude", "skills", "deploy", "SKILL.md"), "project deploy");
+ const root = claudeUserSkillsDir(data, home, cwd)!;
+ expect(root).not.toBe(join(data, "claude-user-skills"));
+ expect(existsSync(join(root, ".claude", "skills", "deploy"))).toBe(false);
+ expect(readFileSync(join(root, ".claude", "skills", "crm", "SKILL.md"), "utf8")).toBe("personal crm");
+ // The project drops its copy: the personal one comes back on the next turn.
+ rmSync(join(cwd, ".claude", "skills", "deploy"), { recursive: true });
+ expect(claudeUserSkillsDir(data, home, cwd)).toBe(join(data, "claude-user-skills"));
+ expect(claudeUserSkillsDir(data, home, temp())).toBe(join(data, "claude-user-skills"));
+ });
+
it("has nothing to add without a skills folder", () => {
expect(claudeUserSkillsDir(temp(), temp())).toBeNull();
});
@@ -62,6 +80,20 @@ describe("turn fields from Settings", () => {
expect(readFileSync(join(home, ".claude", "skills", "deploy", "SKILL.md"), "utf8")).toBe("mine");
});
+ it("takes a project's own links away too once the switch is off, never what they point to", () => {
+ const data = temp(), home = temp(), cwd = temp();
+ for (const name of ["deploy", "crm"]) {
+ mkdirSync(join(home, ".claude", "skills", name), { recursive: true });
+ writeFileSync(join(home, ".claude", "skills", name, "SKILL.md"), `personal ${name}`);
+ }
+ mkdirSync(join(cwd, ".claude", "skills", "deploy"), { recursive: true });
+ const on = settingsTurnFields({ features: { claudeUserSkills: true } } as AppConfig, data, false, home, cwd);
+ expect(on.userSkillsDir).toContain(join(data, "claude-user-skills", "for"));
+ settingsTurnFields({} as AppConfig, data, false, home, cwd);
+ expect(existsSync(join(data, "claude-user-skills"))).toBe(false);
+ expect(readFileSync(join(home, ".claude", "skills", "crm", "SKILL.md"), "utf8")).toBe("personal crm");
+ });
+
it("keeps the MCP switch its own, and an organization's MCP limit wins", () => {
const on = { features: { claudeUserMcp: true } } as AppConfig;
expect(settingsTurnFields(on, temp(), false, temp()).mcpFromUserConfig).toBe(true);
diff --git a/server/turn-settings.ts b/server/turn-settings.ts
index bbc59cc36f..67419e1320 100644
--- a/server/turn-settings.ts
+++ b/server/turn-settings.ts
@@ -1,4 +1,5 @@
-import { lstatSync, mkdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
+import { createHash } from "node:crypto";
+import { existsSync, lstatSync, mkdirSync, readdirSync, readlinkSync, rmdirSync, statSync, symlinkSync, unlinkSync } from "node:fs";
import { homedir } from "node:os";
import { join, resolve } from "node:path";
import { claudeUserMcpEnabled, mcpCallTimeoutMinutes, type AppConfig } from "./config.ts";
@@ -9,14 +10,17 @@ export function claudeUserSkillsEnabled(cfg: AppConfig): boolean {
}
/** A folder whose `.claude/skills` links to the person's own `~/.claude/skills`, for Claude Code's `--add-dir`: each skill
- * loads as it is on disk, scripts and references included, and edits arrive live. Null when there is nothing to link. */
-export function claudeUserSkillsDir(dataDir: string, home = homedir()): string | null {
+ * loads as it is on disk, scripts and references included, and edits arrive live. Null when there is nothing to link.
+ * A skill the project in `cwd` ships under the same name stays the project's. */
+export function claudeUserSkillsDir(dataDir: string, home = homedir(), cwd?: string): string | null {
const source = join(home, ".claude", "skills");
try {
if (!statSync(source).isDirectory()) return null;
} catch {
return null;
}
+ const shadowed = projectSkillNames(cwd).filter((name) => existsSync(join(source, name)));
+ if (cwd && shadowed.length > 0) return claudeUserSkillsDirWithout(dataDir, source, cwd, shadowed);
const root = join(dataDir, "claude-user-skills");
const link = join(root, ".claude", "skills");
try {
@@ -34,21 +38,85 @@ export function claudeUserSkillsDir(dataDir: string, home = homedir()): string |
}
}
-/** The link and its folders, once the switch is off; only the link itself, never what it points to. */
-export function forgetClaudeUserSkillsDir(dataDir: string): void {
- const root = join(dataDir, "claude-user-skills");
- const link = join(root, ".claude", "skills");
+/** The skill names the project in `cwd` ships in its own `.claude/skills`. */
+function projectSkillNames(cwd: string | undefined): string[] {
+ if (!cwd) return [];
+ try {
+ return readdirSync(join(cwd, ".claude", "skills")).filter((name) => !name.startsWith("."));
+ } catch {
+ return [];
+ }
+}
+
+/** Removes a link and only the link: a Windows junction is removed as a folder, and a real folder with anything in it
+ * is left alone. */
+function dropLink(path: string): void {
+ try {
+ if (!lstatSync(path).isSymbolicLink()) return;
+ } catch {
+ return;
+ }
+ try {
+ unlinkSync(path);
+ } catch {
+ try {
+ rmdirSync(path);
+ } catch {}
+ }
+}
+
+/** Claude Code keeps both when a project skill and a skill under `--add-dir` share a name, so the bot sees each twice. A
+ * project with such a skill gets a folder of its own, one link per personal skill and the shadowed names left out, so
+ * the project's version wins as it does in a terminal. */
+function claudeUserSkillsDirWithout(dataDir: string, source: string, cwd: string, shadowed: string[]): string | null {
+ const root = join(dataDir, "claude-user-skills", "for", createHash("sha1").update(resolve(cwd)).digest("hex").slice(0, 12));
+ const dir = join(root, ".claude", "skills");
try {
- if (lstatSync(link).isSymbolicLink()) {
+ mkdirSync(dir, { recursive: true, mode: 0o700 });
+ const wanted = new Set(readdirSync(source).filter((name) => !name.startsWith(".") && !shadowed.includes(name)));
+ for (const entry of readdirSync(dir)) {
+ let target = "";
+ try {
+ target = readlinkSync(join(dir, entry));
+ } catch {}
+ if (!wanted.has(entry) || resolve(target) !== resolve(join(source, entry))) dropLink(join(dir, entry));
+ }
+ for (const name of wanted) {
try {
- unlinkSync(link);
+ lstatSync(join(dir, name));
} catch {
- // A Windows junction is removed as a folder.
- rmdirSync(link);
+ symlinkSync(join(source, name), join(dir, name), process.platform === "win32" ? "junction" : "dir");
}
}
+ return root;
+ } catch {
+ return null;
+ }
+}
+
+/** The links and their folders, once the switch is off; only the links themselves, never what they point to. */
+export function forgetClaudeUserSkillsDir(dataDir: string): void {
+ const root = join(dataDir, "claude-user-skills");
+ dropLink(join(root, ".claude", "skills"));
+ const perProject = join(root, "for");
+ let projects: string[] = [];
+ try {
+ projects = readdirSync(perProject);
} catch {}
- for (const folder of [join(root, ".claude"), root]) {
+ for (const project of projects) {
+ const skills = join(perProject, project, ".claude", "skills");
+ let entries: string[] = [];
+ try {
+ entries = readdirSync(skills);
+ } catch {}
+ for (const entry of entries) dropLink(join(skills, entry));
+ for (const folder of [skills, join(perProject, project, ".claude"), join(perProject, project)]) {
+ try {
+ rmdirSync(folder);
+ } catch {}
+ }
+ }
+ for (const folder of [perProject, join(root, ".claude"), root]) {
try {
rmdirSync(folder);
} catch {}
@@ -56,13 +124,13 @@ export function forgetClaudeUserSkillsDir(dataDir: string): void {
}
/** The fields of an engine turn that come from Settings. */
-export function settingsTurnFields(cfg: AppConfig, dataDir: string, restrictsMcp: boolean, home = homedir()): {
+export function settingsTurnFields(cfg: AppConfig, dataDir: string, restrictsMcp: boolean, home = homedir(), cwd?: string): {
mcpFromUserConfig: boolean;
userSkillsDir?: string;
mcpCallTimeoutMs: number;
toolErrorCorrectiveRounds: number;
} {
- const userSkillsDir = claudeUserSkillsEnabled(cfg) ? claudeUserSkillsDir(dataDir, home) : null;
+ const userSkillsDir = claudeUserSkillsEnabled(cfg) ? claudeUserSkillsDir(dataDir, home, cwd) : null;
if (!claudeUserSkillsEnabled(cfg)) forgetClaudeUserSkillsDir(dataDir);
return {
mcpFromUserConfig: claudeUserMcpEnabled(cfg) && !restrictsMcp,