UNPKG

omnifocus-mcp-enhanced

Version:

🚀 NEW: Native Custom Perspective Access! Enhanced MCP server with OmniFocus custom perspective support, hierarchical task display, AI-optimized tool selection, and comprehensive task management

77 lines (76 loc) 3.81 kB
import { executeOmniFocusScript } from '../../utils/scriptExecution.js'; export async function getFlaggedTasks(options = {}) { const { hideCompleted = true, projectFilter } = options; try { // Execute the flagged tasks script const result = await executeOmniFocusScript('@flaggedTasks.js', { hideCompleted: hideCompleted, projectFilter: projectFilter }); if (typeof result === 'string') { return result; } // If result is an object, format it if (result && typeof result === 'object') { const data = result; if (data.error) { throw new Error(data.error); } // Format the flagged tasks let output = `# 🚩 FLAGGED TASKS\n\n`; if (projectFilter) { output = `# 🚩 FLAGGED TASKS - Project: ${projectFilter}\n\n`; } if (data.tasks && Array.isArray(data.tasks)) { if (data.tasks.length === 0) { output += projectFilter ? `No flagged tasks found in project "${projectFilter}"\n` : "🎉 No flagged tasks - nice and clean!\n"; } else { const taskCount = data.tasks.length; output += `Found ${taskCount} flagged task${taskCount === 1 ? '' : 's'}:\n\n`; // Group tasks by project for better organization const tasksByProject = new Map(); data.tasks.forEach((task) => { const projectName = task.projectName || '📥 Inbox'; if (!tasksByProject.has(projectName)) { tasksByProject.set(projectName, []); } tasksByProject.get(projectName).push(task); }); // Display tasks grouped by project tasksByProject.forEach((tasks, projectName) => { if (tasksByProject.size > 1) { output += `## 📁 ${projectName}\n`; } tasks.forEach((task, index) => { const dueDateStr = task.dueDate ? ` [DUE: ${new Date(task.dueDate).toLocaleDateString()}]` : ''; const deferDateStr = task.deferDate ? ` [DEFER: ${new Date(task.deferDate).toLocaleDateString()}]` : ''; const statusStr = task.taskStatus !== 'Available' ? ` (${task.taskStatus})` : ''; const estimateStr = task.estimatedMinutes ? ` ⏱${task.estimatedMinutes}m` : ''; output += `• 🚩 ${task.name}${dueDateStr}${deferDateStr}${statusStr}${estimateStr}\n`; if (task.note && task.note.trim()) { output += ` 📝 ${task.note.trim()}\n`; } if (task.tags && task.tags.length > 0) { const tagNames = task.tags.map((tag) => tag.name).join(', '); output += ` 🏷 ${tagNames}\n`; } output += '\n'; }); }); } } else { output += "No flagged tasks data available\n"; } return output; } return "Unexpected result format from OmniFocus"; } catch (error) { console.error("Error in getFlaggedTasks:", error); throw new Error(`Failed to get flagged tasks: ${error instanceof Error ? error.message : 'Unknown error'}`); } }