From af30fbe360def278cd56858d88c5373c80a2dab6 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 27 May 2025 10:19:31 -0700 Subject: [PATCH 1/6] feat: `requestRule` tool --- core/config/load.ts | 4 +- core/config/profile/doLoadConfig.ts | 24 +++++++++ core/config/yaml/loadYaml.ts | 4 +- core/index.d.ts | 6 +++ core/tools/builtIn.ts | 3 +- core/tools/callTool.ts | 3 ++ core/tools/definitions/requestRule.ts | 60 +++++++++++++++++++++++ core/tools/implementations/requestRule.ts | 19 +++++++ core/tools/index.ts | 8 ++- gui/src/redux/slices/uiSlice.ts | 1 + gui/src/redux/thunks/callCurrentTool.ts | 4 +- 11 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 core/tools/definitions/requestRule.ts create mode 100644 core/tools/implementations/requestRule.ts diff --git a/core/config/load.ts b/core/config/load.ts index de08ecfc7..e2f3d71c3 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -51,7 +51,6 @@ import { LLMReranker } from "../llm/llms/llm"; import TransformersJsEmbeddingsProvider from "../llm/llms/TransformersJsEmbeddingsProvider"; import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile"; import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles"; -import { allTools } from "../tools"; import { copyOf } from "../util"; import { GlobalContext } from "../util/GlobalContext"; import mergeJson from "../util/merge"; @@ -67,6 +66,7 @@ import { } from "../util/paths"; import { localPathToUri } from "../util/pathToUri"; +import { baseToolDefinitions } from "../tools"; import { modifyAnyConfigWithSharedConfig } from "./sharedConfig"; import { getModelByRole, @@ -529,7 +529,7 @@ async function intermediateToFinalConfig({ const continueConfig: ContinueConfig = { ...config, contextProviders, - tools: [...allTools], + tools: baseToolDefinitions, mcpServerStatuses: [], slashCommands: config.slashCommands ?? [], modelsByRole: { diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index cc1b98e49..2a66398b7 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -25,6 +25,7 @@ import { ControlPlaneClient } from "../../control-plane/client.js"; import { getControlPlaneEnv } from "../../control-plane/env.js"; import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js"; import ContinueProxy from "../../llm/llms/stubs/ContinueProxy"; +import { getConfigDependentToolDefinitions } from "../../tools"; import { encodeMCPToolUri } from "../../tools/callTool"; import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths"; import { localPathOrUriToPath } from "../../util/pathToUri"; @@ -193,6 +194,8 @@ export default async function doLoadConfig(options: { } } + newConfig.tools.push(...getConfigDependentTools(newConfig)); + // Detect duplicate tool names const counts: Record = {}; newConfig.tools.forEach((tool) => { @@ -202,6 +205,7 @@ export default async function doLoadConfig(options: { counts[tool.function.name] = 1; } }); + Object.entries(counts).forEach(([toolName, count]) => { if (count > 1) { errors!.push({ @@ -309,3 +313,23 @@ async function getWorkspaceConfigs(ide: IDE): Promise { return workspaceConfigs; } + +/** + * Returns a list of tools that depend on the configuration. + * @param {ContinueConfig} config - The configuration object. + * @returns {Tool[]} Array of tools + * @todo Why is `doLoadConfig` getting called multiple times causing us to have duplicates here unless we filter + */ +function getConfigDependentTools(config: ContinueConfig): Tool[] { + const configDependentTools = getConfigDependentToolDefinitions({ + rules: config.rules, + }); + + return configDependentTools.filter( + (configTool) => + !config.tools.some( + (existingTool) => + existingTool.function.name === configTool.function.name, + ), + ); +} diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 0a0dd03fc..24a60f855 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -36,11 +36,11 @@ import FreeTrial from "../../llm/llms/FreeTrial"; import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider"; import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile"; import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles"; -import { allTools } from "../../tools"; import { GlobalContext } from "../../util/GlobalContext"; import { modifyAnyConfigWithSharedConfig } from "../sharedConfig"; import { getControlPlaneEnvSync } from "../../control-plane/env"; +import { baseToolDefinitions } from "../../tools"; import { getCleanUriPath } from "../../util/uri"; import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants"; import { LocalPlatformClient } from "./LocalPlatformClient"; @@ -193,7 +193,7 @@ async function configYamlToContinueConfig(options: { const continueConfig: ContinueConfig = { slashCommands: [], - tools: [...allTools], + tools: baseToolDefinitions, mcpServerStatuses: [], contextProviders: [], modelsByRole: { diff --git a/core/index.d.ts b/core/index.d.ts index 7ff7f0f20..cb3057b95 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -1003,6 +1003,12 @@ interface ToolChoice { }; } +export interface ConfigDependentToolParams { + rules: RuleWithSource[]; +} + +export type GetTool = (params: ConfigDependentToolParams) => Tool; + export interface BaseCompletionOptions { temperature?: number; topP?: number; diff --git a/core/tools/builtIn.ts b/core/tools/builtIn.ts index 9f70b1a22..892cc3ff8 100644 --- a/core/tools/builtIn.ts +++ b/core/tools/builtIn.ts @@ -10,6 +10,7 @@ export enum BuiltInToolNames { ViewDiff = "builtin_view_diff", LSTool = "builtin_ls", CreateRuleBlock = "builtin_create_rule_block", + RequestRule = "builtin_request_rule", // excluded from allTools for now ViewRepoMap = "builtin_view_repo_map", @@ -18,4 +19,4 @@ export enum BuiltInToolNames { export const BUILT_IN_GROUP_NAME = "Built-In"; -export const CLIENT_TOOLS = [BuiltInToolNames.EditExistingFile]; +export const CLIENT_TOOLS_IMPLS = [BuiltInToolNames.EditExistingFile]; diff --git a/core/tools/callTool.ts b/core/tools/callTool.ts index 34501550b..243c162bb 100644 --- a/core/tools/callTool.ts +++ b/core/tools/callTool.ts @@ -10,6 +10,7 @@ import { grepSearchImpl } from "./implementations/grepSearch"; import { lsToolImpl } from "./implementations/lsTool"; import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFile"; import { readFileImpl } from "./implementations/readFile"; +import { requestRuleImpl } from "./implementations/requestRule"; import { runTerminalCommandImpl } from "./implementations/runTerminalCommand"; import { searchWebImpl } from "./implementations/searchWeb"; import { viewDiffImpl } from "./implementations/viewDiff"; @@ -157,6 +158,8 @@ async function callBuiltInTool( return await readCurrentlyOpenFileImpl(args, extras); case BuiltInToolNames.CreateRuleBlock: return await createRuleBlockImpl(args, extras); + case BuiltInToolNames.RequestRule: + return await requestRuleImpl(args, extras); default: throw new Error(`Tool "${functionName}" not found`); } diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts new file mode 100644 index 000000000..650ab4162 --- /dev/null +++ b/core/tools/definitions/requestRule.ts @@ -0,0 +1,60 @@ +import { ConfigDependentToolParams, GetTool } from "../.."; +import { BUILT_IN_GROUP_NAME, BuiltInToolNames } from "../builtIn"; + +export interface RequestRuleArgs { + filepath: string; + name: string; +} + +export function getRequestRuleDescription( + rules: ConfigDependentToolParams["rules"], +): string { + // Must be explicitly false + const agentRequestedRules = rules.filter( + (rule) => rule.alwaysApply === false, + ); + + const prefix = + "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"); + + if (body.length === 0) { + return prefix + "No rules available."; + } + + return prefix + body; +} + +export const requestRuleTool: GetTool = ({ rules }) => ({ + type: "function", + displayTitle: "Request Rules", + wouldLikeTo: "request rule {{{ name }}}", + isCurrently: "reading rule {{{ name }}}", + hasAlready: "read rule {{{ name }}}", + group: BUILT_IN_GROUP_NAME, + readonly: false, + function: { + name: BuiltInToolNames.RequestRule, + description: getRequestRuleDescription(rules), + parameters: { + type: "object", + required: ["name", "filepath"], + 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 new file mode 100644 index 000000000..ac34f66e5 --- /dev/null +++ b/core/tools/implementations/requestRule.ts @@ -0,0 +1,19 @@ +import { ToolImpl } from "."; +import { parseMarkdownRule } from "../../config/markdown/parseMarkdownRule"; + +export const requestRuleImpl: ToolImpl = async (args, extras) => { + const fileContent = await extras.ide.readFile(args.filepath); + const { markdown, frontmatter } = parseMarkdownRule(fileContent); + + return [ + { + name: frontmatter.name ?? "", + description: frontmatter.description ?? "", + content: markdown, + uri: { + type: "file", + value: args.filepath, + }, + }, + ]; +}; diff --git a/core/tools/index.ts b/core/tools/index.ts index d89cf8744..f7ed3be4b 100644 --- a/core/tools/index.ts +++ b/core/tools/index.ts @@ -1,3 +1,4 @@ +import { ConfigDependentToolParams, Tool } from ".."; import { createNewFileTool } from "./definitions/createNewFile"; import { createRuleBlock } from "./definitions/createRuleBlock"; import { editFileTool } from "./definitions/editFile"; @@ -6,11 +7,12 @@ import { grepSearchTool } from "./definitions/grepSearch"; import { lsTool } from "./definitions/lsTool"; import { readCurrentlyOpenFileTool } from "./definitions/readCurrentlyOpenFile"; import { readFileTool } from "./definitions/readFile"; +import { requestRuleTool } from "./definitions/requestRule"; import { runTerminalCommandTool } from "./definitions/runTerminalCommand"; import { searchWebTool } from "./definitions/searchWeb"; import { viewDiffTool } from "./definitions/viewDiff"; -export const allTools = [ +export const baseToolDefinitions = [ readFileTool, editFileTool, createNewFileTool, @@ -26,3 +28,7 @@ export const allTools = [ // viewSubdirectoryTool, // viewRepoMapTool, ]; + +export const getConfigDependentToolDefinitions = ( + params: ConfigDependentToolParams, +): Tool[] => [requestRuleTool(params)]; diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 4105d3319..d995ab8eb 100644 --- a/gui/src/redux/slices/uiSlice.ts +++ b/gui/src/redux/slices/uiSlice.ts @@ -56,6 +56,7 @@ export const uiSlice = createSlice({ [BuiltInToolNames.ViewDiff]: "allowedWithoutPermission", [BuiltInToolNames.LSTool]: "allowedWithoutPermission", [BuiltInToolNames.CreateRuleBlock]: "allowedWithPermission", + [BuiltInToolNames.RequestRule]: "allowedWithoutPermission", }, toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include", diff --git a/gui/src/redux/thunks/callCurrentTool.ts b/gui/src/redux/thunks/callCurrentTool.ts index f6f408238..84270fdd8 100644 --- a/gui/src/redux/thunks/callCurrentTool.ts +++ b/gui/src/redux/thunks/callCurrentTool.ts @@ -1,6 +1,6 @@ import { createAsyncThunk, unwrapResult } from "@reduxjs/toolkit"; import { ContextItem } from "core"; -import { CLIENT_TOOLS } from "core/tools/builtIn"; +import { CLIENT_TOOLS_IMPLS } from "core/tools/builtIn"; import { callClientTool } from "../../util/clientTools/callClientTool"; import { selectCurrentToolCall } from "../selectors/selectCurrentToolCall"; import { selectSelectedChatModel } from "../slices/configSlice"; @@ -51,7 +51,7 @@ export const callCurrentTool = createAsyncThunk( // Errors that occur outside specifically calling the tool // Should not be caught here - should be handled as normal stream errors if ( - CLIENT_TOOLS.find( + CLIENT_TOOLS_IMPLS.find( (toolName) => toolName === toolCallState.toolCall.function.name, ) ) { From 4ddd2755996012677c15069648158bd4334fa3dd Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 27 May 2025 13:12:01 -0700 Subject: [PATCH 2/6] fix: spread tool degs --- core/config/load.ts | 2 +- core/config/profile/doLoadConfig.ts | 26 +++++--------------------- core/config/yaml/loadYaml.ts | 2 +- 3 files changed, 7 insertions(+), 23 deletions(-) diff --git a/core/config/load.ts b/core/config/load.ts index e2f3d71c3..6f63374e5 100644 --- a/core/config/load.ts +++ b/core/config/load.ts @@ -529,7 +529,7 @@ async function intermediateToFinalConfig({ const continueConfig: ContinueConfig = { ...config, contextProviders, - tools: baseToolDefinitions, + tools: [...baseToolDefinitions], mcpServerStatuses: [], slashCommands: config.slashCommands ?? [], modelsByRole: { diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index 2a66398b7..cfaa38ffa 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -194,7 +194,11 @@ export default async function doLoadConfig(options: { } } - newConfig.tools.push(...getConfigDependentTools(newConfig)); + newConfig.tools.push( + ...getConfigDependentToolDefinitions({ + rules: newConfig.rules, + }), + ); // Detect duplicate tool names const counts: Record = {}; @@ -313,23 +317,3 @@ async function getWorkspaceConfigs(ide: IDE): Promise { return workspaceConfigs; } - -/** - * Returns a list of tools that depend on the configuration. - * @param {ContinueConfig} config - The configuration object. - * @returns {Tool[]} Array of tools - * @todo Why is `doLoadConfig` getting called multiple times causing us to have duplicates here unless we filter - */ -function getConfigDependentTools(config: ContinueConfig): Tool[] { - const configDependentTools = getConfigDependentToolDefinitions({ - rules: config.rules, - }); - - return configDependentTools.filter( - (configTool) => - !config.tools.some( - (existingTool) => - existingTool.function.name === configTool.function.name, - ), - ); -} diff --git a/core/config/yaml/loadYaml.ts b/core/config/yaml/loadYaml.ts index 24a60f855..daeecf57e 100644 --- a/core/config/yaml/loadYaml.ts +++ b/core/config/yaml/loadYaml.ts @@ -193,7 +193,7 @@ async function configYamlToContinueConfig(options: { const continueConfig: ContinueConfig = { slashCommands: [], - tools: baseToolDefinitions, + tools: [...baseToolDefinitions], mcpServerStatuses: [], contextProviders: [], modelsByRole: { From ae5b18b10daa493e43b31c9888677f8b12e926eb Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 27 May 2025 14:45:58 -0700 Subject: [PATCH 3/6] Update requestRule.ts --- core/tools/definitions/requestRule.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/tools/definitions/requestRule.ts b/core/tools/definitions/requestRule.ts index 650ab4162..569fd794a 100644 --- a/core/tools/definitions/requestRule.ts +++ b/core/tools/definitions/requestRule.ts @@ -9,9 +9,9 @@ export interface RequestRuleArgs { export function getRequestRuleDescription( rules: ConfigDependentToolParams["rules"], ): string { - // Must be explicitly false + // Must be explicitly false and no globs const agentRequestedRules = rules.filter( - (rule) => rule.alwaysApply === false, + (rule) => rule.alwaysApply === false && !rule.globs, ); const prefix = From 03e75521cdee2c6fca95e547ac55c3b62af10347 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Tue, 27 May 2025 14:50:59 -0700 Subject: [PATCH 4/6] Create requestRule.test.ts --- core/tools/definitions/requestRule.test.ts | 253 +++++++++++++++++++++ 1 file changed, 253 insertions(+) create mode 100644 core/tools/definitions/requestRule.test.ts diff --git a/core/tools/definitions/requestRule.test.ts b/core/tools/definitions/requestRule.test.ts new file mode 100644 index 000000000..49aac9c6e --- /dev/null +++ b/core/tools/definitions/requestRule.test.ts @@ -0,0 +1,253 @@ +import { getRequestRuleDescription } from "./requestRule"; +import { RuleWithSource } from "../.."; + +describe("getRequestRuleDescription", () => { + it("should return no rules message when no agent-requested rules exist", () => { + const rules: RuleWithSource[] = [ + { + name: "Always Apply Rule", + description: "This rule always applies", + source: "default-chat", + rule: "Always use semicolons", + alwaysApply: true, + ruleFile: "/path/to/rule1.md", + }, + { + name: "Rule with Globs", + description: "This rule has globs", + source: "rules-block", + rule: "Use TypeScript", + globs: "**/*.ts", + ruleFile: "/path/to/rule2.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + expect(result).toBe( + "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available." + ); + }); + + it("should return formatted rules when agent-requested rules exist", () => { + const rules: RuleWithSource[] = [ + { + name: "Agent Rule 1", + description: "First agent-requested rule", + source: "rules-block", + rule: "Use consistent formatting", + alwaysApply: false, + ruleFile: "/path/to/agent-rule1.md", + }, + { + name: "Agent Rule 2", + description: "Second agent-requested rule", + source: "default-agent", + rule: "Follow naming conventions", + alwaysApply: false, + ruleFile: "/path/to/agent-rule2.md", + }, + // These should be filtered out + { + name: "Always Apply Rule", + description: "This rule always applies", + source: "default-chat", + rule: "Always use semicolons", + alwaysApply: true, + ruleFile: "/path/to/rule1.md", + }, + { + name: "Rule with Globs", + description: "This rule has globs", + source: "rules-block", + rule: "Use TypeScript", + globs: "**/*.ts", + ruleFile: "/path/to/rule2.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should handle rules with missing description", () => { + const rules: RuleWithSource[] = [ + { + name: "Rule Without Description", + source: "rules-block", + rule: "Some rule content", + alwaysApply: false, + ruleFile: "/path/to/no-desc-rule.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should handle rules with missing name", () => { + const rules: RuleWithSource[] = [ + { + description: "Rule without name", + source: "rules-block", + rule: "Some rule content", + alwaysApply: false, + ruleFile: "/path/to/no-name-rule.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should handle rules with missing ruleFile", () => { + const rules: RuleWithSource[] = [ + { + name: "Rule Without File", + description: "Rule without file path", + source: "rules-block", + rule: "Some rule content", + alwaysApply: false, + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should filter out rules with alwaysApply undefined (truthy)", () => { + const rules: RuleWithSource[] = [ + { + name: "Rule with undefined alwaysApply", + description: "This should be filtered out", + source: "rules-block", + rule: "Some rule", + ruleFile: "/path/to/rule.md", + // alwaysApply is undefined, which is truthy in the filter condition + }, + { + name: "Valid Agent Rule", + description: "This should be included", + source: "rules-block", + rule: "Some rule", + alwaysApply: false, + ruleFile: "/path/to/valid-rule.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should filter out rules with any globs defined", () => { + const rules: RuleWithSource[] = [ + { + name: "Rule with string globs", + description: "This should be filtered out", + source: "rules-block", + rule: "Some rule", + alwaysApply: false, + globs: "**/*.ts", + ruleFile: "/path/to/rule1.md", + }, + { + name: "Rule with array globs", + description: "This should also be filtered out", + source: "rules-block", + rule: "Some rule", + alwaysApply: false, + globs: ["**/*.ts", "**/*.js"], + ruleFile: "/path/to/rule2.md", + }, + { + name: "Valid Agent Rule", + description: "This should be included", + source: "rules-block", + rule: "Some rule", + alwaysApply: false, + ruleFile: "/path/to/valid-rule.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); + + it("should handle empty rules array", () => { + const rules: RuleWithSource[] = []; + + const result = getRequestRuleDescription(rules); + + expect(result).toBe( + "Use this tool to select additional rules, specifically based on their descriptions. Available rules:\nNo rules available." + ); + }); + + it("should handle single agent-requested rule", () => { + const rules: RuleWithSource[] = [ + { + name: "Single Rule", + description: "The only agent-requested rule", + source: "rules-block", + rule: "Follow this guideline", + alwaysApply: false, + ruleFile: "/path/to/single-rule.md", + }, + ]; + + const result = getRequestRuleDescription(rules); + + 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"; + + expect(result).toBe(expected); + }); +}); \ No newline at end of file From 33b1d3994654f311dcae385f6ef2ef78696d1d89 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 28 May 2025 16:19:11 -0700 Subject: [PATCH 5/6] 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", From d158fab740cf803074106717560941cca8cb96c9 Mon Sep 17 00:00:00 2001 From: Patrick Erichsen Date: Wed, 28 May 2025 18:57:35 -0700 Subject: [PATCH 6/6] feat: dallin feedback pt 2 --- core/config/profile/doLoadConfig.ts | 20 ++++++++++++++++++++ gui/src/redux/slices/uiSlice.ts | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/core/config/profile/doLoadConfig.ts b/core/config/profile/doLoadConfig.ts index cfaa38ffa..865667ecb 100644 --- a/core/config/profile/doLoadConfig.ts +++ b/core/config/profile/doLoadConfig.ts @@ -219,6 +219,26 @@ export default async function doLoadConfig(options: { } }); + const ruleCounts: Record = {}; + newConfig.rules.forEach((rule) => { + if (rule.name) { + if (ruleCounts[rule.name]) { + ruleCounts[rule.name] = ruleCounts[rule.name] + 1; + } else { + ruleCounts[rule.name] = 1; + } + } + }); + + Object.entries(ruleCounts).forEach(([ruleName, count]) => { + if (count > 1) { + errors!.push({ + fatal: false, + message: `Duplicate (${count}) rules named "${ruleName}" detected. This may cause unexpected behavior`, + }); + } + }); + newConfig.allowAnonymousTelemetry = newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled()); diff --git a/gui/src/redux/slices/uiSlice.ts b/gui/src/redux/slices/uiSlice.ts index 28e91d052..b8961a0b1 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]: "allowedWithPermission", + [BuiltInToolNames.RequestRule]: "disabled", }, toolGroupSettings: { [BUILT_IN_GROUP_NAME]: "include",