-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat: agent skills #9353
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
+230
−15
Merged
feat: agent skills #9353
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
207469a
read and inject skills to system message
uinstinct b6eddec
add read skill tool
uinstinct d754331
prevent loading in system message
uinstinct cef4b8d
get config dependent tool definitions async
uinstinct c219e3e
read skill is a tool definition
uinstinct 5f7ecab
fix test lints
uinstinct 0c2ad71
Merge branch 'main' into agent-skills
uinstinct 6df421f
remove system message skill
uinstinct e0753f5
simplify tool frontmatter validation
uinstinct 2ecccb0
Merge branch 'main' into agent-skills
uinstinct 8575945
load skills from .claude directory
uinstinct b9bcd33
add supporting files for skill tool
uinstinct f5c3452
support relative path for workspace dirs
uinstinct 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
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,112 @@ | ||
| import { | ||
| ConfigValidationError, | ||
| parseMarkdownRule, | ||
| } from "@continuedev/config-yaml"; | ||
| import z from "zod"; | ||
| import { IDE, Skill } from "../.."; | ||
| import { walkDir } from "../../indexing/walkDir"; | ||
| import { localPathToUri } from "../../util/pathToUri"; | ||
| import { getGlobalFolderWithName } from "../../util/paths"; | ||
| import { findUriInDirs, joinPathsToUri } from "../../util/uri"; | ||
| import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants"; | ||
|
|
||
| const skillFrontmatterSchema = z.object({ | ||
| name: z.string().min(1), | ||
| description: z.string().min(1), | ||
| }); | ||
|
|
||
| const SKILLS_DIR = "skills"; | ||
|
|
||
| /** | ||
| * Get skills from .claude/skills directory | ||
| */ | ||
| async function getClaudeSkillsDir(ide: IDE) { | ||
| const fullDirs = (await ide.getWorkspaceDirs()).map((dir) => | ||
| joinPathsToUri(dir, ".claude", SKILLS_DIR), | ||
| ); | ||
|
|
||
| fullDirs.push(localPathToUri(getGlobalFolderWithName(SKILLS_DIR))); | ||
|
|
||
| return ( | ||
| await Promise.all( | ||
| fullDirs.map(async (dir) => { | ||
| const exists = await ide.fileExists(dir); | ||
| if (!exists) return []; | ||
| const uris = await walkDir(dir, ide, { | ||
| source: "get .claude skills files", | ||
| }); | ||
| // filter markdown files only | ||
| return uris.filter((uri) => uri.endsWith(".md")); | ||
| }), | ||
| ) | ||
| ).flat(); | ||
| } | ||
|
|
||
| export async function loadMarkdownSkills(ide: IDE) { | ||
| const errors: ConfigValidationError[] = []; | ||
| const skills: Skill[] = []; | ||
|
|
||
| try { | ||
| const yamlAndMarkdownFileUris = [ | ||
| ...( | ||
| await getAllDotContinueDefinitionFiles( | ||
| ide, | ||
| { | ||
| includeGlobal: true, | ||
| includeWorkspace: true, | ||
| fileExtType: "markdown", | ||
| }, | ||
| SKILLS_DIR, | ||
| ) | ||
| ).map((file) => file.path), | ||
| ...(await getClaudeSkillsDir(ide)), | ||
| ]; | ||
|
|
||
| const skillFiles = yamlAndMarkdownFileUris.filter((path) => | ||
| path.endsWith("SKILL.md"), | ||
| ); | ||
|
|
||
| const workspaceDirs = await ide.getWorkspaceDirs(); | ||
| for (const fileUri of skillFiles) { | ||
| try { | ||
| const content = await ide.readFile(fileUri); | ||
| const { frontmatter, markdown } = parseMarkdownRule( | ||
| content, | ||
| ) as unknown as { frontmatter: Skill; markdown: string }; | ||
|
|
||
| const validatedFrontmatter = skillFrontmatterSchema.parse(frontmatter); | ||
|
|
||
| const filesInSkillsDirectory = ( | ||
| await walkDir(fileUri.substring(0, fileUri.lastIndexOf("/")), ide, { | ||
| source: "get skill files", | ||
| }) | ||
| ) | ||
| // do not include SKILL.md as it is already in content | ||
| .filter((file) => !file.endsWith("SKILL.md")); | ||
|
|
||
| const foundRelativeUri = findUriInDirs(fileUri, workspaceDirs); | ||
|
|
||
| skills.push({ | ||
| ...validatedFrontmatter, | ||
| content: markdown, | ||
| path: foundRelativeUri.foundInDir | ||
| ? foundRelativeUri.relativePathOrBasename | ||
| : fileUri, | ||
| files: filesInSkillsDirectory, | ||
| }); | ||
| } catch (error) { | ||
| errors.push({ | ||
| fatal: false, | ||
| message: `Failed to parse markdown skill file: ${error instanceof Error ? error.message : error}`, | ||
| }); | ||
| } | ||
| } | ||
| } catch (err) { | ||
| errors.push({ | ||
| fatal: false, | ||
| message: `Error loading markdown skill files: ${err instanceof Error ? err.message : err}`, | ||
| }); | ||
| } | ||
|
|
||
| return { skills, errors }; | ||
| } |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { GetTool } from "../.."; | ||
| import { loadMarkdownSkills } from "../../config/markdown/loadMarkdownSkills"; | ||
| import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; | ||
|
|
||
| export const readSkillTool: GetTool = async (params) => { | ||
| const { skills } = await loadMarkdownSkills(params.ide); | ||
| return { | ||
| type: "function", | ||
| displayTitle: "Read Skill", | ||
| wouldLikeTo: "read skill {{{ skillName }}}", | ||
| isCurrently: "reading skill {{{ skillName }}}", | ||
| hasAlready: "read skill {{{ skillName }}}", | ||
| readonly: true, | ||
| isInstant: true, | ||
| group: BUILT_IN_GROUP_NAME, | ||
| function: { | ||
| name: BuiltInToolNames.ReadSkill, | ||
| description: ` | ||
| Use this tool to read the content of a skill by its name. Skills contain detailed instructions for specific tasks. The skill name should match one of the available skills listed below: | ||
| ${skills.map((skill) => `\nname: ${skill.name}\ndescription: ${skill.description}\n`)}`, | ||
| parameters: { | ||
| type: "object", | ||
| required: ["skillName"], | ||
| properties: { | ||
| skillName: { | ||
| type: "string", | ||
| description: | ||
| "The name of the skill to read. This should match the name from the available skills.", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { ToolImpl } from "."; | ||
| import { loadMarkdownSkills } from "../../config/markdown/loadMarkdownSkills"; | ||
| import { ContinueError, ContinueErrorReason } from "../../util/errors"; | ||
| import { getStringArg } from "../parseArgs"; | ||
|
|
||
| export const readSkillImpl: ToolImpl = async (args, extras) => { | ||
| const skillName = getStringArg(args, "skillName"); | ||
|
|
||
| const { skills } = await loadMarkdownSkills(extras.ide); | ||
|
|
||
| const skill = skills.find((s) => s.name === skillName); | ||
|
|
||
| if (!skill) { | ||
| const availableSkills = skills.map((s) => s.name).join(", "); | ||
| throw new ContinueError( | ||
| ContinueErrorReason.SkillNotFound, | ||
| `Skill "${skillName}" not found. Available skills: ${availableSkills || "none"}`, | ||
| ); | ||
| } | ||
|
|
||
| let content = skill.content; | ||
|
|
||
| if (skill.files.length > 0) { | ||
| content += `\n | ||
| ## Supporting files | ||
| Skill directory: | ||
| ${skill.files.join("\n")} | ||
| Use the read file tool to access these files as needed.`; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| name: `Skill: ${skill.name}`, | ||
| description: skill.description, | ||
| content, | ||
| uri: { | ||
| type: "file", | ||
| value: skill.path, | ||
| }, | ||
| }, | ||
| ]; | ||
| }; | ||
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.
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.