mirror of
https://github.com/cjo4m06/mcp-shrimp-task-manager.git
synced 2025-07-27 08:32:27 +08:00
移除多處不必要的錯誤日誌輸出,避免 Cursor 報錯
This commit is contained in:
parent
bf5f3678ba
commit
552eed82ad
20
src/index.ts
20
src/index.ts
@ -71,7 +71,6 @@ async function main() {
|
|||||||
|
|
||||||
// 發送 SSE 事件的輔助函數
|
// 發送 SSE 事件的輔助函數
|
||||||
function sendSseUpdate() {
|
function sendSseUpdate() {
|
||||||
console.log("Tasks changed, sending update to clients...");
|
|
||||||
sseClients.forEach((client) => {
|
sseClients.forEach((client) => {
|
||||||
// 檢查客戶端是否仍然連接
|
// 檢查客戶端是否仍然連接
|
||||||
if (!client.writableEnded) {
|
if (!client.writableEnded) {
|
||||||
@ -102,7 +101,6 @@ async function main() {
|
|||||||
const tasksData = await fsPromises.readFile(TASKS_FILE_PATH, "utf-8");
|
const tasksData = await fsPromises.readFile(TASKS_FILE_PATH, "utf-8");
|
||||||
res.json(JSON.parse(tasksData));
|
res.json(JSON.parse(tasksData));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error reading tasks.json:", error);
|
|
||||||
// 確保檔案不存在時返回空任務列表
|
// 確保檔案不存在時返回空任務列表
|
||||||
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
||||||
res.json({ tasks: [] });
|
res.json({ tasks: [] });
|
||||||
@ -153,18 +151,8 @@ async function main() {
|
|||||||
sendSseUpdate();
|
sendSseUpdate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
console.warn(
|
|
||||||
`${TASKS_FILE_PATH} does not exist. File watching not started. It will start if the file is created later by the application.`
|
|
||||||
);
|
|
||||||
// 可以考慮在這裡也設置一個 watcher 監聽目錄創建或檔案創建
|
|
||||||
}
|
|
||||||
} catch (watchError) {
|
|
||||||
console.error(
|
|
||||||
`Error setting up file watch on ${TASKS_FILE_PATH}:`,
|
|
||||||
watchError
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
} catch (watchError) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 將 URL 寫入 ebGUI.md
|
// 將 URL 寫入 ebGUI.md
|
||||||
@ -172,9 +160,7 @@ async function main() {
|
|||||||
const websiteUrl = `[Task Manager UI](http://localhost:${port})`;
|
const websiteUrl = `[Task Manager UI](http://localhost:${port})`;
|
||||||
const websiteFilePath = path.join(DATA_DIR, "WebGUI.md");
|
const websiteFilePath = path.join(DATA_DIR, "WebGUI.md");
|
||||||
await fsPromises.writeFile(websiteFilePath, websiteUrl, "utf-8");
|
await fsPromises.writeFile(websiteFilePath, websiteUrl, "utf-8");
|
||||||
} catch (error) {
|
} catch (error) {}
|
||||||
console.error("Error writing website URL to file:", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 設置進程終止事件處理 (確保移除 watcher)
|
// 設置進程終止事件處理 (確保移除 watcher)
|
||||||
const shutdownHandler = async () => {
|
const shutdownHandler = async () => {
|
||||||
@ -470,7 +456,6 @@ async function main() {
|
|||||||
throw new Error(`Tool ${request.params.name} does not exist`);
|
throw new Error(`Tool ${request.params.name} does not exist`);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error executing tool:", error);
|
|
||||||
const errorMsg =
|
const errorMsg =
|
||||||
error instanceof Error ? error.message : String(error);
|
error instanceof Error ? error.message : String(error);
|
||||||
return {
|
return {
|
||||||
@ -491,7 +476,6 @@ async function main() {
|
|||||||
|
|
||||||
console.log("Shrimp Task Manager service started");
|
console.log("Shrimp Task Manager service started");
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to start service:", error);
|
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,11 +128,6 @@ export async function updateTask(
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (disallowedFields.length > 0) {
|
if (disallowedFields.length > 0) {
|
||||||
console.warn(
|
|
||||||
`Warning: Attempted to update illegal fields on a completed task: ${disallowedFields.join(
|
|
||||||
", "
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -383,20 +378,6 @@ export async function batchCreateOrUpdateTasks(
|
|||||||
|
|
||||||
// 從tasksToKeep中移除此任務,因為它已經被更新並添加到newTasks中了
|
// 從tasksToKeep中移除此任務,因為它已經被更新並添加到newTasks中了
|
||||||
tasksToKeep = tasksToKeep.filter((task) => task.id !== existingTaskId);
|
tasksToKeep = tasksToKeep.filter((task) => task.id !== existingTaskId);
|
||||||
} else {
|
|
||||||
// 如果任務已完成或找不到,則跳過更新,可能在控制台輸出警告
|
|
||||||
if (
|
|
||||||
existingTaskIndex !== -1 &&
|
|
||||||
existingTasks[existingTaskIndex].status === TaskStatus.COMPLETED
|
|
||||||
) {
|
|
||||||
console.warn(
|
|
||||||
`Warning: Attempted to update completed task "${taskData.name}", operation ignored`
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.warn(
|
|
||||||
`Warning: Attempted to update non-existent task "${taskData.name}", operation ignored`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 創建新任務
|
// 創建新任務
|
||||||
@ -450,9 +431,6 @@ export async function batchCreateOrUpdateTasks(
|
|||||||
if (taskNameToIdMap.has(dependencyName)) {
|
if (taskNameToIdMap.has(dependencyName)) {
|
||||||
dependencyTaskId = taskNameToIdMap.get(dependencyName)!;
|
dependencyTaskId = taskNameToIdMap.get(dependencyName)!;
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
|
||||||
`Warning: Task "${taskData.name}" references unknown dependency task "${dependencyName}", dependency ignored`
|
|
||||||
);
|
|
||||||
continue; // 跳過此依賴
|
continue; // 跳過此依賴
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -461,9 +439,6 @@ export async function batchCreateOrUpdateTasks(
|
|||||||
(task) => task.id === dependencyTaskId
|
(task) => task.id === dependencyTaskId
|
||||||
);
|
);
|
||||||
if (!idExists) {
|
if (!idExists) {
|
||||||
console.warn(
|
|
||||||
`Warning: Task "${taskData.name}" references unknown dependency task ID "${dependencyTaskId}", dependency ignored`
|
|
||||||
);
|
|
||||||
continue; // 跳過此依賴
|
continue; // 跳過此依賴
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -747,7 +722,6 @@ export async function clearAllTasks(): Promise<{
|
|||||||
backupFile: backupFileName,
|
backupFile: backupFileName,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error occurred while clearing all tasks:", error);
|
|
||||||
return {
|
return {
|
||||||
success: false,
|
success: false,
|
||||||
message: `清除任務時發生錯誤: ${
|
message: `清除任務時發生錯誤: ${
|
||||||
@ -789,7 +763,6 @@ export async function searchTasksWithCommand(
|
|||||||
// 如果有搜尋命令,執行它
|
// 如果有搜尋命令,執行它
|
||||||
if (cmd) {
|
if (cmd) {
|
||||||
try {
|
try {
|
||||||
console.log(`Executing command: ${cmd}`);
|
|
||||||
const { stdout } = await execPromise(cmd, {
|
const { stdout } = await execPromise(cmd, {
|
||||||
maxBuffer: 1024 * 1024 * 10,
|
maxBuffer: 1024 * 1024 * 10,
|
||||||
});
|
});
|
||||||
@ -862,23 +835,12 @@ export async function searchTasksWithCommand(
|
|||||||
});
|
});
|
||||||
|
|
||||||
memoryTasks.push(...filteredTasks);
|
memoryTasks.push(...filteredTasks);
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {}
|
||||||
console.error(`Error reading file ${filePath}:`, error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (error: unknown) {}
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {}
|
||||||
// grep沒有找到匹配項時會返回錯誤,但這不是真正的錯誤
|
|
||||||
// 只有當錯誤代碼不是1(沒有匹配)時才記錄錯誤
|
|
||||||
const err = error as { code?: number };
|
|
||||||
if (err.code !== 1) {
|
|
||||||
console.error("Error executing search command:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error: unknown) {
|
|
||||||
console.error("Error searching memory directory:", error);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 從當前任務中過濾符合條件的任務
|
// 從當前任務中過濾符合條件的任務
|
||||||
const filteredCurrentTasks = filterCurrentTasks(currentTasks, query, isId);
|
const filteredCurrentTasks = filterCurrentTasks(currentTasks, query, isId);
|
||||||
|
@ -92,9 +92,7 @@ export async function planTask({
|
|||||||
pendingTasks = allTasks.filter(
|
pendingTasks = allTasks.filter(
|
||||||
(task) => task.status !== TaskStatus.COMPLETED
|
(task) => task.status !== TaskStatus.COMPLETED
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {}
|
||||||
console.error("Error loading existing tasks:", error);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 使用prompt生成器獲取最終prompt
|
// 使用prompt生成器獲取最終prompt
|
||||||
@ -402,7 +400,6 @@ export async function splitTasks({
|
|||||||
try {
|
try {
|
||||||
allTasks = await getAllTasks();
|
allTasks = await getAllTasks();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error retrieving all tasks:", error);
|
|
||||||
allTasks = [...createdTasks]; // 如果獲取失敗,至少使用剛創建的任務
|
allTasks = [...createdTasks]; // 如果獲取失敗,至少使用剛創建的任務
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -429,8 +426,6 @@ export async function splitTasks({
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error executing task split:", error);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@ -622,7 +617,6 @@ export async function executeTask({
|
|||||||
? relatedFilesResult
|
? relatedFilesResult
|
||||||
: relatedFilesResult.summary || "";
|
: relatedFilesResult.summary || "";
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error loading related files:", error);
|
|
||||||
relatedFilesSummary =
|
relatedFilesSummary =
|
||||||
"Error loading related files, please check the files manually.";
|
"Error loading related files, please check the files manually.";
|
||||||
}
|
}
|
||||||
@ -645,7 +639,6 @@ export async function executeTask({
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error executing task:", error);
|
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@ -1122,7 +1115,6 @@ export async function queryTask({
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error querying tasks:", error);
|
|
||||||
return {
|
return {
|
||||||
content: [
|
content: [
|
||||||
{
|
{
|
||||||
@ -1187,8 +1179,6 @@ export async function getTaskDetail({
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error retrieving task details:", error);
|
|
||||||
|
|
||||||
// 使用prompt生成器獲取錯誤訊息
|
// 使用prompt生成器獲取錯誤訊息
|
||||||
const errorPrompt = getGetTaskDetailPrompt({
|
const errorPrompt = getGetTaskDetailPrompt({
|
||||||
taskId,
|
taskId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user