feat(core): 更新工具描述支持动态模板变量

- grep.txt: 使用 ${GREP_TOOL_NAME}、${BASH_TOOL_NAME}、${TASK_TOOL_NAME} 变量
- ask_user_question: 将 description 移至独立 txt 文件
- load_description.ts: 添加 ask_user_question -> plan 分类映射
This commit is contained in:
2025-12-16 16:26:27 +08:00
parent 1d380d0bcb
commit 7706af2c79
4 changed files with 23 additions and 42 deletions
@@ -1 +1,9 @@
在指定目录中搜索文件内容。支持正则表达式,可以指定文件类型过滤。用于查找代码中的特定文本、函数调用、变量引用等。
A powerful search tool built on ripgrep
Usage:
- ALWAYS use ${GREP_TOOL_NAME} for search tasks. NEVER invoke `grep` or `rg` as a ${BASH_TOOL_NAME} command. The ${GREP_TOOL_NAME} tool has been optimized for correct permissions and access.
- Supports full regex syntax (e.g., "log.*Error", "function\\s+\\w+")
- Filter files with glob parameter (e.g., "*.js", "**/*.tsx") or type parameter (e.g., "js", "py", "rust")
- Output modes: "content" shows matching lines, "files_with_matches" shows only file paths (default), "count" shows match counts
- Use ${TASK_TOOL_NAME} tool for open-ended searches requiring multiple rounds
- Pattern syntax: Uses ripgrep (not grep) - literal braces need escaping (use `interface\{\}` to find `interface{}` in Go code)
- Multiline matching: By default patterns match within single lines only. For cross-line patterns like `struct \{[\s\S]*?field`, use `multiline: true`
@@ -0,0 +1,10 @@
Use this tool when you need to ask the user questions during execution. This allows you to:
1. Gather user preferences or requirements
2. Clarify ambiguous instructions
3. Get decisions on implementation choices as you work
4. Offer choices to the user about what direction to take.
Usage notes:
- Users will always be able to select "Other" to provide custom text input
- Use multiSelect: true to allow multiple answers to be selected for a question
- If you recommend a specific option, make that the first option in the list and add "(Recommended)" at the end of the label
@@ -40,6 +40,8 @@ const TOOL_CATEGORY_MAP: Record<string, string> = {
// todo
todo_read: 'todo',
todo_write: 'todo',
// plan
ask_user_question: 'plan',
};
export function loadDescription(toolName: string): string {
@@ -13,6 +13,7 @@
import type { ToolWithMetadata } from '../types.js';
import type { ToolResult } from '../../types/index.js';
import { loadDescription } from '../load_description.js';
/**
* 选项定义
@@ -133,47 +134,7 @@ function formatQuestions(questions: Question[]): string {
*/
export const askUserQuestionTool: ToolWithMetadata = {
name: 'ask_user_question',
description: `向用户提问以澄清需求或获取决策。
使用场景:
- 需要用户在多个方案中做选择
- 需要澄清不明确的需求
- 需要用户确认关键决策
参数结构:
{
"questions": [
{
"question": "问题内容(以问号结尾)",
"header": "简短标签(最多12字符,可选)",
"options": [
{ "label": "选项1", "description": "说明(可选)" },
{ "label": "选项2", "description": "说明" }
],
"multiSelect": false
}
]
}
约束:
- questions: 1-4 个问题
- options: 每个问题 2-4 个选项(系统自动添加 "Other" 选项)
- header: 最多 12 字符
- label: 建议 1-5 个词
示例:
ask_user_question({
questions: [{
question: "您希望使用哪种状态管理方案?",
header: "状态管理",
options: [
{ label: "Redux", description: "成熟稳定,生态丰富" },
{ label: "Zustand", description: "轻量简洁,学习曲线低" },
{ label: "Jotai", description: "原子化状态,适合细粒度更新" }
],
multiSelect: false
}]
})`,
description: loadDescription('ask_user_question'),
metadata: {
name: 'ask_user_question',