mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-26 07:52:25 +08:00
新增 processThought 生成器及相關模板,整合思維處理邏輯,提升任務執行的靈活性與可讀性。
This commit is contained in:
parent
5513235d82
commit
304e0cd4f2
45
src/prompts/generators/processThought.ts
Normal file
45
src/prompts/generators/processThought.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import {
|
||||
loadPrompt,
|
||||
generatePrompt,
|
||||
loadPromptFromTemplate,
|
||||
} from "../loader.js";
|
||||
|
||||
export interface ProcessThoughtPromptParams {
|
||||
thought: string;
|
||||
thoughtNumber: number;
|
||||
totalThoughts: number;
|
||||
nextThoughtNeeded: boolean;
|
||||
stage: string;
|
||||
tags: string[];
|
||||
axioms_used: string[];
|
||||
assumptions_challenged: string[];
|
||||
}
|
||||
|
||||
export function getProcessThoughtPrompt(
|
||||
param: ProcessThoughtPromptParams
|
||||
): string {
|
||||
let nextThoughtNeeded = "";
|
||||
if (param.nextThoughtNeeded) {
|
||||
nextThoughtNeeded = loadPromptFromTemplate("processThought/moreThought.md");
|
||||
} else {
|
||||
nextThoughtNeeded = loadPromptFromTemplate(
|
||||
"processThought/complatedThought.md"
|
||||
);
|
||||
}
|
||||
|
||||
const indexTemplate = loadPromptFromTemplate("processThought/index.md");
|
||||
|
||||
const prompt = generatePrompt(indexTemplate, {
|
||||
thought: param.thought,
|
||||
thoughtNumber: param.thoughtNumber,
|
||||
totalThoughts: param.totalThoughts,
|
||||
stage: param.stage,
|
||||
tags: param.tags.join(", ") || "no tags",
|
||||
axioms_used: param.axioms_used.join(", ") || "no axioms used",
|
||||
assumptions_challenged:
|
||||
param.assumptions_challenged.join(", ") || "no assumptions challenged",
|
||||
nextThoughtNeeded,
|
||||
});
|
||||
|
||||
return loadPrompt(prompt, "PROCESS_THOUGHT");
|
||||
}
|
6
src/prompts/templates/processThought/complatedThought.md
Normal file
6
src/prompts/templates/processThought/complatedThought.md
Normal file
@ -0,0 +1,6 @@
|
||||
## 思考完成
|
||||
|
||||
下一步使用「analyze_task」 提交分析結果
|
||||
|
||||
1. **任務摘要** - 目標、範圍、挑戰和限制條件
|
||||
2. **初步解答構想** - 可行的技術方案和實施計劃
|
13
src/prompts/templates/processThought/index.md
Normal file
13
src/prompts/templates/processThought/index.md
Normal file
@ -0,0 +1,13 @@
|
||||
## 思維 {thoughtNumber}/{totalThoughts} - {stage}
|
||||
|
||||
{thought}
|
||||
|
||||
**標籤:** {tags}
|
||||
|
||||
**使用的原則:** {axioms_used}
|
||||
|
||||
**挑戰的假設:** {assumptions_challenged}
|
||||
|
||||
**禁止事項:** 你應該禁止一切猜測,任何疑慮請完整查看相關程式碼或使用網路搜尋工具查詢
|
||||
|
||||
{nextThoughtNeeded}
|
1
src/prompts/templates/processThought/moreThought.md
Normal file
1
src/prompts/templates/processThought/moreThought.md
Normal file
@ -0,0 +1 @@
|
||||
需要更多思考,繼續使用 「process_thought」 工具思考找尋答案
|
@ -1,60 +1,8 @@
|
||||
import { z } from "zod";
|
||||
import { ThoughtData, ThoughtStage } from "../types/index.js";
|
||||
|
||||
/**
|
||||
* 格式化思維內容,返回美觀的格式化輸出
|
||||
* @param thoughtData 思維資料
|
||||
* @returns 格式化後的思維輸出
|
||||
*/
|
||||
function formatThought(thoughtData: ThoughtData): string {
|
||||
// 創建基本思維標題,包含編號、總數和階段
|
||||
const thoughtHeader = `## 思維 ${thoughtData.thoughtNumber}/${thoughtData.totalThoughts} - ${thoughtData.stage}`;
|
||||
|
||||
// 格式化思維正文
|
||||
const thoughtContent = thoughtData.thought;
|
||||
|
||||
// 準備可選元素的陣列
|
||||
const optionalElements: string[] = [];
|
||||
|
||||
// 如果有標籤,則添加到可選元素
|
||||
if (thoughtData.tags && thoughtData.tags.length > 0) {
|
||||
optionalElements.push(`**標籤:** ${thoughtData.tags.join(", ")}`);
|
||||
}
|
||||
|
||||
// 如果有使用的公理,則添加到可選元素
|
||||
if (thoughtData.axioms_used && thoughtData.axioms_used.length > 0) {
|
||||
optionalElements.push(
|
||||
`**使用的原則:** ${thoughtData.axioms_used.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
// 如果有挑戰的假設,則添加到可選元素
|
||||
if (
|
||||
thoughtData.assumptions_challenged &&
|
||||
thoughtData.assumptions_challenged.length > 0
|
||||
) {
|
||||
optionalElements.push(
|
||||
`**挑戰的假設:** ${thoughtData.assumptions_challenged.join(", ")}`
|
||||
);
|
||||
}
|
||||
|
||||
optionalElements.push(
|
||||
`**禁止事項:** 你應該禁止一切猜測,任何疑慮請完整查看相關程式碼或使用網路搜尋工具查詢`
|
||||
);
|
||||
|
||||
// 添加下一步指示
|
||||
const nextStepIndication = thoughtData.nextThoughtNeeded
|
||||
? "需要更多思考,繼續使用 「process_thought」 工具思考找尋答案"
|
||||
: "思考完成。下一步使用「analyze_task」 提交分析結果\n1. **任務摘要** - 目標、範圍、挑戰和限制條件\n2. **初步解答構想** - 可行的技術方案和實施計劃";
|
||||
|
||||
// 組合所有元素
|
||||
return [
|
||||
thoughtHeader,
|
||||
thoughtContent,
|
||||
...optionalElements,
|
||||
`\n*${nextStepIndication}*`,
|
||||
].join("\n\n");
|
||||
}
|
||||
import {
|
||||
getProcessThoughtPrompt,
|
||||
ProcessThoughtPromptParams,
|
||||
} from "../prompts/generators/processThought.js";
|
||||
|
||||
/**
|
||||
* processThought工具的參數結構
|
||||
@ -108,15 +56,15 @@ export async function processThought(
|
||||
) {
|
||||
try {
|
||||
// 將參數轉換為規範的ThoughtData格式
|
||||
const thoughtData: ThoughtData = {
|
||||
const thoughtData: ProcessThoughtPromptParams = {
|
||||
thought: params.thought,
|
||||
thoughtNumber: params.thought_number,
|
||||
totalThoughts: params.total_thoughts,
|
||||
nextThoughtNeeded: params.next_thought_needed,
|
||||
stage: params.stage,
|
||||
tags: params.tags,
|
||||
axioms_used: params.axioms_used,
|
||||
assumptions_challenged: params.assumptions_challenged,
|
||||
tags: params.tags || [],
|
||||
axioms_used: params.axioms_used || [],
|
||||
assumptions_challenged: params.assumptions_challenged || [],
|
||||
};
|
||||
|
||||
// 確保思維編號不超過總思維數
|
||||
@ -126,7 +74,7 @@ export async function processThought(
|
||||
}
|
||||
|
||||
// 格式化思維輸出
|
||||
const formattedThought = formatThought(thoughtData);
|
||||
const formattedThought = getProcessThoughtPrompt(thoughtData);
|
||||
|
||||
// 返回成功響應
|
||||
return {
|
||||
|
Loading…
x
Reference in New Issue
Block a user