validate_pattern_runtime
Validate Strudel music patterns by checking for runtime errors during execution, ensuring code runs correctly before live performance.
Instructions
Validate pattern with runtime error checking (monitors Strudel console for errors)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Pattern code to validate | |
| waitMs | No | How long to wait for errors (default 500ms) |
Implementation Reference
- src/StrudelController.ts:606-642 (handler)Main handler function that executes the runtime pattern validation by writing the pattern to the editor, briefly playing it to trigger evaluation, capturing console errors and warnings from Strudel.async validatePatternRuntime(pattern: string, waitMs: number = 500): Promise<{ valid: boolean; errors: string[]; warnings: string[]; }> { if (!this._page) { throw new Error('Browser not initialized. Run init tool first.'); } // Clear previous errors this.clearConsoleMessages(); // Write pattern await this.writePattern(pattern); // Brief play to trigger evaluation - Strudel uses lazy evaluation // so errors only appear when the pattern is actually executed try { await this._page.keyboard.press('ControlOrMeta+Enter'); await this._page.waitForTimeout(Math.min(waitMs, 300)); await this._page.keyboard.press('ControlOrMeta+Period'); } catch (e) { this.logger.warn('Failed to trigger pattern evaluation', e); } // Wait for potential errors to appear await this._page.waitForTimeout(waitMs); const errors = this.getConsoleErrors(); const warnings = this.getConsoleWarnings(); return { valid: errors.length === 0, errors, warnings }; }
- src/server/EnhancedMCPServerFixed.ts:292-302 (registration)Tool registration in the getTools() array, including name, description, and input schema definition.name: 'validate_pattern_runtime', description: 'Validate pattern with runtime error checking (monitors Strudel console for errors)', inputSchema: { type: 'object', properties: { pattern: { type: 'string', description: 'Pattern code to validate' }, waitMs: { type: 'number', description: 'How long to wait for errors (default 500ms)' } }, required: ['pattern'] } },
- Tool dispatch handler in the executeTool switch statement that calls the controller's validatePatternRuntime method and formats the response.case 'validate_pattern_runtime': if (!this.isInitialized) { return 'Browser not initialized. Run init first.'; } InputValidator.validateStringLength(args.pattern, 'pattern', 10000, false); const validation = await this.controller.validatePatternRuntime( args.pattern, args.waitMs || 500 ); if (validation.valid) { return `✅ Pattern valid - no runtime errors detected`; } else { return `❌ Pattern has runtime errors:\n${validation.errors.join('\n')}\n` + (validation.warnings.length > 0 ? `\nWarnings:\n${validation.warnings.join('\n')}` : ''); }