Skip to content

Commit fe5bcfe

Browse files
Merge pull request #5867 from continuedev/pe/agent-requested-rule
feat: `requestRule` tool
2 parents 10ba83b + d158fab commit fe5bcfe

File tree

13 files changed

+372
-8
lines changed

13 files changed

+372
-8
lines changed

core/config/load.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ import { LLMReranker } from "../llm/llms/llm";
5151
import TransformersJsEmbeddingsProvider from "../llm/llms/TransformersJsEmbeddingsProvider";
5252
import { slashCommandFromPromptFileV1 } from "../promptFiles/v1/slashCommandFromPromptFile";
5353
import { getAllPromptFiles } from "../promptFiles/v2/getPromptFiles";
54-
import { allTools } from "../tools";
5554
import { copyOf } from "../util";
5655
import { GlobalContext } from "../util/GlobalContext";
5756
import mergeJson from "../util/merge";
@@ -67,6 +66,7 @@ import {
6766
} from "../util/paths";
6867
import { localPathToUri } from "../util/pathToUri";
6968

69+
import { baseToolDefinitions } from "../tools";
7070
import { modifyAnyConfigWithSharedConfig } from "./sharedConfig";
7171
import {
7272
getModelByRole,
@@ -529,7 +529,7 @@ async function intermediateToFinalConfig({
529529
const continueConfig: ContinueConfig = {
530530
...config,
531531
contextProviders,
532-
tools: [...allTools],
532+
tools: [...baseToolDefinitions],
533533
mcpServerStatuses: [],
534534
slashCommands: config.slashCommands ?? [],
535535
modelsByRole: {

core/config/profile/doLoadConfig.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { ControlPlaneClient } from "../../control-plane/client.js";
2525
import { getControlPlaneEnv } from "../../control-plane/env.js";
2626
import { TeamAnalytics } from "../../control-plane/TeamAnalytics.js";
2727
import ContinueProxy from "../../llm/llms/stubs/ContinueProxy";
28+
import { getConfigDependentToolDefinitions } from "../../tools";
2829
import { encodeMCPToolUri } from "../../tools/callTool";
2930
import { getConfigJsonPath, getConfigYamlPath } from "../../util/paths";
3031
import { localPathOrUriToPath } from "../../util/pathToUri";
@@ -202,6 +203,12 @@ export default async function doLoadConfig(options: {
202203
}
203204
}
204205

206+
newConfig.tools.push(
207+
...getConfigDependentToolDefinitions({
208+
rules: newConfig.rules,
209+
}),
210+
);
211+
205212
// Detect duplicate tool names
206213
const counts: Record<string, number> = {};
207214
newConfig.tools.forEach((tool) => {
@@ -211,6 +218,7 @@ export default async function doLoadConfig(options: {
211218
counts[tool.function.name] = 1;
212219
}
213220
});
221+
214222
Object.entries(counts).forEach(([toolName, count]) => {
215223
if (count > 1) {
216224
errors!.push({
@@ -220,6 +228,26 @@ export default async function doLoadConfig(options: {
220228
}
221229
});
222230

231+
const ruleCounts: Record<string, number> = {};
232+
newConfig.rules.forEach((rule) => {
233+
if (rule.name) {
234+
if (ruleCounts[rule.name]) {
235+
ruleCounts[rule.name] = ruleCounts[rule.name] + 1;
236+
} else {
237+
ruleCounts[rule.name] = 1;
238+
}
239+
}
240+
});
241+
242+
Object.entries(ruleCounts).forEach(([ruleName, count]) => {
243+
if (count > 1) {
244+
errors!.push({
245+
fatal: false,
246+
message: `Duplicate (${count}) rules named "${ruleName}" detected. This may cause unexpected behavior`,
247+
});
248+
}
249+
});
250+
223251
newConfig.allowAnonymousTelemetry =
224252
newConfig.allowAnonymousTelemetry && (await ide.isTelemetryEnabled());
225253

core/config/yaml/loadYaml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ import FreeTrial from "../../llm/llms/FreeTrial";
3636
import TransformersJsEmbeddingsProvider from "../../llm/llms/TransformersJsEmbeddingsProvider";
3737
import { slashCommandFromPromptFileV1 } from "../../promptFiles/v1/slashCommandFromPromptFile";
3838
import { getAllPromptFiles } from "../../promptFiles/v2/getPromptFiles";
39-
import { allTools } from "../../tools";
4039
import { GlobalContext } from "../../util/GlobalContext";
4140
import { modifyAnyConfigWithSharedConfig } from "../sharedConfig";
4241

4342
import { getControlPlaneEnvSync } from "../../control-plane/env";
43+
import { baseToolDefinitions } from "../../tools";
4444
import { getCleanUriPath } from "../../util/uri";
4545
import { getAllDotContinueDefinitionFiles } from "../loadLocalAssistants";
4646
import { LocalPlatformClient } from "./LocalPlatformClient";
@@ -193,7 +193,7 @@ async function configYamlToContinueConfig(options: {
193193

194194
const continueConfig: ContinueConfig = {
195195
slashCommands: [],
196-
tools: [...allTools],
196+
tools: [...baseToolDefinitions],
197197
mcpServerStatuses: [],
198198
contextProviders: [],
199199
modelsByRole: {

core/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,7 @@ export class Core {
723723
};
724724

725725
return await callTool(tool, toolCall.function.arguments, {
726+
config,
726727
ide: this.ide,
727728
llm: config.selectedModelByRole.chat,
728729
fetch: (url, init) =>

core/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ export interface ToolExtras {
975975
toolCallId: string;
976976
contextItems: ContextItem[];
977977
}) => void;
978+
config: ContinueConfig;
978979
}
979980

980981
export interface Tool {
@@ -1004,6 +1005,12 @@ interface ToolChoice {
10041005
};
10051006
}
10061007

1008+
export interface ConfigDependentToolParams {
1009+
rules: RuleWithSource[];
1010+
}
1011+
1012+
export type GetTool = (params: ConfigDependentToolParams) => Tool;
1013+
10071014
export interface BaseCompletionOptions {
10081015
temperature?: number;
10091016
topP?: number;

core/tools/builtIn.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export enum BuiltInToolNames {
1010
ViewDiff = "builtin_view_diff",
1111
LSTool = "builtin_ls",
1212
CreateRuleBlock = "builtin_create_rule_block",
13+
RequestRule = "builtin_request_rule",
1314

1415
// excluded from allTools for now
1516
ViewRepoMap = "builtin_view_repo_map",
@@ -18,4 +19,4 @@ export enum BuiltInToolNames {
1819

1920
export const BUILT_IN_GROUP_NAME = "Built-In";
2021

21-
export const CLIENT_TOOLS = [BuiltInToolNames.EditExistingFile];
22+
export const CLIENT_TOOLS_IMPLS = [BuiltInToolNames.EditExistingFile];

core/tools/callTool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { grepSearchImpl } from "./implementations/grepSearch";
1010
import { lsToolImpl } from "./implementations/lsTool";
1111
import { readCurrentlyOpenFileImpl } from "./implementations/readCurrentlyOpenFile";
1212
import { readFileImpl } from "./implementations/readFile";
13+
import { requestRuleImpl } from "./implementations/requestRule";
1314
import { runTerminalCommandImpl } from "./implementations/runTerminalCommand";
1415
import { searchWebImpl } from "./implementations/searchWeb";
1516
import { viewDiffImpl } from "./implementations/viewDiff";
@@ -157,6 +158,8 @@ async function callBuiltInTool(
157158
return await readCurrentlyOpenFileImpl(args, extras);
158159
case BuiltInToolNames.CreateRuleBlock:
159160
return await createRuleBlockImpl(args, extras);
161+
case BuiltInToolNames.RequestRule:
162+
return await requestRuleImpl(args, extras);
160163
default:
161164
throw new Error(`Tool "${functionName}" not found`);
162165
}

0 commit comments

Comments
 (0)