feat: add GSD tool command adapter#1082
Conversation
Add support for GSD (Pi's project management system) as a new AI tool integration. GSD uses agent definition files stored in .gsd/agents/ directory with YAML frontmatter containing name and description fields. Changes: - Add gsd.ts adapter with YAML frontmatter formatting and path generation - Register gsdAdapter in CommandAdapterRegistry and adapters index - Add unit tests covering toolId, file path generation, YAML formatting, and special character escaping in YAML values GSD agent files follow the pattern: .gsd/agents/opsx-<command-id>.md
📝 WalkthroughWalkthroughA new GSD command adapter is implemented with YAML escaping utilities, exported through the adapters module index, and registered in the CommandAdapterRegistry static initializer. Tests validate toolId, file path generation, frontmatter formatting, and YAML special character handling. ChangesGSD Command Adapter
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
支持gsd2 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/core/command-generation/adapters/gsd.ts`:
- Around line 16-23: The escapeYamlValue function currently quotes strings that
contain carriage returns but the replacement sequence only escapes backslashes,
double quotes, and newlines; update escapeYamlValue to also escape carriage
returns by adding a replacement for '\r' (e.g., replace(/\r/g, '\\r')) alongside
the existing .replace calls so any detected '\r' is properly escaped before
wrapping in quotes.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: ec4b8bb6-07cc-40c7-ba0d-6552cb6789b0
📒 Files selected for processing (4)
src/core/command-generation/adapters/gsd.tssrc/core/command-generation/adapters/index.tssrc/core/command-generation/registry.tstest/core/command-generation/adapters.test.ts
| 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; | ||
| } |
There was a problem hiding this comment.
Carriage return detection vs. escaping mismatch.
The regex on line 17 correctly detects \r as a character requiring quoting, but the escape logic on line 19 only handles \, ", and \n. If a value contains a carriage return, it will be quoted but the \r won't be escaped, potentially producing invalid YAML.
🛡️ Proposed fix to escape carriage returns
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');
+ const escaped = value.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n').replace(/\r/g, '\\r');
return `"${escaped}"`;
}
return value;
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| 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; | |
| } | |
| 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').replace(/\r/g, '\\r'); | |
| return `"${escaped}"`; | |
| } | |
| return value; | |
| } |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/core/command-generation/adapters/gsd.ts` around lines 16 - 23, The
escapeYamlValue function currently quotes strings that contain carriage returns
but the replacement sequence only escapes backslashes, double quotes, and
newlines; update escapeYamlValue to also escape carriage returns by adding a
replacement for '\r' (e.g., replace(/\r/g, '\\r')) alongside the existing
.replace calls so any detected '\r' is properly escaped before wrapping in
quotes.
Add support for GSD (Pi's project management system) as a new AI tool integration. GSD uses agent definition files stored in .gsd/agents/ directory with YAML frontmatter containing name and description fields.
Changes:
GSD agent files follow the pattern: .gsd/agents/opsx-.md
Summary by CodeRabbit
Release Notes
New Features
Tests