add read skill tool

This commit is contained in:
uinstinct 2025-12-30 12:51:16 +05:30
parent 207469af85
commit b6eddec2f4
12 changed files with 77 additions and 2 deletions

View file

@ -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,

1
core/index.d.ts vendored
View file

@ -1148,6 +1148,7 @@ interface ToolChoice {
export interface ConfigDependentToolParams {
rules: RuleWithSource[];
skills: Skill[];
enableExperimentalTools: boolean;
isSignedIn: boolean;
isRemote: boolean;

View file

@ -13,7 +13,6 @@ export function getSystemMessageWithSkills(
lines.push(" <skill>");
lines.push(` <name>${skill.name}</name>`);
lines.push(` <description>${skill.description}</description>`);
lines.push(` <location>${skill.path}</location>`);
lines.push(" </skill>");
}
lines.push("</available_skills>");

View file

@ -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",

View file

@ -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:

View file

@ -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";

View file

@ -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.",
},
},
},
},
};

View file

@ -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,

View file

@ -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,
},
},
];
};

View file

@ -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);

View file

@ -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,

View file

@ -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