Repository navigation
feat: canonical flow text and per-node notes - #52
Merged
Merged
Conversation
The document is now the whole truth, so editing is parse, change the model, serialize, in either language (docs/01-canonical-document.md). - Schema: optional `note` on the flow and every node kind (v1, v2). - Rust: maps are `IndexMap` (author order kept); `Flow::to_yaml` writes the canonical text; `edit::load` / `load_draft` refuse unknown fields and unsupported versions and return the comments a save drops; `is_generated_clip_ref`, `is_local_audio_ref`, `prompt_fields`. - TS: `serializeFlow`; `note` decoded; comments reported as `comment_ignored`; `mutate.ts` ops rebuilt on the model, refusing `invalid_document`, `unknown_field` and `unsupported_version`. - `conformance/canonical/`: both languages write the same bytes. API changes: `Flow::to_yaml` returns `String`; generated maps and `Node::exits()` are `IndexMap`; nodes gain `note`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNFHhzw4ZsqCFnv6ERigjd
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GNFHhzw4ZsqCFnv6ERigjd
wavekat-eason
added this pull request to stack #53
October 17, 2026 11:19
libyaml refuses a ':' inside a plain scalar in flow style, so the Rust reader could not load a canonical text that had one (for example 'Ext 5:30' in options). Both emitters now quote it. The scalars case pins it.
findComments counted the yaml lexer's control tokens in its offsets, so ranges drifted by one per scalar. It now skips them. Rust comments() now skips a leading BOM and finds a comment right after a closing quote, as the TS side does. Adds a range test, edge-case tests and unknown-field tests for hours.
A newer document has fields this build does not know. Rust edit::load already answers with the version error first; mutate.ts now does too.
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.
Summary
This implements
docs/01-canonical-document.md(#51; this PR is stacked on it). The flow document is the whole truth, so any tool, in either language and offline, edits by parse → change the model → serialize.Schema
noteon the flow (afterversion) and on every node kind (afterkind), in v1 and v2. This is a compatible addition: nodes already allow unknown fields, the engine ignoresnote, and no frozen case changes.Rust (
wavekat-flow)indexmap::IndexMap(typifywith_map_type), so node, exit and option order survive.serde_jsonhaspreserve_orderforui. The crate re-exportsindexmap.Flow::to_yaml()writes the canonical text, using a hand-written emitter guided by the bundled schema: property order, required fields and defaults all come from the schema.edit::load(src)/edit::load_draft(src, Missing { id, name }):uistays opaque) and unsupportedschema_versions;load_draftfills a new draft's missingid/namefirst.is_generated_clip_ref(twin ofisGeneratedClipRef),is_local_audio_ref,prompt_fields(kind)/PROMPT_FIELDS, andNode::prompt_slots()/prompt_slots_mut()(each prompt with its field name, so a tool can voice or swap prompts in place).TS (
@wavekat/flow-schema)serializeFlow(flow): the twin emitter, guided by the same schema.parseFlow: decodesnote, and reports each comment as acomment_ignoredwarning, found with theyamllibrary's own lexer.findComments(source)is exported, and itsrangeis a true source offset.mutate.ts: same API, rebuilt on the model.EditErrors:invalid_document(doesn't decode; validation-only problems are still editable),unknown_fieldandunsupported_version.stampIdentitysetsid/name/versionon a draft that lacks them, then goes through the model like every other op.Fixed in review
findCommentscounted the lexer's control tokens, sorange(and thecomment_ignoredrange) was off by one per scalar before it. It now skips them. A test checkssource.slice(range)starts with#."x"# c, as the TS side does. Lines already agreed.Ext 5:30was written plain inside{ ... }, and libyaml (the Rust reader) refuses that. Both emitters now quote:in flow style. The doc rule and the scalars case are updated.mutate.tsnow answersunsupported_versionbeforeunknown_field, likeedit::load.edit::load, comment edge cases, version precedence.ui). They were byte-identical, and each text re-read to itself.Known gap
ui(for example1e20) is written in digits, as JavaScript does. The Rust reader can't read an integer that big back. Nothing in the format uses one, so I left it.Corpus
conformance/canonical/: 5 cases (defaults, order, scalars, ui, comments). Both languages must write exactly the canonical bytes, reach a fixed point, and agree on the comment count.Breaking API (0.0.x)
Flow::to_yaml()now returnsString, notResult.Node::exits()areIndexMap, notHashMap.get/iter/valueswork the same.note: Option<String>field. Code that buildsNodevalues directly addsnote: None.mutate.tsoutput drops comments, and its ops refuse documents that don't decode.This stays
feat:, notfeat!. We're pre-1.0, and the CLI and voice PRs pin crate0.0.11while the platform pins npm^0.0.14. Withbump-minor-pre-major, afeat!would make release-please jump to0.1.0and break those pins. Asfeat:it gives crate0.0.10→0.0.11and npm0.0.13→0.0.14.Consumers
These are the draft PRs against this branch, listed in the doc's Consumers section:
notefield);Test plan
cargo fmt --check,cargo clippy --all-targets -D warnings,cargo test -p wavekat-flow(77 unit + corpus),cargo package.pnpm typecheck,vitest(188 tests),pnpm build.#inside quotes, block scalars andC#are not comments).mutatesuite updated for the intended changes. New tests cover the refusals and stamping a draft that has no id.🤖 Generated with Claude Code
https://claude.ai/code/session_01GNFHhzw4ZsqCFnv6ERigjd