From 33b1d3994654f311dcae385f6ef2ef78696d1d89 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 28 May 2025 16:19:11 -0700 Subject: [PATCH] feat: dallins feedback --- core/core.ts | 1 + core/index.d.ts | 3 +- core/tools/definitions/requestRule.test.ts | 56 ++++++++-------------- core/tools/definitions/requestRule.ts | 14 ++---- core/tools/implementations/requestRule.ts | 13 ++++- gui/src/redux/slices/uiSlice.ts | 2 +- 6 files changed, 38 insertions(+), 51 deletions(-) diff --git a/core/core.ts b/core/core.ts index 6b5f9814e..497e64c66 100644 --- a/core/core.ts +++ b/core/core.ts @@ -723,6 +723,7 @@ export class Core { }; return await callTool(tool, toolCall.function.arguments, { + config, ide: this.ide, llm: config.selectedModelByRole.chat, fetch: (url, init) => diff --git a/core/index.d.ts b/core/index.d.ts index cb90b5bf9..afbdc9eac 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -975,6 +975,7 @@ export interface ToolExtras { toolCallId: string; contextItems: ContextItem[]; }) => void; + config: ContinueConfig; } export interface Tool { @@ -1147,7 +1148,7 @@ export interface StreamableHTTPOptions { requestOptions?: RequestOptions; } -export type TransportOptions = +export type TransportOptions = | StdioOptions | WebSocketOptions | SSEOptions diff --git a/core/tools/definitions/requestRule.test.ts b/core/tools/definitions/requestRule.test.ts index 49aac9c6e..e1d0feb81 100644 --- a/core/tools/definitions/requestRule.test.ts +++ b/core/tools/definitions/requestRule.test.ts @@ -1,5 +1,5 @@ -import { getRequestRuleDescription } from "./requestRule"; import { RuleWithSource } from "../.."; +import { getRequestRuleDescription } from "./requestRule"; describe("getRequestRuleDescription", () => { it("should return no rules message when no agent-requested rules exist", () => { @@ -25,7 +25,7 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); expect(result).toBe( - "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available." + "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available.", ); }); @@ -68,14 +68,10 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Agent Rule 1\n" + - "Description: First agent-requested rule\n" + - "Filepath: /path/to/agent-rule1.md\n\n" + - "Rule: Agent Rule 2\n" + - "Description: Second agent-requested rule\n" + - "Filepath: /path/to/agent-rule2.md"; + "Agent Rule 1: First agent-requested rule\n" + + "Agent Rule 2: Second agent-requested rule"; expect(result).toBe(expected); }); @@ -93,11 +89,9 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Rule Without Description\n" + - "Description: undefined\n" + - "Filepath: /path/to/no-desc-rule.md"; + "Rule Without Description: undefined"; expect(result).toBe(expected); }); @@ -115,11 +109,9 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: undefined\n" + - "Description: Rule without name\n" + - "Filepath: /path/to/no-name-rule.md"; + "undefined: Rule without name"; expect(result).toBe(expected); }); @@ -137,11 +129,9 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Rule Without File\n" + - "Description: Rule without file path\n" + - "Filepath: undefined"; + "Rule Without File: Rule without file path"; expect(result).toBe(expected); }); @@ -168,11 +158,9 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Valid Agent Rule\n" + - "Description: This should be included\n" + - "Filepath: /path/to/valid-rule.md"; + "Valid Agent Rule: This should be included"; expect(result).toBe(expected); }); @@ -191,7 +179,7 @@ describe("getRequestRuleDescription", () => { { name: "Rule with array globs", description: "This should also be filtered out", - source: "rules-block", + source: "rules-block", rule: "Some rule", alwaysApply: false, globs: ["**/*.ts", "**/*.js"], @@ -209,11 +197,9 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Valid Agent Rule\n" + - "Description: This should be included\n" + - "Filepath: /path/to/valid-rule.md"; + "Valid Agent Rule: This should be included"; expect(result).toBe(expected); }); @@ -224,7 +210,7 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); expect(result).toBe( - "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available." + "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available.", ); }); @@ -242,12 +228,10 @@ describe("getRequestRuleDescription", () => { const result = getRequestRuleDescription(rules); - const expected = + const expected = "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n" + - "Rule: Single Rule\n" + - "Description: The only agent-requested rule\n" + - "Filepath: /path/to/single-rule.md"; + "Single Rule: The only agent-requested rule"; expect(result).toBe(expected); }); -}); \ No newline at end of file +}); diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts index 569fd794a..cb60cda73 100644 --- a/core/tools/definitions/requestRule.ts +++ b/core/tools/definitions/requestRule.ts @@ -2,7 +2,6 @@ import { ConfigDependentToolParams, GetTool } from "../.."; import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; export interface RequestRuleArgs { - filepath: string; name: string; } @@ -18,11 +17,8 @@ export function getRequestRuleDescription( "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\n"; const body = agentRequestedRules - .map( - (rule) => - `Rule: ${rule.name}\nDescription: ${rule.description}\nFilepath: ${rule.ruleFile}`, - ) - .join("\n\n"); + .map((rule) => `${rule.name}: ${rule.description}`) + .join("\n"); if (body.length === 0) { return prefix + "No rules available."; @@ -44,12 +40,8 @@ export const requestRuleTool: GetTool = ({ rules }) => ({ description: getRequestRuleDescription(rules), parameters: { type: "object", - required: ["name", "filepath"], + required: ["name"], properties: { - filepath: { - type: "string", - description: "The path of the rule file", - }, name: { type: "string", description: "Name of the rule", diff --git a/core/tools/implementations/requestRule.ts b/core/tools/implementations/requestRule.ts index ac34f66e5..86aff6280 100644 --- a/core/tools/implementations/requestRule.ts +++ b/core/tools/implementations/requestRule.ts @@ -2,7 +2,16 @@ import { ToolImpl } from "."; import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule"; export const requestRuleImpl: ToolImpl = async (args, extras) => { - const fileContent = await extras.ide.readFile(args.filepath); + // Find the rule by name in the config + const rule = extras.config.rules.find((r) => r.name === args.name); + + if (!rule || !rule.ruleFile) { + throw new Error( + `Rule with name "${args.name}" not found or has no file path`, + ); + } + + const fileContent = await extras.ide.readFile(rule.ruleFile); const { markdown, frontmatter } = parseMarkdownRule(fileContent); return [ @@ -12,7 +21,7 @@ export const requestRuleImpl: ToolImpl = async (args, extras) => { content: markdown, uri: { type: "file", - value: args.filepath, + value: rule.ruleFile, }, }, ]; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index d995ab8eb..28e91d052 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -56,7 +56,7 @@ export const uiSlice = createSlice({ [BuiltInToolNames.ViewDiff]: "allowedWithoutPermission", [BuiltInToolNames.LSTool]: "allowedWithoutPermission", [BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission", - [BuiltInToolNames.RequestRule]: "allowedWithoutPermission", + [BuiltInToolNames.RequestRule]: "allowedWithPermission", }, toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include",