fix(claude): discover enabled installed plugin skills #15662
Mergedmaria-rcksmerged 17 commits into
main fromrefs/pull/15662/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Drivers/ClaudeSkills.ts line 333OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -284,0 +313,21 @@313+ scope: Schema.Literals(["user", "project", "local"]),314+ installPath: Schema.NonEmptyString,315+ projectPath: Schema.optional(Schema.NonEmptyString),316+ }),317+);318+const PluginManifest = Schema.fromJsonString(319+ Schema.Struct({320+ skills: Schema.optional(Schema.Union([Schema.String, Schema.Array(Schema.String)])),321+ }),322+);323+324+/** Installed plugin records are authoritative; marketplace catalogs include uninstalled plugins. */325+const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function* (326+ configDirPath: string,327+ cwd: string | undefined,328+ enabledPlugins: ReadonlyMap<string, boolean>,329+): Effect.fn.Return<ReadonlyArray<ClaudeSkillRoot>, never, FileSystem.FileSystem | Path.Path> {330+ const fileSystem = yield* FileSystem.FileSystem;331+ const path = yield* Path.Path;332+ const installed = yield* fileSystem333+ .readFileString(path.join(configDirPath, "plugins", "installed_plugins.json"))apps/server/src/provider/Drivers/ClaudeSkills.ts line 344OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -284,0 +324,21 @@324+/** Installed plugin records are authoritative; marketplace catalogs include uninstalled plugins. */325+const discoverPluginSkillRoots = Effect.fn("discoverPluginSkillRoots")(function* (326+ configDirPath: string,327+ cwd: string | undefined,328+ enabledPlugins: ReadonlyMap<string, boolean>,329+): Effect.fn.Return<ReadonlyArray<ClaudeSkillRoot>, never, FileSystem.FileSystem | Path.Path> {330+ const fileSystem = yield* FileSystem.FileSystem;331+ const path = yield* Path.Path;332+ const installed = yield* fileSystem333+ .readFileString(path.join(configDirPath, "plugins", "installed_plugins.json"))334+ .pipe(335+ Effect.flatMap(Schema.decodeUnknownEffect(InstalledPlugins)),336+ Effect.orElseSucceed(() => undefined),337+ );338+ const roots: Array<ClaudeSkillRoot> = [];339+ const workspace = cwd === undefined ? undefined : path.resolve(cwd);340+ const scopePriority = { user: 0, project: 1, local: 2 };341+342+ for (const [key, entries] of Object.entries(installed?.plugins ?? {}).sort()) {343+ if (enabledPlugins.get(key) !== true) continue;344+ const prefix = key.split("@")[0];apps/server/src/provider/Drivers/ClaudeSkills.ts lines 361 to 361OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -284,0 +341,21 @@341+342+ for (const [key, entries] of Object.entries(installed?.plugins ?? {}).sort()) {343+ if (enabledPlugins.get(key) !== true) continue;344+ const prefix = key.split("@")[0];345+ if (!prefix) continue;346+ const install = entries347+ .flatMap((entry) => {348+ const record = Option.getOrUndefined(decodeInstalledPlugin(entry));349+ if (!record) return [];350+ if (351+ record.scope !== "user" &&352+ (record.projectPath === undefined || path.resolve(record.projectPath) !== workspace)353+ ) {354+ return [];355+ }356+ return [record];357+ })358+ .sort((left, right) => scopePriority[right.scope] - scopePriority[left.scope])[0];359+ if (!install) continue;360+ const scope = install.scope === "user" ? "user" : "project";361+ roots.push({ directory: path.join(install.installPath, "skills"), scope, prefix });apps/server/src/provider/Drivers/ClaudeSkills.ts lines 373 to 373OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -284,0 +353,21 @@353+ ) {354+ return [];355+ }356+ return [record];357+ })358+ .sort((left, right) => scopePriority[right.scope] - scopePriority[left.scope])[0];359+ if (!install) continue;360+ const scope = install.scope === "user" ? "user" : "project";361+ roots.push({ directory: path.join(install.installPath, "skills"), scope, prefix });362+363+ // Plugins such as mattpocock-skills declare individual nested folders;364+ // a declared path can also be a directory containing several skills.365+ const manifest = yield* fileSystem366+ .readFileString(path.join(install.installPath, ".claude-plugin", "plugin.json"))367+ .pipe(368+ Effect.flatMap(Schema.decodeUnknownEffect(PluginManifest)),369+ Effect.orElseSucceed(() => undefined),370+ );371+ const declared = manifest?.skills;372+ for (const relative of typeof declared === "string" ? [declared] : (declared ?? [])) {373+ const directory = path.resolve(install.installPath, relative);
- apps/server/src/provider/Drivers/ClaudeSkills.ts lines 372 to 377OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -284,0 +357,21 @@357+ })358+ .sort((left, right) => scopePriority[right.scope] - scopePriority[left.scope])[0];359+ if (!install) continue;360+ const scope = install.scope === "user" ? "user" : "project";361+ roots.push({ directory: path.join(install.installPath, "skills"), scope, prefix });362+363+ // Plugins such as mattpocock-skills declare individual nested folders;364+ // a declared path can also be a directory containing several skills.365+ const manifest = yield* fileSystem366+ .readFileString(path.join(install.installPath, ".claude-plugin", "plugin.json"))367+ .pipe(368+ Effect.flatMap(Schema.decodeUnknownEffect(PluginManifest)),369+ Effect.orElseSucceed(() => undefined),370+ );371+ const declared = manifest?.skills;372+ for (const relative of typeof declared === "string" ? [declared] : (declared ?? [])) {373+ const directory = path.resolve(install.installPath, relative);374+ const singleSkill = yield* fileSystem375+ .exists(path.join(directory, "SKILL.md"))376+ .pipe(Effect.orElseSucceed(() => false));377+ roots.push({ directory, scope, prefix, singleSkill });
- apps/server/src/provider/Drivers/ClaudeSkills.ts line 524OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -360,13 +507,18 @@360507 continue;361508 }362509363- // Claude Code identifies a skill by its directory, not by the510+ // Claude Code identifies a user/project skill by its directory, not by the364511 // frontmatter `name`: verified against the CLI, a skill in `probe-alias/`365512 // declaring `name: probe-alias-frontmatter` is published as366513 // `probe-alias`, and only `skillOverrides["probe-alias"]` switches it367514 // off. Keying off the frontmatter name would report a command that does368515 // not exist and miss the override that disables it.369- const name = entry.trim();370- if (!name) {516+ const directoryName = entry.trim();517+ if (!directoryName) {371518 continue;372519 }520+ // Plugin skills use their frontmatter name, with a sanitized directory fallback.521+ const pluginSkillName =522+ root.prefix && frontmatter.kind === "parsed" ? frontmatter.name : undefined;523+ const name = root.prefix524+ ? `${root.prefix}:${pluginSkillName ?? directoryName.replace(/[^a-zA-Z0-9_-]/g, "-")}`
- apps/server/src/provider/Drivers/ClaudeSkills.ts lines 520 to 525OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -361,12 +508,18 @@361508 }362509363- // Claude Code identifies a skill by its directory, not by the510+ // Claude Code identifies a user/project skill by its directory, not by the364511 // frontmatter `name`: verified against the CLI, a skill in `probe-alias/`365512 // declaring `name: probe-alias-frontmatter` is published as366513 // `probe-alias`, and only `skillOverrides["probe-alias"]` switches it367514 // off. Keying off the frontmatter name would report a command that does368515 // not exist and miss the override that disables it.369- const name = entry.trim();370- if (!name) {516+ const directoryName = entry.trim();517+ if (!directoryName) {371518 continue;372519 }520+ // Plugin skills use their frontmatter name, with a sanitized directory fallback.521+ const pluginSkillName =522+ root.prefix && frontmatter.kind === "parsed" ? frontmatter.name : undefined;523+ const name = root.prefix524+ ? `${root.prefix}:${pluginSkillName ?? directoryName.replace(/[^a-zA-Z0-9_-]/g, "-")}`525+ : directoryName;
- apps/server/src/provider/Drivers/ClaudeSkillDispatch.ts line 33OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -25,9 +25,9 @@2525 */26262727 /**28- * Same token shape the composer and timeline chips recognise29- * (`packages/shared/src/composerInlineTokens.ts`), so a rendered chip and a30- * dispatched skill are always the same set.28+ * Composer tokens plus namespaced plugin names, checked against the discovered29+ * catalog below. Native plugin names can contain punctuation; whitespace ends30+ * the command name and starts its arguments.3131 */3232 const SKILL_MENTION_PATTERN =33- /(^|\s)\p{Sc}(?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])([a-zA-Z0-9][a-zA-Z0-9:_-]*)(?=\s|$)/gu;33+ /(^|\s)\p{Sc}((?![0-9][0-9_]*(?:[kKmMbBtT]|[eE][0-9]+)?(?:\s|$))(?=[a-zA-Z0-9:_-]*[a-zA-Z])[a-zA-Z0-9][a-zA-Z0-9:_-]*|[^\s:]+:[^\s]+)(?=\s|$)/gu;
juliusmarminge added labelsmacroscope-review
juliusmarminge assignedjuliusmarminge
- apps/server/src/provider/Drivers/ClaudeSkills.ts line 179Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -157,3 +168,12 @@157168 }158169 });159170171+const findPluginRepositoryRoot = Effect.fn("findPluginRepositoryRoot")(function* (cwd: string) {172+ const fileSystem = yield* FileSystem.FileSystem;173+ const path = yield* Path.Path;174+ const root = yield* findRepositoryRoot(cwd);175+ if (root === undefined) return undefined;176+ const gitFile = yield* fileSystem177+ .readFileString(path.join(root, ".git"))178+ .pipe(Effect.orElseSucceed(() => ""));179+ if (!gitFile.trim().startsWith("gitdir:")) return root;
juliusmarminge merged thisc2b127f
juliusmarminge closed this
Sign in to join this conversation.


macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed