Skip to content

Commit 305fea4

Browse files
fix: Address review findings in Qwen converter
- 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 <noreply@anthropic.com>
1 parent e1d5bde commit 305fea4

4 files changed

Lines changed: 255 additions & 57 deletions

File tree

src/commands/install.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default defineCommand({
4545
qwenHome: {
4646
type: "string",
4747
alias: "qwen-home",
48-
description: "Write Qwen output to this Qwen extensions root (ex: ~/.qwen/extensions/compound-engineering)",
48+
description: "Write Qwen output to this Qwen extensions root (ex: ~/.qwen/extensions)",
4949
},
5050
also: {
5151
type: "string",
@@ -89,7 +89,7 @@ export default defineCommand({
8989
const outputRoot = resolveOutputRoot(args.output)
9090
const codexHome = resolveTargetHome(args.codexHome, path.join(os.homedir(), ".codex"))
9191
const piHome = resolveTargetHome(args.piHome, path.join(os.homedir(), ".pi", "agent"))
92-
const qwenHome = resolveTargetHome(args.qwenHome, path.join(os.homedir(), ".qwen", "extensions", "compound-engineering"))
92+
const qwenHome = resolveTargetHome(args.qwenHome, path.join(os.homedir(), ".qwen", "extensions"))
9393

9494
const options = {
9595
agentMode: String(args.agentMode) === "primary" ? "primary" : "subagent",
@@ -102,7 +102,7 @@ export default defineCommand({
102102
throw new Error(`Target ${targetName} did not return a bundle.`)
103103
}
104104
const hasExplicitOutput = Boolean(args.output && String(args.output).trim())
105-
const primaryOutputRoot = resolveTargetOutputRoot(targetName, outputRoot, codexHome, piHome, hasExplicitOutput)
105+
const primaryOutputRoot = resolveTargetOutputRoot(targetName, outputRoot, codexHome, piHome, qwenHome, plugin.manifest.name, hasExplicitOutput)
106106
await target.write(primaryOutputRoot, bundle)
107107
console.log(`Installed ${plugin.manifest.name} to ${primaryOutputRoot}`)
108108

@@ -123,7 +123,7 @@ export default defineCommand({
123123
console.warn(`Skipping ${extra}: no output returned.`)
124124
continue
125125
}
126-
const extraRoot = resolveTargetOutputRoot(extra, path.join(outputRoot, extra), codexHome, piHome, hasExplicitOutput)
126+
const extraRoot = resolveTargetOutputRoot(extra, path.join(outputRoot, extra), codexHome, piHome, qwenHome, plugin.manifest.name, hasExplicitOutput)
127127
await handler.write(extraRoot, extraBundle)
128128
console.log(`Installed ${plugin.manifest.name} to ${extraRoot}`)
129129
}
@@ -180,13 +180,14 @@ function resolveTargetOutputRoot(
180180
outputRoot: string,
181181
codexHome: string,
182182
piHome: string,
183+
qwenHome: string,
184+
pluginName: string,
183185
hasExplicitOutput: boolean,
184186
): string {
185187
if (targetName === "codex") return codexHome
186188
if (targetName === "pi") return piHome
187189
if (targetName === "qwen") {
188-
const base = hasExplicitOutput ? outputRoot : path.join(os.homedir(), ".qwen", "extensions")
189-
return path.join(base, "compound-engineering")
190+
return path.join(qwenHome, pluginName)
190191
}
191192
if (targetName === "droid") return path.join(os.homedir(), ".factory")
192193
if (targetName === "cursor") {

src/converters/claude-to-qwen.ts

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,6 @@ export type ClaudeToQwenOptions = {
1414
inferTemperature: boolean
1515
}
1616

17-
const TOOL_MAP: Record<string, string> = {
18-
bash: "bash",
19-
read: "read",
20-
write: "write",
21-
edit: "edit",
22-
grep: "grep",
23-
glob: "glob",
24-
list: "list",
25-
webfetch: "webfetch",
26-
skill: "skill",
27-
patch: "patch",
28-
task: "task",
29-
question: "question",
30-
todowrite: "todowrite",
31-
todoread: "todoread",
32-
}
33-
3417
export function convertClaudeToQwen(plugin: ClaudePlugin, options: ClaudeToQwenOptions): QwenBundle {
3518
const agentFiles = plugin.agents.map((agent) => convertAgent(agent, options))
3619
const cmdFiles = convertCommands(plugin.commands)
@@ -119,20 +102,15 @@ function convertMcp(servers: Record<string, ClaudeMcpServer>): Record<string, Qw
119102
command: server.command,
120103
args: server.args,
121104
env: server.env,
122-
cwd: "${extensionPath}${/}",
123105
}
124106
continue
125107
}
126108

127109
if (server.url) {
128-
// Qwen doesn't support remote MCP servers in the same way
129-
// Convert to local with proxy or skip
130-
console.warn(`Warning: Remote MCP server '${name}' with URL ${server.url} is not fully supported in Qwen format`)
131-
result[name] = {
132-
command: "curl",
133-
args: [server.url],
134-
env: server.headers,
135-
}
110+
// Qwen only supports stdio (command-based) MCP servers — skip remote servers
111+
console.warn(
112+
`Warning: Remote MCP server '${name}' (URL: ${server.url}) is not supported in Qwen format. Qwen only supports stdio MCP servers. Skipping.`,
113+
)
136114
}
137115
}
138116
return result
@@ -172,10 +150,10 @@ function generateContextFile(plugin: ClaudePlugin): string {
172150
const sections: string[] = []
173151

174152
// Plugin description
175-
sections.push(`# ${plugin.name}`)
153+
sections.push(`# ${plugin.manifest.name}`)
176154
sections.push("")
177-
if (plugin.description) {
178-
sections.push(plugin.description)
155+
if (plugin.manifest.description) {
156+
sections.push(plugin.manifest.description)
179157
sections.push("")
180158
}
181159

@@ -216,10 +194,8 @@ function generateContextFile(plugin: ClaudePlugin): string {
216194

217195
function rewriteQwenPaths(body: string): string {
218196
return body
219-
.replace(/~\/\.claude\//g, "~/.qwen/")
220-
.replace(/\.claude\//g, ".qwen/")
221-
.replace(/~\/\.config\/opencode\//g, "~/.qwen/")
222-
.replace(/\.opencode\//g, ".qwen/")
197+
.replace(/(?<=^|\s|["'`])~\/\.claude\//gm, "~/.qwen/")
198+
.replace(/(?<=^|\s|["'`])\.claude\//gm, ".qwen/")
223199
}
224200

225201
const CLAUDE_FAMILY_ALIASES: Record<string, string> = {
@@ -258,5 +234,5 @@ function inferTemperature(agent: ClaudeAgent): number | undefined {
258234
if (/(brainstorm|creative|ideate|design|concept)/.test(sample)) {
259235
return 0.6
260236
}
261-
return 0.3
237+
return undefined
262238
}

src/targets/qwen.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@ export async function writeQwenBundle(outputRoot: string, bundle: QwenBundle): P
5353
}
5454

5555
function resolveQwenPaths(outputRoot: string) {
56-
const base = path.basename(outputRoot)
57-
// Global install: ~/.qwen/extensions/<extension-name>
58-
// Project install: .qwen/extensions/<extension-name> or <extension-name> at root
59-
// If the output root already ends with "extensions" or contains ".qwen/extensions", write directly
60-
if (base === "extensions" || outputRoot.includes(".qwen/extensions")) {
61-
return {
62-
root: outputRoot,
63-
configPath: path.join(outputRoot, "qwen-extension.json"),
64-
contextPath: path.join(outputRoot, "QWEN.md"),
65-
agentsDir: path.join(outputRoot, "agents"),
66-
commandsDir: path.join(outputRoot, "commands"),
67-
skillsDir: path.join(outputRoot, "skills"),
68-
}
69-
}
70-
71-
// Custom output directory - write directly to the output root (not nested)
72-
// This is for project-level installs like ./my-extension
7356
return {
7457
root: outputRoot,
7558
configPath: path.join(outputRoot, "qwen-extension.json"),

tests/qwen-converter.test.ts

Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
import { describe, expect, test } from "bun:test"
2+
import { convertClaudeToQwen } from "../src/converters/claude-to-qwen"
3+
import { parseFrontmatter } from "../src/utils/frontmatter"
4+
import type { ClaudePlugin } from "../src/types/claude"
5+
6+
const fixturePlugin: ClaudePlugin = {
7+
root: "/tmp/plugin",
8+
manifest: { name: "compound-engineering", version: "1.2.0", description: "A plugin for engineers" },
9+
agents: [
10+
{
11+
name: "security-sentinel",
12+
description: "Security-focused agent",
13+
capabilities: ["Threat modeling", "OWASP"],
14+
model: "claude-sonnet-4-20250514",
15+
body: "Focus on vulnerabilities in ~/.claude/settings.",
16+
sourcePath: "/tmp/plugin/agents/security-sentinel.md",
17+
},
18+
{
19+
name: "brainstorm-agent",
20+
description: "Creative brainstormer",
21+
model: "inherit",
22+
body: "Generate ideas.",
23+
sourcePath: "/tmp/plugin/agents/brainstorm-agent.md",
24+
},
25+
],
26+
commands: [
27+
{
28+
name: "workflows:plan",
29+
description: "Planning command",
30+
argumentHint: "[FOCUS]",
31+
model: "inherit",
32+
allowedTools: ["Read"],
33+
body: "Plan the work. Config at ~/.claude/settings.",
34+
sourcePath: "/tmp/plugin/commands/workflows/plan.md",
35+
},
36+
{
37+
name: "disabled-cmd",
38+
description: "Disabled",
39+
model: "inherit",
40+
allowedTools: [],
41+
body: "Should be excluded.",
42+
disableModelInvocation: true,
43+
sourcePath: "/tmp/plugin/commands/disabled-cmd.md",
44+
},
45+
],
46+
skills: [
47+
{
48+
name: "existing-skill",
49+
description: "Existing skill",
50+
sourceDir: "/tmp/plugin/skills/existing-skill",
51+
skillPath: "/tmp/plugin/skills/existing-skill/SKILL.md",
52+
},
53+
],
54+
hooks: undefined,
55+
mcpServers: {
56+
local: { command: "npx", args: ["-y", "some-mcp"], env: { API_KEY: "${YOUR_API_KEY}" } },
57+
remote: { url: "https://mcp.example.com/api", headers: { Authorization: "Bearer token" } },
58+
},
59+
}
60+
61+
const defaultOptions = {
62+
agentMode: "subagent" as const,
63+
inferTemperature: false,
64+
}
65+
66+
describe("convertClaudeToQwen", () => {
67+
test("converts agents to yaml format with frontmatter", () => {
68+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
69+
70+
const agent = bundle.agents.find((a) => a.name === "security-sentinel")
71+
expect(agent).toBeDefined()
72+
expect(agent!.format).toBe("yaml")
73+
const parsed = parseFrontmatter(agent!.content)
74+
expect(parsed.data.name).toBe("security-sentinel")
75+
expect(parsed.data.description).toBe("Security-focused agent")
76+
expect(parsed.data.model).toBe("anthropic/claude-sonnet-4-20250514")
77+
expect(parsed.body).toContain("Focus on vulnerabilities")
78+
})
79+
80+
test("agent with inherit model has no model field in frontmatter", () => {
81+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
82+
const agent = bundle.agents.find((a) => a.name === "brainstorm-agent")
83+
expect(agent).toBeDefined()
84+
const parsed = parseFrontmatter(agent!.content)
85+
expect(parsed.data.model).toBeUndefined()
86+
})
87+
88+
test("inferTemperature injects temperature based on agent name/description", () => {
89+
const bundle = convertClaudeToQwen(fixturePlugin, { ...defaultOptions, inferTemperature: true })
90+
91+
const sentinel = bundle.agents.find((a) => a.name === "security-sentinel")
92+
const parsed = parseFrontmatter(sentinel!.content)
93+
expect(parsed.data.temperature).toBe(0.1) // review/security → 0.1
94+
95+
const brainstorm = bundle.agents.find((a) => a.name === "brainstorm-agent")
96+
const bParsed = parseFrontmatter(brainstorm!.content)
97+
expect(bParsed.data.temperature).toBe(0.6) // brainstorm → 0.6
98+
})
99+
100+
test("inferTemperature returns undefined for unrecognized agents (no temperature set)", () => {
101+
const plugin: ClaudePlugin = {
102+
...fixturePlugin,
103+
agents: [{ name: "my-helper", description: "Generic helper", model: "inherit", body: "help", sourcePath: "/tmp/a.md" }],
104+
}
105+
const bundle = convertClaudeToQwen(plugin, { ...defaultOptions, inferTemperature: true })
106+
const agent = bundle.agents[0]
107+
const parsed = parseFrontmatter(agent.content)
108+
expect(parsed.data.temperature).toBeUndefined()
109+
})
110+
111+
test("converts commands to command files excluding disableModelInvocation", () => {
112+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
113+
114+
const planCmd = bundle.commandFiles.find((c) => c.name === "workflows:plan")
115+
expect(planCmd).toBeDefined()
116+
const parsed = parseFrontmatter(planCmd!.content)
117+
expect(parsed.data.description).toBe("Planning command")
118+
expect(parsed.data.allowedTools).toEqual(["Read"])
119+
120+
const disabled = bundle.commandFiles.find((c) => c.name === "disabled-cmd")
121+
expect(disabled).toBeUndefined()
122+
})
123+
124+
test("config uses plugin manifest name and version", () => {
125+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
126+
expect(bundle.config.name).toBe("compound-engineering")
127+
expect(bundle.config.version).toBe("1.2.0")
128+
expect(bundle.config.commands).toBe("commands")
129+
expect(bundle.config.skills).toBe("skills")
130+
expect(bundle.config.agents).toBe("agents")
131+
})
132+
133+
test("stdio MCP servers are included in config", () => {
134+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
135+
expect(bundle.config.mcpServers).toBeDefined()
136+
const local = bundle.config.mcpServers!.local
137+
expect(local.command).toBe("npx")
138+
expect(local.args).toEqual(["-y", "some-mcp"])
139+
// No cwd field
140+
expect((local as any).cwd).toBeUndefined()
141+
})
142+
143+
test("remote MCP servers are skipped with a warning (not converted to curl)", () => {
144+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
145+
// Only local (stdio) server should be present
146+
expect(bundle.config.mcpServers).toBeDefined()
147+
expect(bundle.config.mcpServers!.remote).toBeUndefined()
148+
expect(bundle.config.mcpServers!.local).toBeDefined()
149+
})
150+
151+
test("placeholder env vars are extracted as settings", () => {
152+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
153+
expect(bundle.config.settings).toBeDefined()
154+
const apiKeySetting = bundle.config.settings!.find((s) => s.envVar === "API_KEY")
155+
expect(apiKeySetting).toBeDefined()
156+
expect(apiKeySetting!.sensitive).toBe(true)
157+
expect(apiKeySetting!.name).toBe("Api Key")
158+
})
159+
160+
test("plugin with no MCP servers has no mcpServers in config", () => {
161+
const plugin: ClaudePlugin = { ...fixturePlugin, mcpServers: undefined }
162+
const bundle = convertClaudeToQwen(plugin, defaultOptions)
163+
expect(bundle.config.mcpServers).toBeUndefined()
164+
})
165+
166+
test("context file uses plugin.manifest.name and manifest.description", () => {
167+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
168+
expect(bundle.contextFile).toContain("# compound-engineering")
169+
expect(bundle.contextFile).toContain("A plugin for engineers")
170+
expect(bundle.contextFile).toContain("## Agents")
171+
expect(bundle.contextFile).toContain("security-sentinel")
172+
expect(bundle.contextFile).toContain("## Commands")
173+
expect(bundle.contextFile).toContain("/workflows:plan")
174+
// Disabled commands excluded
175+
expect(bundle.contextFile).not.toContain("disabled-cmd")
176+
expect(bundle.contextFile).toContain("## Skills")
177+
expect(bundle.contextFile).toContain("existing-skill")
178+
})
179+
180+
test("paths are rewritten from .claude/ to .qwen/ in agent and command content", () => {
181+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
182+
183+
const agent = bundle.agents.find((a) => a.name === "security-sentinel")
184+
expect(agent!.content).toContain("~/.qwen/settings")
185+
expect(agent!.content).not.toContain("~/.claude/settings")
186+
187+
const cmd = bundle.commandFiles.find((c) => c.name === "workflows:plan")
188+
expect(cmd!.content).toContain("~/.qwen/settings")
189+
expect(cmd!.content).not.toContain("~/.claude/settings")
190+
})
191+
192+
test("opencode paths are NOT rewritten (only claude paths)", () => {
193+
const plugin: ClaudePlugin = {
194+
...fixturePlugin,
195+
agents: [
196+
{
197+
name: "test-agent",
198+
description: "test",
199+
model: "inherit",
200+
body: "See .opencode/config and ~/.config/opencode/settings",
201+
sourcePath: "/tmp/a.md",
202+
},
203+
],
204+
}
205+
const bundle = convertClaudeToQwen(plugin, defaultOptions)
206+
const agent = bundle.agents[0]
207+
// opencode paths should NOT be rewritten
208+
expect(agent.content).toContain(".opencode/config")
209+
expect(agent.content).not.toContain(".qwen/config")
210+
})
211+
212+
test("skillDirs passes through original skills", () => {
213+
const bundle = convertClaudeToQwen(fixturePlugin, defaultOptions)
214+
const skill = bundle.skillDirs.find((s) => s.name === "existing-skill")
215+
expect(skill).toBeDefined()
216+
expect(skill!.sourceDir).toBe("/tmp/plugin/skills/existing-skill")
217+
})
218+
219+
test("normalizeModel prefixes claude models with anthropic/", () => {
220+
const plugin: ClaudePlugin = {
221+
...fixturePlugin,
222+
agents: [{ name: "a", description: "d", model: "claude-opus-4-5", body: "b", sourcePath: "/tmp/a.md" }],
223+
}
224+
const bundle = convertClaudeToQwen(plugin, defaultOptions)
225+
const parsed = parseFrontmatter(bundle.agents[0].content)
226+
expect(parsed.data.model).toBe("anthropic/claude-opus-4-5")
227+
})
228+
229+
test("normalizeModel passes through already-namespaced models unchanged", () => {
230+
const plugin: ClaudePlugin = {
231+
...fixturePlugin,
232+
agents: [{ name: "a", description: "d", model: "google/gemini-2.0", body: "b", sourcePath: "/tmp/a.md" }],
233+
}
234+
const bundle = convertClaudeToQwen(plugin, defaultOptions)
235+
const parsed = parseFrontmatter(bundle.agents[0].content)
236+
expect(parsed.data.model).toBe("google/gemini-2.0")
237+
})
238+
})

0 commit comments

Comments
 (0)