-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add Trae opsx command adapter #776
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,3 +156,6 @@ opencode.json | |
|
|
||
| # Codex | ||
| .codex/ | ||
|
|
||
| # Trae | ||
| .trae/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * Trae Command Adapter | ||
| * | ||
| * Formats commands for Trae following its frontmatter specification. | ||
| */ | ||
| 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 { | ||
| const needsQuoting = /[:\n\r#{}[\],&*!|>'"%@`]|^\s|\s$/.test(value); | ||
| if (needsQuoting) { | ||
| const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n'); | ||
| return `"${escaped}"`; | ||
| } | ||
| return value; | ||
| } | ||
|
|
||
| /** | ||
| * Formats a tags array as a YAML array with proper escaping. | ||
| */ | ||
| function formatTagsArray(tags: string[]): string { | ||
| const escapedTags = tags.map((tag) => escapeYamlValue(tag)); | ||
| return `[${escapedTags.join(', ')}]`; | ||
| } | ||
|
|
||
| /** | ||
| * Trae adapter for command generation. | ||
| * File path: .trae/commands/opsx-<id>.md | ||
| * Frontmatter: name, description, category, tags | ||
| */ | ||
| export const traeAdapter: ToolCommandAdapter = { | ||
| toolId: 'trae', | ||
|
|
||
| getFilePath(commandId: string): string { | ||
| return path.join('.trae', 'commands', 'opsx', `${commandId}.md`); | ||
| }, | ||
|
|
||
| formatFile(content: CommandContent): string { | ||
| return `--- | ||
| name: /opsx:${content.id} | ||
| description: ${escapeYamlValue(content.description)} | ||
| category: ${escapeYamlValue(content.category)} | ||
| tags: ${formatTagsArray(content.tags)} | ||
| --- | ||
|
|
||
| ${content.body} | ||
| `; | ||
| }, | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -554,6 +554,16 @@ export class InitCommand { | |
| if (shouldGenerateCommands) { | ||
| const adapter = CommandAdapterRegistry.get(tool.value); | ||
| if (adapter) { | ||
| if (tool.value === 'trae') { | ||
| for (const workflow of ALL_WORKFLOWS) { | ||
| const legacyCommandFile = path.join(projectPath, '.trae', 'commands', `opsx-${workflow}.md`); | ||
| try { | ||
| if (fs.existsSync(legacyCommandFile)) { | ||
| await fs.promises.unlink(legacyCommandFile); | ||
| } | ||
| } catch {} | ||
| } | ||
| } | ||
|
Comment on lines
+557
to
+566
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Delete the adapter-resolved Trae files here too. Lines 559-563 only purge 🤖 Prompt for AI Agents |
||
| const generatedCommands = generateCommands(commandContents, adapter); | ||
|
|
||
| for (const cmd of generatedCommands) { | ||
|
|
@@ -763,12 +773,19 @@ export class InitCommand { | |
| for (const workflow of ALL_WORKFLOWS) { | ||
| const cmdPath = adapter.getFilePath(workflow); | ||
| const fullPath = path.isAbsolute(cmdPath) ? cmdPath : path.join(projectPath, cmdPath); | ||
| const legacyTraePath = toolId === 'trae' | ||
| ? path.join(projectPath, '.trae', 'commands', `opsx-${workflow}.md`) | ||
| : null; | ||
|
|
||
| try { | ||
| if (fs.existsSync(fullPath)) { | ||
| await fs.promises.unlink(fullPath); | ||
| removed++; | ||
| } | ||
| if (legacyTraePath && fs.existsSync(legacyTraePath)) { | ||
| await fs.promises.unlink(legacyTraePath); | ||
| removed++; | ||
| } | ||
| } catch { | ||
| // Ignore errors | ||
| } | ||
|
|
||
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.
Escape
\ras well when quoting YAML values.Line 5 treats carriage returns as special, but Line 7 only escapes
\n. Escaping\rtoo avoids malformed/fragile frontmatter on CRLF-origin text.💡 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents