mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-26 07:52:25 +08:00
Add research mode functionality with associated prompts and schemas
This commit is contained in:
parent
9d7ed3aabd
commit
5267fa4490
19
src/index.ts
19
src/index.ts
@ -47,6 +47,8 @@ import {
|
||||
processThoughtSchema,
|
||||
initProjectRules,
|
||||
initProjectRulesSchema,
|
||||
researchMode,
|
||||
researchModeSchema,
|
||||
} from "./tools/index.js";
|
||||
|
||||
async function main() {
|
||||
@ -290,6 +292,13 @@ async function main() {
|
||||
),
|
||||
inputSchema: zodToJsonSchema(initProjectRulesSchema),
|
||||
},
|
||||
{
|
||||
name: "research_mode",
|
||||
description: loadPromptFromTemplate(
|
||||
"toolsDescription/researchMode.md"
|
||||
),
|
||||
inputSchema: zodToJsonSchema(researchModeSchema),
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
@ -436,6 +445,16 @@ async function main() {
|
||||
return await processThought(parsedArgs.data);
|
||||
case "init_project_rules":
|
||||
return await initProjectRules();
|
||||
case "research_mode":
|
||||
parsedArgs = await researchModeSchema.safeParseAsync(
|
||||
request.params.arguments
|
||||
);
|
||||
if (!parsedArgs.success) {
|
||||
throw new Error(
|
||||
`Invalid arguments for tool ${request.params.name}: ${parsedArgs.error.message}`
|
||||
);
|
||||
}
|
||||
return await researchMode(parsedArgs.data);
|
||||
default:
|
||||
throw new Error(`Tool ${request.params.name} does not exist`);
|
||||
}
|
||||
|
57
src/prompts/generators/researchMode.ts
Normal file
57
src/prompts/generators/researchMode.ts
Normal file
@ -0,0 +1,57 @@
|
||||
/**
|
||||
* researchMode prompt 生成器
|
||||
* 負責將模板和參數組合成最終的 prompt
|
||||
*/
|
||||
|
||||
import {
|
||||
loadPrompt,
|
||||
generatePrompt,
|
||||
loadPromptFromTemplate,
|
||||
} from "../loader.js";
|
||||
|
||||
/**
|
||||
* researchMode prompt 參數介面
|
||||
*/
|
||||
export interface ResearchModePromptParams {
|
||||
topic: string;
|
||||
previousState: string;
|
||||
currentState: string;
|
||||
nextSteps: string;
|
||||
memoryDir: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 獲取 researchMode 的完整 prompt
|
||||
* @param params prompt 參數
|
||||
* @returns 生成的 prompt
|
||||
*/
|
||||
export function getResearchModePrompt(
|
||||
params: ResearchModePromptParams
|
||||
): string {
|
||||
// 處理之前的研究狀態
|
||||
let previousStateContent = "";
|
||||
if (params.previousState && params.previousState.trim() !== "") {
|
||||
const previousStateTemplate = loadPromptFromTemplate(
|
||||
"researchMode/previousState.md"
|
||||
);
|
||||
previousStateContent = generatePrompt(previousStateTemplate, {
|
||||
previousState: params.previousState,
|
||||
});
|
||||
} else {
|
||||
previousStateContent = "這是第一次進行此主題的研究,沒有之前的研究狀態。";
|
||||
}
|
||||
|
||||
// 載入主要模板
|
||||
const indexTemplate = loadPromptFromTemplate("researchMode/index.md");
|
||||
let prompt = generatePrompt(indexTemplate, {
|
||||
topic: params.topic,
|
||||
previousStateContent: previousStateContent,
|
||||
currentState: params.currentState,
|
||||
nextSteps: params.nextSteps,
|
||||
memoryDir: params.memoryDir,
|
||||
time: new Date().toLocaleString(),
|
||||
});
|
||||
|
||||
// 載入可能的自定義 prompt
|
||||
return loadPrompt(prompt, "RESEARCH_MODE");
|
||||
}
|
@ -22,3 +22,4 @@ export { getInitProjectRulesPrompt } from "./generators/initProjectRules.js";
|
||||
export { getDeleteTaskPrompt } from "./generators/deleteTask.js";
|
||||
export { getClearAllTasksPrompt } from "./generators/clearAllTasks.js";
|
||||
export { getUpdateTaskContentPrompt } from "./generators/updateTaskContent.js";
|
||||
export { getResearchModePrompt } from "./generators/researchMode.js";
|
||||
|
94
src/prompts/templates_en/researchMode/index.md
Normal file
94
src/prompts/templates_en/researchMode/index.md
Normal file
@ -0,0 +1,94 @@
|
||||
# Programming Research Mode
|
||||
|
||||
You are an AI research assistant equipped with web search, codebase file lookup, and library API query capabilities.
|
||||
You are now entering a specialized programming-focused **Research Mode**, similar to the research functions of ChatGPT or Perplexity, but focused on software development.
|
||||
Your mission is to conduct in-depth and comprehensive research and analysis on the **Research Topic**, and ultimately propose a final design solution.
|
||||
|
||||
In **Research Mode**, you should adopt an academic research mindset, maintaining **curiosity** and a **critical attitude** toward all retrieved information.
|
||||
You must **continually search and verify facts**, rather than trusting search results directly.
|
||||
Also, be mindful of the **timeliness** of the information — you are only interested in **the most up-to-date knowledge**.
|
||||
|
||||
Current time: **`{time}`**
|
||||
|
||||
## Research Topic
|
||||
|
||||
**{topic}**
|
||||
|
||||
## Research State Management
|
||||
|
||||
### Previous Research State
|
||||
|
||||
{previousStateContent}
|
||||
|
||||
### Current Execution State
|
||||
|
||||
**Current Task:** {currentState}
|
||||
|
||||
### Next Steps
|
||||
|
||||
**Next Directions:** {nextSteps}
|
||||
|
||||
## Research Guidelines
|
||||
|
||||
### 1. Depth and Breadth Requirements
|
||||
|
||||
- **Deep Exploration**: For every concept, technique, or solution found, use a **search strategy** to dig deeper into its principles, implementation details, pros and cons.
|
||||
- **Broad Exploration**: Use **search strategies** to explore alternatives, competing technologies, and related tools in the ecosystem.
|
||||
- **Continuous Exploration**: Every search result should trigger a desire to further explore, continuing until the topic is sufficiently covered.
|
||||
|
||||
### 2. Search Strategy
|
||||
|
||||
You have the following tools available:
|
||||
|
||||
When searching, keep your **keywords concise and precise**.
|
||||
**Avoid using too many keywords at once**. Limit each search to **2–4 keywords** to **prevent ineffective searches**.
|
||||
Use **multiple searches**, refining the keywords based on previous results.
|
||||
Whenever you feel **curious or uncertain about a search result**, you must **search again** multiple times to validate the content.
|
||||
|
||||
- **Web Search Tools**: For the latest technical info, documentation, tutorials, best practices, such as `web_search` or any web search tool.
|
||||
- **Browser Operation Tools**: For browsing recent documentation or sites, such as `use_browser` or any browser automation tool.
|
||||
- **Code Search Tools**: For searching implementations, patterns, and examples in the existing project, such as `codebase_search`, `read_file`, or any relevant tool.
|
||||
|
||||
### 3. Research Execution Flow
|
||||
|
||||
1. **Understand Current State**: Clearly identify the task at hand.
|
||||
2. **Perform Search**: Use appropriate search tools to collect information.
|
||||
3. **Deep Analysis**: Analyze the results thoroughly and extract key insights.
|
||||
4. **Expand Breadth**: Identify additional directions for exploration based on the analysis.
|
||||
5. **Iterative Exploration**: Repeat the search and analysis process until sufficient information is gathered. Ensure at least 3 rounds of research for quality.
|
||||
6. **Synthesize Summary**: Integrate all findings into a valuable research outcome.
|
||||
|
||||
### 4. Research Quality Standards
|
||||
|
||||
- **Accuracy**: All information must come from reliable sources, avoiding outdated or incorrect content.
|
||||
- **Practicality**: The outcome must be of practical value to software development.
|
||||
- **Completeness**: Cover all critical aspects of the topic without missing key information.
|
||||
- **Timeliness**: Prioritize the most recent technical advancements and best practices.
|
||||
|
||||
### 5. Avoiding Topic Deviation
|
||||
|
||||
- Always remember the **Research Topic**
|
||||
- Ensure all searches and analysis stay relevant to the topic
|
||||
- Refer to **Next Steps** to maintain correct direction
|
||||
|
||||
### 6. Final Report
|
||||
|
||||
When the research is complete, you must generate a detailed research report in **Markdown** format and wait for the user's next instruction.
|
||||
|
||||
## Execution Instructions
|
||||
|
||||
**Immediately begin executing the task described in the Current State**:
|
||||
{currentState}
|
||||
|
||||
Remember:
|
||||
|
||||
- Don’t settle for surface-level results — explore deeper.
|
||||
- After each search, reflect on what else might be worth exploring.
|
||||
- Maintain curiosity for new findings and expand the research scope.
|
||||
- Record important discoveries throughout the process for future state updates.
|
||||
- **Do not guess, hallucinate, or simulate** — all information **must be verified through web search tools**.
|
||||
- Throughout the process, continually call `research_mode` to log progress. **This is important!** You should call `research_mode` again after completing each stage to log detailed findings and determine the next direction.
|
||||
- When you feel the research is complete, generate the **Final Report**.
|
||||
|
||||
**Start the research task now.**
|
||||
**⚠️ Critical Warning: You are only responsible for research, so you are strictly prohibited from using `editing tools` or `plan task`. You must complete your research and provide a final report, then wait for the user's next instruction.**
|
9
src/prompts/templates_en/researchMode/previousState.md
Normal file
9
src/prompts/templates_en/researchMode/previousState.md
Normal file
@ -0,0 +1,9 @@
|
||||
**Previous Research Results Summary:**
|
||||
|
||||
{previousState}
|
||||
|
||||
**Based on previous research, please note:**
|
||||
|
||||
- Avoid repeating content that has already been explored
|
||||
- Deepen or expand based on previous research
|
||||
- If you find information that conflicts with previous research, pay special attention and verify
|
@ -0,0 +1 @@
|
||||
When you need to conduct in-depth research on programming-related topics, you can use this tool to enter a specialized research mode. This tool will guide you on how to use web search and code search tools to systematically research technical topics, ensuring research depth and breadth while avoiding topic deviation. Suitable for technical research, best practice exploration, solution comparison, and other scenarios.
|
89
src/prompts/templates_zh/researchMode/index.md
Normal file
89
src/prompts/templates_zh/researchMode/index.md
Normal file
@ -0,0 +1,89 @@
|
||||
# 程式編程研究模式
|
||||
|
||||
你是一個擁有網頁搜尋、程式碼檔案查詢和程式庫 API 查詢功能的 AI 研究助理,
|
||||
你現在進入了專門的程式編程`研究模式`,類似於 ChatGPT 或 Perplexity 的研究功能,但專注於程式開發領域。
|
||||
你的任務是針對 【研究主題】 進行深入且全面的調研分析,並提出最終的設計方案。
|
||||
|
||||
在`研究模式`你應該專注於學術研究,必須對搜尋到的資訊保持`好奇心`與`質疑的態度`,你將透過`不斷地搜尋與研究來驗證事實`,而不是直接相信搜尋結果,同時你也要注意`資訊的時效性`,你只對`最新的資訊`有興趣。
|
||||
|
||||
現在時間是:`{time}`
|
||||
|
||||
## 研究主題
|
||||
|
||||
**{topic}**
|
||||
|
||||
## 研究狀態管理
|
||||
|
||||
### 之前的研究狀態
|
||||
|
||||
{previousStateContent}
|
||||
|
||||
### 當前執行狀態
|
||||
|
||||
**當前任務:** {currentState}
|
||||
|
||||
### 下一步計劃
|
||||
|
||||
**後續方向:** {nextSteps}
|
||||
|
||||
## 研究指導原則
|
||||
|
||||
### 1. 研究深度與廣度要求
|
||||
|
||||
- **深度探索**:對於找到的每個概念、技術或解決方案,必須使用 `搜尋策略` 繼續深入了解其原理、實作細節、優缺點
|
||||
- **廣度探索**:使用`搜尋策略`探索相關的替代方案、競爭技術、生態系統中的相關工具
|
||||
- **持續探索**:每次搜尋結果都應該觸發進一步的探索慾望,直到內容完善
|
||||
|
||||
### 2. 搜尋策略
|
||||
|
||||
你有以下工具可以使用:
|
||||
|
||||
在搜尋時提供的`關鍵字`需`簡潔`與`精準`,`切勿使用大量的關鍵字`再一次搜尋,每次搜尋應該勁量保持在`2~4個關鍵字`,這樣可以`避免太多關鍵字導致無效搜尋`,你應該使用`多次搜尋`並根據`搜尋結果修改關鍵字`慢慢地縮小範圍,當你對搜尋的`內容感到好奇或疑惑`你必須`再次使用搜尋工具`進行多次的搜尋來驗證內容
|
||||
|
||||
- **網路搜尋工具**:用於搜尋最新的技術資訊、文檔、教學、最佳實踐,例如 `web_search` 或其他任何網路搜尋工具
|
||||
- **瀏覽器操作工具**:用於搜尋最新的技術資訊、文檔、教學、最佳實踐,例如 `use_browser` 或其他任何瀏覽器操作工具
|
||||
- **程式碼搜尋工具**:用於在現有專案中搜尋相關實作、模式、範例,例如 `codebase_search`、`read_file` 或其他任何有幫助的工具
|
||||
|
||||
### 3. 研究執行流程
|
||||
|
||||
1. **理解當前狀態**:明確當前需要執行的具體任務
|
||||
2. **執行搜尋**:使用適當的搜尋工具收集資訊
|
||||
3. **深度分析**:對搜尋結果進行深入分析,提取關鍵資訊
|
||||
4. **廣度擴展**:基於分析結果,識別需要進一步探索的方向
|
||||
5. **持續探索**:重複執行搜尋和分析,直到獲得充分的資訊,確保至少經過三輪的研究來保證質量
|
||||
6. **整合總結**:將所有發現整合成有價值的研究成果
|
||||
|
||||
### 4. 研究品質標準
|
||||
|
||||
- **準確性**:所有資訊必須來自可靠來源,避免過時或錯誤的資訊
|
||||
- **實用性**:研究結果必須對程式開發有實際價值
|
||||
- **完整性**:涵蓋主題的各個重要面向,不遺漏關鍵資訊
|
||||
- **時效性**:優先關注最新的技術發展和最佳實踐
|
||||
|
||||
### 5. 避免偏離主題
|
||||
|
||||
- 始終記住`研究主題`
|
||||
- 確保所有搜尋和分析都與主題相關
|
||||
- 參考`下一步計劃`確保研究方向正確
|
||||
|
||||
### 6. 結論報告
|
||||
|
||||
當研究完畢時你必須使用 `markdown` 格式產生一份詳細的研究成果,並等待用戶的下一步指示
|
||||
|
||||
## 執行指示
|
||||
|
||||
**立即開始執行當前狀態中描述的任務**:
|
||||
{currentState}
|
||||
|
||||
記住:
|
||||
|
||||
- 不要滿足於表面的搜尋結果,要深入探索
|
||||
- 每次搜尋後都要思考還有什麼相關的內容需要探索
|
||||
- 保持對新發現的好奇心,持續擴展研究範圍
|
||||
- 將研究過程中的重要發現記錄下來,為後續狀態更新做準備
|
||||
- 禁止一切`猜測與幻覺與模擬`,所有資訊`必須透過網路搜尋工具`來驗證
|
||||
- 過程中你將持續的呼叫 `research_mode` 來記錄狀態,`注意這很重要`!你應該每研究完一個階段就重新互叫`research_mode`來記錄你的詳細研究結果並再次決定研究的方向
|
||||
- 當你覺得研究足夠完善時請產生`結論報告`
|
||||
|
||||
**現在開始執行研究任務**
|
||||
**嚴重警告:你只負責研究所以禁止使用`編輯工具`或`plan task`,你應該完善報告後提供`結論報告`並等待用戶下一步指示**
|
9
src/prompts/templates_zh/researchMode/previousState.md
Normal file
9
src/prompts/templates_zh/researchMode/previousState.md
Normal file
@ -0,0 +1,9 @@
|
||||
**之前的研究成果摘要:**
|
||||
|
||||
{previousState}
|
||||
|
||||
**基於之前的研究,請注意:**
|
||||
|
||||
- 避免重複已經探索過的內容
|
||||
- 在之前研究的基礎上進行深化或擴展
|
||||
- 如果發現與之前研究有衝突的資訊,請特別注意並進行驗證
|
@ -0,0 +1 @@
|
||||
當你需要進行程式編程相關的深度研究時,可以使用該工具進入專門的研究模式。該工具會引導你如何使用網路搜尋和程式碼搜尋工具來系統性地研究技術主題,確保研究的深度與廣度,並避免偏離主題。適用於技術調研、最佳實踐探索、解決方案比較等場景。
|
@ -6,3 +6,6 @@ export * from "./project/index.js";
|
||||
|
||||
// 導出所有思維鏈工具
|
||||
export * from "./thought/index.js";
|
||||
|
||||
// 導出所有研究工具
|
||||
export * from "./research/index.js";
|
||||
|
4
src/tools/research/index.ts
Normal file
4
src/tools/research/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
// 導出研究模式工具
|
||||
|
||||
// researchMode
|
||||
export { researchMode, researchModeSchema } from "./researchMode.js";
|
63
src/tools/research/researchMode.ts
Normal file
63
src/tools/research/researchMode.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import { z } from "zod";
|
||||
import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { getResearchModePrompt } from "../../prompts/index.js";
|
||||
|
||||
// 研究模式工具
|
||||
export const researchModeSchema = z.object({
|
||||
topic: z
|
||||
.string()
|
||||
.min(5, {
|
||||
message: "研究主題不能少於5個字符,請提供明確的研究主題",
|
||||
})
|
||||
.describe("要研究的程式編程主題內容,應該明確且具體"),
|
||||
previousState: z
|
||||
.string()
|
||||
.optional()
|
||||
.default("")
|
||||
.describe(
|
||||
"之前的研究狀態和內容摘要,第一次執行時為空,後續會包含之前詳細且關鍵的研究成果,這將幫助後續的研究"
|
||||
),
|
||||
currentState: z
|
||||
.string()
|
||||
.describe(
|
||||
"當前 Agent 主要該執行的內容,例如使用網路工具搜尋某些關鍵字或分析特定程式碼,研究完畢後請呼叫 research_mode 來記錄狀態並與之前的`previousState`整合,這將幫助你更好的保存與執行研究內容"
|
||||
),
|
||||
nextSteps: z
|
||||
.string()
|
||||
.describe(
|
||||
"後續的計劃、步驟或研究方向,用來約束 Agent 不偏離主題或走錯方向,如果研究過程中發現需要調整研究方向,請更新此欄位"
|
||||
),
|
||||
});
|
||||
|
||||
export async function researchMode({
|
||||
topic,
|
||||
previousState = "",
|
||||
currentState,
|
||||
nextSteps,
|
||||
}: z.infer<typeof researchModeSchema>) {
|
||||
// 獲取基礎目錄路徑
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = path.dirname(__filename);
|
||||
const PROJECT_ROOT = path.resolve(__dirname, "../../..");
|
||||
const DATA_DIR = process.env.DATA_DIR || path.join(PROJECT_ROOT, "data");
|
||||
const MEMORY_DIR = path.join(DATA_DIR, "memory");
|
||||
|
||||
// 使用prompt生成器獲取最終prompt
|
||||
const prompt = getResearchModePrompt({
|
||||
topic,
|
||||
previousState,
|
||||
currentState,
|
||||
nextSteps,
|
||||
memoryDir: MEMORY_DIR,
|
||||
});
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: prompt,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user