mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-27 08:32:27 +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 { z } from "zod";
|
||||||
import { ThoughtData, ThoughtStage } from "../types/index.js";
|
import {
|
||||||
|
getProcessThoughtPrompt,
|
||||||
/**
|
ProcessThoughtPromptParams,
|
||||||
* 格式化思維內容,返回美觀的格式化輸出
|
} from "../prompts/generators/processThought.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");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* processThought工具的參數結構
|
* processThought工具的參數結構
|
||||||
@ -108,15 +56,15 @@ export async function processThought(
|
|||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
// 將參數轉換為規範的ThoughtData格式
|
// 將參數轉換為規範的ThoughtData格式
|
||||||
const thoughtData: ThoughtData = {
|
const thoughtData: ProcessThoughtPromptParams = {
|
||||||
thought: params.thought,
|
thought: params.thought,
|
||||||
thoughtNumber: params.thought_number,
|
thoughtNumber: params.thought_number,
|
||||||
totalThoughts: params.total_thoughts,
|
totalThoughts: params.total_thoughts,
|
||||||
nextThoughtNeeded: params.next_thought_needed,
|
nextThoughtNeeded: params.next_thought_needed,
|
||||||
stage: params.stage,
|
stage: params.stage,
|
||||||
tags: params.tags,
|
tags: params.tags || [],
|
||||||
axioms_used: params.axioms_used,
|
axioms_used: params.axioms_used || [],
|
||||||
assumptions_challenged: params.assumptions_challenged,
|
assumptions_challenged: params.assumptions_challenged || [],
|
||||||
};
|
};
|
||||||
|
|
||||||
// 確保思維編號不超過總思維數
|
// 確保思維編號不超過總思維數
|
||||||
@ -126,7 +74,7 @@ export async function processThought(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 格式化思維輸出
|
// 格式化思維輸出
|
||||||
const formattedThought = formatThought(thoughtData);
|
const formattedThought = getProcessThoughtPrompt(thoughtData);
|
||||||
|
|
||||||
// 返回成功響應
|
// 返回成功響應
|
||||||
return {
|
return {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user