mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-26 07:52:25 +08:00
移除不再使用的更新任務相關文件工具
This commit is contained in:
parent
a395686689
commit
fc1a5c89f9
@ -32,8 +32,6 @@ import {
|
||||
clearAllTasksSchema,
|
||||
updateTaskContent,
|
||||
updateTaskContentSchema,
|
||||
updateTaskRelatedFiles,
|
||||
updateTaskRelatedFilesSchema,
|
||||
queryTask,
|
||||
queryTaskSchema,
|
||||
getTaskDetail,
|
||||
@ -150,12 +148,6 @@ async function main() {
|
||||
"更新任務內容,包括名稱、描述和注記、依賴任務、相關文件、實現指南和驗證標準,已完成的任務僅允許更新摘要和相關文件",
|
||||
inputSchema: zodToJsonSchema(updateTaskContentSchema),
|
||||
},
|
||||
// {
|
||||
// name: "update_task_files",
|
||||
// description:
|
||||
// "更新任務相關文件列表,用於記錄與任務相關的代碼文件、參考資料等",
|
||||
// inputSchema: zodToJsonSchema(updateTaskRelatedFilesSchema),
|
||||
// },
|
||||
{
|
||||
name: "query_task",
|
||||
description: "根據關鍵字或ID搜尋任務,顯示省略版的任務資訊",
|
||||
|
@ -1123,190 +1123,6 @@ export async function updateTaskContent({
|
||||
};
|
||||
}
|
||||
|
||||
// 更新任務相關文件工具
|
||||
export const updateTaskRelatedFilesSchema = z.object({
|
||||
taskId: z
|
||||
.string()
|
||||
.uuid({ message: "任務ID格式無效,請提供有效的UUID格式" })
|
||||
.describe("待更新任務的唯一標識符,必須是系統中存在且未完成的任務ID"),
|
||||
relatedFiles: z
|
||||
.array(
|
||||
z.object({
|
||||
path: z
|
||||
.string()
|
||||
.min(1, { message: "文件路徑不能為空,請提供有效的文件路徑" })
|
||||
.describe("文件路徑,可以是相對於項目根目錄的路徑或絕對路徑"),
|
||||
type: z
|
||||
.nativeEnum(RelatedFileType)
|
||||
.describe(
|
||||
"文件與任務的關係類型 (TO_MODIFY, REFERENCE, CREATE, DEPENDENCY, OTHER)"
|
||||
),
|
||||
description: z.string().optional().describe("文件的補充描述(選填)"),
|
||||
lineStart: z
|
||||
.number()
|
||||
.int()
|
||||
.positive()
|
||||
.optional()
|
||||
.describe("相關代碼區塊的起始行(選填)"),
|
||||
lineEnd: z
|
||||
.number()
|
||||
.int()
|
||||
.positive()
|
||||
.optional()
|
||||
.describe("相關代碼區塊的結束行(選填)"),
|
||||
})
|
||||
)
|
||||
.min(1, { message: "至少需要提供一個相關文件,請確保文件列表不為空" })
|
||||
.describe("與任務相關的文件列表"),
|
||||
});
|
||||
|
||||
export async function updateTaskRelatedFiles({
|
||||
taskId,
|
||||
relatedFiles,
|
||||
}: z.infer<typeof updateTaskRelatedFilesSchema>) {
|
||||
if (relatedFiles) {
|
||||
for (const file of relatedFiles) {
|
||||
if (
|
||||
(file.lineStart && !file.lineEnd) ||
|
||||
(!file.lineStart && file.lineEnd) ||
|
||||
(file.lineStart && file.lineEnd && file.lineStart > file.lineEnd)
|
||||
) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: `## 操作失敗\n\n行號設置無效:必須同時設置起始行和結束行,且起始行必須小於結束行`,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 獲取任務以檢查它是否存在
|
||||
const task = await getTaskById(taskId);
|
||||
|
||||
if (!task) {
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: `## 系統錯誤\n\n找不到ID為 \`${taskId}\` 的任務。請使用「list_tasks」工具確認有效的任務ID後再試。`,
|
||||
},
|
||||
],
|
||||
isError: true,
|
||||
};
|
||||
}
|
||||
|
||||
// 記錄要更新的任務和相關文件
|
||||
const fileTypeCount = relatedFiles.reduce((acc, file) => {
|
||||
acc[file.type] = (acc[file.type] || 0) + 1;
|
||||
return acc;
|
||||
}, {} as Record<string, number>);
|
||||
|
||||
const fileTypeSummary = Object.entries(fileTypeCount)
|
||||
.map(([type, count]) => `${type} ${count} 個`)
|
||||
.join(",");
|
||||
|
||||
// 執行更新操作
|
||||
const result = await modelUpdateTaskRelatedFiles(taskId, relatedFiles);
|
||||
|
||||
// 構建響應消息
|
||||
const responseTitle = result.success ? "操作成功" : "操作失敗";
|
||||
let responseMessage = result.message;
|
||||
|
||||
if (result.success && result.task && result.task.relatedFiles) {
|
||||
// 顯示更新後的相關文件列表
|
||||
responseMessage += "\n\n### 任務相關文件列表\n";
|
||||
|
||||
// 按文件類型分組顯示
|
||||
const filesByType = result.task.relatedFiles.reduce((acc, file) => {
|
||||
acc[file.type] = acc[file.type] || [];
|
||||
acc[file.type].push(file);
|
||||
return acc;
|
||||
}, {} as Record<string, RelatedFile[]>);
|
||||
|
||||
for (const [type, files] of Object.entries(filesByType)) {
|
||||
responseMessage += `\n#### ${type} (${files.length} 個)\n`;
|
||||
files.forEach((file, index) => {
|
||||
responseMessage += `${index + 1}. \`${file.path}\`${
|
||||
file.description ? ` - ${file.description}` : ""
|
||||
}${
|
||||
file.lineStart && file.lineEnd
|
||||
? ` (行 ${file.lineStart}-${file.lineEnd})`
|
||||
: ""
|
||||
}\n`;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
content: [
|
||||
{
|
||||
type: "text" as const,
|
||||
text: `## ${responseTitle}\n\n${responseMessage}`,
|
||||
},
|
||||
],
|
||||
isError: !result.success,
|
||||
};
|
||||
}
|
||||
|
||||
// 格式化單個任務的詳細資訊
|
||||
const formatTaskDetails = (task: Task) => {
|
||||
let details = `### ${task.name}\n**ID:** \`${task.id}\`\n**描述:** ${task.description}\n`;
|
||||
|
||||
if (task.notes) {
|
||||
details += `**注記:** ${task.notes}\n`;
|
||||
}
|
||||
|
||||
details += `**狀態:** ${task.status}\n`;
|
||||
|
||||
if (task.dependencies.length > 0) {
|
||||
const depIds = task.dependencies
|
||||
.map((dep: TaskDependency) => `\`${dep.taskId}\``)
|
||||
.join(", ");
|
||||
details += `**依賴任務:** ${depIds}\n`;
|
||||
}
|
||||
|
||||
// 添加相關文件信息
|
||||
if (task.relatedFiles && task.relatedFiles.length > 0) {
|
||||
details += `**相關文件:** ${task.relatedFiles.length} 個\n`;
|
||||
|
||||
// 按文件類型分組
|
||||
const filesByType = task.relatedFiles.reduce(
|
||||
(acc: Record<string, RelatedFile[]>, file: RelatedFile) => {
|
||||
if (!acc[file.type]) {
|
||||
acc[file.type] = [];
|
||||
}
|
||||
acc[file.type].push(file);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, RelatedFile[]>
|
||||
);
|
||||
|
||||
for (const [type, files] of Object.entries(filesByType)) {
|
||||
details += ` - ${type} (${files.length} 個): `;
|
||||
details += files
|
||||
.map((file: RelatedFile) => `\`${file.path}\``)
|
||||
.join(", ");
|
||||
details += "\n";
|
||||
}
|
||||
}
|
||||
|
||||
details += `**創建時間:** ${new Date(task.createdAt).toISOString()}\n`;
|
||||
details += `**更新時間:** ${new Date(task.updatedAt).toISOString()}\n`;
|
||||
|
||||
if (task.completedAt) {
|
||||
details += `**完成時間:** ${new Date(task.completedAt).toISOString()}\n`;
|
||||
}
|
||||
|
||||
if (task.summary) {
|
||||
details += `**完成摘要:** ${task.summary}\n`;
|
||||
}
|
||||
|
||||
return details;
|
||||
};
|
||||
|
||||
// 查詢任務工具
|
||||
export const queryTaskSchema = z.object({
|
||||
query: z
|
||||
@ -1497,55 +1313,3 @@ export async function getTaskDetail({
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// 格式化完整任務詳情的輔助函數,不截斷長內容
|
||||
function formatFullTaskDetail(task: Task): string {
|
||||
let taskDetail = `### ${task.name}\n\n**ID:** \`${task.id}\`\n\n**狀態:** ${task.status}\n\n**描述:**\n${task.description}\n\n`;
|
||||
|
||||
if (task.notes) {
|
||||
taskDetail += `**注記:**\n${task.notes}\n\n`;
|
||||
}
|
||||
|
||||
if (task.dependencies && task.dependencies.length > 0) {
|
||||
taskDetail += `**依賴任務:** ${task.dependencies
|
||||
.map((dep) => `\`${dep.taskId}\``)
|
||||
.join(", ")}\n\n`;
|
||||
}
|
||||
|
||||
if (task.implementationGuide) {
|
||||
taskDetail += `**實現指南:**\n\`\`\`\n${task.implementationGuide}\n\`\`\`\n\n`;
|
||||
}
|
||||
|
||||
if (task.verificationCriteria) {
|
||||
taskDetail += `**驗證標準:**\n\`\`\`\n${task.verificationCriteria}\n\`\`\`\n\n`;
|
||||
}
|
||||
|
||||
if (task.relatedFiles && task.relatedFiles.length > 0) {
|
||||
taskDetail += `**相關文件:**\n`;
|
||||
for (const file of task.relatedFiles) {
|
||||
taskDetail += `- \`${file.path}\` (${file.type})${
|
||||
file.description ? `: ${file.description}` : ""
|
||||
}\n`;
|
||||
}
|
||||
taskDetail += `\n`;
|
||||
}
|
||||
|
||||
taskDetail += `**創建時間:** ${new Date(task.createdAt).toLocaleString(
|
||||
"zh-TW"
|
||||
)}\n`;
|
||||
taskDetail += `**更新時間:** ${new Date(task.updatedAt).toLocaleString(
|
||||
"zh-TW"
|
||||
)}\n`;
|
||||
|
||||
if (task.completedAt) {
|
||||
taskDetail += `**完成時間:** ${new Date(task.completedAt).toLocaleString(
|
||||
"zh-TW"
|
||||
)}\n\n`;
|
||||
}
|
||||
|
||||
if (task.summary) {
|
||||
taskDetail += `**完成摘要:**\n${task.summary}\n\n`;
|
||||
}
|
||||
|
||||
return taskDetail;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user