Skip to content
This repository was archived by the owner on Oct 21, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion apps/server/src/provider/Drivers/ClaudeDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
normalizeCommandPath,
resolveProviderMaintenanceCapabilitiesEffect,
} from "../providerMaintenance.ts";
import type { ServerProviderDraft } from "../providerSnapshot.ts";
import {
haveProviderSnapshotSettingsChanged,
makeProviderSnapshotSettingsSource,
Expand Down Expand Up @@ -153,13 +154,16 @@ export const ClaudeDriver: ProviderDriver<ClaudeSettings, ClaudeDriverEnv> = {
? configDir
: undefined,
);
const stampIdentity = withInstanceIdentity({
const stampInstance = withInstanceIdentity({
instanceId,
driverKind: DRIVER_KIND,
displayName,
accentColor,
continuationGroupKey,
});
// The resolved config dir tells the Skills catalog where this instance's personal skills live.
const stampIdentity = (draft: ServerProviderDraft) =>
stampInstance({ ...draft, runtimePaths: { homePath: configDir, shadowHomePath: null } });

// One per instance: the status probe writes the model-scoped bucket
// names it saw, the adapter reads them to place turn-driven events.
Expand Down
70 changes: 70 additions & 0 deletions apps/server/src/workspace/SkillFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,76 @@ describe("file skills catalog", () => {
expect(result.skills).toEqual([]);
});

it("skips deleted skills a provider keeps in a hidden trash folder", async () => {
const trashed = NodePath.join(home, ".claude", "skills", ".trash", "1790310884383", "review");
await NodeFSP.mkdir(trashed, { recursive: true });
const file = NodePath.join(trashed, "SKILL.md");
await NodeFSP.writeFile(file, "---\nname: review\n---\n");
const result = await listSkillFiles(
{ workspaceRoots: [] },
[provider([{ name: "review", path: file, scope: "user", enabled: true }])],
home,
);
expect(result.skills).toEqual([]);
});

it("labels a provider-reported skill by the folder it lives in", async () => {
const synced = NodePath.join(home, ".claude", "skills", "synced", "account-id", "docs");
await NodeFSP.mkdir(synced, { recursive: true });
const file = NodePath.join(synced, "SKILL.md");
await NodeFSP.writeFile(file, "---\nname: docs\n---\n");
const opencode = {
...provider([{ name: "docs", path: file, scope: "user", enabled: true }]),
driver: ProviderDriverKind.make("opencode"),
};
const result = await listSkillFiles({ workspaceRoots: [] }, [opencode], home);
expect(result.skills.map(({ name, source }) => [name, source])).toEqual([["docs", "claude"]]);
});

it("keeps personal skills from a provider's custom home", async () => {
const customHome = NodePath.join(home, ".codex-work");
const file = NodePath.join(customHome, "skills", "review", "SKILL.md");
await NodeFSP.mkdir(NodePath.dirname(file), { recursive: true });
await NodeFSP.writeFile(file, "---\nname: review\n---\n");
const codex = {
...provider([{ name: "review", path: file, scope: "user", enabled: true }]),
runtimePaths: { homePath: customHome, shadowHomePath: null },
};
const result = await listSkillFiles({ workspaceRoots: [] }, [codex], home);
expect(result.skills.map(({ name, scope, source }) => [name, scope, source])).toEqual([
["review", "personal", "codex"],
]);
});

it("ignores skills providers report from worktrees, other checkouts, and plugin caches", async () => {
const worktree = NodePath.join(home, ".t3", "worktrees", "app", "feature-1");
const otherCheckout = NodePath.join(home, "Git", "other-repo");
const pluginCache = NodePath.join(home, ".codex", "plugins", "cache", "vendor", "tool");
const reported = await Promise.all([
writeSkill(worktree, "from-worktree"),
writeSkill(otherCheckout, "from-other-repo"),
writeSkill(pluginCache, "from-plugin-cache"),
writeSkill(project, "from-selected-project"),
]);
const result = await listSkillFiles(
{ workspaceRoots: [project] },
[
provider(
reported.map((path) => ({
name: NodePath.basename(NodePath.dirname(path)),
path,
scope: "user",
enabled: true,
})),
),
],
home,
);
expect(result.skills.map(({ name, scope }) => [name, scope])).toEqual([
["from-selected-project", "project"],
]);
});

it("reports malformed or oversized frontmatter instead of silently showing a complete catalog", async () => {
await writeSkill(project, "bad", "---\nname: [invalid\n---\n");
await writeSkill(project, "huge", "---\ndescription: " + "x".repeat(20_000) + "\n---\n");
Expand Down
58 changes: 43 additions & 15 deletions apps/server/src/workspace/SkillFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,31 @@ function within(file: string, root: string) {
!NodePath.isAbsolute(relative))
);
}
function builtin(file: string) {
return file.replaceAll("\\", "/").includes("/skills/.system/");
/**
* Skills inside a hidden folder of a skills directory are not installed skills: `.system` holds
* provider built-ins and `.trash` holds deleted skills a provider keeps around.
*/
function hiddenSkillFile(file: string) {
const segments = file.replaceAll("\\", "/").split("/");
const skillsIndex = segments.lastIndexOf("skills");
return (
skillsIndex >= 0 && segments.slice(skillsIndex + 1).some((segment) => segment.startsWith("."))
);
}

/**
* The folder family a skill file lives in, such as `claude` for anything under `.claude/skills`.
* Providers also report skills from other tools' folders (OpenCode reads `~/.claude/skills`), so
* the folder, not the reporting provider, says where a skill comes from.
*/
function folderSource(file: string): string | null {
const normalized = file.replaceAll("\\", "/");
let match: { readonly index: number; readonly source: string } | null = null;
for (const [folder, source] of PERSONAL_SKILL_FOLDERS) {
const index = normalized.lastIndexOf(`/${folder}/`);
if (index >= 0 && (match === null || index > match.index)) match = { index, source };
}
return match?.source ?? null;
}

/** Limit open handles, not catalog size. Cancellation stops scheduling further disk reads. */
Expand Down Expand Up @@ -108,14 +131,22 @@ export async function listSkillFiles(
})),
),
];
const personalRoots = PERSONAL_SKILL_FOLDERS.map(([folder]) => NodePath.join(home, folder));
// Providers can run from a custom home, such as `~/.codex-work`, whose skills folder is personal.
const personalRoots = [
...PERSONAL_SKILL_FOLDERS.map(([folder]) => NodePath.join(home, folder)),
...providers.flatMap(({ runtimePaths }) =>
[runtimePaths?.homePath, runtimePaths?.shadowHomePath].flatMap((providerHome) =>
providerHome ? [NodePath.join(NodePath.resolve(providerHome), "skills")] : [],
),
),
];
const addCandidate = (file: string, scope: FileSkill["scope"], source: string) => {
if (builtin(file)) return;
if (hiddenSkillFile(file)) return;
const personal = personalRoots.some((root) => within(file, root));
const previous = candidates.get(file);
candidates.set(file, {
scope: personal || previous?.scope === "personal" ? "personal" : scope,
source: previous?.source ?? source,
source: previous?.source ?? folderSource(file) ?? source,
});
};
await forEachConcurrent(
Expand Down Expand Up @@ -151,17 +182,13 @@ export async function listSkillFiles(
}
if (!provider.enabled || !provider.installed) continue;
providerPaths.add(file);
const homeSkill =
within(file, home) && !roots.some((root) => root !== home && within(file, root));
if (
homeSkill &&
!["project", "repo", "workspace", "local"].includes(skill.scope?.toLowerCase() ?? "")
) {
// Providers report every skill they can see from wherever they run, including worktrees,
// other checkouts, and plugin caches under home. Only personal skill folders and the
// selected projects belong in this catalog.
if (personalRoots.some((root) => within(file, root))) {
addCandidate(file, "personal", provider.driver);
} else if (roots.some((root) => within(file, root))) {
} else if (roots.some((root) => root !== home && within(file, root))) {
addCandidate(file, "project", provider.driver);
} else if (["user", "personal"].includes(skill.scope?.toLowerCase() ?? "")) {
addCandidate(file, "personal", provider.driver);
}
}
}
Expand All @@ -182,7 +209,8 @@ export async function listSkillFiles(
async ([file, location]) => {
try {
const canonical = await NodeFSP.realpath(file);
if (builtin(canonical) || excludedPaths.has(file) || excludedPaths.has(canonical)) return;
if (hiddenSkillFile(canonical) || excludedPaths.has(file) || excludedPaths.has(canonical))
return;
if (!(await NodeFSP.stat(file)).isFile()) return;
const handle = await NodeFSP.open(file, "r");
let contents: string;
Expand Down
Loading
Loading