mirror of
https://github.com/QwenLM/qwen-code.git
synced 2025-12-21 17:27:54 +00:00
ability to override core system prompt (via .gemini/system.md) and specify core tools via coreTools setting (e.g. coreTools:["ls", "GrepTool", ...]) ; added tests, but did not update docs for now (#413)
This commit is contained in:
@@ -19,7 +19,6 @@ import { ShellTool } from '../tools/shell.js';
|
||||
import { WriteFileTool } from '../tools/write-file.js';
|
||||
import { WebFetchTool } from '../tools/web-fetch.js';
|
||||
import { ReadManyFilesTool } from '../tools/read-many-files.js';
|
||||
import { BaseTool, ToolResult } from '../tools/tools.js';
|
||||
import { MemoryTool } from '../tools/memoryTool.js';
|
||||
|
||||
export class MCPServerConfig {
|
||||
@@ -43,6 +42,7 @@ export class Config {
|
||||
private readonly debugMode: boolean,
|
||||
private readonly question: string | undefined, // Keep undefined possibility
|
||||
private readonly fullContext: boolean = false, // Default value here
|
||||
private readonly coreTools: string[] | undefined,
|
||||
private readonly toolDiscoveryCommand: string | undefined,
|
||||
private readonly toolCallCommand: string | undefined,
|
||||
private readonly mcpServerCommand: string | undefined,
|
||||
@@ -87,6 +87,10 @@ export class Config {
|
||||
return this.fullContext;
|
||||
}
|
||||
|
||||
getCoreTools(): string[] | undefined {
|
||||
return this.coreTools;
|
||||
}
|
||||
|
||||
getToolDiscoveryCommand(): string | undefined {
|
||||
return this.toolDiscoveryCommand;
|
||||
}
|
||||
@@ -168,6 +172,7 @@ export function createServerConfig(
|
||||
debugMode: boolean,
|
||||
question: string,
|
||||
fullContext?: boolean,
|
||||
coreTools?: string[],
|
||||
toolDiscoveryCommand?: string,
|
||||
toolCallCommand?: string,
|
||||
mcpServerCommand?: string,
|
||||
@@ -185,6 +190,7 @@ export function createServerConfig(
|
||||
debugMode,
|
||||
question,
|
||||
fullContext,
|
||||
coreTools,
|
||||
toolDiscoveryCommand,
|
||||
toolCallCommand,
|
||||
mcpServerCommand,
|
||||
@@ -199,23 +205,30 @@ export function createServerConfig(
|
||||
function createToolRegistry(config: Config): ToolRegistry {
|
||||
const registry = new ToolRegistry(config);
|
||||
const targetDir = config.getTargetDir();
|
||||
const tools = config.getCoreTools()
|
||||
? new Set(config.getCoreTools())
|
||||
: undefined;
|
||||
|
||||
const tools: Array<BaseTool<unknown, ToolResult>> = [
|
||||
new LSTool(targetDir),
|
||||
new ReadFileTool(targetDir),
|
||||
new GrepTool(targetDir),
|
||||
new GlobTool(targetDir),
|
||||
new EditTool(config),
|
||||
new WriteFileTool(config),
|
||||
new WebFetchTool(),
|
||||
new ReadManyFilesTool(targetDir),
|
||||
new ShellTool(config),
|
||||
new MemoryTool(),
|
||||
];
|
||||
// helper to create & register core tools that are enabled
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const registerCoreTool = (ToolClass: any, ...args: unknown[]) => {
|
||||
// check both the tool name (.Name) and the class name (.name)
|
||||
if (!tools || tools.has(ToolClass.Name) || tools.has(ToolClass.name)) {
|
||||
registry.registerTool(new ToolClass(...args));
|
||||
}
|
||||
};
|
||||
|
||||
registerCoreTool(LSTool, targetDir);
|
||||
registerCoreTool(ReadFileTool, targetDir);
|
||||
registerCoreTool(GrepTool, targetDir);
|
||||
registerCoreTool(GlobTool, targetDir);
|
||||
registerCoreTool(EditTool, config);
|
||||
registerCoreTool(WriteFileTool, config);
|
||||
registerCoreTool(WebFetchTool);
|
||||
registerCoreTool(ReadManyFilesTool, targetDir);
|
||||
registerCoreTool(ShellTool, config);
|
||||
registerCoreTool(MemoryTool);
|
||||
|
||||
for (const tool of tools) {
|
||||
registry.registerTool(tool);
|
||||
}
|
||||
registry.discoverTools();
|
||||
return registry;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user