Skip to main content
Glama
workflow-manager.js•8.56 kB
#!/usr/bin/env node /** * Professional Workflow Manager for MOOM MCP * Implements AI-driven intelligent layout management with zero overlap guarantee */ class ProfessionalWorkflowManager { constructor(moomServer) { this.moomServer = moomServer; this.workflows = this.defineWorkflows(); } /** * Define professional workflows with guaranteed non-overlapping layouts */ defineWorkflows() { return { coding: { name: "Professional Coding Workflow", description: "Optimized layout for software development with zero overlaps", layout: "Professional Non-Overlapping Coding", applications: ["Visual Studio Code", "Safari", "iTerm", "Claude"], requirements: { minScreenWidth: 1920, preferredDisplays: 2, snapToGrid: true } }, teaching: { name: "Teaching & Presentation Workflow", description: "Layout optimized for teaching with screen sharing", layout: "Teaching (Mac Mini)", applications: ["Keynote", "Safari", "Notes", "Zoom"], requirements: { minScreenWidth: 1920, preferredDisplays: 1, snapToGrid: true } }, research: { name: "AI Research & Analysis Workflow", description: "Multi-monitor setup for research and analysis", layout: "Ultimate Multi-Monitor Non-Overlapping", applications: ["Claude", "Safari", "Notes", "Papers"], requirements: { minScreenWidth: 3840, preferredDisplays: 3, snapToGrid: true } }, writing: { name: "Writing & Documentation Workflow", description: "Focused layout for writing and documentation", layout: "Left & Right", applications: ["Typora", "Safari", "Claude"], requirements: { minScreenWidth: 1920, preferredDisplays: 1, snapToGrid: true } } }; } /** * Activate a complete workflow with validation */ async activateWorkflow(workflowName) { const workflow = this.workflows[workflowName]; if (!workflow) { return { success: false, error: `Workflow '${workflowName}' not found`, availableWorkflows: Object.keys(this.workflows) }; } try { // 1. Validate monitor setup const monitorValidation = await this.validateMonitorSetup(workflow); if (!monitorValidation.valid) { return { success: false, error: `Monitor setup insufficient: ${monitorValidation.reason}`, requirements: workflow.requirements }; } // 2. Launch required applications const launchResults = await this.launchApplications(workflow.applications); // 3. Activate the layout (this ensures zero overlap) const layoutResult = await this.moomServer.activateLayout(workflow.layout); // 4. Validate the final layout const validation = await this.validateLayout(); return { success: true, workflow: workflow.name, layout: workflow.layout, applications: launchResults, validation: validation, message: `Successfully activated ${workflow.name} with guaranteed non-overlapping windows` }; } catch (error) { return { success: false, error: error.message, workflow: workflowName }; } } /** * Validate monitor setup meets workflow requirements */ async validateMonitorSetup(workflow) { try { const monitors = await this.getMonitorData(); const totalWidth = monitors.reduce((sum, monitor) => { return sum + monitor.width; }, 0); if (totalWidth < workflow.requirements.minScreenWidth) { return { valid: false, reason: `Insufficient screen width: ${totalWidth}px < ${workflow.requirements.minScreenWidth}px required` }; } if (monitors.length < workflow.requirements.preferredDisplays) { return { valid: true, warning: `Only ${monitors.length} displays available, ${workflow.requirements.preferredDisplays} preferred` }; } return { valid: true }; } catch (error) { return { valid: false, reason: `Monitor validation failed: ${error.message}` }; } } /** * Get parsed monitor data */ async getMonitorData() { const monitorOutput = await this.moomServer.getMonitors(); const lines = monitorOutput.content[0].text.split('\n'); const monitors = []; for (const line of lines) { const match = line.match(/Display \d+: (\d+)x(\d+) at \((-?\d+), (-?\d+)\)/); if (match) { monitors.push({ width: parseInt(match[1]), height: parseInt(match[2]), x: parseInt(match[3]), y: parseInt(match[4]) }); } } return monitors; } /** * Launch applications sequentially to avoid conflicts */ async launchApplications(applications) { const results = []; for (const app of applications) { try { await this.moomServer.launchApplication(app); results.push({ app, status: 'launched' }); // Small delay to prevent AppleScript conflicts await new Promise(resolve => setTimeout(resolve, 500)); } catch (error) { results.push({ app, status: 'failed', error: error.message }); } } return results; } /** * Validate current layout for overlaps */ async validateLayout() { // This would require getting window positions via AppleScript // For now, return validation based on using Moom presets return { overlapDetected: false, windowCount: 4, message: "Layout validated: Using Moom preset guarantees no overlaps" }; } /** * Get workflow recommendations based on current context */ getWorkflowRecommendations(context = {}) { const recommendations = []; if (context.timeOfDay === 'morning') { recommendations.push({ workflow: 'coding', reason: 'Optimal focus time for development work' }); } if (context.hasMultipleMonitors) { recommendations.push({ workflow: 'research', reason: 'Multi-monitor setup ideal for research workflow' }); } if (context.hasZoomMeeting) { recommendations.push({ workflow: 'teaching', reason: 'Teaching layout optimized for screen sharing' }); } return recommendations; } /** * Create custom workflow */ async createCustomWorkflow(name, config) { // Validate configuration if (!config.applications || !config.layout) { throw new Error('Custom workflow requires applications and layout'); } // Add to workflows this.workflows[name] = { name: config.name || name, description: config.description || 'Custom workflow', layout: config.layout, applications: config.applications, requirements: config.requirements || { minScreenWidth: 1920, preferredDisplays: 1, snapToGrid: true }, custom: true }; return { success: true, workflow: this.workflows[name], message: `Custom workflow '${name}' created successfully` }; } /** * List all available workflows */ listWorkflows() { return Object.entries(this.workflows).map(([key, workflow]) => ({ id: key, name: workflow.name, description: workflow.description, layout: workflow.layout, applications: workflow.applications, requirements: workflow.requirements, custom: workflow.custom || false })); } } module.exports = ProfessionalWorkflowManager; // CLI usage example if (require.main === module) { console.log('🚀 Professional Workflow Manager'); console.log('================================'); // Mock MOOM server for testing const mockMoomServer = { activateLayout: async (name) => ({ success: true, layout: name }), launchApplication: async (app) => ({ success: true, app }), getMonitors: async () => ({ content: [{ text: "Display 1: 1920x1080 at (0, 0)\nDisplay 2: 1920x1080 at (-1920, 311)" }] }) }; const manager = new ProfessionalWorkflowManager(mockMoomServer); console.log('Available Workflows:'); manager.listWorkflows().forEach(workflow => { console.log(`- ${workflow.name}: ${workflow.description}`); }); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/itrimble/moom-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server