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:
@@ -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"),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user