From 3b1031e8f28c9a58e6a991ba212133e02ea0ed9d Mon Sep 17 00:00:00 2001 From: weijihui Date: Tue, 25 Nov 2025 20:36:09 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=86=85=E7=BD=AE=E5=B7=A5=E5=85=B7?= =?UTF-8?q?=E5=BC=80=E5=85=B3=E9=BB=98=E8=AE=A4=E6=89=93=E5=BC=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../executeCommandTool.ts | 9 +- .../builtInToolsPresenter/listFilesTool.ts | 9 +- .../builtInToolsPresenter/readFileTool.ts | 8 +- .../builtInToolsPresenter/writeFileTool.ts | 8 +- src/main/presenter/configPresenter/index.ts | 2 +- .../promptPresenter/sections/index.ts | 2 - .../sections/tool-descriptions.ts | 118 ------------------ .../sections/tool-use-guidelines.ts | 18 --- src/renderer/src/stores/settings.ts | 2 +- 9 files changed, 23 insertions(+), 153 deletions(-) delete mode 100644 src/main/presenter/promptPresenter/sections/tool-descriptions.ts delete mode 100644 src/main/presenter/promptPresenter/sections/tool-use-guidelines.ts diff --git a/src/main/presenter/builtInToolsPresenter/executeCommandTool.ts b/src/main/presenter/builtInToolsPresenter/executeCommandTool.ts index d0fd460..8ee5ffe 100644 --- a/src/main/presenter/builtInToolsPresenter/executeCommandTool.ts +++ b/src/main/presenter/builtInToolsPresenter/executeCommandTool.ts @@ -9,7 +9,7 @@ const execAsync = promisify(execCallback) export const executeCommandTool: BuiltInToolDefinition = { name: 'execute_command', description: - 'Executes a command-line command in the current or specified working directory, and returns standard output and standard error.', + "Requests the execution of a command line instruction and returns the standard output and standard error. Use this tool only when needing to run commands related to the system itself; it cannot be used for network requests or accessing external websites. That is, use it only when there is a clear need, and carefully evaluate the potential side effects of the command. You must tailor the command to the user's system and clearly explain its function. For command chaining, use the appropriate chaining syntax for the user's shell. By default, it runs in the current working directory; other directories or shells can be specified as needed.This tool can only be run on the local system where it is installed. When performing operations such as package installation and uninstallation, it is necessary to first determine the correct package management command.", parameters: { type: 'object', properties: { @@ -20,16 +20,17 @@ export const executeCommandTool: BuiltInToolDefinition = { working_directory: { type: 'string', description: - 'The working directory to use when executing the command (optional; the current process directory is the default).' + 'The directory to use when executing the command. When the path is necessary, confirm with the user.' }, timeout: { type: 'number', - description: 'Maximum time the command is allowed to run (milliseconds, default 30000)。' + description: + 'The maximum allowed runtime for the command in milliseconds, number type. Leave empty for the default of 30000.' }, shell: { type: 'string', description: - 'The shell to use to execute the command (optional; if left blank, the system default is used)。' + 'The shell used to execute the command, eg \`powershell.exe\`?\`bash\`, Leave empty to use the system default.?' } }, required: ['command'] diff --git a/src/main/presenter/builtInToolsPresenter/listFilesTool.ts b/src/main/presenter/builtInToolsPresenter/listFilesTool.ts index 55c1c6b..9a27dc3 100644 --- a/src/main/presenter/builtInToolsPresenter/listFilesTool.ts +++ b/src/main/presenter/builtInToolsPresenter/listFilesTool.ts @@ -4,17 +4,20 @@ import { BuiltInToolDefinition, BuiltInToolResponse, buildRawData } from './base export const listFilesTool: BuiltInToolDefinition = { name: 'list_files', - description: 'List files and directories in the specified directory', + description: + 'equests to list the names of files and subdirectories in a specified directory. Use this tool when you need to understand the directory structure or confirm the existence of files. By default, it only lists the current level, recursion can be enabled if necessary.', parameters: { type: 'object', properties: { directory_path: { type: 'string', - description: 'Directory path to list content' + description: + 'The path of the directory to list (When the path is uncertain, confirm with the user).' }, recursive: { type: 'boolean', - description: 'Whether to recursively list subdirectories', + description: + 'Whether to recursively list subdirectories, boolean type, defaults to false. Set to true only when the complete directory tree is genuinely needed to avoid excessive output.', default: false } }, diff --git a/src/main/presenter/builtInToolsPresenter/readFileTool.ts b/src/main/presenter/builtInToolsPresenter/readFileTool.ts index 3687277..0d1df17 100644 --- a/src/main/presenter/builtInToolsPresenter/readFileTool.ts +++ b/src/main/presenter/builtInToolsPresenter/readFileTool.ts @@ -4,13 +4,15 @@ import { BuiltInToolDefinition, BuiltInToolResponse, buildRawData } from './base export const readFileTool: BuiltInToolDefinition = { name: 'read_file', - description: 'Read the contents of a file at a specified path', + description: + 'Requests to read the content of a file at a specified path. Use this tool when you need to inspect an existing file whose content you are unaware of, such as analyzing code, viewing a text file, or extracting information from a configuration file.The output content will have line numbers prefixed to each line (e.g., "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. It can automatically extract raw text from PDF and DOCX files. It might not work for other types of binary files as it returns the raw content as a string.', parameters: { type: 'object', properties: { file_path: { type: 'string', - description: 'The path to the file to read, either absolute or relative' + description: + 'The path of the file to read (When the path is uncertain, confirm with the user).' }, encoding: { type: 'string', @@ -77,7 +79,7 @@ export async function executeReadFileTool( } } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error) - const failureMessage = `读取文件失败: ${errorMessage}` + const failureMessage = `Read file failures: ${errorMessage}` const metadata = { error: errorMessage } return { toolCallId, diff --git a/src/main/presenter/builtInToolsPresenter/writeFileTool.ts b/src/main/presenter/builtInToolsPresenter/writeFileTool.ts index 2984256..18e7269 100644 --- a/src/main/presenter/builtInToolsPresenter/writeFileTool.ts +++ b/src/main/presenter/builtInToolsPresenter/writeFileTool.ts @@ -4,18 +4,20 @@ import { BuiltInToolDefinition, BuiltInToolResponse, buildRawData } from './base export const writeFileTool: BuiltInToolDefinition = { name: 'write_file', - description: 'Write the content into a file in the specified path', + description: + 'Requests to write the complete content to a file at a specified path. If the file already exists, it will be overwritten with the provided content. If the file does not exist, a new file will be created. This tool automatically creates all necessary directories required to write the file.', parameters: { type: 'object', properties: { file_path: { type: 'string', description: - 'The file path to be written can be either an absolute path or a relative path.' + 'The path of the file to write to (When the path is uncertain, confirm with the user).' }, content: { type: 'string', - description: 'The content to be written into the file' + description: + 'The content to write to the file. Always provide the complete intended content of the file, without any truncation or omission. You must include all parts of the file, even if they are unmodified. However, do not include line numbers in the content, only provide the actual content of the file.' }, encoding: { type: 'string', diff --git a/src/main/presenter/configPresenter/index.ts b/src/main/presenter/configPresenter/index.ts index d848d31..6ab07ee 100644 --- a/src/main/presenter/configPresenter/index.ts +++ b/src/main/presenter/configPresenter/index.ts @@ -127,7 +127,7 @@ export class ConfigPresenter implements IConfigPresenter { lastSyncTime: 0, soundEnabled: false, copyWithCotEnabled: true, - useBuiltInToolsEnabled: false, + useBuiltInToolsEnabled: true, loggingEnabled: false, floatingButtonEnabled: false, default_system_prompt: '', diff --git a/src/main/presenter/promptPresenter/sections/index.ts b/src/main/presenter/promptPresenter/sections/index.ts index 88d77eb..0a57190 100644 --- a/src/main/presenter/promptPresenter/sections/index.ts +++ b/src/main/presenter/promptPresenter/sections/index.ts @@ -2,6 +2,4 @@ export { getSystemInfoSection } from './system-info' export { getObjectiveSection } from './objective' export { addCustomInstructions } from './custom-instructions' export { getSharedToolUseSection } from './tool-use' -export { getToolDescriptionsSection } from './tool-descriptions' -export { getToolUseGuidelinesSection } from './tool-use-guidelines' export { markdownFormattingSection } from './markdown-formatting' diff --git a/src/main/presenter/promptPresenter/sections/tool-descriptions.ts b/src/main/presenter/promptPresenter/sections/tool-descriptions.ts deleted file mode 100644 index 7315d50..0000000 --- a/src/main/presenter/promptPresenter/sections/tool-descriptions.ts +++ /dev/null @@ -1,118 +0,0 @@ -export function getToolDescriptionsSection(): string { - return `# Tool Descriptions - -## read_file -Description: Requests to read the content of a file at a specified path. -Use this tool when you need to inspect an existing file whose content you are unaware of, such as analyzing code, viewing a text file, or extracting information from a configuration file. -The output content will have line numbers prefixed to each line (e.g., "1 | const x = 1"), making it easier to reference specific lines when creating diffs or discussing code. -It can automatically extract raw text from PDF and DOCX files. It might not work for other types of binary files as it returns the raw content as a string. -Parameters: -- file_path:(Required) The path of the file to read (When the path is uncertain, confirm with the user). -Usage: - - -Fill in the file path here - - - -Example: Request to read the frontend-config.json file - - -frontend-config.json - - - -## write_file -Description: Requests to write the complete content to a file at a specified path. If the file already exists, it will be overwritten with the provided content. -If the file does not exist, a new file will be created. This tool automatically creates all necessary directories required to write the file. -Parameters: -- file_path: (Required) The path of the file to write to (When the path is uncertain, confirm with the user). -- content: (Required) The content to write to the file. Always provide the complete intended content of the file, without any truncation or omission. You must include all parts of the file, even if they are unmodified. However, do not include line numbers in the content, only provide the actual content of the file. -- line_count: (Required) The number of lines in the file. Ensure this count is based on the actual content of the file, not the number of lines in the content you provide. -Usage: - - -Fill in the file path here - -Fill in the file content here - -Total number of lines in the file, including empty lines - - - -Example: Request to write to frontend-config.json - - -frontend-config.json - -{ - "apiEndpoint": "https://api.example.com", - "theme": { - "primaryColor": "#007bff", - "secondaryColor": "#6c757d", - "fontFamily": "Arial, sans-serif" - }, - "features": { - "darkMode": true, - "notifications": true, - "analytics": false - }, - "version": "1.0.0" -} - -14 - - - -## list_files -Description: Requests to list the names of files and subdirectories in a specified directory. -Use this tool when you need to understand the directory structure or confirm the existence of files. -By default, it only lists the current level, recursion can be enabled if necessary. -Parameters: -- directory_path: (Required) The path of the directory to list (When the path is uncertain, confirm with the user). -- recursive: (Optional) Whether to recursively list subdirectories, boolean type, defaults to false. Set to true only when the complete directory tree is genuinely needed to avoid excessive output. -Usage: - - -Fill in the directory path here -false - - - -Example: Request to list the src/main directory - - -src/main -false - - - -## execute_command -Description: Requests the execution of a command line instruction and returns the standard output and standard error. Use this tool only when needing to run commands related to the system itself; it cannot be used for network requests or accessing external websites. -That is, use it only when there is a clear need, and carefully evaluate the potential side effects of the command. You must tailor the command to the user's system and clearly explain its function. For command chaining, use the appropriate chaining syntax for the user's shell. -By default, it runs in the current working directory; other directories or shells can be specified as needed. -This tool can only be run on the local system where it is installed. When performing operations such as package installation and uninstallation, it is necessary to first determine the correct package management command. -Parameters: -- command: (Required) The complete command string to execute. -- working_directory: (Optional) The directory to use when executing the command. When the path is necessary, confirm with the user. -- timeout: (Optional) The maximum allowed runtime for the command in milliseconds, number type. Leave empty for the default of 30000. -- shell: (Optional) The shell used to execute the command, eg \`powershell.exe\`、\`bash\`, Leave empty to use the system default.。 -Usage: - - -Fill in the command here -Optional working directory -30000 -Optional shell - - - -Example: Check Node.js version - - -node -v -5000 - - -` -} diff --git a/src/main/presenter/promptPresenter/sections/tool-use-guidelines.ts b/src/main/presenter/promptPresenter/sections/tool-use-guidelines.ts deleted file mode 100644 index e9af01b..0000000 --- a/src/main/presenter/promptPresenter/sections/tool-use-guidelines.ts +++ /dev/null @@ -1,18 +0,0 @@ -export function getToolUseGuidelinesSection(): string { - return `# Tool Use Guidelines - -1. Analyze user intent, determine whether to call the tool based on its description, and select the most matching tool or tools. -2. Assess what information you already have ,and proactively and clearly inquire about missing necessary parameters to ensure that the format of the call request fully complies with the tool interface specifications. -3. If multiple actions are needed, use one tool at a time per message to accomplish the task iteratively, with each tool use being informed by the result of the previous tool use. Each step must be informed by the previous step's result. -4. Formulate your tool use using the XML format specified for each tool. -5. Properly handle any errors in tool calls, convert them into user-friendly prompts that users can understand, and do not expose technical details. -6. ALWAYS wait for user confirmation after each tool use before proceeding. Never assume the success of a tool use without explicit confirmation of the result from the user. - -It is crucial to proceed step-by-step, waiting for the user's message after each tool use before moving forward with the task. This approach allows you to: -1. Confirm the success of each step before proceeding. -2. Address any issues or errors that arise immediately. -3. Adapt your approach based on new information or unexpected results. -4. Ensure that each action builds correctly on the previous ones. - -By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work.` -} diff --git a/src/renderer/src/stores/settings.ts b/src/renderer/src/stores/settings.ts index c639871..84ed2f6 100644 --- a/src/renderer/src/stores/settings.ts +++ b/src/renderer/src/stores/settings.ts @@ -33,7 +33,7 @@ export const useSettingsStore = defineStore('settings', () => { const searchPreviewEnabled = ref(true) // 搜索预览是否启用,默认启用 const contentProtectionEnabled = ref(true) // 投屏保护是否启用,默认启用 const copyWithCotEnabled = ref(true) - const useBuiltInToolsEnabled = ref(false) // 内置工具是否启用,默认不启用 + const useBuiltInToolsEnabled = ref(true) // 内置工具是否启用,默认启用 const notificationsEnabled = ref(true) // 系统通知是否启用,默认启用 const fontSizeLevel = ref(DEFAULT_FONT_SIZE_LEVEL) // 字体大小级别,默认为 1 // Ollama 相关状态 -- Gitee