Skip to content

feat: add report-audit-token-usage MCP tool#30

Open
poltorak wants to merge 3 commits intomainfrom
feat/audit-token-tool
Open

feat: add report-audit-token-usage MCP tool#30
poltorak wants to merge 3 commits intomainfrom
feat/audit-token-tool

Conversation

@poltorak
Copy link
Copy Markdown
Collaborator

New tool for auditing design token health in consumer style files. Two modes — validate (typo detection with suggestions) and overrides (token re-declaration detection).

Validate mode

  • Checks var() references against the loaded token dataset
  • Suggests corrections for invalid tokens using Levenshtein distance (threshold ≤ 3)
  • Supports multiple token prefixes — derives all distinct prefixes (--semantic-, --ds-, etc.) from the dataset automatically when propertyPrefix is null
  • Optional brand-specific warnings for tokens not available in all brands

Overrides mode

  • Detects token re-declarations via :host, ::ng-deep, class selectors, :root[data-theme]
  • Detects !important on token-consuming declarations
  • Works without token data (detection-only / zero-config mode)
  • Optional classification when token dataset is available: legitimate, component-override, deep-override, important-override, inline-override, scope-violation

Supporting changes

  • styles-ast-utils: ScssPropertyEntry now exposes important: boolean from PostCSS (PostCSS strips !important from decl.value into decl.important)
  • glob-utils: new tests for glob-to-regex conversion
  • token-dataset-loader: minor adjustments for token loading
  • docs: added tool entry in tools.md, clarified propertyPrefix behaviour in architecture-internal-design.md

Files added

Path Purpose
audit-token-usage.tool.ts Main handler, formatter, prefix derivation, persistence
models/schema.ts MCP tool schema definition
models/types.ts Input/output type definitions
utils/validate-mode.ts Validate pipeline — var() extraction, prefix matching, typo suggestions
utils/overrides-mode.ts Overrides pipeline — declaration/consumption scanning
utils/override-classifier.ts Mechanism detection and override classification
utils/edit-distance.ts Levenshtein distance (Wagner-Fischer, O(min(m,n)) space)
index.ts Public API exports

Test coverage

  • audit-token-usage.tool.spec.ts — output structure, summary counts, formatter
  • graceful-degradation.spec.ts — missing config, empty dataset, detection-only mode
  • edit-distance.spec.ts — identity, symmetry, empty string, known distances
  • overrides-mode.spec.ts — mechanism detection, classification, runOverridesMode pipeline
  • validate-mode.spec.ts — prefix filtering, suggestion threshold, invalid token report fields

@poltorak poltorak changed the title ## feat: add report-audit-token-usage MCP tool feat: add report-audit-token-usage MCP tool Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant