feat(layout): Option A shape grammar — seg/h/v terse bijective node arms (2de.15)#107
Merged
Merged
Conversation
…rms (2de.15)
Adds three new spellings to the root node grammar, all purely ADDITIVE (the
canonical {kind:"container"/"segment"} form remains accepted unchanged):
Node :=
| "name" // bare string → segment ref
| { seg: "name", when? } // segment ref + optional predicate
| { h: [Node, …], when? } // horizontal container
| { v: [Node, …], when? } // vertical container
[LAW:types-are-the-program] BIJECTIVE: every legal canonical tree has exactly
one A-grammar spelling; no illegal node is representable. The "exactly one of
seg/h/v" invariant is enforced at dispatch (key-count check → loud error) so
a two-key object is a load error, not a silently-accepted edge case.
[LAW:one-source-of-truth] Lowering happens at validateRoot (the single
existing lowering boundary) via a const-before-object-dispatch ordering, so
nothing downstream ever sees a seg/h/v node — only container|segment.
[LAW:composability] Group sugar (2de.4) children already recurse through
validateRoot, so they accept A-grammar for free with no code change.
Implementation: new RecordSchemas (SEG_ARM_SCHEMA, H_ARM_SCHEMA, V_ARM_SCHEMA)
using the existing childrenSpec + optionalStringSpec primitives; the exactly-
one-key guard runs before the unknown-kind fallthrough; layoutNodeJson() adds
the new arms plus {type:"string"} to the anyOf. Schema regenerated.
Tests: bijectivity round-trip (A-grammar == canonical tree), all node forms
(bare string / seg / h / v / when on each), nested h-in-v-in-h, A-grammar
inside group children, both-keys reject, bare-empty-string reject — both
schema-parity and loader-contract layers.
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
Adds the Option A shape grammar to the root node validator — three terse bijective spellings of the canonical
container|segmenttree, purely additive (the verbose{kind:"container"/"segment"}form remains accepted unchanged):Bijective: every legal canonical tree has exactly one A-grammar spelling; no illegal node is representable. A two-key object (
{h:[…], v:[…]}) is a loud load error.Lowering at the single boundary:
validateRootalready is the one place the root grammar becomes acontainer|segmenttree — the new arms lower there, so nothing downstream seesseg/h/v.Group sugar composes for free: group children already recurse through
validateRoot— no code change needed, pinned by a test.Changes
src/config/loader/layout.ts— bare-string arm +SEG_ARM_SCHEMA/H_ARM_SCHEMA/V_ARM_SCHEMA+ exactly-one-key dispatch guard + updated error messages +layoutNodeJson()extendedschema/cc-candybar.schema.json— regenerated viapnpm gen:schematest/dsl-loader.test.ts— bijectivity round-trip, all node forms, nesting, group-children compose, bad-arm errorstest/config-schema.test.ts— schema-parity GOOD/BAD casesTest plan
pnpm typecheck— cleanpnpm lint— clean (1 pre-existingrequireStringSpecunused-import warning)pnpm check:schema— committed schema matches loaderpnpm test— 1195 passing (2 pre-existing flaky daemon-contention failures, pass in isolation)