移除不再使用的任務提示模板及相關代碼,簡化主程式邏輯,提升代碼可讀性與維護性。

This commit is contained in:
siage 2025-04-12 14:55:07 +08:00
parent 72d402eef1
commit 9581d2125e
2 changed files with 0 additions and 199 deletions

View File

@ -38,16 +38,6 @@ import {
clearConversationLogSchema, clearConversationLogSchema,
} from "./tools/logTools.js"; } from "./tools/logTools.js";
// 導入提示模板
import {
planTaskPrompt,
planTaskPromptSchema,
executeTaskPrompt,
executeTaskPromptSchema,
verifyTaskPrompt,
verifyTaskPromptSchema,
} from "./prompts/taskPrompts.js";
async function main() { async function main() {
try { try {
console.log("啟動蝦米任務管理器服務..."); console.log("啟動蝦米任務管理器服務...");
@ -394,57 +384,6 @@ async function main() {
} }
); );
// 註冊提示 - 使用同樣的錯誤處理模式
server.prompt(
"plan_task_prompt",
"生成結構化的新任務規劃,包含明確目標、評估標準與執行步驟",
{
taskType: z
.string()
.describe("任務類型,例如 'bug修復'、'功能開發'、'性能優化'等"),
description: z
.string()
.describe("完整詳細的任務問題描述,包含任務背景和目標"),
codeContext: z
.string()
.optional()
.describe("相關代碼片段或文件路徑(選填)"),
},
async (args) => {
return await planTaskPrompt(args);
}
);
server.prompt(
"execute_task_prompt",
"提供執行特定任務的詳細指南,包含所有必要上下文與技術細節",
{
taskId: z.string().describe("待執行任務的唯一標識符"),
additionalContext: z
.string()
.optional()
.describe("執行任務時需要參考的額外信息(選填)"),
},
async (args) => {
return await executeTaskPrompt(args);
}
);
server.prompt(
"verify_task_prompt",
"生成全面的任務驗證標準與檢查清單,確保質量與完整性",
{
taskId: z.string().describe("待驗證任務的唯一標識符"),
verificationFocus: z
.string()
.optional()
.describe("特別需要關注的驗證方向,如'安全性'、'性能'等(選填)"),
},
async (args) => {
return await verifyTaskPrompt(args);
}
);
// 建立連接 // 建立連接
const transport = new StdioServerTransport(); const transport = new StdioServerTransport();
await server.connect(transport); await server.connect(transport);

View File

@ -1,138 +0,0 @@
import { z } from "zod";
import { Task } from "../types/index.js";
import { getTaskById, getAllTasks } from "../models/taskModel.js";
// 開始規劃提示
export const planTaskPromptSchema = z.object({
description: z
.string()
.describe("完整詳細的任務問題描述,應包含任務目標、背景及預期成果"),
requirements: z
.string()
.optional()
.describe("任務的特定技術要求、業務約束條件或品質標準(選填)"),
});
export function planTaskPrompt({
description,
requirements,
}: z.infer<typeof planTaskPromptSchema>) {
let prompt = `## 任務分析請求\n\n請仔細分析以下任務問題理解其核心要求、範圍和約束條件\n\n\`\`\`\n${description}\n\`\`\`\n\n`;
if (requirements) {
prompt += `## 附加要求與限制條件\n\n請確保方案完全符合以下要求\n\n\`\`\`\n${requirements}\n\`\`\`\n\n`;
}
prompt += `## 分析指引\n\n請執行以下步驟進行全面分析\n\n1. 定義問題域和範圍界限\n2. 識別關鍵技術挑戰和決策點\n3. 評估可行的技術方案和架構選擇\n4. 考慮潛在的系統限制和擴展需求\n5. 識別成功標準和驗收條件\n\n如有任何疑問或需要澄清的部分請立即向用戶提出具體問題。\n\n## 交付成果要求\n\n完成分析後請提供\n\n1. **結構化任務摘要** - 準確概括任務的目標、範圍及關鍵挑戰\n2. **初步解答構想** - 提出技術可行的解決方案,包括實施策略和關鍵技術選擇\n\n完成分析後必須使用「分析問題」工具提交完整的分析結果。`;
return {
messages: [
{
role: "user" as const,
content: {
type: "text" as const,
text: prompt,
},
},
],
};
}
// 執行任務提示
export const executeTaskPromptSchema = z.object({
taskId: z
.string()
.describe("待執行任務的唯一標識符必須是系統中存在的有效任務ID"),
});
export async function executeTaskPrompt({
taskId,
}: z.infer<typeof executeTaskPromptSchema>) {
const task = await getTaskById(taskId);
if (!task) {
throw new Error(`找不到 ID 為 ${taskId} 的任務`);
}
// 獲取依賴任務的名稱,以便更直觀地顯示
let dependenciesText = "";
if (task.dependencies && task.dependencies.length > 0) {
const allTasks = await getAllTasks();
const depTasksInfo = task.dependencies.map((dep) => {
const depTask = allTasks.find((t) => t.id === dep.taskId);
return depTask
? `"${depTask.name}" (ID: \`${dep.taskId}\`)`
: `ID: \`${dep.taskId}\``;
});
dependenciesText = `\n\n### 依賴任務\n前置任務${depTasksInfo.join(", ")}`;
}
const prompt = `## 任務執行指示\n\n### 任務詳情\n\n- **名稱:** ${
task.name
}\n- **ID:** \`${task.id}\`\n- **描述:** ${task.description}\n${
task.notes ? `- **注意事項:** ${task.notes}\n` : ""
}${dependenciesText}
## \n\n請嚴格遵守以下操作範圍限制\n\n- \n- \n- \n-
## \n\n請嚴格按照以下階段性流程執行任務\n\n### 1. (20%)\n- \n- \n- \n\n### 2. (20%)\n- \n- \n- \n\n### 3. (40%)\n- \n- \n- \n\n### 4. (20%)\n- \n- \n- \n\n## \n- \n- \n- \n\n## \n\n完成實施後使`;
return {
messages: [
{
role: "user" as const,
content: {
type: "text" as const,
text: prompt,
},
},
],
};
}
// 檢驗任務提示
export const verifyTaskPromptSchema = z.object({
taskId: z
.string()
.describe("待驗證任務的唯一標識符必須是狀態為「進行中」的有效任務ID"),
});
export async function verifyTaskPrompt({
taskId,
}: z.infer<typeof verifyTaskPromptSchema>) {
const task = await getTaskById(taskId);
if (!task) {
throw new Error(`找不到 ID 為 ${taskId} 的任務`);
}
const prompt = `## 任務驗證評估\n\n### 任務資料\n\n- **名稱:** ${
task.name
}\n- **ID:** \`${task.id}\`\n- **描述:** ${task.description}\n${
task.notes ? `- **注意事項:** ${task.notes}\n` : ""
}
## \n\n請對實現結果進行全面且嚴格的評估
### 1. (30%)\n- \n- \n-
### 2. (30%)\n- \n- \n-
### 3. (20%)\n- \n- \n-
### 4. (20%)\n- \n- \n-
## \n\n請執行以下驗證步驟\n\n1. \n2. \n3. \n4. \n\n## \n\n請提供詳細的評估報告\n\n## \n\n- \n- 使`;
return {
messages: [
{
role: "user" as const,
content: {
type: "text" as const,
text: prompt,
},
},
],
};
}