-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: Add $skill-name autocomplete functionality #10455
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
Closed
Closed
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
187 changes: 187 additions & 0 deletions
187
src/core/mentions/__tests__/parseMentions-skills.test.ts
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,187 @@ | ||
| import { describe, it, expect, vi, beforeEach } from "vitest" | ||
| import { parseMentions } from "../index" | ||
| import type { SkillsManager } from "../../../services/skills/SkillsManager" | ||
|
|
||
| describe("parseMentions - Skill Resolution", () => { | ||
| let mockSkillsManager: Partial<SkillsManager> | ||
| let mockUrlContentFetcher: any | ||
|
|
||
| beforeEach(() => { | ||
| mockUrlContentFetcher = { | ||
| launchBrowser: vi.fn(), | ||
| urlToMarkdown: vi.fn(), | ||
| closeBrowser: vi.fn(), | ||
| } | ||
|
|
||
| mockSkillsManager = { | ||
| getSkillContent: vi.fn(), | ||
| } | ||
| }) | ||
|
|
||
| it("should replace $skill-name tokens with placeholders", async () => { | ||
| vi.mocked(mockSkillsManager.getSkillContent!).mockResolvedValue({ | ||
| name: "pdf-processing", | ||
| description: "Extract text from PDFs", | ||
| path: "/path/to/skill/SKILL.md", | ||
| source: "global", | ||
| instructions: "# PDF Processing\n\nInstructions here", | ||
| }) | ||
|
|
||
| const result = await parseMentions( | ||
| "Please help with $pdf-processing task", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| mockSkillsManager as SkillsManager, | ||
| "code", | ||
| ) | ||
|
|
||
| expect(result.text).toContain("Skill '$pdf-processing' (see below for skill content)") | ||
| expect(result.text).toContain('<skill name="pdf-processing">') | ||
| expect(result.text).toContain("# PDF Processing") | ||
| expect(result.text).toContain("Instructions here") | ||
| expect(result.text).toContain("</skill>") | ||
| }) | ||
|
|
||
| it("should handle multiple skills in one message", async () => { | ||
| vi.mocked(mockSkillsManager.getSkillContent!).mockImplementation(async (name: string) => { | ||
| const skills: Record<string, any> = { | ||
| "pdf-processing": { | ||
| name: "pdf-processing", | ||
| description: "Extract text from PDFs", | ||
| path: "/path/to/pdf/SKILL.md", | ||
| source: "global", | ||
| instructions: "# PDF Processing", | ||
| }, | ||
| "code-review": { | ||
| name: "code-review", | ||
| description: "Review code", | ||
| path: "/path/to/review/SKILL.md", | ||
| source: "global", | ||
| instructions: "# Code Review", | ||
| }, | ||
| } | ||
| return skills[name] || null | ||
| }) | ||
|
|
||
| const result = await parseMentions( | ||
| "Use $pdf-processing and $code-review", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| mockSkillsManager as SkillsManager, | ||
| "code", | ||
| ) | ||
|
|
||
| expect(result.text).toContain("Skill '$pdf-processing'") | ||
| expect(result.text).toContain("Skill '$code-review'") | ||
| expect(result.text).toContain('<skill name="pdf-processing">') | ||
| expect(result.text).toContain('<skill name="code-review">') | ||
| }) | ||
|
|
||
| it("should handle invalid skill names gracefully", async () => { | ||
| vi.mocked(mockSkillsManager.getSkillContent!).mockResolvedValue(null) | ||
|
|
||
| const result = await parseMentions( | ||
| "Use $nonexistent skill", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| mockSkillsManager as SkillsManager, | ||
| "code", | ||
| ) | ||
|
|
||
| // Should not replace invalid skills | ||
| expect(result.text).toBe("Use $nonexistent skill") | ||
| expect(result.text).not.toContain("<skill") | ||
| }) | ||
|
|
||
| it("should work without skillsManager", async () => { | ||
| const result = await parseMentions( | ||
| "Use $pdf-processing", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| undefined, | ||
| "code", | ||
| ) | ||
|
|
||
| // Should not process skills without manager | ||
| expect(result.text).toBe("Use $pdf-processing") | ||
| expect(result.text).not.toContain("<skill") | ||
| }) | ||
|
|
||
| it("should handle skills with @ mentions and / commands", async () => { | ||
| vi.mocked(mockSkillsManager.getSkillContent!).mockResolvedValue({ | ||
| name: "pdf-processing", | ||
| description: "Extract text from PDFs", | ||
| path: "/path/to/skill/SKILL.md", | ||
| source: "global", | ||
| instructions: "# PDF Processing", | ||
| }) | ||
|
|
||
| const result = await parseMentions( | ||
| "Use $pdf-processing on @/test.pdf", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| mockSkillsManager as SkillsManager, | ||
| "code", | ||
| ) | ||
|
|
||
| // Both should be processed | ||
| expect(result.text).toContain("Skill '$pdf-processing'") | ||
| expect(result.text).toContain("'test.pdf' (see below for file content)") | ||
| }) | ||
|
|
||
| it("should handle skill names with hyphens and underscores", async () => { | ||
| vi.mocked(mockSkillsManager.getSkillContent!).mockResolvedValue({ | ||
| name: "my-special_skill", | ||
| description: "A test skill", | ||
| path: "/path/to/skill/SKILL.md", | ||
| source: "global", | ||
| instructions: "# My Skill", | ||
| }) | ||
|
|
||
| const result = await parseMentions( | ||
| "Use $my-special_skill", | ||
| "/workspace", | ||
| mockUrlContentFetcher, | ||
| undefined, | ||
| undefined, | ||
| false, | ||
| true, | ||
| 50, | ||
| undefined, | ||
| mockSkillsManager as SkillsManager, | ||
| "code", | ||
| ) | ||
|
|
||
| expect(result.text).toContain("Skill '$my-special_skill'") | ||
| }) | ||
| }) |
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
This reads the skill content from the filesystem, but
getSkillContent()already reads and parses the file (returning content in itsinstructionsfield). This creates two issues:Redundant file I/O: The skill file is read twice - once in the validation loop via
getSkillContent()and again here.Test mismatch: The tests mock
getSkillContentto return skill metadata withinstructions, but this code ignores that and reads from the path directly. Since mocked paths like/path/to/skill/SKILL.mddon't exist,fs.readFilethrows and the tests would fail unlessfsis globally mocked.Consider storing the skill content during validation and reusing it here, or using the
instructionsfield fromSkillContent.Fix it with Roo Code or mention @roomote and request a fix.