-
Notifications
You must be signed in to change notification settings - Fork 55
feat(skills): auto-bundle skills referenced in a skill's prose for cloud runs #3400
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
Merged
Merged
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
36 changes: 36 additions & 0 deletions
36
packages/workspace-server/src/services/skills/parse-skill-references.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,36 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { parseSkillReferences } from "./parse-skill-references"; | ||
|
|
||
| const KNOWN = new Set(["rs-review", "dep-skill", "usr", "foo", "My-Helper"]); | ||
|
|
||
| describe("parseSkillReferences", () => { | ||
| it.each([ | ||
| ["a bare slash reference", "Run /rs-review on the diff.", ["rs-review"]], | ||
| ["a reference at line start", "/rs-review\nthen stop", ["rs-review"]], | ||
| [ | ||
| "backticked and quoted references", | ||
| 'Use `/rs-review` or "/dep-skill" here.', | ||
| ["rs-review", "dep-skill"], | ||
| ], | ||
| ["a parenthesized reference", "(see /dep-skill)", ["dep-skill"]], | ||
| ["a wiki-style link", "Details in [[dep-skill]].", ["dep-skill"]], | ||
| [ | ||
| "mixed reference styles, deduplicated", | ||
| "Run /rs-review, then [[rs-review]] again and /dep-skill.", | ||
| ["rs-review", "dep-skill"], | ||
| ], | ||
| ["a sentence-final reference", "First run /dep-skill.", ["dep-skill"]], | ||
| [ | ||
| "an uppercase frontmatter name", | ||
| "Use /My-Helper then [[My-Helper]].", | ||
| ["My-Helper"], | ||
| ], | ||
| ["an unknown skill name", "Run /not-a-skill now.", []], | ||
| ["a URL path segment", "See https://example.com/foo for docs.", []], | ||
| ["a file path segment", "Look in /usr/bin and /foo/bar.", []], | ||
| ["a mid-word slash", "either/foo works", []], | ||
| ["an empty body", "", []], | ||
| ])("handles %s", (_label, content, expected) => { | ||
| expect(parseSkillReferences(content, KNOWN)).toEqual(expected); | ||
| }); | ||
| }); |
33 changes: 33 additions & 0 deletions
33
packages/workspace-server/src/services/skills/parse-skill-references.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,33 @@ | ||
| const SLASH_REFERENCE_REGEX = | ||
| /(?<=^|[\s(`"'[])\/([A-Za-z0-9][A-Za-z0-9._-]*)(?![A-Za-z0-9._/-])/gm; | ||
| const WIKI_LINK_REGEX = /\[\[([A-Za-z0-9][A-Za-z0-9._-]*)\]\]/g; | ||
|
|
||
| /** | ||
| * Finds `/skill-name` and `[[skill-name]]` references in a SKILL.md body. | ||
| * Only names in `knownNames` are returned, so paths (`/usr/bin`), URL | ||
| * segments, and unrelated slash-words can't match. A slash reference must | ||
| * span its whole path segment — `/foo/bar` never matches a skill named `foo`. | ||
| */ | ||
| export function parseSkillReferences( | ||
| content: string, | ||
| knownNames: ReadonlySet<string>, | ||
| ): string[] { | ||
| const references = new Set<string>(); | ||
|
|
||
| for (const regex of [SLASH_REFERENCE_REGEX, WIKI_LINK_REGEX]) { | ||
| for (const match of content.matchAll(regex)) { | ||
| const name = match[1]; | ||
| if (knownNames.has(name)) { | ||
| references.add(name); | ||
| continue; | ||
| } | ||
| // dots are valid name chars, so a sentence-final "/dep-skill." captures the period | ||
| const withoutTrailingDots = name.replace(/\.+$/, ""); | ||
| if (withoutTrailingDots !== name && knownNames.has(withoutTrailingDots)) { | ||
| references.add(withoutTrailingDots); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return [...references]; | ||
| } |
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.
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.