You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
cue-gen: generate Go from the design grammar with charly's own CUE-API generator, retiring gengotypes and the hand mirrors #271
category:runtimeThe host/framework, loader/provider registration, or a cross-cutting contract.type:designA design-contract amendment that is the primary deliverable.
cue-gen builds Go types with cue exp gengotypes and a regex retag pass (internal/schemaretag). gengotypes cannot express the shapes the design schema is written in:
a key-tagged union becomes map[string]any;
an enum becomes a bare string, with no constants;
a {[#Name]: T} collection becomes an empty struct, so the data is lost;
a definition reached through a comprehension becomes an anonymous struct.
That is why about 11k lines in spec/spec mirror CUE by hand: union_types.go, the *_consts.go enums, charly_methods.go, the op strings, and the untyped params_json/result_json payloads. DESIGN.md forbids this (D-SCH-1, D-GEN-1/3/4).
DESIGN.md §6 now gives every schema shape exactly one Go mapping (C1–C7) and makes the generator charly's own, built on the CUE Go API at the pinned CUE version (D-GEN-7). Each shape has one spelling (D-GEN-8), and the design check enforces it.
Vocabulary tables: a typed word plus Valid(); a core or plugin-owned table also gets its constants.
Tag tables: a one-of struct with an exactly-one decoder.
Method tables: per-role interfaces, typed clients and servers, the request and reply one-ofs, and streams.
Derived shapes: generated from the table rows, never read back from an evaluated comprehension.
Feasibility, measured
A throw-away spike on cuelang.org/go v0.18.0-rc.1 read DESIGN.cue-shaped CUE through cue/load and the syntax tree. It emitted a Phase enum with constants and Valid(), a homogeneous Source one-of with Tag(), and KindRole/VerbRole interfaces with a stream parameter for log. The output passed go vet and go build.
Three findings the generator must honour:
A hidden table needs a package-qualified selector (cue.Hid(name, inst.ID())).
A reference's name does not survive a comprehension, so each derived shape is generated from its rows.
A payload named #X<Tag> collides with a generated arm struct of the same name. Homogeneous unions therefore map arms to their tag's value type (no arm structs), and heterogeneous unions generate X<Tag> arm structs.
Scope
Extend internal/schemagen along the lines internal/wiregen already follows.
Delete schemaretag and the hand mirrors it replaces.
Gate on a byte-for-byte regeneration, as TestGenReproducible does today.
This lands after the schema in spec/schema moves to the grammar. It is not part of #619, which changes DESIGN.* and design/ only.
Agent: design-grammar Assisted-by: Claude Code Claude Opus 5.5 (analysed on a live system)
Direction 1 (the in-process generator for params) landed in #299 (head 47738b7067571a475f304f9072a29d1470dc6c01). The cue exp gengotypes shell-out is gone: params are generated by charly's own CUE-API generator over the same offline module resolution schemacompose uses, and an imported definition is emitted through the Go package that owns it.
This does not close the issue. Still ahead from the scope here: the grammar-table mapping (vocabulary tables with Valid(), tag tables, method tables, derived shapes), the retirement of schemaretag and the hand-written mirrors, and the byte-for-byte gate over that new output. Next update when #299 merges.
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
#299 merged (squash 9428017f5b182ccfd3f87efd92a3456b7158a797, tag v0.2026313.1428): Direction 1 landed. Params are now generated in-process by charly's CUE-API generator over the offline compose, and the cue exp gengotypes shell-out is gone.
This issue stays open for the grammar-table mapping, the derived shapes, and the retirement of schemaretag and the hand mirrors.
Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
Measured: the pattern-keyed map collapse is silent, and one shape survives
Found while porting DESIGN.cue's §8 capability surface into schema/capability.cue (the first place in the shipped schema that carries a {[<pattern>]: T} collection at all — grep -rn '\[#[A-Za-z]*\]:' schema/*.cue matched nothing before it).
Isolated, cue exp gengotypes on this module's pinned CUE (v0.16.1):
$ cue exp gengotypes .
$ cat cue_types_p_gen.gotype Word stringtype A struct {}type B struct {}type C struct {}type D map[string]int64type E struct { Foo struct { } `json:"foo,omitempty"`}
So: only [string] survives. A regex key (#Word, #Name, #EnvName) and a literal-disjunction key (or(_gpuWord)) both collapse the whole collection to struct{} — silently, with rc 0, no warning, and no difference between "collection of records" and "no data at all".
Why this blocks the capability surface
#Need/#Use/#Provide are exactly this shape ({[#EnvName]: {}}, {[or(_gpuWord)]: {}}, {[#Name]: #CountNeed}, …). On branch feat/capability-port the generated spec.Need/spec.Use/spec.Provide therefore carry the 21 type keys correctly (pinned by TestTheNeedUseProvideAreDerivedFromTheTable) but every per-type collection is struct{}:
typeNeedstruct {
Envstruct { // ← `{[#EnvName]: {}}`, the map is gone
} `yaml:"env,omitempty" json:"env,omitempty"`...Cpustruct { // ← `{[or(_cpuWord)]: {count!}}`, `count` is gone
} `yaml:"cpu,omitempty" json:"cpu,omitempty"`
A caller can express that it needs cpu, never what it needs — which is the whole contract. Five consuming units (D-CAP-*/D-HW-* wiring, the candy need:/use: migration, the solver) read these structs, so the port is blocked on this issue rather than worked around: flattening the keys to [string] would make the generator's gap permanent in the contract.
What the fix has to generate
Per C5/C7's own rule, a {[<pattern>]: T} is a map whose key type is the pattern's Valid()-checked word (type EnvName string already generates) and whose value type is T — i.e. map[EnvName]struct{…} for env, map[string]CandyNeedEntry-shaped values for the parameter rows. The key's regex must not defeat the map: validation belongs in the key type's Valid(), which is the same place every other vocabulary already puts it.
The two other findings this port produced (the S3 gate's shape assumptions, and three generic _-names already spent on vendor detail elsewhere) are separate and are being handled on their own tracks.
category:runtimeThe host/framework, loader/provider registration, or a cross-cutting contract.type:designA design-contract amendment that is the primary deliverable.
Activity
aitrawog commentedon Nov 9, 2026
STATUS
Direction 1 (the in-process generator for params) landed in #299 (head
47738b7067571a475f304f9072a29d1470dc6c01). Thecue exp gengotypesshell-out is gone: params are generated by charly's own CUE-API generator over the same offline module resolutionschemacomposeuses, and an imported definition is emitted through the Go package that owns it.This does not close the issue. Still ahead from the scope here: the grammar-table mapping (vocabulary tables with
Valid(), tag tables, method tables, derived shapes), the retirement ofschemaretagand the hand-written mirrors, and the byte-for-byte gate over that new output. Next update when #299 merges.Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
feat(schemaparams): generate params in-process over the offline compo…
aitrawog commentedon Nov 9, 2026
STATUS
#299 merged (squash
9428017f5b182ccfd3f87efd92a3456b7158a797, tagv0.2026313.1428): Direction 1 landed. Params are now generated in-process by charly's CUE-API generator over the offline compose, and thecue exp gengotypesshell-out is gone.This issue stays open for the grammar-table mapping, the derived shapes, and the retirement of
schemaretagand the hand mirrors.Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)
aitrawog commentedon Nov 17, 2026
Measured: the pattern-keyed map collapse is silent, and one shape survives
Found while porting DESIGN.cue's §8 capability surface into
schema/capability.cue(the first place in the shipped schema that carries a{[<pattern>]: T}collection at all —grep -rn '\[#[A-Za-z]*\]:' schema/*.cuematched nothing before it).Isolated,
cue exp gengotypeson this module's pinned CUE (v0.16.1):So: only
[string]survives. A regex key (#Word,#Name,#EnvName) and a literal-disjunction key (or(_gpuWord)) both collapse the whole collection tostruct{}— silently, with rc 0, no warning, and no difference between "collection of records" and "no data at all".Why this blocks the capability surface
#Need/#Use/#Provideare exactly this shape ({[#EnvName]: {}},{[or(_gpuWord)]: {}},{[#Name]: #CountNeed}, …). On branchfeat/capability-portthe generatedspec.Need/spec.Use/spec.Providetherefore carry the 21 type keys correctly (pinned byTestTheNeedUseProvideAreDerivedFromTheTable) but every per-type collection isstruct{}:A caller can express that it needs cpu, never what it needs — which is the whole contract. Five consuming units (
D-CAP-*/D-HW-*wiring, the candyneed:/use:migration, the solver) read these structs, so the port is blocked on this issue rather than worked around: flattening the keys to[string]would make the generator's gap permanent in the contract.What the fix has to generate
Per C5/C7's own rule, a
{[<pattern>]: T}is a map whose key type is the pattern'sValid()-checked word (type EnvName stringalready generates) and whose value type isT— i.e.map[EnvName]struct{…}forenv,map[string]CandyNeedEntry-shaped values for the parameter rows. The key's regex must not defeat the map: validation belongs in the key type'sValid(), which is the same place every other vocabulary already puts it.The two other findings this port produced (the S3 gate's shape assumptions, and three generic
_-names already spent on vendor detail elsewhere) are separate and are being handled on their own tracks.Agent: audit-protocol
Assisted-by: DeepSeek Harness ollama-cloud/deepseek-v4.1-flash (syntax check only)
fix(schema,schemagen): the leasable need entry keeps its payload
fix(schemagen): emit a map for a pattern-keyed collection (#360)