From b6eddec2f474c92c11c13d2e11a8a6a6fa334716 Mon Sep 17 00:00:00 2001 From: uinstinct <61635505+uinstinct@users.noreply.github.com> Date: Tue, 30 Dec 2025 12:51:16 +0530 Subject: [PATCH] add read skill tool --- core/config/profile/doLoadConfig.ts | 1 + core/index.d.ts | 1 + core/llm/skills.ts | 1 - core/tools/builtIn.ts | 1 + core/tools/callTool.ts | 3 ++ core/tools/definitions/index.ts | 1 + core/tools/definitions/readSkill.ts | 29 +++++++++++++++++++ .../tools/definitions/toolDefinitions.test.ts | 1 + core/tools/implementations/readSkill.ts | 29 +++++++++++++++++++ core/tools/index.ts | 7 ++++- core/tools/searchWebGating.vitest.ts | 2 ++ core/util/errors.ts | 3 ++ 12 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 core/tools/definitions/readSkill.ts create mode 100644 core/tools/implementations/readSkill.ts diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index d06e5541f..f18f44536 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -308,6 +308,7 @@ export default async function doLoadConfig(options: { newConfig.tools.push( ...getConfigDependentToolDefinitions({ rules: newConfig.rules, + skills: newConfig.skills, enableExperimentalTools: newConfig.experimental?.enableExperimentalTools ?? false, isSignedIn, diff --git a/core/index.d.ts b/core/index.d.ts index d6d964e94..a61603837 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1148,6 +1148,7 @@ interface ToolChoice { export interface ConfigDependentToolParams { rules: RuleWithSource[]; + skills: Skill[]; enableExperimentalTools: boolean; isSignedIn: boolean; isRemote: boolean; diff --git a/core/llm/skills.ts b/core/llm/skills.ts index 6a186c2d4..fdb6a27cc 100644 --- a/core/llm/skills.ts +++ b/core/llm/skills.ts @@ -13,7 +13,6 @@ export function getSystemMessageWithSkills( lines.push(" "); lines.push(` ${skill.name}`); lines.push(` ${skill.description}`); - lines.push(` ${skill.path}`); lines.push(" "); } lines.push(""); diff --git a/core/tools/builtIn.ts b/core/tools/builtIn.ts index 47cd6769f..0b1346bbc 100644 --- a/core/tools/builtIn.ts +++ b/core/tools/builtIn.ts @@ -16,6 +16,7 @@ export enum BuiltInToolNames { RequestRule = "request_rule", FetchUrlContent = "fetch_url_content", CodebaseTool = "codebase", + ReadSkill = "read_skill", // excluded from allTools for now ViewRepoMap = "view_repo_map", diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts index 8d695e1e1..2dd53474c 100644 --- a/core/tools/callTool.ts +++ b/core/tools/callTool.ts @@ -16,6 +16,7 @@ import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFi import { readFileImpl } from "./implementations/readFile"; import { readFileRangeImpl } from "./implementations/readFileRange"; +import { readSkillImpl } from "./implementations/readSkill"; import { requestRuleImpl } from "./implementations/requestRule"; import { runTerminalCommandImpl } from "./implementations/runTerminalCommand"; import { searchWebImpl } from "./implementations/searchWeb"; @@ -179,6 +180,8 @@ export async function callBuiltInTool( return await requestRuleImpl(args, extras); case BuiltInToolNames.CodebaseTool: return await codebaseToolImpl(args, extras); + case BuiltInToolNames.ReadSkill: + return await readSkillImpl(args, extras); case BuiltInToolNames.ViewRepoMap: return await viewRepoMapImpl(args, extras); case BuiltInToolNames.ViewSubdirectory: diff --git a/core/tools/definitions/index.ts b/core/tools/definitions/index.ts index bf3dc02d9..bfc78ac3d 100644 --- a/core/tools/definitions/index.ts +++ b/core/tools/definitions/index.ts @@ -11,6 +11,7 @@ export { readCurrentlyOpenFileTool } from "./readCurrentlyOpenFile"; export { readFileTool } from "./readFile"; export { readFileRangeTool } from "./readFileRange"; +export { readSkillTool } from "./readSkill"; export { requestRuleTool } from "./requestRule"; export { runTerminalCommandTool } from "./runTerminalCommand"; export { searchWebTool } from "./searchWeb"; diff --git a/core/tools/definitions/readSkill.ts b/core/tools/definitions/readSkill.ts new file mode 100644 index 000000000..66044760e --- /dev/null +++ b/core/tools/definitions/readSkill.ts @@ -0,0 +1,29 @@ +import { Tool } from "../.."; +import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; + +export const readSkillTool: Tool = { + 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 in the system message.", + parameters: { + type: "object", + required: ["skillName"], + properties: { + skillName: { + type: "string", + description: + "The name of the skill to read. This should match the name field from the available skills.", + }, + }, + }, + }, +}; diff --git a/core/tools/definitions/toolDefinitions.test.ts b/core/tools/definitions/toolDefinitions.test.ts index 265ebe5e1..2534958f5 100644 --- a/core/tools/definitions/toolDefinitions.test.ts +++ b/core/tools/definitions/toolDefinitions.test.ts @@ -6,6 +6,7 @@ describe("Tool Definitions", () => { // Mock params for tools that need them const mockParams: ConfigDependentToolParams = { rules: [], + skills: [], enableExperimentalTools: false, isSignedIn: false, isRemote: false, diff --git a/core/tools/implementations/readSkill.ts b/core/tools/implementations/readSkill.ts new file mode 100644 index 000000000..28b479a72 --- /dev/null +++ b/core/tools/implementations/readSkill.ts @@ -0,0 +1,29 @@ +import { ToolImpl } from "."; +import { ContinueError, ContinueErrorReason } from "../../util/errors"; +import { getStringArg } from "../parseArgs"; + +export const readSkillImpl: ToolImpl = async (args, extras) => { + const skillName = getStringArg(args, "skillName"); + + const skill = extras.config.skills.find((s) => s.name === skillName); + + if (!skill) { + const availableSkills = extras.config.skills.map((s) => s.name).join(", "); + throw new ContinueError( + ContinueErrorReason.SkillNotFound, + `Skill "${skillName}" not found. Available skills: ${availableSkills || "none"}`, + ); + } + + return [ + { + name: `Skill: ${skill.name}`, + description: skill.description, + content: `# ${skill.name}\n\n${skill.description}\n\n## Instructions\n\n${skill.content}`, + uri: { + type: "file", + value: skill.path, + }, + }, + ]; +}; diff --git a/core/tools/index.ts b/core/tools/index.ts index bdc519dc9..c85de5dbb 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -18,11 +18,16 @@ export const getBaseToolDefinitions = () => [ export const getConfigDependentToolDefinitions = ( params: ConfigDependentToolParams, ): Tool[] => { - const { modelName, isSignedIn, enableExperimentalTools, isRemote } = params; + const { modelName, isSignedIn, enableExperimentalTools, isRemote, skills } = + params; const tools: Tool[] = []; tools.push(toolDefinitions.requestRuleTool(params)); + if (skills.length > 0) { + tools.push(toolDefinitions.readSkillTool); + } + if (isSignedIn) { // Web search is only available for signed-in users tools.push(toolDefinitions.searchWebTool); diff --git a/core/tools/searchWebGating.vitest.ts b/core/tools/searchWebGating.vitest.ts index 4ebb6e5b4..2a76d4fa3 100644 --- a/core/tools/searchWebGating.vitest.ts +++ b/core/tools/searchWebGating.vitest.ts @@ -6,6 +6,7 @@ test("searchWeb tool is only available when user is signed in", () => { // Test with signed-in user const signedInTools = getConfigDependentToolDefinitions({ rules: [], + skills: [], enableExperimentalTools: false, isSignedIn: true, isRemote: false, @@ -21,6 +22,7 @@ test("searchWeb tool is only available when user is signed in", () => { // Test with non-signed-in user const notSignedInTools = getConfigDependentToolDefinitions({ rules: [], + skills: [], enableExperimentalTools: false, isSignedIn: false, isRemote: false, diff --git a/core/util/errors.ts b/core/util/errors.ts index 69df7c814..b94b5ac00 100644 --- a/core/util/errors.ts +++ b/core/util/errors.ts @@ -62,6 +62,9 @@ export enum ContinueErrorReason { // Rules RuleNotFound = "rule_not_found", + // Skills + SkillNotFound = "skill_not_found", + // Other Unspecified = "unspecified", // I.e. a known error but no specific code for it Unknown = "unknown", // I.e. an unexpected error