-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Support Trae by Slash Command #658
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?
Conversation
📝 WalkthroughWalkthroughAdds a new Trae command adapter to the command-generation system that formats commands into Trae's frontmatter-based Markdown files. The adapter is exported from the adapters index and registered in the command adapter registry. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Important Action Needed: IP Allowlist UpdateIf your organization protects your Git platform with IP whitelisting, please add the new CodeRabbit IP address to your allowlist:
Reviews will stop working after February 8, 2026 if the new IP is not added to your allowlist. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
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.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/core/command-generation/adapters/trae.ts`:
- Around line 32-45: Sanitize the commandId before using it in file paths and
frontmatter: in getFilePath(commandId) normalize and strip any path separators,
drive letters or unsafe characters (e.g., allow only alphanumerics,
dashes/underscores) to produce a safeId and use that for the path (replace
path.join('.trae','commands',`opsx-${safeId}.md`)). In formatFile(content)
compute the same sanitized id from content.id and use it for both the
frontmatter name and id fields, and ensure those fields are escaped or quoted
(in addition to using escapeYamlValue for category/description) so YAML-breaking
characters cannot corrupt the frontmatter.
🧹 Nitpick comments (1)
src/core/command-generation/adapters/trae.ts (1)
15-21: Consider quoting YAML implicit scalars to avoid type coercion.
escapeYamlValuedoesn’t quote values liketrue,null, or123, which YAML will parse as booleans/null/numbers instead of strings. If Trae expects strings, consider quoting those scalars too.
| getFilePath(commandId: string): string { | ||
| return path.join('.trae', 'commands', `opsx-${commandId}.md`); | ||
| }, | ||
|
|
||
| formatFile(content: CommandContent): string { | ||
| return `--- | ||
| name: /opsx-${content.id} | ||
| id: opsx-${content.id} | ||
| category: ${escapeYamlValue(content.category)} | ||
| description: ${escapeYamlValue(content.description)} | ||
| --- | ||
|
|
||
| ${content.body} | ||
| `; |
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.
Sanitize commandId for file paths and escape name/id in frontmatter.
Line 33 builds a path directly from commandId; if it contains path separators or drive prefixes, it can escape .trae/commands. Also name/id are unescaped, so YAML-breaking characters in content.id could corrupt frontmatter. Sanitize the ID and reuse it for both the path and the frontmatter values.
🔧 Suggested fix
+function sanitizeCommandId(commandId: string): string {
+ const sanitized = commandId
+ .replace(/[\\/:]/g, '-')
+ .replace(/[\r\n]/g, ' ')
+ .trim();
+ if (!sanitized) {
+ throw new Error('Command id must not be empty');
+ }
+ return sanitized;
+}
+
export const traeAdapter: ToolCommandAdapter = {
toolId: 'trae',
getFilePath(commandId: string): string {
- return path.join('.trae', 'commands', `opsx-${commandId}.md`);
+ const safeId = sanitizeCommandId(commandId);
+ return path.join('.trae', 'commands', `opsx-${safeId}.md`);
},
formatFile(content: CommandContent): string {
+ const safeId = sanitizeCommandId(content.id);
+ const name = `/opsx-${safeId}`;
+ const id = `opsx-${safeId}`;
return `---
-name: /opsx-${content.id}
-id: opsx-${content.id}
+name: ${escapeYamlValue(name)}
+id: ${escapeYamlValue(id)}
category: ${escapeYamlValue(content.category)}
description: ${escapeYamlValue(content.description)}
---
${content.body}
`;
},
};🤖 Prompt for AI Agents
In `@src/core/command-generation/adapters/trae.ts` around lines 32 - 45, Sanitize
the commandId before using it in file paths and frontmatter: in
getFilePath(commandId) normalize and strip any path separators, drive letters or
unsafe characters (e.g., allow only alphanumerics, dashes/underscores) to
produce a safeId and use that for the path (replace
path.join('.trae','commands',`opsx-${safeId}.md`)). In formatFile(content)
compute the same sanitized id from content.id and use it for both the
frontmatter name and id fields, and ensure those fields are escaped or quoted
(in addition to using escapeYamlValue for category/description) so YAML-breaking
characters cannot corrupt the frontmatter.
Description
Enhance the use of OpenSpec in Trae by supporting slash commands.
Changes
A new adapter has been added to src/core/command-generation/adapters/trae.ts to generate trae slash command files.
Commands Directory
Commands are installed to .trae/commands/
Summary by CodeRabbit