compare_patterns
Compare two music patterns to identify differences in their structure and composition for analysis and refinement.
Instructions
Compare two patterns from history showing differences
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id1 | Yes | First pattern ID | |
| id2 | No | Second pattern ID (default: current pattern) |
Implementation Reference
- Handler function for compare_patterns tool in executeTool switch statement. Finds patterns from history by ID, gets current or second pattern, generates diff and summary using helper methods.case 'compare_patterns': const entry1 = this.historyStack.find(e => e.id === args.id1); if (!entry1) { return `History entry #${args.id1} not found.`; } let pattern2: string; let label2: string; if (args.id2) { const entry2 = this.historyStack.find(e => e.id === args.id2); if (!entry2) { return `History entry #${args.id2} not found.`; } pattern2 = entry2.pattern; label2 = `#${args.id2}`; } else { pattern2 = await this.getCurrentPatternSafe(); label2 = 'current'; } const diff = this.generateDiff(entry1.pattern, pattern2); return { pattern1: { id: args.id1, chars: entry1.pattern.length }, pattern2: { id: label2, chars: pattern2.length }, diff: diff, summary: this.summarizeDiff(entry1.pattern, pattern2) };
- src/server/EnhancedMCPServerFixed.ts:430-441 (registration)Tool registration in getTools() method, including name, description, and input schema.{ name: 'compare_patterns', description: 'Compare two patterns from history showing differences', inputSchema: { type: 'object', properties: { id1: { type: 'number', description: 'First pattern ID' }, id2: { type: 'number', description: 'Second pattern ID (default: current pattern)' } }, required: ['id1'] } },
- Helper method to generate line-by-line diff between two patterns, used by compare_patterns handler.private generateDiff(pattern1: string, pattern2: string): string[] { const lines1 = pattern1.split('\n'); const lines2 = pattern2.split('\n'); const diff: string[] = []; const maxLines = Math.max(lines1.length, lines2.length); for (let i = 0; i < maxLines; i++) { const line1 = lines1[i] || ''; const line2 = lines2[i] || ''; if (line1 === line2) { diff.push(` ${line1}`); } else { if (line1) diff.push(`- ${line1}`); if (line2) diff.push(`+ ${line2}`); } } return diff; }
- Helper method to summarize differences (lines added/removed/changed, char diff) between two patterns, used by compare_patterns handler.private summarizeDiff(pattern1: string, pattern2: string): { linesAdded: number; linesRemoved: number; linesChanged: number; charsDiff: number; } { const lines1 = pattern1.split('\n'); const lines2 = pattern2.split('\n'); let linesAdded = 0; let linesRemoved = 0; let linesChanged = 0; const maxLines = Math.max(lines1.length, lines2.length); for (let i = 0; i < maxLines; i++) { const line1 = lines1[i]; const line2 = lines2[i]; if (line1 === undefined && line2 !== undefined) { linesAdded++; } else if (line1 !== undefined && line2 === undefined) { linesRemoved++; } else if (line1 !== line2) { linesChanged++; } } return { linesAdded, linesRemoved, linesChanged, charsDiff: pattern2.length - pattern1.length }; }