[tools] Add optimize_style_tool for style optimization#54
Merged
Conversation
Implements a comprehensive style optimization tool that reduces Mapbox style file size and improves performance by removing redundancies and simplifying structure. Key features: - Remove unused sources not referenced by any layer - Remove duplicate layers with identical properties - Simplify boolean expressions (["all", true] → true, etc.) - Remove empty layers with no visible properties - Identify layers with identical filters for consolidation The tool extends BaseTool for offline operation (no API calls). Performs deep analysis of style JSON to identify optimization opportunities and tracks all changes with detailed reporting. Optimizations: - remove-unused-sources: Identifies and removes unreferenced sources - remove-duplicate-layers: Detects and removes layers with identical properties (excluding ID) - simplify-expressions: Simplifies boolean logic in filters and paint/layout properties - remove-empty-layers: Removes layers with no paint or layout (preserves background layers) - consolidate-filters: Identifies groups of layers with identical filter expressions Returns optimized style with detailed report including: - List of optimizations applied with counts - Size comparison (original vs optimized in bytes) - Percentage reduction achieved Test coverage: 21 comprehensive test cases covering all optimization types, combined optimizations, size calculations, error handling, and edge cases including already-optimized styles. Documentation: Added comprehensive README documentation with parameters, all optimization types, return value structure, example JSON output, and example prompts. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
mattpodwysocki
added a commit
that referenced
this pull request
Jan 9, 2026
…roduction prompt Adds comprehensive style quality validation capabilities: Skill: - Created mapbox-style-quality skill document (390+ lines) - Pre-production checklist and validation best practices - Guidance on expression validation, GeoJSON validation, and accessibility - Optimization strategies and workflow recommendations - Integration patterns for Git hooks, CI/CD, and code review Prompt: - Created prepare-style-for-production prompt - Orchestrates validation workflow using 5 quality tools: * validate_expression_tool - Validate expressions in filters/paint/layout * validate_geojson_tool - Validate GeoJSON sources * check_color_contrast_tool - WCAG accessibility compliance * optimize_style_tool - Remove redundancies and optimize * compare_styles_tool - Compare versions (implicit in workflow) - Configurable WCAG level (AA/AAA) and optional optimization skip - Generates comprehensive quality report with deployment readiness assessment Testing: - 15 test cases for PrepareStyleForProductionPrompt - All 386 tests passing - Updated prompt registry tests Documentation: - Updated README with new skill listing - Added prompt documentation with usage examples - Cross-referenced skill and prompt Related PRs: - PR #50: validate_geojson_tool - PR #51: validate_expression_tool - PR #52: compare_styles_tool - PR #53: check_color_contrast_tool - PR #54: optimize_style_tool Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Valiunia
approved these changes
Jan 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a comprehensive style optimization tool that reduces Mapbox style file size and improves performance by removing redundancies and simplifying structure.
Key Features
Implementation Details
BaseToolfor offline operation (no API calls required)Optimizations
Remove Unused Sources
Scans all layers to identify which sources are referenced, then removes any sources not in use.
Remove Duplicate Layers
Compares layers excluding their ID to find exact duplicates and removes them.
Simplify Expressions
Simplifies boolean expressions in filters and properties:
["all", true]→true["any", false]→false["!", false]→true["!", true]→falseRemove Empty Layers
Removes layers with no paint or layout properties (background layers are preserved since they're valid even when empty).
Consolidate Filters
Identifies groups of layers with identical filter expressions that could potentially be consolidated.
Testing
All tests passing ✅
Documentation
Added comprehensive README documentation with:
Use Cases
This tool enables:
Related PRs
Completes the offline validation tools initiative:
🤖 Generated with Claude Code