Skip to content

feat(sdk): implement write_token operation in sdk/core#978

Merged
GarthDB merged 5 commits into
mainfrom
feat/write-token
May 19, 2026
Merged

feat(sdk): implement write_token operation in sdk/core#978
GarthDB merged 5 commits into
mainfrom
feat/write-token

Conversation

@GarthDB
Copy link
Copy Markdown
Member

@GarthDB GarthDB commented May 19, 2026

Description

Implements the write_token operation in sdk/core, closing #976. This is a prerequisite for TUI RFC #973 M4 (the wizard write path).

What's new:

  • sdk/core/src/write.rs — new write_token function: validates a token fragment against its $schema, merges it into a legacy JSON file (preserving existing key order), and records rationale in product-context.json per the agent-capture-behavior spec.
  • sdk/cli — new write-token subcommand that exposes the operation. Auto-discovers the schemas directory by walking up from the target file path.
  • serde_json preserve_order feature enabled in sdk/core so merged files maintain their original key order.

Related Issue

Closes #976
Part of TUI RFC #973 (gates M4 — wizard write path)

Motivation and Context

Phase 8 epic (#830) shipped the agent-readable surface (primer, component, resolve, query, validate, diff) but deferred write_token and suggest_token. The TUI wizard's Screen 4 confirm step calls write_token to persist the authored token to the product-layer file and capture rationale in product-context.json. Without this, M4 of the TUI cannot ship.

How Has This Been Tested?

7 unit tests in sdk/core/src/write.rs covering:

  • Creates new file when target doesn't exist
  • Merges into existing file without clobbering other keys
  • Injects rationale into the token object
  • Creates product-context.json with extensions.tokens[] entry for net-new tokens
  • Records overrides[] entry for override tokens
  • Errors on unknown $schema URL
  • Errors on missing $schema field

Full test run: cargo test -p design-data-core -p design-data-cli — 371 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 write_token operation deferred from Phase 8 epic #830.
Prerequisite for TUI RFC #973 M4 (wizard write path).

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: f4e36b4

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 f4e36b4e

Total time: 1m 55s | Comparison time: 5m 27s | Estimated savings: 3m 31s (64.6% faster)

Action Time Status Info
⬛️ SetupProto(0.51.4) 0ms Skipped
🟩 SyncWorkspace 10.8ms Passed
🟩 SyncProject(sdk) 0.5ms Passed
🟩 SyncProject(tokens) 0.5ms Passed
⬛️ SetupToolchain(node:20.17.0) 2s Skipped
🟩 SetupToolchain(rust:1.85.0) 15.1s Passed
🟩 InstallWorkspaceDeps(rust:1.85.0, sdk) 1.2s Passed
🟩 InstallProjectDeps(node:20.17.0, sdk) 17s Passed
🟩 RunTask(sdk:codegen-check) 142.2ms Passed
🟩 InstallWorkspaceDeps(node:20.17.0) 17.4s Passed
🟩 RunTask(sdk:lint) 40.9s Passed
🟩 RunTask(tokens:buildTokens) 1m 25s Passed
🟩 RunTask(sdk:build) 1m 29s Passed
🟩 RunTask(tokens:verifyLegacyRoundtrip) 1.6s Passed
🟩 RunTask(tokens:verifyDesignDataSnapshot) 1.9s Passed
🟩 RunTask(tokens:validateDesignData) 2s Passed
🟩 RunTask(sdk:test) 1m 36s Passed
🟩 RunTask(tokens:test) 5.1s Passed
Touched files
.changeset/write-token-operation.md
sdk/cli/src/main.rs
sdk/core/Cargo.toml
sdk/core/src/lib.rs
sdk/core/src/validate/rules/spec003.rs
sdk/core/src/write.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 4 commits May 19, 2026 12:59
- cli/src/main.rs: group run_write_token args into WriteTokenOpts
  struct to fix too_many_arguments lint (8/7)
- core/src/validate/rules/spec003.rs: rewrite loop as while-let
  to fix while_let_loop lint

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…okens

- **sdk/core/src/write.rs**: drop `WriteTokenResult::warnings` — the field
  was never populated and always returned empty, misleading callers.
  Replace the silent `if let Some(tokens_arr)` drop in the extensions
  upsert path with `ok_or_else` so a non-object `extensions` or
  non-array `extensions.tokens` returns an explicit error instead of
  silently swallowing the write. Add regression test covering the
  previously-silent bad-type case.
- **sdk/cli/src/main.rs**: remove now-dead `result.warnings` loop.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- **write.rs**: destructure `input` early so only `token` is `mut`.
- **write.rs**: extensions upsert now matches overrides — finds existing
  entry by UUID (or name string via `.as_str()`, not `.to_string()`)
  and updates value + rationale in-place instead of silently skipping.
  Adds regression test `write_token_upserts_extension_entry_in_place`.
- **Cargo.toml**: document why `preserve_order` is enabled (IndexMap
  swap is crate-wide; needed for stable key order on write round-trip).
- **main.rs**: import `ArgGroup`; annotate `WriteToken` variant so Clap
  enforces exactly one of `--token-json` / `--token-file` at parse time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@GarthDB GarthDB merged commit dea6b44 into main May 19, 2026
5 checks passed
@GarthDB GarthDB deleted the feat/write-token branch May 19, 2026 20:50
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 write_token operation in sdk/core/ (Phase 8 follow-up)

1 participant