mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-27 08:32:27 +08:00
新增任務複雜度評估功能,包含複雜度級別、評估指標及處理建議,並在任務執行過程中顯示評估結果。更新相關模型和工具以支持此功能,提升任務管理的靈活性與可操作性。
This commit is contained in:
parent
17937e7a9b
commit
7630185773
@ -1,4 +1,11 @@
|
|||||||
import { Task, TaskStatus, TaskDependency } from "../types/index.js";
|
import {
|
||||||
|
Task,
|
||||||
|
TaskStatus,
|
||||||
|
TaskDependency,
|
||||||
|
TaskComplexityLevel,
|
||||||
|
TaskComplexityThresholds,
|
||||||
|
TaskComplexityAssessment,
|
||||||
|
} from "../types/index.js";
|
||||||
import fs from "fs/promises";
|
import fs from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { v4 as uuidv4 } from "uuid";
|
import { v4 as uuidv4 } from "uuid";
|
||||||
@ -298,3 +305,136 @@ export async function deleteTask(
|
|||||||
|
|
||||||
return { success: true, message: "任務刪除成功" };
|
return { success: true, message: "任務刪除成功" };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 評估任務複雜度
|
||||||
|
export async function assessTaskComplexity(
|
||||||
|
taskId: string
|
||||||
|
): Promise<TaskComplexityAssessment | null> {
|
||||||
|
const task = await getTaskById(taskId);
|
||||||
|
|
||||||
|
if (!task) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 評估各項指標
|
||||||
|
const descriptionLength = task.description.length;
|
||||||
|
const dependenciesCount = task.dependencies.length;
|
||||||
|
const notesLength = task.notes ? task.notes.length : 0;
|
||||||
|
const hasNotes = !!task.notes;
|
||||||
|
|
||||||
|
// 基於各項指標評估複雜度級別
|
||||||
|
let level = TaskComplexityLevel.LOW;
|
||||||
|
|
||||||
|
// 描述長度評估
|
||||||
|
if (
|
||||||
|
descriptionLength >= TaskComplexityThresholds.DESCRIPTION_LENGTH.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.VERY_HIGH;
|
||||||
|
} else if (
|
||||||
|
descriptionLength >= TaskComplexityThresholds.DESCRIPTION_LENGTH.HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.HIGH;
|
||||||
|
} else if (
|
||||||
|
descriptionLength >= TaskComplexityThresholds.DESCRIPTION_LENGTH.MEDIUM
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.MEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 依賴數量評估(取最高級別)
|
||||||
|
if (
|
||||||
|
dependenciesCount >= TaskComplexityThresholds.DEPENDENCIES_COUNT.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.VERY_HIGH;
|
||||||
|
} else if (
|
||||||
|
dependenciesCount >= TaskComplexityThresholds.DEPENDENCIES_COUNT.HIGH &&
|
||||||
|
level !== TaskComplexityLevel.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.HIGH;
|
||||||
|
} else if (
|
||||||
|
dependenciesCount >= TaskComplexityThresholds.DEPENDENCIES_COUNT.MEDIUM &&
|
||||||
|
level !== TaskComplexityLevel.HIGH &&
|
||||||
|
level !== TaskComplexityLevel.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.MEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 注記長度評估(取最高級別)
|
||||||
|
if (notesLength >= TaskComplexityThresholds.NOTES_LENGTH.VERY_HIGH) {
|
||||||
|
level = TaskComplexityLevel.VERY_HIGH;
|
||||||
|
} else if (
|
||||||
|
notesLength >= TaskComplexityThresholds.NOTES_LENGTH.HIGH &&
|
||||||
|
level !== TaskComplexityLevel.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.HIGH;
|
||||||
|
} else if (
|
||||||
|
notesLength >= TaskComplexityThresholds.NOTES_LENGTH.MEDIUM &&
|
||||||
|
level !== TaskComplexityLevel.HIGH &&
|
||||||
|
level !== TaskComplexityLevel.VERY_HIGH
|
||||||
|
) {
|
||||||
|
level = TaskComplexityLevel.MEDIUM;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 根據複雜度級別生成處理建議
|
||||||
|
const recommendations: string[] = [];
|
||||||
|
|
||||||
|
// 低複雜度任務建議
|
||||||
|
if (level === TaskComplexityLevel.LOW) {
|
||||||
|
recommendations.push("此任務複雜度較低,可直接執行");
|
||||||
|
recommendations.push("建議設定清晰的完成標準,確保驗收有明確依據");
|
||||||
|
}
|
||||||
|
// 中等複雜度任務建議
|
||||||
|
else if (level === TaskComplexityLevel.MEDIUM) {
|
||||||
|
recommendations.push("此任務具有一定複雜性,建議詳細規劃執行步驟");
|
||||||
|
recommendations.push("可分階段執行並定期檢查進度,確保理解準確且實施完整");
|
||||||
|
if (dependenciesCount > 0) {
|
||||||
|
recommendations.push("注意檢查所有依賴任務的完成狀態和輸出質量");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 高複雜度任務建議
|
||||||
|
else if (level === TaskComplexityLevel.HIGH) {
|
||||||
|
recommendations.push("此任務複雜度較高,建議先進行充分的分析和規劃");
|
||||||
|
recommendations.push("考慮將任務拆分為較小的、可獨立執行的子任務");
|
||||||
|
recommendations.push("建立清晰的里程碑和檢查點,便於追蹤進度和品質");
|
||||||
|
if (
|
||||||
|
dependenciesCount > TaskComplexityThresholds.DEPENDENCIES_COUNT.MEDIUM
|
||||||
|
) {
|
||||||
|
recommendations.push(
|
||||||
|
"依賴任務較多,建議製作依賴關係圖,確保執行順序正確"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 極高複雜度任務建議
|
||||||
|
else if (level === TaskComplexityLevel.VERY_HIGH) {
|
||||||
|
recommendations.push("⚠️ 此任務複雜度極高,強烈建議拆分為多個獨立任務");
|
||||||
|
recommendations.push(
|
||||||
|
"在執行前進行詳盡的分析和規劃,明確定義各子任務的範圍和介面"
|
||||||
|
);
|
||||||
|
recommendations.push(
|
||||||
|
"對任務進行風險評估,識別可能的阻礙因素並制定應對策略"
|
||||||
|
);
|
||||||
|
recommendations.push("建立具體的測試和驗證標準,確保每個子任務的輸出質量");
|
||||||
|
if (
|
||||||
|
descriptionLength >= TaskComplexityThresholds.DESCRIPTION_LENGTH.VERY_HIGH
|
||||||
|
) {
|
||||||
|
recommendations.push(
|
||||||
|
"任務描述非常長,建議整理關鍵點並建立結構化的執行清單"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (dependenciesCount >= TaskComplexityThresholds.DEPENDENCIES_COUNT.HIGH) {
|
||||||
|
recommendations.push(
|
||||||
|
"依賴任務數量過多,建議重新評估任務邊界,確保任務切分合理"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
level,
|
||||||
|
metrics: {
|
||||||
|
descriptionLength,
|
||||||
|
dependenciesCount,
|
||||||
|
notesLength,
|
||||||
|
hasNotes,
|
||||||
|
},
|
||||||
|
recommendations,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -7,8 +7,13 @@ import {
|
|||||||
batchCreateOrUpdateTasks,
|
batchCreateOrUpdateTasks,
|
||||||
deleteTask as modelDeleteTask,
|
deleteTask as modelDeleteTask,
|
||||||
updateTaskSummary,
|
updateTaskSummary,
|
||||||
|
assessTaskComplexity,
|
||||||
} from "../models/taskModel.js";
|
} from "../models/taskModel.js";
|
||||||
import { TaskStatus, ConversationParticipant } from "../types/index.js";
|
import {
|
||||||
|
TaskStatus,
|
||||||
|
ConversationParticipant,
|
||||||
|
TaskComplexityLevel,
|
||||||
|
} from "../types/index.js";
|
||||||
import { addConversationEntry } from "../models/conversationLogModel.js";
|
import { addConversationEntry } from "../models/conversationLogModel.js";
|
||||||
import {
|
import {
|
||||||
extractSummary,
|
extractSummary,
|
||||||
@ -501,6 +506,9 @@ export async function executeTask({
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ===== 新增:評估任務複雜度 =====
|
||||||
|
const complexityAssessment = await assessTaskComplexity(taskId);
|
||||||
|
|
||||||
// 更新任務狀態為進行中
|
// 更新任務狀態為進行中
|
||||||
await updateTaskStatus(taskId, TaskStatus.IN_PROGRESS);
|
await updateTaskStatus(taskId, TaskStatus.IN_PROGRESS);
|
||||||
|
|
||||||
@ -508,7 +516,11 @@ export async function executeTask({
|
|||||||
try {
|
try {
|
||||||
await addConversationEntry(
|
await addConversationEntry(
|
||||||
ConversationParticipant.MCP,
|
ConversationParticipant.MCP,
|
||||||
`開始執行任務:${task.name} (ID: ${task.id})`,
|
`開始執行任務:${task.name} (ID: ${task.id})${
|
||||||
|
complexityAssessment
|
||||||
|
? `, 複雜度評估:${complexityAssessment.level}`
|
||||||
|
: ""
|
||||||
|
}`,
|
||||||
task.id,
|
task.id,
|
||||||
"任務啟動"
|
"任務啟動"
|
||||||
);
|
);
|
||||||
@ -516,13 +528,52 @@ export async function executeTask({
|
|||||||
console.error("記錄對話日誌時發生錯誤:", error);
|
console.error("記錄對話日誌時發生錯誤:", error);
|
||||||
}
|
}
|
||||||
|
|
||||||
const prompt = `## 任務執行指示\n\n### 任務詳情\n\n- **名稱:** ${
|
// 構建任務執行提示
|
||||||
|
let prompt = `## 任務執行指示\n\n### 任務詳情\n\n- **名稱:** ${
|
||||||
task.name
|
task.name
|
||||||
}\n- **ID:** \`${task.id}\`\n- **描述:** ${task.description}\n${
|
}\n- **ID:** \`${task.id}\`\n- **描述:** ${task.description}\n${
|
||||||
task.notes ? `- **注意事項:** ${task.notes}\n` : ""
|
task.notes ? `- **注意事項:** ${task.notes}\n` : ""
|
||||||
|
}\n`;
|
||||||
|
|
||||||
|
// 新增:添加複雜度評估部分
|
||||||
|
if (complexityAssessment) {
|
||||||
|
// 添加複雜度評估部分
|
||||||
|
prompt += `\n## 任務複雜度評估\n\n- **複雜度級別:** ${complexityAssessment.level}`;
|
||||||
|
|
||||||
|
// 根據複雜度級別使用不同風格
|
||||||
|
let complexityStyle = "";
|
||||||
|
if (complexityAssessment.level === TaskComplexityLevel.VERY_HIGH) {
|
||||||
|
complexityStyle = "⚠️ **警告:此任務複雜度極高** ⚠️";
|
||||||
|
} else if (complexityAssessment.level === TaskComplexityLevel.HIGH) {
|
||||||
|
complexityStyle = "⚠️ **注意:此任務複雜度較高**";
|
||||||
|
} else if (complexityAssessment.level === TaskComplexityLevel.MEDIUM) {
|
||||||
|
complexityStyle = "**提示:此任務具有一定複雜性**";
|
||||||
}
|
}
|
||||||
|
|
||||||
## 執行指引\n\n1. 請仔細分析任務要求,確保理解所有細節和約束條件
|
if (complexityStyle) {
|
||||||
|
prompt += `\n\n${complexityStyle}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加評估指標
|
||||||
|
prompt += `\n### 評估指標\n`;
|
||||||
|
prompt += `- 描述長度: ${complexityAssessment.metrics.descriptionLength} 字符\n`;
|
||||||
|
prompt += `- 依賴任務數: ${complexityAssessment.metrics.dependenciesCount} 個\n`;
|
||||||
|
if (complexityAssessment.metrics.hasNotes) {
|
||||||
|
prompt += `- 注記長度: ${complexityAssessment.metrics.notesLength} 字符\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加處理建議
|
||||||
|
if (complexityAssessment.recommendations.length > 0) {
|
||||||
|
prompt += `\n### 處理建議\n`;
|
||||||
|
complexityAssessment.recommendations.forEach((recommendation, index) => {
|
||||||
|
prompt += `${index + 1}. ${recommendation}\n`;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt += `\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
prompt += `## 執行指引\n\n1. 請仔細分析任務要求,確保理解所有細節和約束條件
|
||||||
2. 設計詳細的執行方案,包括具體步驟和技術選擇
|
2. 設計詳細的執行方案,包括具體步驟和技術選擇
|
||||||
3. 系統性地實施您的方案,遵循最佳實踐和項目慣例
|
3. 系統性地實施您的方案,遵循最佳實踐和項目慣例
|
||||||
4. 完整記錄您的實施過程,包括重要決策點和遇到的挑戰
|
4. 完整記錄您的實施過程,包括重要決策點和遇到的挑戰
|
||||||
|
@ -97,3 +97,43 @@ export interface ListConversationLogArgs {
|
|||||||
limit?: number; // 返回結果數量限制(選填)
|
limit?: number; // 返回結果數量限制(選填)
|
||||||
offset?: number; // 分頁偏移量(選填)
|
offset?: number; // 分頁偏移量(選填)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 任務複雜度級別:定義任務的複雜程度分類
|
||||||
|
export enum TaskComplexityLevel {
|
||||||
|
LOW = "低複雜度", // 簡單且直接的任務,通常不需要特殊處理
|
||||||
|
MEDIUM = "中等複雜度", // 具有一定複雜性但仍可管理的任務
|
||||||
|
HIGH = "高複雜度", // 複雜且耗時的任務,需要特別關注
|
||||||
|
VERY_HIGH = "極高複雜度", // 極其複雜的任務,建議拆分處理
|
||||||
|
}
|
||||||
|
|
||||||
|
// 任務複雜度閾值:定義任務複雜度評估的參考標準
|
||||||
|
export const TaskComplexityThresholds = {
|
||||||
|
DESCRIPTION_LENGTH: {
|
||||||
|
MEDIUM: 500, // 超過此字數判定為中等複雜度
|
||||||
|
HIGH: 1000, // 超過此字數判定為高複雜度
|
||||||
|
VERY_HIGH: 2000, // 超過此字數判定為極高複雜度
|
||||||
|
},
|
||||||
|
DEPENDENCIES_COUNT: {
|
||||||
|
MEDIUM: 2, // 超過此依賴數量判定為中等複雜度
|
||||||
|
HIGH: 5, // 超過此依賴數量判定為高複雜度
|
||||||
|
VERY_HIGH: 10, // 超過此依賴數量判定為極高複雜度
|
||||||
|
},
|
||||||
|
NOTES_LENGTH: {
|
||||||
|
MEDIUM: 200, // 超過此字數判定為中等複雜度
|
||||||
|
HIGH: 500, // 超過此字數判定為高複雜度
|
||||||
|
VERY_HIGH: 1000, // 超過此字數判定為極高複雜度
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// 任務複雜度評估結果:記錄任務複雜度分析的詳細結果
|
||||||
|
export interface TaskComplexityAssessment {
|
||||||
|
level: TaskComplexityLevel; // 整體複雜度級別
|
||||||
|
metrics: {
|
||||||
|
// 各項評估指標的詳細數據
|
||||||
|
descriptionLength: number; // 描述長度
|
||||||
|
dependenciesCount: number; // 依賴數量
|
||||||
|
notesLength: number; // 注記長度
|
||||||
|
hasNotes: boolean; // 是否有注記
|
||||||
|
};
|
||||||
|
recommendations: string[]; // 處理建議列表
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user