Skip to content

feat(sdk): implement suggest_token operation in sdk/core#979

Merged
GarthDB merged 4 commits into
mainfrom
feat/suggest-token
May 19, 2026
Merged

feat(sdk): implement suggest_token operation in sdk/core#979
GarthDB merged 4 commits into
mainfrom
feat/suggest-token

Conversation

@GarthDB
Copy link
Copy Markdown
Member

@GarthDB GarthDB commented May 19, 2026

Description

Implements the suggest_token operation in sdk/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.rssuggest() 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 optional property_hint filter hard-excludes tokens whose name.property doesn't match.
  • sdk/cli — new suggest subcommand: 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. Without suggest_token, the wizard falls back to a raw query_tokens expression — 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:

  • Empty intent returns nothing
  • Matching token ranks above unrelated token
  • Property hint filters correctly
  • Limit is respected
  • UUID and value are carried through
  • Zero-confidence tokens are excluded

Smoke test against real Spectrum tokens: design-data suggest "accent background color" packages/tokens/src --limit 3 returns accent-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

  • New feature (non-breaking change which adds functionality)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

Adds the suggest_token operation deferred from Phase 8 epic #830.
Prerequisite for TUI RFC #973 Screen 1 "reuse first" wizard banner.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 19, 2026

🦋 Changeset detected

Latest 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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 19, 2026

Run report for 39be00dd

Total time: 1m 51s | Comparison time: 5m 1s | Estimated savings: 3m 9s (63.0% faster)

Action Time Status Info
⬛️ SetupProto(0.51.4) 0.1ms Skipped
🟩 SyncWorkspace 7ms Passed
🟩 SyncProject(sdk) 0.4ms Passed
🟩 SyncProject(tokens) 0.5ms Passed
⬛️ SetupToolchain(node:20.17.0) 1.8s Skipped
🟩 SetupToolchain(rust:1.85.0) 15.3s Passed
🟩 InstallWorkspaceDeps(rust:1.85.0, sdk) 1s Passed
🟩 InstallProjectDeps(node:20.17.0, sdk) 16.7s Passed
🟩 RunTask(sdk:codegen-check) 188.2ms Passed
🟩 InstallWorkspaceDeps(node:20.17.0) 17.2s Passed
🟩 RunTask(sdk:lint) 36.7s Passed
🟩 RunTask(tokens:buildTokens) 1m 13s Passed
🟩 RunTask(sdk:build) 1m 18s Passed
🟩 RunTask(tokens:verifyLegacyRoundtrip) 2.2s Passed
🟩 RunTask(tokens:validateDesignData) 2.2s Passed
🟩 RunTask(tokens:verifyDesignDataSnapshot) 2.7s Passed
🟩 RunTask(tokens:test) 4.6s Passed
🟩 RunTask(sdk:test) 1m 32s Passed
Touched files
.changeset/suggest-token-operation.md
sdk/cli/src/main.rs
sdk/core/src/graph.rs
sdk/core/src/lib.rs
sdk/core/src/suggest.rs

GarthDB added a commit that referenced this pull request May 19, 2026
- **docs/rfc-coordination.md**: update #973 row status to reflect
  write_token (#976/#978) and suggest_token (#975/#979) closed;
  mark Q5 theming resolved — terminal-native default, --theme spectrum opt-in.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GarthDB and others added 3 commits May 19, 2026 14:50
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>
@GarthDB GarthDB merged commit 6a122bc into main May 19, 2026
5 checks passed
@GarthDB GarthDB deleted the feat/suggest-token branch May 19, 2026 21:21
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.

feat(sdk): implement suggest_token operation (Phase 8 follow-up)

1 participant