@bldg-7/cc-plugin-loader 0.1.1 → 0.2.1
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 +4 -2
- package/src/constants.ts +4 -1
- package/src/hooks/config.ts +31 -3
- package/src/loader.ts +1 -0
- package/src/parser.ts +9 -4
- package/src/types.ts +4 -2
package/package.json
CHANGED
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
|
-
|
|
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) */
|
package/src/hooks/config.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
mode: "
|
|
53
|
+
mode: "all",
|
|
27
54
|
prompt: agent.prompt,
|
|
28
55
|
tools: mapTools(agent.tools),
|
|
29
|
-
...(
|
|
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
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
|
|
31
|
-
|
|
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
|
|