[tools] Add optimize_style_tool for style optimization #54
+1,044
−0
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