chore: Resolve merge conflict with main (openclaw + qwen + windsurf)
- Combine windsurf scope support from this branch with openclaw/qwen targets from main - Update resolve-output.ts utility to handle openclaw/qwen with openclawHome/qwenHome/pluginName - Add openclawHome/qwenHome args to install.ts and convert.ts - Register openclaw and qwen in targets/index.ts alongside windsurf - Add openclaw/qwen coverage to resolve-output.test.ts (4 new tests → 288 total) - Update README to document all 10 targets including windsurf and openclaw Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
240
src/converters/claude-to-openclaw.ts
Normal file
240
src/converters/claude-to-openclaw.ts
Normal file
@@ -0,0 +1,240 @@
|
||||
import { formatFrontmatter } from "../utils/frontmatter"
|
||||
import type {
|
||||
ClaudeAgent,
|
||||
ClaudeCommand,
|
||||
ClaudePlugin,
|
||||
ClaudeMcpServer,
|
||||
} from "../types/claude"
|
||||
import type {
|
||||
OpenClawBundle,
|
||||
OpenClawCommandRegistration,
|
||||
OpenClawPluginManifest,
|
||||
OpenClawSkillFile,
|
||||
} from "../types/openclaw"
|
||||
import type { ClaudeToOpenCodeOptions } from "./claude-to-opencode"
|
||||
|
||||
export type ClaudeToOpenClawOptions = ClaudeToOpenCodeOptions
|
||||
|
||||
export function convertClaudeToOpenClaw(
|
||||
plugin: ClaudePlugin,
|
||||
_options: ClaudeToOpenClawOptions,
|
||||
): OpenClawBundle {
|
||||
const enabledCommands = plugin.commands.filter((cmd) => !cmd.disableModelInvocation)
|
||||
|
||||
const agentSkills = plugin.agents.map(convertAgentToSkill)
|
||||
const commandSkills = enabledCommands.map(convertCommandToSkill)
|
||||
const commands = enabledCommands.map(convertCommand)
|
||||
|
||||
const skills: OpenClawSkillFile[] = [...agentSkills, ...commandSkills]
|
||||
|
||||
const skillDirCopies = plugin.skills.map((skill) => ({
|
||||
sourceDir: skill.sourceDir,
|
||||
name: skill.name,
|
||||
}))
|
||||
|
||||
const allSkillDirs = [
|
||||
...agentSkills.map((s) => s.dir),
|
||||
...commandSkills.map((s) => s.dir),
|
||||
...plugin.skills.map((s) => s.name),
|
||||
]
|
||||
|
||||
const manifest = buildManifest(plugin, allSkillDirs)
|
||||
|
||||
const packageJson = buildPackageJson(plugin)
|
||||
|
||||
const openclawConfig = plugin.mcpServers
|
||||
? buildOpenClawConfig(plugin.mcpServers)
|
||||
: undefined
|
||||
|
||||
const entryPoint = generateEntryPoint(commands)
|
||||
|
||||
return {
|
||||
manifest,
|
||||
packageJson,
|
||||
entryPoint,
|
||||
skills,
|
||||
skillDirCopies,
|
||||
commands,
|
||||
openclawConfig,
|
||||
}
|
||||
}
|
||||
|
||||
function buildManifest(plugin: ClaudePlugin, skillDirs: string[]): OpenClawPluginManifest {
|
||||
return {
|
||||
id: plugin.manifest.name,
|
||||
name: formatDisplayName(plugin.manifest.name),
|
||||
kind: "tool",
|
||||
skills: skillDirs.map((dir) => `skills/${dir}`),
|
||||
}
|
||||
}
|
||||
|
||||
function buildPackageJson(plugin: ClaudePlugin): Record<string, unknown> {
|
||||
return {
|
||||
name: `openclaw-${plugin.manifest.name}`,
|
||||
version: plugin.manifest.version,
|
||||
type: "module",
|
||||
private: true,
|
||||
description: plugin.manifest.description,
|
||||
main: "index.ts",
|
||||
openclaw: {
|
||||
extensions: [
|
||||
{
|
||||
id: plugin.manifest.name,
|
||||
entry: "./index.ts",
|
||||
},
|
||||
],
|
||||
},
|
||||
keywords: [
|
||||
"openclaw",
|
||||
"openclaw-plugin",
|
||||
...(plugin.manifest.keywords ?? []),
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
function convertAgentToSkill(agent: ClaudeAgent): OpenClawSkillFile {
|
||||
const frontmatter: Record<string, unknown> = {
|
||||
name: agent.name,
|
||||
description: agent.description,
|
||||
}
|
||||
|
||||
if (agent.model && agent.model !== "inherit") {
|
||||
frontmatter.model = agent.model
|
||||
}
|
||||
|
||||
const body = rewritePaths(agent.body)
|
||||
const content = formatFrontmatter(frontmatter, body)
|
||||
|
||||
return {
|
||||
name: agent.name,
|
||||
content,
|
||||
dir: `agent-${agent.name}`,
|
||||
}
|
||||
}
|
||||
|
||||
function convertCommandToSkill(command: ClaudeCommand): OpenClawSkillFile {
|
||||
const frontmatter: Record<string, unknown> = {
|
||||
name: `cmd-${command.name}`,
|
||||
description: command.description,
|
||||
}
|
||||
|
||||
if (command.model && command.model !== "inherit") {
|
||||
frontmatter.model = command.model
|
||||
}
|
||||
|
||||
const body = rewritePaths(command.body)
|
||||
const content = formatFrontmatter(frontmatter, body)
|
||||
|
||||
return {
|
||||
name: command.name,
|
||||
content,
|
||||
dir: `cmd-${command.name}`,
|
||||
}
|
||||
}
|
||||
|
||||
function convertCommand(command: ClaudeCommand): OpenClawCommandRegistration {
|
||||
return {
|
||||
name: command.name.replace(/:/g, "-"),
|
||||
description: command.description ?? `Run ${command.name}`,
|
||||
acceptsArgs: Boolean(command.argumentHint),
|
||||
body: rewritePaths(command.body),
|
||||
}
|
||||
}
|
||||
|
||||
function buildOpenClawConfig(
|
||||
servers: Record<string, ClaudeMcpServer>,
|
||||
): Record<string, unknown> {
|
||||
const mcpServers: Record<string, unknown> = {}
|
||||
|
||||
for (const [name, server] of Object.entries(servers)) {
|
||||
if (server.command) {
|
||||
mcpServers[name] = {
|
||||
type: "stdio",
|
||||
command: server.command,
|
||||
args: server.args ?? [],
|
||||
env: server.env,
|
||||
}
|
||||
} else if (server.url) {
|
||||
mcpServers[name] = {
|
||||
type: "http",
|
||||
url: server.url,
|
||||
headers: server.headers,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { mcpServers }
|
||||
}
|
||||
|
||||
function generateEntryPoint(commands: OpenClawCommandRegistration[]): string {
|
||||
const commandRegistrations = commands
|
||||
.map((cmd) => {
|
||||
// JSON.stringify produces a fully-escaped string literal safe for JS/TS source embedding
|
||||
const safeName = JSON.stringify(cmd.name)
|
||||
const safeDesc = JSON.stringify(cmd.description ?? "")
|
||||
const safeNotFound = JSON.stringify(`Command ${cmd.name} not found. Check skills directory.`)
|
||||
return ` api.registerCommand({
|
||||
name: ${safeName},
|
||||
description: ${safeDesc},
|
||||
acceptsArgs: ${cmd.acceptsArgs},
|
||||
requireAuth: false,
|
||||
handler: (ctx) => ({
|
||||
text: skills[${safeName}] ?? ${safeNotFound},
|
||||
}),
|
||||
});`
|
||||
})
|
||||
.join("\n\n")
|
||||
|
||||
return `// Auto-generated OpenClaw plugin entry point
|
||||
// Converted from Claude Code plugin format by compound-plugin CLI
|
||||
import { promises as fs } from "fs";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
// Pre-load skill bodies for command responses
|
||||
const skills: Record<string, string> = {};
|
||||
|
||||
async function loadSkills() {
|
||||
const skillsDir = path.join(__dirname, "skills");
|
||||
try {
|
||||
const entries = await fs.readdir(skillsDir, { withFileTypes: true });
|
||||
for (const entry of entries) {
|
||||
if (!entry.isDirectory()) continue;
|
||||
const skillPath = path.join(skillsDir, entry.name, "SKILL.md");
|
||||
try {
|
||||
const content = await fs.readFile(skillPath, "utf8");
|
||||
// Strip frontmatter
|
||||
const body = content.replace(/^---[\\s\\S]*?---\\n*/, "");
|
||||
skills[entry.name.replace(/^cmd-/, "")] = body.trim();
|
||||
} catch {
|
||||
// Skill file not found, skip
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Skills directory not found
|
||||
}
|
||||
}
|
||||
|
||||
export default async function register(api) {
|
||||
await loadSkills();
|
||||
|
||||
${commandRegistrations}
|
||||
}
|
||||
`
|
||||
}
|
||||
|
||||
function rewritePaths(body: string): string {
|
||||
return body
|
||||
.replace(/(?<=^|\s|["'`])~\/\.claude\//gm, "~/.openclaw/")
|
||||
.replace(/(?<=^|\s|["'`])\.claude\//gm, ".openclaw/")
|
||||
.replace(/\.claude-plugin\//g, "openclaw-plugin/")
|
||||
}
|
||||
|
||||
function formatDisplayName(name: string): string {
|
||||
return name
|
||||
.split("-")
|
||||
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
||||
.join(" ")
|
||||
}
|
||||
238
src/converters/claude-to-qwen.ts
Normal file
238
src/converters/claude-to-qwen.ts
Normal file
@@ -0,0 +1,238 @@
|
||||
import { formatFrontmatter } from "../utils/frontmatter"
|
||||
import type { ClaudeAgent, ClaudeCommand, ClaudeMcpServer, ClaudePlugin } from "../types/claude"
|
||||
import type {
|
||||
QwenAgentFile,
|
||||
QwenBundle,
|
||||
QwenCommandFile,
|
||||
QwenExtensionConfig,
|
||||
QwenMcpServer,
|
||||
QwenSetting,
|
||||
} from "../types/qwen"
|
||||
|
||||
export type ClaudeToQwenOptions = {
|
||||
agentMode: "primary" | "subagent"
|
||||
inferTemperature: boolean
|
||||
}
|
||||
|
||||
export function convertClaudeToQwen(plugin: ClaudePlugin, options: ClaudeToQwenOptions): QwenBundle {
|
||||
const agentFiles = plugin.agents.map((agent) => convertAgent(agent, options))
|
||||
const cmdFiles = convertCommands(plugin.commands)
|
||||
const mcp = plugin.mcpServers ? convertMcp(plugin.mcpServers) : undefined
|
||||
const settings = extractSettings(plugin.mcpServers)
|
||||
|
||||
const config: QwenExtensionConfig = {
|
||||
name: plugin.manifest.name,
|
||||
version: plugin.manifest.version || "1.0.0",
|
||||
commands: "commands",
|
||||
skills: "skills",
|
||||
agents: "agents",
|
||||
}
|
||||
|
||||
if (mcp && Object.keys(mcp).length > 0) {
|
||||
config.mcpServers = mcp
|
||||
}
|
||||
|
||||
if (settings && settings.length > 0) {
|
||||
config.settings = settings
|
||||
}
|
||||
|
||||
const contextFile = generateContextFile(plugin)
|
||||
|
||||
return {
|
||||
config,
|
||||
agents: agentFiles,
|
||||
commandFiles: cmdFiles,
|
||||
skillDirs: plugin.skills.map((skill) => ({ sourceDir: skill.sourceDir, name: skill.name })),
|
||||
contextFile,
|
||||
}
|
||||
}
|
||||
|
||||
function convertAgent(agent: ClaudeAgent, options: ClaudeToQwenOptions): QwenAgentFile {
|
||||
const frontmatter: Record<string, unknown> = {
|
||||
name: agent.name,
|
||||
description: agent.description,
|
||||
}
|
||||
|
||||
if (agent.model && agent.model !== "inherit") {
|
||||
frontmatter.model = normalizeModel(agent.model)
|
||||
}
|
||||
|
||||
if (options.inferTemperature) {
|
||||
const temperature = inferTemperature(agent)
|
||||
if (temperature !== undefined) {
|
||||
frontmatter.temperature = temperature
|
||||
}
|
||||
}
|
||||
|
||||
// Qwen supports both YAML and Markdown for agents
|
||||
// Using YAML format for structured config
|
||||
const content = formatFrontmatter(frontmatter, rewriteQwenPaths(agent.body))
|
||||
|
||||
return {
|
||||
name: agent.name,
|
||||
content,
|
||||
format: "yaml",
|
||||
}
|
||||
}
|
||||
|
||||
function convertCommands(commands: ClaudeCommand[]): QwenCommandFile[] {
|
||||
const files: QwenCommandFile[] = []
|
||||
for (const command of commands) {
|
||||
if (command.disableModelInvocation) continue
|
||||
const frontmatter: Record<string, unknown> = {
|
||||
description: command.description,
|
||||
}
|
||||
if (command.model && command.model !== "inherit") {
|
||||
frontmatter.model = normalizeModel(command.model)
|
||||
}
|
||||
if (command.allowedTools && command.allowedTools.length > 0) {
|
||||
frontmatter.allowedTools = command.allowedTools
|
||||
}
|
||||
const content = formatFrontmatter(frontmatter, rewriteQwenPaths(command.body))
|
||||
files.push({ name: command.name, content })
|
||||
}
|
||||
return files
|
||||
}
|
||||
|
||||
function convertMcp(servers: Record<string, ClaudeMcpServer>): Record<string, QwenMcpServer> {
|
||||
const result: Record<string, QwenMcpServer> = {}
|
||||
for (const [name, server] of Object.entries(servers)) {
|
||||
if (server.command) {
|
||||
result[name] = {
|
||||
command: server.command,
|
||||
args: server.args,
|
||||
env: server.env,
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (server.url) {
|
||||
// Qwen only supports stdio (command-based) MCP servers — skip remote servers
|
||||
console.warn(
|
||||
`Warning: Remote MCP server '${name}' (URL: ${server.url}) is not supported in Qwen format. Qwen only supports stdio MCP servers. Skipping.`,
|
||||
)
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
function extractSettings(mcpServers?: Record<string, ClaudeMcpServer>): QwenSetting[] {
|
||||
const settings: QwenSetting[] = []
|
||||
if (!mcpServers) return settings
|
||||
|
||||
for (const [name, server] of Object.entries(mcpServers)) {
|
||||
if (server.env) {
|
||||
for (const [envVar, value] of Object.entries(server.env)) {
|
||||
// Only add settings for environment variables that look like placeholders
|
||||
if (value.startsWith("${") || value.includes("YOUR_") || value.includes("XXX")) {
|
||||
settings.push({
|
||||
name: formatSettingName(envVar),
|
||||
description: `Environment variable for ${name} MCP server`,
|
||||
envVar,
|
||||
sensitive: envVar.toLowerCase().includes("key") || envVar.toLowerCase().includes("token") || envVar.toLowerCase().includes("secret"),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return settings
|
||||
}
|
||||
|
||||
function formatSettingName(envVar: string): string {
|
||||
return envVar
|
||||
.replace(/_/g, " ")
|
||||
.toLowerCase()
|
||||
.replace(/\b\w/g, (c) => c.toUpperCase())
|
||||
}
|
||||
|
||||
function generateContextFile(plugin: ClaudePlugin): string {
|
||||
const sections: string[] = []
|
||||
|
||||
// Plugin description
|
||||
sections.push(`# ${plugin.manifest.name}`)
|
||||
sections.push("")
|
||||
if (plugin.manifest.description) {
|
||||
sections.push(plugin.manifest.description)
|
||||
sections.push("")
|
||||
}
|
||||
|
||||
// Agents section
|
||||
if (plugin.agents.length > 0) {
|
||||
sections.push("## Agents")
|
||||
sections.push("")
|
||||
for (const agent of plugin.agents) {
|
||||
sections.push(`- **${agent.name}**: ${agent.description || "No description"}`)
|
||||
}
|
||||
sections.push("")
|
||||
}
|
||||
|
||||
// Commands section
|
||||
if (plugin.commands.length > 0) {
|
||||
sections.push("## Commands")
|
||||
sections.push("")
|
||||
for (const command of plugin.commands) {
|
||||
if (!command.disableModelInvocation) {
|
||||
sections.push(`- **/${command.name}**: ${command.description || "No description"}`)
|
||||
}
|
||||
}
|
||||
sections.push("")
|
||||
}
|
||||
|
||||
// Skills section
|
||||
if (plugin.skills.length > 0) {
|
||||
sections.push("## Skills")
|
||||
sections.push("")
|
||||
for (const skill of plugin.skills) {
|
||||
sections.push(`- ${skill.name}`)
|
||||
}
|
||||
sections.push("")
|
||||
}
|
||||
|
||||
return sections.join("\n")
|
||||
}
|
||||
|
||||
function rewriteQwenPaths(body: string): string {
|
||||
return body
|
||||
.replace(/(?<=^|\s|["'`])~\/\.claude\//gm, "~/.qwen/")
|
||||
.replace(/(?<=^|\s|["'`])\.claude\//gm, ".qwen/")
|
||||
}
|
||||
|
||||
const CLAUDE_FAMILY_ALIASES: Record<string, string> = {
|
||||
haiku: "claude-haiku",
|
||||
sonnet: "claude-sonnet",
|
||||
opus: "claude-opus",
|
||||
}
|
||||
|
||||
function normalizeModel(model: string): string {
|
||||
if (model.includes("/")) return model
|
||||
if (CLAUDE_FAMILY_ALIASES[model]) {
|
||||
const resolved = `anthropic/${CLAUDE_FAMILY_ALIASES[model]}`
|
||||
console.warn(
|
||||
`Warning: bare model alias "${model}" mapped to "${resolved}".`,
|
||||
)
|
||||
return resolved
|
||||
}
|
||||
if (/^claude-/.test(model)) return `anthropic/${model}`
|
||||
if (/^(gpt-|o1-|o3-)/.test(model)) return `openai/${model}`
|
||||
if (/^gemini-/.test(model)) return `google/${model}`
|
||||
if (/^qwen-/.test(model)) return `qwen/${model}`
|
||||
return `anthropic/${model}`
|
||||
}
|
||||
|
||||
function inferTemperature(agent: ClaudeAgent): number | undefined {
|
||||
const sample = `${agent.name} ${agent.description ?? ""}`.toLowerCase()
|
||||
if (/(review|audit|security|sentinel|oracle|lint|verification|guardian)/.test(sample)) {
|
||||
return 0.1
|
||||
}
|
||||
if (/(plan|planning|architecture|strategist|analysis|research)/.test(sample)) {
|
||||
return 0.2
|
||||
}
|
||||
if (/(doc|readme|changelog|editor|writer)/.test(sample)) {
|
||||
return 0.3
|
||||
}
|
||||
if (/(brainstorm|creative|ideate|design|concept)/.test(sample)) {
|
||||
return 0.6
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
Reference in New Issue
Block a user