From 8a530f7e25448b8377686d84ae688e8e6990caa3 Mon Sep 17 00:00:00 2001 From: Brian Solon Date: Fri, 27 Feb 2026 16:43:51 -0500 Subject: [PATCH 1/3] fix: quote argument-hint values to prevent YAML object parsing Unquoted bracket syntax in `argument-hint` frontmatter causes YAML to parse the value as an array/mapping instead of a string literal. This crashes Claude Code's tab-completion TUI with React error #31 ("Objects are not valid as a React child") when the renderer tries to display the hint. Two commands affected: - `heal-skill`: `[optional: ...]` parsed as `[{optional: "..."}]` - `create-agent-skill`: `[skill ...]` parsed as `["skill ..."]` Fix: wrap values in quotes, consistent with the other 18 commands in the plugin that already quote their `argument-hint` values. Ref: https://github.com/anthropics/claude-code/issues/29422 --- plugins/compound-engineering/commands/create-agent-skill.md | 2 +- plugins/compound-engineering/commands/heal-skill.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/compound-engineering/commands/create-agent-skill.md b/plugins/compound-engineering/commands/create-agent-skill.md index 9ec53f9..2b3052b 100644 --- a/plugins/compound-engineering/commands/create-agent-skill.md +++ b/plugins/compound-engineering/commands/create-agent-skill.md @@ -2,7 +2,7 @@ name: create-agent-skill description: Create or edit Claude Code skills with expert guidance on structure and best practices allowed-tools: Skill(create-agent-skills) -argument-hint: [skill description or requirements] +argument-hint: "[skill description or requirements]" disable-model-invocation: true --- diff --git a/plugins/compound-engineering/commands/heal-skill.md b/plugins/compound-engineering/commands/heal-skill.md index 02d48a4..a021f31 100644 --- a/plugins/compound-engineering/commands/heal-skill.md +++ b/plugins/compound-engineering/commands/heal-skill.md @@ -1,7 +1,7 @@ --- name: heal-skill description: Fix incorrect SKILL.md files when a skill has wrong instructions or outdated API references -argument-hint: [optional: specific issue to fix] +argument-hint: "[optional: specific issue to fix]" allowed-tools: [Read, Edit, Bash(ls:*), Bash(git:*)] disable-model-invocation: true --- From e1d5bdedb39801a8b38c423b379de4dd36f14a12 Mon Sep 17 00:00:00 2001 From: Raymond Lam Date: Sat, 28 Feb 2026 11:51:28 -0500 Subject: [PATCH 2/3] 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 --- README.md | 8 +- src/commands/install.ts | 12 +- src/converters/claude-to-qwen.ts | 262 +++++++++++++++++++++++++++++++ src/targets/index.ts | 9 ++ src/targets/qwen.ts | 81 ++++++++++ src/types/qwen.ts | 48 ++++++ 6 files changed, 417 insertions(+), 3 deletions(-) create mode 100644 src/converters/claude-to-qwen.ts create mode 100644 src/targets/qwen.ts create mode 100644 src/types/qwen.ts diff --git a/README.md b/README.md index 5885038..f805f8e 100644 --- a/README.md +++ b/README.md @@ -18,9 +18,9 @@ A Claude Code plugin marketplace featuring the **Compound Engineering Plugin** /add-plugin compound-engineering ``` -## OpenCode, Codex, Droid, Pi, Gemini, Copilot & Kiro (experimental) Install +## OpenCode, Codex, Droid, Pi, Gemini, Copilot, Kiro & Qwen (experimental) Install -This repo includes a Bun/TypeScript CLI that converts Claude Code plugins to OpenCode, Codex, Factory Droid, Pi, Gemini CLI, GitHub Copilot, and Kiro CLI. +This repo includes a Bun/TypeScript CLI that converts Claude Code plugins to OpenCode, Codex, Factory Droid, Pi, Gemini CLI, GitHub Copilot, Kiro CLI, and Qwen Code. ```bash # convert the compound-engineering plugin into OpenCode format @@ -43,6 +43,9 @@ bunx @every-env/compound-plugin install compound-engineering --to copilot # convert to Kiro CLI format bunx @every-env/compound-plugin install compound-engineering --to kiro + +# convert to Qwen Code format +bunx @every-env/compound-plugin install compound-engineering --to qwen ``` Local dev: @@ -58,6 +61,7 @@ Pi output is written to `~/.pi/agent/` by default with prompts, skills, extensio Gemini output is written to `.gemini/` with skills (from agents), commands (`.toml`), and `settings.json` (MCP servers). Namespaced commands create directory structure (`workflows:plan` → `commands/workflows/plan.toml`). Skills use the identical SKILL.md standard and pass through unchanged. Copilot output is written to `.github/` with agents (`.agent.md`), skills (`SKILL.md`), and `copilot-mcp-config.json`. Agents get Copilot frontmatter (`description`, `tools: ["*"]`, `infer: true`), commands are converted to agent skills, and MCP server env vars are prefixed with `COPILOT_MCP_`. Kiro output is written to `.kiro/` with custom agents (`.json` configs + prompt `.md` files), skills (from commands), pass-through skills, steering files (from CLAUDE.md), and `mcp.json`. Agents get `includeMcpJson: true` for MCP server access. Only stdio MCP servers are supported (HTTP servers are skipped with a warning). +Qwen output is written to `~/.qwen/extensions/compound-engineering/` by default with `qwen-extension.json` (MCP servers), `QWEN.md` (context), agents (`.yaml`), commands (`.md`), and skills. Claude tool names are passed through unchanged. MCP server environment variables with placeholder values are extracted as settings in `qwen-extension.json`. Nested commands use colon separator (`workflows:plan` → `commands/workflows/plan.md`). All provider targets are experimental and may change as the formats evolve. diff --git a/src/commands/install.ts b/src/commands/install.ts index eeb5a85..edf9496 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -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() diff --git a/src/converters/claude-to-qwen.ts b/src/converters/claude-to-qwen.ts new file mode 100644 index 0000000..99e4e64 --- /dev/null +++ b/src/converters/claude-to-qwen.ts @@ -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 = { + 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 = { + 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 = { + 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): Record { + const result: Record = {} + 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): 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 = { + 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 +} diff --git a/src/targets/index.ts b/src/targets/index.ts index b7b3ea2..37d4d41 100644 --- a/src/targets/index.ts +++ b/src/targets/index.ts @@ -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 = { name: string @@ -71,4 +74,10 @@ export const targets: Record = { convert: convertClaudeToKiro as TargetHandler["convert"], write: writeKiroBundle as TargetHandler["write"], }, + qwen: { + name: "qwen", + implemented: true, + convert: convertClaudeToQwen as TargetHandler["convert"], + write: writeQwenBundle as TargetHandler["write"], + }, } diff --git a/src/targets/qwen.ts b/src/targets/qwen.ts new file mode 100644 index 0000000..450524a --- /dev/null +++ b/src/targets/qwen.ts @@ -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 { + 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/ + // Project install: .qwen/extensions/ or 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"), + } +} diff --git a/src/types/qwen.ts b/src/types/qwen.ts new file mode 100644 index 0000000..82cf178 --- /dev/null +++ b/src/types/qwen.ts @@ -0,0 +1,48 @@ +export type QwenExtensionConfig = { + name: string + version: string + mcpServers?: Record + contextFileName?: string + commands?: string + skills?: string + agents?: string + settings?: QwenSetting[] +} + +export type QwenMcpServer = { + command?: string + args?: string[] + env?: Record + 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 +} From 305fea486f57661a1922a5764a3a1aa0f7cc9b8b Mon Sep 17 00:00:00 2001 From: Kieran Klaassen Date: Sun, 1 Mar 2026 14:38:42 -0800 Subject: [PATCH 3/3] fix: Address review findings in Qwen converter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix P1: Remove dead TOOL_MAP constant (defined but never referenced) - Fix P1: Replace curl fallback for remote MCP servers with warn-and-skip, matching the kiro pattern — curl is not an MCP server - Fix P1: Remove incorrect literal cwd field ("${extensionPath}${/}") from stdio MCP server config; the value was never interpolated - Fix P1: Fix plugin.name → plugin.manifest.name in generateContextFile (plugin.name does not exist on ClaudePlugin; produced "# undefined") - Fix P1: Wire qwenHome through resolveTargetOutputRoot; previously the --qwen-home CLI flag was parsed but silently discarded - Fix P1: Remove hardcoded "compound-engineering" from qwen output path; now uses plugin.manifest.name via new qwenHome + pluginName params - Fix P1: Collapse dead-code resolveQwenPaths branches (both returned identical structures; simplify to a single return) - Fix P3: Remove rewriting of .opencode/ paths to .qwen/ — Claude plugins do not reference opencode paths, and rewriting them is incorrect - Fix P3: inferTemperature now returns undefined for unrecognized agents instead of 0.3 (matching the explicit doc branch), letting the model use its default temperature - Fix P2: Add lookbehind guards to rewriteQwenPaths() matching kiro pattern to avoid rewriting paths inside compound tokens or URLs - Update --qwen-home default to ~/.qwen/extensions (plugin name appended) - Add qwen-converter.test.ts with 16 tests covering all scenarios Co-Authored-By: Claude --- src/commands/install.ts | 13 +- src/converters/claude-to-qwen.ts | 44 ++---- src/targets/qwen.ts | 17 --- tests/qwen-converter.test.ts | 238 +++++++++++++++++++++++++++++++ 4 files changed, 255 insertions(+), 57 deletions(-) create mode 100644 tests/qwen-converter.test.ts diff --git a/src/commands/install.ts b/src/commands/install.ts index edf9496..5f1ac09 100644 --- a/src/commands/install.ts +++ b/src/commands/install.ts @@ -45,7 +45,7 @@ export default defineCommand({ qwenHome: { type: "string", alias: "qwen-home", - description: "Write Qwen output to this Qwen extensions root (ex: ~/.qwen/extensions/compound-engineering)", + description: "Write Qwen output to this Qwen extensions root (ex: ~/.qwen/extensions)", }, also: { type: "string", @@ -89,7 +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 qwenHome = resolveTargetHome(args.qwenHome, path.join(os.homedir(), ".qwen", "extensions")) const options = { agentMode: String(args.agentMode) === "primary" ? "primary" : "subagent", @@ -102,7 +102,7 @@ export default defineCommand({ throw new Error(`Target ${targetName} did not return a bundle.`) } const hasExplicitOutput = Boolean(args.output && String(args.output).trim()) - const primaryOutputRoot = resolveTargetOutputRoot(targetName, outputRoot, codexHome, piHome, hasExplicitOutput) + const primaryOutputRoot = resolveTargetOutputRoot(targetName, outputRoot, codexHome, piHome, qwenHome, plugin.manifest.name, hasExplicitOutput) await target.write(primaryOutputRoot, bundle) console.log(`Installed ${plugin.manifest.name} to ${primaryOutputRoot}`) @@ -123,7 +123,7 @@ export default defineCommand({ console.warn(`Skipping ${extra}: no output returned.`) continue } - const extraRoot = resolveTargetOutputRoot(extra, path.join(outputRoot, extra), codexHome, piHome, hasExplicitOutput) + const extraRoot = resolveTargetOutputRoot(extra, path.join(outputRoot, extra), codexHome, piHome, qwenHome, plugin.manifest.name, hasExplicitOutput) await handler.write(extraRoot, extraBundle) console.log(`Installed ${plugin.manifest.name} to ${extraRoot}`) } @@ -180,13 +180,14 @@ function resolveTargetOutputRoot( outputRoot: string, codexHome: string, piHome: string, + qwenHome: string, + pluginName: string, hasExplicitOutput: boolean, ): 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") + return path.join(qwenHome, pluginName) } if (targetName === "droid") return path.join(os.homedir(), ".factory") if (targetName === "cursor") { diff --git a/src/converters/claude-to-qwen.ts b/src/converters/claude-to-qwen.ts index 99e4e64..c07b177 100644 --- a/src/converters/claude-to-qwen.ts +++ b/src/converters/claude-to-qwen.ts @@ -14,23 +14,6 @@ export type ClaudeToQwenOptions = { inferTemperature: boolean } -const TOOL_MAP: Record = { - 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) @@ -119,20 +102,15 @@ function convertMcp(servers: Record): Record = { @@ -258,5 +234,5 @@ function inferTemperature(agent: ClaudeAgent): number | undefined { if (/(brainstorm|creative|ideate|design|concept)/.test(sample)) { return 0.6 } - return 0.3 + return undefined } diff --git a/src/targets/qwen.ts b/src/targets/qwen.ts index 450524a..a822857 100644 --- a/src/targets/qwen.ts +++ b/src/targets/qwen.ts @@ -53,23 +53,6 @@ export async function writeQwenBundle(outputRoot: string, bundle: QwenBundle): P } function resolveQwenPaths(outputRoot: string) { - const base = path.basename(outputRoot) - // Global install: ~/.qwen/extensions/ - // Project install: .qwen/extensions/ or 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"), diff --git a/tests/qwen-converter.test.ts b/tests/qwen-converter.test.ts new file mode 100644 index 0000000..b9690a3 --- /dev/null +++ b/tests/qwen-converter.test.ts @@ -0,0 +1,238 @@ +import { describe, expect, test } from "bun:test" +import { convertClaudeToQwen } from "../src/converters/claude-to-qwen" +import { parseFrontmatter } from "../src/utils/frontmatter" +import type { ClaudePlugin } from "../src/types/claude" + +const fixturePlugin: ClaudePlugin = { + root: "/tmp/plugin", + manifest: { name: "compound-engineering", version: "1.2.0", description: "A plugin for engineers" }, + agents: [ + { + name: "security-sentinel", + description: "Security-focused agent", + capabilities: ["Threat modeling", "OWASP"], + model: "claude-sonnet-4-20250514", + body: "Focus on vulnerabilities in ~/.claude/settings.", + sourcePath: "/tmp/plugin/agents/security-sentinel.md", + }, + { + name: "brainstorm-agent", + description: "Creative brainstormer", + model: "inherit", + body: "Generate ideas.", + sourcePath: "/tmp/plugin/agents/brainstorm-agent.md", + }, + ], + commands: [ + { + name: "workflows:plan", + description: "Planning command", + argumentHint: "[FOCUS]", + model: "inherit", + allowedTools: ["Read"], + body: "Plan the work. Config at ~/.claude/settings.", + sourcePath: "/tmp/plugin/commands/workflows/plan.md", + }, + { + name: "disabled-cmd", + description: "Disabled", + model: "inherit", + allowedTools: [], + body: "Should be excluded.", + disableModelInvocation: true, + sourcePath: "/tmp/plugin/commands/disabled-cmd.md", + }, + ], + skills: [ + { + name: "existing-skill", + description: "Existing skill", + sourceDir: "/tmp/plugin/skills/existing-skill", + skillPath: "/tmp/plugin/skills/existing-skill/SKILL.md", + }, + ], + hooks: undefined, + mcpServers: { + local: { command: "npx", args: ["-y", "some-mcp"], env: { API_KEY: "${YOUR_API_KEY}" } }, + remote: { url: "https://mcp.example.com/api", headers: { Authorization: "Bearer token" } }, + }, +} + +const defaultOptions = { + agentMode: "subagent" as const, + inferTemperature: false, +} + +describe("convertClaudeToQwen", () => { + test("converts agents to yaml format with frontmatter", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + + const agent = bundle.agents.find((a) => a.name === "security-sentinel") + expect(agent).toBeDefined() + expect(agent!.format).toBe("yaml") + const parsed = parseFrontmatter(agent!.content) + expect(parsed.data.name).toBe("security-sentinel") + expect(parsed.data.description).toBe("Security-focused agent") + expect(parsed.data.model).toBe("anthropic/claude-sonnet-4-20250514") + expect(parsed.body).toContain("Focus on vulnerabilities") + }) + + test("agent with inherit model has no model field in frontmatter", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + const agent = bundle.agents.find((a) => a.name === "brainstorm-agent") + expect(agent).toBeDefined() + const parsed = parseFrontmatter(agent!.content) + expect(parsed.data.model).toBeUndefined() + }) + + test("inferTemperature injects temperature based on agent name/description", () => { + const bundle = convertClaudeToQwen(fixturePlugin, { ...defaultOptions, inferTemperature: true }) + + const sentinel = bundle.agents.find((a) => a.name === "security-sentinel") + const parsed = parseFrontmatter(sentinel!.content) + expect(parsed.data.temperature).toBe(0.1) // review/security → 0.1 + + const brainstorm = bundle.agents.find((a) => a.name === "brainstorm-agent") + const bParsed = parseFrontmatter(brainstorm!.content) + expect(bParsed.data.temperature).toBe(0.6) // brainstorm → 0.6 + }) + + test("inferTemperature returns undefined for unrecognized agents (no temperature set)", () => { + const plugin: ClaudePlugin = { + ...fixturePlugin, + agents: [{ name: "my-helper", description: "Generic helper", model: "inherit", body: "help", sourcePath: "/tmp/a.md" }], + } + const bundle = convertClaudeToQwen(plugin, { ...defaultOptions, inferTemperature: true }) + const agent = bundle.agents[0] + const parsed = parseFrontmatter(agent.content) + expect(parsed.data.temperature).toBeUndefined() + }) + + test("converts commands to command files excluding disableModelInvocation", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + + const planCmd = bundle.commandFiles.find((c) => c.name === "workflows:plan") + expect(planCmd).toBeDefined() + const parsed = parseFrontmatter(planCmd!.content) + expect(parsed.data.description).toBe("Planning command") + expect(parsed.data.allowedTools).toEqual(["Read"]) + + const disabled = bundle.commandFiles.find((c) => c.name === "disabled-cmd") + expect(disabled).toBeUndefined() + }) + + test("config uses plugin manifest name and version", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + expect(bundle.config.name).toBe("compound-engineering") + expect(bundle.config.version).toBe("1.2.0") + expect(bundle.config.commands).toBe("commands") + expect(bundle.config.skills).toBe("skills") + expect(bundle.config.agents).toBe("agents") + }) + + test("stdio MCP servers are included in config", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + expect(bundle.config.mcpServers).toBeDefined() + const local = bundle.config.mcpServers!.local + expect(local.command).toBe("npx") + expect(local.args).toEqual(["-y", "some-mcp"]) + // No cwd field + expect((local as any).cwd).toBeUndefined() + }) + + test("remote MCP servers are skipped with a warning (not converted to curl)", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + // Only local (stdio) server should be present + expect(bundle.config.mcpServers).toBeDefined() + expect(bundle.config.mcpServers!.remote).toBeUndefined() + expect(bundle.config.mcpServers!.local).toBeDefined() + }) + + test("placeholder env vars are extracted as settings", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + expect(bundle.config.settings).toBeDefined() + const apiKeySetting = bundle.config.settings!.find((s) => s.envVar === "API_KEY") + expect(apiKeySetting).toBeDefined() + expect(apiKeySetting!.sensitive).toBe(true) + expect(apiKeySetting!.name).toBe("Api Key") + }) + + test("plugin with no MCP servers has no mcpServers in config", () => { + const plugin: ClaudePlugin = { ...fixturePlugin, mcpServers: undefined } + const bundle = convertClaudeToQwen(plugin, defaultOptions) + expect(bundle.config.mcpServers).toBeUndefined() + }) + + test("context file uses plugin.manifest.name and manifest.description", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + expect(bundle.contextFile).toContain("# compound-engineering") + expect(bundle.contextFile).toContain("A plugin for engineers") + expect(bundle.contextFile).toContain("## Agents") + expect(bundle.contextFile).toContain("security-sentinel") + expect(bundle.contextFile).toContain("## Commands") + expect(bundle.contextFile).toContain("/workflows:plan") + // Disabled commands excluded + expect(bundle.contextFile).not.toContain("disabled-cmd") + expect(bundle.contextFile).toContain("## Skills") + expect(bundle.contextFile).toContain("existing-skill") + }) + + test("paths are rewritten from .claude/ to .qwen/ in agent and command content", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + + const agent = bundle.agents.find((a) => a.name === "security-sentinel") + expect(agent!.content).toContain("~/.qwen/settings") + expect(agent!.content).not.toContain("~/.claude/settings") + + const cmd = bundle.commandFiles.find((c) => c.name === "workflows:plan") + expect(cmd!.content).toContain("~/.qwen/settings") + expect(cmd!.content).not.toContain("~/.claude/settings") + }) + + test("opencode paths are NOT rewritten (only claude paths)", () => { + const plugin: ClaudePlugin = { + ...fixturePlugin, + agents: [ + { + name: "test-agent", + description: "test", + model: "inherit", + body: "See .opencode/config and ~/.config/opencode/settings", + sourcePath: "/tmp/a.md", + }, + ], + } + const bundle = convertClaudeToQwen(plugin, defaultOptions) + const agent = bundle.agents[0] + // opencode paths should NOT be rewritten + expect(agent.content).toContain(".opencode/config") + expect(agent.content).not.toContain(".qwen/config") + }) + + test("skillDirs passes through original skills", () => { + const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions) + const skill = bundle.skillDirs.find((s) => s.name === "existing-skill") + expect(skill).toBeDefined() + expect(skill!.sourceDir).toBe("/tmp/plugin/skills/existing-skill") + }) + + test("normalizeModel prefixes claude models with anthropic/", () => { + const plugin: ClaudePlugin = { + ...fixturePlugin, + agents: [{ name: "a", description: "d", model: "claude-opus-4-5", body: "b", sourcePath: "/tmp/a.md" }], + } + const bundle = convertClaudeToQwen(plugin, defaultOptions) + const parsed = parseFrontmatter(bundle.agents[0].content) + expect(parsed.data.model).toBe("anthropic/claude-opus-4-5") + }) + + test("normalizeModel passes through already-namespaced models unchanged", () => { + const plugin: ClaudePlugin = { + ...fixturePlugin, + agents: [{ name: "a", description: "d", model: "google/gemini-2.0", body: "b", sourcePath: "/tmp/a.md" }], + } + const bundle = convertClaudeToQwen(plugin, defaultOptions) + const parsed = parseFrontmatter(bundle.agents[0].content) + expect(parsed.data.model).toBe("google/gemini-2.0") + }) +})