feat: Add Qwen Code support
- Add Qwen Code target for converting Claude Code plugins - Implement claude-to-qwen converter with agent/command/skill mapping - Write qwen-extension.json config with MCP servers and settings - Generate QWEN.md context file with plugin documentation - Support nested commands with colon separator (workflows:plan) - Extract MCP environment placeholders as settings - Add --to qwen and --qwen-home CLI options - Document Qwen installation in README Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -25,7 +25,7 @@ export default defineCommand({
|
||||
to: {
|
||||
type: "string",
|
||||
default: "opencode",
|
||||
description: "Target format (opencode | codex | droid | cursor | pi | copilot | gemini | kiro)",
|
||||
description: "Target format (opencode | codex | droid | cursor | pi | copilot | gemini | kiro | qwen)",
|
||||
},
|
||||
output: {
|
||||
type: "string",
|
||||
@@ -42,6 +42,11 @@ export default defineCommand({
|
||||
alias: "pi-home",
|
||||
description: "Write Pi output to this Pi root (ex: ~/.pi/agent or ./.pi)",
|
||||
},
|
||||
qwenHome: {
|
||||
type: "string",
|
||||
alias: "qwen-home",
|
||||
description: "Write Qwen output to this Qwen extensions root (ex: ~/.qwen/extensions/compound-engineering)",
|
||||
},
|
||||
also: {
|
||||
type: "string",
|
||||
description: "Comma-separated extra targets to generate (ex: codex)",
|
||||
@@ -84,6 +89,7 @@ export default defineCommand({
|
||||
const outputRoot = resolveOutputRoot(args.output)
|
||||
const codexHome = resolveTargetHome(args.codexHome, path.join(os.homedir(), ".codex"))
|
||||
const piHome = resolveTargetHome(args.piHome, path.join(os.homedir(), ".pi", "agent"))
|
||||
const qwenHome = resolveTargetHome(args.qwenHome, path.join(os.homedir(), ".qwen", "extensions", "compound-engineering"))
|
||||
|
||||
const options = {
|
||||
agentMode: String(args.agentMode) === "primary" ? "primary" : "subagent",
|
||||
@@ -178,6 +184,10 @@ function resolveTargetOutputRoot(
|
||||
): string {
|
||||
if (targetName === "codex") return codexHome
|
||||
if (targetName === "pi") return piHome
|
||||
if (targetName === "qwen") {
|
||||
const base = hasExplicitOutput ? outputRoot : path.join(os.homedir(), ".qwen", "extensions")
|
||||
return path.join(base, "compound-engineering")
|
||||
}
|
||||
if (targetName === "droid") return path.join(os.homedir(), ".factory")
|
||||
if (targetName === "cursor") {
|
||||
const base = hasExplicitOutput ? outputRoot : process.cwd()
|
||||
|
||||
262
src/converters/claude-to-qwen.ts
Normal file
262
src/converters/claude-to-qwen.ts
Normal file
@@ -0,0 +1,262 @@
|
||||
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
|
||||
}
|
||||
|
||||
const TOOL_MAP: Record<string, string> = {
|
||||
bash: "bash",
|
||||
read: "read",
|
||||
write: "write",
|
||||
edit: "edit",
|
||||
grep: "grep",
|
||||
glob: "glob",
|
||||
list: "list",
|
||||
webfetch: "webfetch",
|
||||
skill: "skill",
|
||||
patch: "patch",
|
||||
task: "task",
|
||||
question: "question",
|
||||
todowrite: "todowrite",
|
||||
todoread: "todoread",
|
||||
}
|
||||
|
||||
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,
|
||||
cwd: "${extensionPath}${/}",
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if (server.url) {
|
||||
// Qwen doesn't support remote MCP servers in the same way
|
||||
// Convert to local with proxy or skip
|
||||
console.warn(`Warning: Remote MCP server '${name}' with URL ${server.url} is not fully supported in Qwen format`)
|
||||
result[name] = {
|
||||
command: "curl",
|
||||
args: [server.url],
|
||||
env: server.headers,
|
||||
}
|
||||
}
|
||||
}
|
||||
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.name}`)
|
||||
sections.push("")
|
||||
if (plugin.description) {
|
||||
sections.push(plugin.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(/~\/\.claude\//g, "~/.qwen/")
|
||||
.replace(/\.claude\//g, ".qwen/")
|
||||
.replace(/~\/\.config\/opencode\//g, "~/.qwen/")
|
||||
.replace(/\.opencode\//g, ".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 0.3
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import type { PiBundle } from "../types/pi"
|
||||
import type { CopilotBundle } from "../types/copilot"
|
||||
import type { GeminiBundle } from "../types/gemini"
|
||||
import type { KiroBundle } from "../types/kiro"
|
||||
import type { QwenBundle } from "../types/qwen"
|
||||
import { convertClaudeToOpenCode, type ClaudeToOpenCodeOptions } from "../converters/claude-to-opencode"
|
||||
import { convertClaudeToCodex } from "../converters/claude-to-codex"
|
||||
import { convertClaudeToDroid } from "../converters/claude-to-droid"
|
||||
@@ -13,6 +14,7 @@ import { convertClaudeToPi } from "../converters/claude-to-pi"
|
||||
import { convertClaudeToCopilot } from "../converters/claude-to-copilot"
|
||||
import { convertClaudeToGemini } from "../converters/claude-to-gemini"
|
||||
import { convertClaudeToKiro } from "../converters/claude-to-kiro"
|
||||
import { convertClaudeToQwen, type ClaudeToQwenOptions } from "../converters/claude-to-qwen"
|
||||
import { writeOpenCodeBundle } from "./opencode"
|
||||
import { writeCodexBundle } from "./codex"
|
||||
import { writeDroidBundle } from "./droid"
|
||||
@@ -20,6 +22,7 @@ import { writePiBundle } from "./pi"
|
||||
import { writeCopilotBundle } from "./copilot"
|
||||
import { writeGeminiBundle } from "./gemini"
|
||||
import { writeKiroBundle } from "./kiro"
|
||||
import { writeQwenBundle } from "./qwen"
|
||||
|
||||
export type TargetHandler<TBundle = unknown> = {
|
||||
name: string
|
||||
@@ -71,4 +74,10 @@ export const targets: Record<string, TargetHandler> = {
|
||||
convert: convertClaudeToKiro as TargetHandler<KiroBundle>["convert"],
|
||||
write: writeKiroBundle as TargetHandler<KiroBundle>["write"],
|
||||
},
|
||||
qwen: {
|
||||
name: "qwen",
|
||||
implemented: true,
|
||||
convert: convertClaudeToQwen as TargetHandler<QwenBundle>["convert"],
|
||||
write: writeQwenBundle as TargetHandler<QwenBundle>["write"],
|
||||
},
|
||||
}
|
||||
|
||||
81
src/targets/qwen.ts
Normal file
81
src/targets/qwen.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import path from "path"
|
||||
import { backupFile, copyDir, ensureDir, writeJson, writeText } from "../utils/files"
|
||||
import type { QwenBundle, QwenExtensionConfig } from "../types/qwen"
|
||||
|
||||
export async function writeQwenBundle(outputRoot: string, bundle: QwenBundle): Promise<void> {
|
||||
const qwenPaths = resolveQwenPaths(outputRoot)
|
||||
await ensureDir(qwenPaths.root)
|
||||
|
||||
// Write qwen-extension.json config
|
||||
const configPath = qwenPaths.configPath
|
||||
const backupPath = await backupFile(configPath)
|
||||
if (backupPath) {
|
||||
console.log(`Backed up existing config to ${backupPath}`)
|
||||
}
|
||||
await writeJson(configPath, bundle.config)
|
||||
|
||||
// Write context file (QWEN.md)
|
||||
if (bundle.contextFile) {
|
||||
await writeText(qwenPaths.contextPath, bundle.contextFile + "\n")
|
||||
}
|
||||
|
||||
// Write agents
|
||||
const agentsDir = qwenPaths.agentsDir
|
||||
await ensureDir(agentsDir)
|
||||
for (const agent of bundle.agents) {
|
||||
const ext = agent.format === "yaml" ? "yaml" : "md"
|
||||
await writeText(path.join(agentsDir, `${agent.name}.${ext}`), agent.content + "\n")
|
||||
}
|
||||
|
||||
// Write commands
|
||||
const commandsDir = qwenPaths.commandsDir
|
||||
await ensureDir(commandsDir)
|
||||
for (const commandFile of bundle.commandFiles) {
|
||||
// Support nested commands with colon separator
|
||||
const parts = commandFile.name.split(":")
|
||||
if (parts.length > 1) {
|
||||
const nestedDir = path.join(commandsDir, ...parts.slice(0, -1))
|
||||
await ensureDir(nestedDir)
|
||||
await writeText(path.join(nestedDir, `${parts[parts.length - 1]}.md`), commandFile.content + "\n")
|
||||
} else {
|
||||
await writeText(path.join(commandsDir, `${commandFile.name}.md`), commandFile.content + "\n")
|
||||
}
|
||||
}
|
||||
|
||||
// Copy skills
|
||||
if (bundle.skillDirs.length > 0) {
|
||||
const skillsRoot = qwenPaths.skillsDir
|
||||
await ensureDir(skillsRoot)
|
||||
for (const skill of bundle.skillDirs) {
|
||||
await copyDir(skill.sourceDir, path.join(skillsRoot, skill.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function resolveQwenPaths(outputRoot: string) {
|
||||
const base = path.basename(outputRoot)
|
||||
// Global install: ~/.qwen/extensions/<extension-name>
|
||||
// Project install: .qwen/extensions/<extension-name> or <extension-name> at root
|
||||
// If the output root already ends with "extensions" or contains ".qwen/extensions", write directly
|
||||
if (base === "extensions" || outputRoot.includes(".qwen/extensions")) {
|
||||
return {
|
||||
root: outputRoot,
|
||||
configPath: path.join(outputRoot, "qwen-extension.json"),
|
||||
contextPath: path.join(outputRoot, "QWEN.md"),
|
||||
agentsDir: path.join(outputRoot, "agents"),
|
||||
commandsDir: path.join(outputRoot, "commands"),
|
||||
skillsDir: path.join(outputRoot, "skills"),
|
||||
}
|
||||
}
|
||||
|
||||
// Custom output directory - write directly to the output root (not nested)
|
||||
// This is for project-level installs like ./my-extension
|
||||
return {
|
||||
root: outputRoot,
|
||||
configPath: path.join(outputRoot, "qwen-extension.json"),
|
||||
contextPath: path.join(outputRoot, "QWEN.md"),
|
||||
agentsDir: path.join(outputRoot, "agents"),
|
||||
commandsDir: path.join(outputRoot, "commands"),
|
||||
skillsDir: path.join(outputRoot, "skills"),
|
||||
}
|
||||
}
|
||||
48
src/types/qwen.ts
Normal file
48
src/types/qwen.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
export type QwenExtensionConfig = {
|
||||
name: string
|
||||
version: string
|
||||
mcpServers?: Record<string, QwenMcpServer>
|
||||
contextFileName?: string
|
||||
commands?: string
|
||||
skills?: string
|
||||
agents?: string
|
||||
settings?: QwenSetting[]
|
||||
}
|
||||
|
||||
export type QwenMcpServer = {
|
||||
command?: string
|
||||
args?: string[]
|
||||
env?: Record<string, string>
|
||||
cwd?: string
|
||||
}
|
||||
|
||||
export type QwenSetting = {
|
||||
name: string
|
||||
description: string
|
||||
envVar: string
|
||||
sensitive?: boolean
|
||||
}
|
||||
|
||||
export type QwenAgentFile = {
|
||||
name: string
|
||||
content: string
|
||||
format: "yaml" | "markdown"
|
||||
}
|
||||
|
||||
export type QwenSkillDir = {
|
||||
sourceDir: string
|
||||
name: string
|
||||
}
|
||||
|
||||
export type QwenCommandFile = {
|
||||
name: string
|
||||
content: string
|
||||
}
|
||||
|
||||
export type QwenBundle = {
|
||||
config: QwenExtensionConfig
|
||||
agents: QwenAgentFile[]
|
||||
commandFiles: QwenCommandFile[]
|
||||
skillDirs: QwenSkillDir[]
|
||||
contextFile?: string
|
||||
}
|
||||
Reference in New Issue
Block a user