feat(sdk): implement write_token operation in sdk/core#978
Merged
Conversation
🦋 Changeset detectedLatest 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 |
Contributor
Run report for f4e36b4eTotal time: 1m 55s | Comparison time: 5m 27s | Estimated savings: 3m 31s (64.6% faster)
Touched files |
- 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>
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
write_tokenoperation insdk/core, closing #976. This is a prerequisite for TUI RFC #973 M4 (the wizard write path).What's new:
sdk/core/src/write.rs— newwrite_tokenfunction: validates a token fragment against its$schema, merges it into a legacy JSON file (preserving existing key order), and records rationale inproduct-context.jsonper the agent-capture-behavior spec.sdk/cli— newwrite-tokensubcommand that exposes the operation. Auto-discovers the schemas directory by walking up from the target file path.serde_jsonpreserve_orderfeature enabled insdk/coreso 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_tokenandsuggest_token. The TUI wizard's Screen 4 confirm step callswrite_tokento persist the authored token to the product-layer file and capture rationale inproduct-context.json. Without this, M4 of the TUI cannot ship.How Has This Been Tested?
7 unit tests in
sdk/core/src/write.rscovering:product-context.jsonwithextensions.tokens[]entry for net-new tokensoverrides[]entry for override tokens$schemaURL$schemafieldFull test run:
cargo test -p design-data-core -p design-data-cli— 371 core + 13 CLI tests pass.Types of changes
Checklist: