@bldg-7/cc-plugin-loader 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bldg-7/cc-plugin-loader",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
6
  "files": [
@@ -0,0 +1,54 @@
1
+ import { readFile } from "fs/promises";
2
+ import { tool } from "@opencode-ai/plugin";
3
+ import { parseFrontmatter } from "../parser.js";
4
+ import type { ParsedPlugin, ParsedSkill, ParsedCommand } from "../types.js";
5
+
6
+ type Loadable = ParsedSkill | ParsedCommand;
7
+
8
+ export function createSkillTool(plugins: ParsedPlugin[]) {
9
+ const lookup = new Map<string, Loadable>();
10
+ const names: string[] = [];
11
+
12
+ for (const plugin of plugins) {
13
+ for (const skill of plugin.skills) {
14
+ lookup.set(skill.qualifiedName, skill);
15
+ names.push(skill.qualifiedName);
16
+ }
17
+ for (const cmd of plugin.commands) {
18
+ lookup.set(cmd.qualifiedName, cmd);
19
+ names.push(cmd.qualifiedName);
20
+ }
21
+ }
22
+
23
+ if (lookup.size === 0) return undefined;
24
+
25
+ return tool({
26
+ description: `Execute a skill/command from Claude Code plugins. Available: ${names.join(", ")}`,
27
+ args: {
28
+ skill: tool.schema.string().describe("Skill name (e.g. plugin-name:skill-name)"),
29
+ args: tool.schema.string().optional().describe("Optional arguments to pass to the skill"),
30
+ },
31
+ async execute({ skill: skillName, args: skillArgs }) {
32
+ const item = lookup.get(skillName);
33
+ if (!item) {
34
+ return `Skill "${skillName}" not found. Available skills: ${names.join(", ")}`;
35
+ }
36
+
37
+ let content: string;
38
+ if (item._content) {
39
+ content = item._content;
40
+ } else {
41
+ try {
42
+ const raw = await readFile(item.contentPath, "utf-8");
43
+ const { body } = parseFrontmatter<unknown>(raw);
44
+ item._content = body;
45
+ content = body;
46
+ } catch (e) {
47
+ return `Failed to load skill "${skillName}": ${e}`;
48
+ }
49
+ }
50
+
51
+ return skillArgs ? `${content}\n\nARGUMENTS: ${skillArgs}` : content;
52
+ },
53
+ });
54
+ }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@ import { createSystemHook } from "./hooks/system.js";
6
6
  import { createCommandHook } from "./hooks/command.js";
7
7
  import { createEnvHook } from "./hooks/env.js";
8
8
  import { createBridgeHooks } from "./hooks/bridge.js";
9
+ import { createSkillTool } from "./hooks/skill-tool.js";
9
10
  import type { ParsedPlugin } from "./types.js";
10
11
 
11
12
  const plugin: Plugin = async (input) => {
@@ -33,11 +34,14 @@ const plugin: Plugin = async (input) => {
33
34
  `[cc-plugin-loader] Loaded ${plugins.length} plugin(s): ${plugins.map((p) => p.name).join(", ")}`,
34
35
  );
35
36
 
37
+ const skillTool = createSkillTool(plugins);
38
+
36
39
  return {
37
40
  config: createConfigHook(plugins),
38
41
  "experimental.chat.system.transform": createSystemHook(plugins),
39
42
  "command.execute.before": createCommandHook(plugins),
40
43
  "shell.env": createEnvHook(plugins),
44
+ ...(skillTool && { tool: { skill: skillTool } }),
41
45
  ...createBridgeHooks(plugins),
42
46
  };
43
47
  };