@bldg-7/cc-plugin-loader 0.1.1 → 0.2.0

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,9 +1,11 @@
1
1
  {
2
2
  "name": "@bldg-7/cc-plugin-loader",
3
- "version": "0.1.1",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "main": "src/index.ts",
6
- "files": ["src"],
6
+ "files": [
7
+ "src"
8
+ ],
7
9
  "publishConfig": {
8
10
  "access": "public"
9
11
  },
package/src/constants.ts CHANGED
@@ -12,7 +12,10 @@ export const TOOL_NAME_MAP: Record<string, string> = {
12
12
  WebFetch: "webfetch",
13
13
  WebSearch: "websearch",
14
14
  Agent: "agent",
15
- NotebookEdit: "notebookedit",
15
+ TodoWrite: "todowrite",
16
+ Task: "task",
17
+ LS: "ls",
18
+ Skill: "skill",
16
19
  };
17
20
 
18
21
  /** OpenCode tool name → Claude Code tool name (reverse of TOOL_NAME_MAP) */
@@ -2,15 +2,41 @@ import type { Config } from "@opencode-ai/sdk";
2
2
  import { TOOL_NAME_MAP, MODEL_MAP } from "../constants.js";
3
3
  import type { ParsedPlugin } from "../types.js";
4
4
 
5
+ /** Claude Code tool names that have no OpenCode equivalent — silently dropped */
6
+ const UNMAPPABLE_TOOLS = new Set([
7
+ "NotebookEdit",
8
+ "NotebookRead",
9
+ "KillShell",
10
+ "BashOutput",
11
+ "AskUserQuestion",
12
+ ]);
13
+
14
+ /**
15
+ * Map Claude Code tool names to OpenCode tool names.
16
+ * - Exact match in TOOL_NAME_MAP takes priority
17
+ * - Scoped patterns like "Bash(git:*)" → "bash"
18
+ * - Tools with no OpenCode equivalent are dropped
19
+ */
5
20
  function mapTools(tools: string[]): Record<string, boolean> {
6
21
  const result: Record<string, boolean> = {};
7
22
  for (const tool of tools) {
8
- const mapped = TOOL_NAME_MAP[tool] || tool.toLowerCase();
23
+ // Handle scoped patterns like "Bash(git:*)"
24
+ const baseMatch = tool.match(/^(\w+)\(/);
25
+ const baseName = baseMatch ? baseMatch[1] : tool;
26
+
27
+ if (UNMAPPABLE_TOOLS.has(baseName)) continue;
28
+
29
+ const mapped = TOOL_NAME_MAP[baseName] || baseName.toLowerCase();
9
30
  result[mapped] = true;
10
31
  }
11
32
  return result;
12
33
  }
13
34
 
35
+ function mapModel(model: string): string | undefined {
36
+ if (model === "inherit") return undefined; // let OpenCode use parent model
37
+ return MODEL_MAP[model] || model;
38
+ }
39
+
14
40
  export function createConfigHook(plugins: ParsedPlugin[]) {
15
41
  return async (config: Config): Promise<void> => {
16
42
  if (!config.agent) config.agent = {};
@@ -21,13 +47,15 @@ export function createConfigHook(plugins: ParsedPlugin[]) {
21
47
  // Register agents
22
48
  for (const agent of plugin.agents) {
23
49
  const key = `${plugin.name}-${agent.name}`;
50
+ const model = agent.model ? mapModel(agent.model) : undefined;
24
51
  config.agent[key] = {
25
52
  description: agent.description,
26
53
  mode: "subagent",
27
54
  prompt: agent.prompt,
28
55
  tools: mapTools(agent.tools),
29
- ...(agent.model && { model: MODEL_MAP[agent.model] || agent.model }),
56
+ ...(model && { model }),
30
57
  ...(agent.maxTurns && { maxSteps: agent.maxTurns }),
58
+ ...(agent.color && { color: agent.color }),
31
59
  };
32
60
  }
33
61
 
package/src/loader.ts CHANGED
@@ -150,6 +150,7 @@ async function loadAgents(
150
150
  model: frontmatter.model,
151
151
  tools: normalizeTools(frontmatter),
152
152
  maxTurns: frontmatter.maxTurns,
153
+ color: frontmatter.color,
153
154
  prompt,
154
155
  });
155
156
  } catch (e) {
package/src/parser.ts CHANGED
@@ -18,17 +18,22 @@ export function parseFrontmatter<T>(content: string): Parsed<T> {
18
18
  }
19
19
 
20
20
  /**
21
- * Normalize tools from either `allowed-tools` (YAML array) or `tools` (comma-separated string).
21
+ * Normalize tools from either `allowed-tools` (YAML array) or `tools` (array or comma-separated string).
22
22
  */
23
23
  export function normalizeTools(fm: {
24
24
  "allowed-tools"?: string[];
25
- tools?: string;
25
+ tools?: string | string[];
26
26
  }): string[] {
27
27
  if (fm["allowed-tools"] && Array.isArray(fm["allowed-tools"])) {
28
28
  return fm["allowed-tools"];
29
29
  }
30
- if (fm.tools && typeof fm.tools === "string") {
31
- return fm.tools.split(",").map((t) => t.trim()).filter(Boolean);
30
+ if (fm.tools) {
31
+ if (Array.isArray(fm.tools)) {
32
+ return fm.tools;
33
+ }
34
+ if (typeof fm.tools === "string") {
35
+ return fm.tools.split(",").map((t) => t.trim()).filter(Boolean);
36
+ }
32
37
  }
33
38
  return [];
34
39
  }
package/src/types.ts CHANGED
@@ -47,7 +47,7 @@ export interface SkillFrontmatter {
47
47
  name?: string;
48
48
  description?: string;
49
49
  "allowed-tools"?: string[];
50
- tools?: string;
50
+ tools?: string | string[];
51
51
  }
52
52
 
53
53
  export interface AgentFrontmatter {
@@ -55,8 +55,9 @@ export interface AgentFrontmatter {
55
55
  description: string;
56
56
  model?: string;
57
57
  "allowed-tools"?: string[];
58
- tools?: string;
58
+ tools?: string | string[];
59
59
  maxTurns?: number;
60
+ color?: string;
60
61
  }
61
62
 
62
63
  export interface CommandFrontmatter {
@@ -94,6 +95,7 @@ export interface ParsedAgent {
94
95
  model?: string;
95
96
  tools: string[];
96
97
  maxTurns?: number;
98
+ color?: string;
97
99
  prompt: string;
98
100
  }
99
101