-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(qwen): generate Markdown commands instead of deprecated TOML format #1191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mc856
wants to merge
2
commits into
Fission-AI:main
Choose a base branch
from
mc856:fix/qwen-markdown-commands
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@fission-ai/openspec': patch | ||
| --- | ||
|
|
||
| Generate Markdown commands for Qwen Code instead of deprecated TOML format. Qwen Code now recommends Markdown custom commands with YAML frontmatter; the old `.qwen/commands/opsx-*.toml` files are cleaned up as legacy artifacts on update. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,30 +1,49 @@ | ||
| /** | ||
| * Qwen Code Command Adapter | ||
| * | ||
| * Formats commands for Qwen Code following its TOML specification. | ||
| * Formats commands for Qwen Code following its Markdown custom command | ||
| * specification. Qwen Code has deprecated TOML commands in favor of | ||
| * Markdown files with YAML frontmatter. | ||
| * | ||
| * @see https://qwenlm.github.io/qwen-code-docs/en/users/features/commands/#markdown-file-format-specification-recommended | ||
| */ | ||
|
|
||
| import path from 'path'; | ||
| import type { CommandContent, ToolCommandAdapter } from '../types.js'; | ||
|
|
||
| /** | ||
| * Escapes a string value for safe YAML output. | ||
| * Quotes the string if it contains special YAML characters. | ||
| */ | ||
| function escapeYamlValue(value: string): string { | ||
| // Check if value needs quoting (contains special YAML characters or starts/ends with whitespace) | ||
| const needsQuoting = /[:\n\r#{}[\],&*!|>'"%@`]|^\s|\s$/.test(value); | ||
| if (needsQuoting) { | ||
| // Use double quotes and escape internal double quotes and backslashes | ||
| const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n'); | ||
| return `"${escaped}"`; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Qwen adapter for command generation. | ||
| * File path: .qwen/commands/opsx-<id>.toml | ||
| * Format: TOML with description and prompt fields | ||
| * File path: .qwen/commands/opsx-<id>.md | ||
| * Format: Markdown with description frontmatter | ||
| */ | ||
| export const qwenAdapter: ToolCommandAdapter = { | ||
| toolId: 'qwen', | ||
|
|
||
| getFilePath(commandId: string): string { | ||
| return path.join('.qwen', 'commands', `opsx-${commandId}.toml`); | ||
| return path.join('.qwen', 'commands', `opsx-${commandId}.md`); | ||
| }, | ||
|
|
||
| formatFile(content: CommandContent): string { | ||
| return `description = "${content.description}" | ||
| return `--- | ||
| description: ${escapeYamlValue(content.description)} | ||
| --- | ||
| prompt = """ | ||
| ${content.body} | ||
| """ | ||
| `; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add carriage return escape sequence for complete YAML compliance.
The regex on line 20 correctly detects
\ras requiring quotes, but line 23 doesn't escape it. Per the YAML 1.2 specification, carriage returns inside double-quoted strings must be escaped. While carriage returns are rare in description strings, adding the escape ensures valid YAML output.🛡️ Proposed fix to add carriage return escaping
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch on the detect/escape asymmetry. This function is an intentional verbatim copy of the existing
escapeYamlValueinpi.tsandclaude.ts(current convention is one copy per adapter), so the same gap exists in both siblings. Since descriptions come from internal command templates, a literal CR can't occur in practice. Rather than diverging this copy from the other two or expanding this PR's scope, I'd prefer a follow-up PR that extractsescapeYamlValueinto a shared util and adds\rescaping in one place. Happy to fix it here instead if maintainers prefer.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mc856, that context makes sense — the detect/escape asymmetry is a pre-existing gap shared across all three adapters, and fixing it consistently via a shared utility is the right approach. Happy to leave this PR as-is.Would you like me to open a follow-up GitHub issue to track:
escapeYamlValueinto a shared YAML utility\r → \\rescaping in that shared locationpi.ts,claude.ts, andqwen.tsto consume itJust let me know and I'll file it.
✏️ Learnings added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coderabbitai yes, please file the follow-up issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 3193
🏁 Script executed:
Length of output: 1527
@mc856, the follow-up issue has been filed: #1205It tracks:
escapeYamlValueinto a shared utility (e.g.,src/core/command-generation/utils/yaml.ts)\r → \\rescaping in that shared implementation for YAML 1.2 compliancepi.ts,claude.ts, andqwen.tsto consume the shared helper\rcaseNote: the integration couldn't set the assignee automatically — you may want to self-assign it via the GitHub UI.
🧬 Code Graph Analysis Results
Relevant code snippets to understand
src/core/command-generation/adapters/qwen.tsand its inputs/outputs:src/core/command-generation/types.ts(lines 12-25)src/core/command-generation/types.ts(lines 32-48)🧠 Learnings used