feat(sdk): implement suggest_token operation in sdk/core#979
Merged
Conversation
🦋 Changeset detectedLatest commit: 39be00d The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Run report for 39be00ddTotal time: 1m 51s | Comparison time: 5m 1s | Estimated savings: 3m 9s (63.0% faster)
Touched files |
Clippy denied .clone() on Layer because it implements Copy. Use direct copy (no method call needed). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- **suggest.rs**: drop `|| hint.contains(property)` from `property_matches`
— the inverse direction caused broad hints (e.g. "background-color") to
pass tokens with `property: "color"`, producing false positives.
- **suggest.rs**: exclude name-object field *keys* from the word bag; only
field *values* carry semantic signal. Schema vocab ("property", "colorFamily",
"variant") inflated every token's bag identically and reduced discrimination.
- **suggest.rs**: replace `.leak()` in the limit test with a local `Vec<String>`
arena so keys live long enough without permanent allocation.
- **graph.rs**: derive `serde::Serialize` on `Layer` with `rename_all =
"lowercase"` so the enum serializes cleanly; drop the `format!("{:?}",
…).to_lowercase()` hack from the CLI JSON output path.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Description
Implements the
suggest_tokenoperation insdk/core, closing #975. This is a prerequisite for the TUI RFC #973 wizard Screen 1 "reuse first" banner.What's new:
sdk/core/src/suggest.rs—suggest()function: scores every token in the graph against a natural-language intent string using Jaccard similarity over key segments and name-object field values. An optionalproperty_hintfilter hard-excludes tokens whosename.propertydoesn't match.sdk/cli— newsuggestsubcommand:design-data suggest "accent background" --property color --limit 5.Related Issue
Closes #975
Part of TUI RFC #973 (Screen 1 "reuse first" wizard banner)
Motivation and Context
Phase 8 (#830) deferred
suggest_token. The TUI wizard's Screen 1 asks "does an existing token already cover your intent?" before the designer creates a new one. Withoutsuggest_token, the wizard falls back to a rawquery_tokensexpression — functional, but missing the confidence-ranked UX.The ranking uses Jaccard similarity (word overlap) — no external NLP dependency, fast against Spectrum-scale datasets, and calibratable against real data once the threshold question from RFC §6 is revisited at M3.
How Has This Been Tested?
6 unit tests in
sdk/core/src/suggest.rs:Smoke test against real Spectrum tokens:
design-data suggest "accent background color" packages/tokens/src --limit 3returnsaccent-background-color-{default,down,hover}at 0.75 confidence.Full test run:
cargo test -p design-data-core -p design-data-cli— 370 core + 13 CLI tests pass.Types of changes
Checklist: