Skip to content

feat(layout): Option A shape grammar — seg/h/v terse bijective node arms (2de.15)#107

Merged
brandon-fryslie merged 1 commit into
mainfrom
brandon-layout-substrate-2de.15
Jun 12, 2026
Merged

feat(layout): Option A shape grammar — seg/h/v terse bijective node arms (2de.15)#107
brandon-fryslie merged 1 commit into
mainfrom
brandon-layout-substrate-2de.15

Conversation

@brandon-fryslie

Copy link
Copy Markdown
Contributor

Summary

Adds the Option A shape grammar to the root node validator — three terse bijective spellings of the canonical container|segment tree, purely additive (the verbose {kind:"container"/"segment"} form remains accepted unchanged):

Node :=
  | "name"                 // bare string  → {kind:"segment", name}
  | { seg: "name", when? } // segment ref + optional predicate
  | { h: [Node, …], when? } // horizontal container
  | { v: [Node, …], when? } // vertical container

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: validateRoot already is the one place the root grammar becomes a container|segment tree — the new arms lower there, so nothing downstream sees seg/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() extended
  • schema/cc-candybar.schema.json — regenerated via pnpm gen:schema
  • test/dsl-loader.test.ts — bijectivity round-trip, all node forms, nesting, group-children compose, bad-arm errors
  • test/config-schema.test.ts — schema-parity GOOD/BAD cases

Test plan

  • pnpm typecheck — clean
  • pnpm lint — clean (1 pre-existing requireStringSpec unused-import warning)
  • pnpm check:schema — committed schema matches loader
  • pnpm test — 1195 passing (2 pre-existing flaky daemon-contention failures, pass in isolation)

…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.
@brandon-fryslie brandon-fryslie merged commit aced980 into main Jun 12, 2026
6 of 7 checks passed
@brandon-fryslie brandon-fryslie deleted the brandon-layout-substrate-2de.15 branch June 12, 2026 09:15
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.

2 participants