Skip to content

schema: the schema becomes a CUE package in a module (the first unit of the concat→package cutover) #294

Closed

Description

@aitrawog

Tracking issue — the concat → CUE-package cutover (first unit: the schema becomes a package)

TODO.md items 2.5, 2.16 and 3.1 all point here, and DESIGN D-SCH-2 / D-SCH-3 require it:
the schema tree must stop being one textual compilation unit and become a real CUE package in a
module. RDD item 0.2 proved the foundation is viable on the pinned CUE v0.18.0-rc.1 (a plugin module
imports a spec package; constraints are enforced through the import; one load.Instances composes
spec + N modules with a registry-derived or() union).

Current state (evidence at origin/main)

  • spec/schema/*.cue — 64 files, 0 carrying a package clause.
  • spec/schemaconcat joins every schema/*.cue body into ONE package-less compilation unit; charly
    core's plugin_loader.go compiles baseBody + "\n" + servedCUE at runtime; internal/schemagen
    prepends package spec + @go(spec) to the concatenation for cue exp gengotypes.
  • schema/_common.cue — the shared definitions — is ignored by CUE (a file whose name starts
    with _ is excluded from a package load) even though the concatenator includes it.

Target

  • cue.mod/module.cue declares github.com/opencharly/spec at a language version the pinned
    v0.18.0-rc.1 binary reads with the SAME semantics the schema relies on today.
  • Every schema/*.cue file carries the one package clause; cue eval ./schema yields the same
    value as the pre-change concatenation.
  • schemaconcat and every consumer keep working unchanged: the dual path is deliberate and its
    removal (charly composing the package through a module import instead of the text splice) is the
    next unit of this cutover.

Units

  1. (this issue's first unit) cue.mod/module.cue, a package clause on every schema file,
    schema/_common.cue renamed so CUE actually loads it, schemaconcat normalizing the clause away
    so the concatenated body stays byte-identical. cue eval ./schema == the pre-change concat.
  2. charly composes github.com/opencharly/spec/schema as a module import; delete the
    baseBody + "\n" + servedCUE text splice and the package-stripping path in schemaconcat.

Activity

  1. self-assigned this
    on Nov 8, 2026
  2. aitrawog commented on Nov 8, 2026

    @aitrawog
    ContributorAuthor

    STATUS — unit 1 is open for review.

    Head 2f0ee09ecfc0abe316f5f11ce3169fd0f41fa965 on feat/cue-module, PR #295.
    schema/*.cue is now one package schema in a module (cue.mod/module.cue); schemaconcat
    strips the clause so the concatenated body is unchanged; the dual path is deliberate and its
    removal is the next unit. cue eval ./schema equals the pre-change concat (719 declarations).
    Next update when the charly/pr-validator verdict lands.

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

  3. aitrawog commented on Nov 8, 2026

    @aitrawog
    ContributorAuthor

    STATUS — unit 1 landed.

    PR #295 merged as 2b39dfeabce670149dd5111dcf382a3af7fa6b54 (squash), tagged
    v0.2026312.2110; CHANGELOG/0.2026312.2110.md was written by tag-on-merge from the PR body.

    Landed: cue.mod/module.cue (module github.com/opencharly/spec, language v0.16.1),
    package schema on all 64 schema/*.cue files, schema/_common.cue → schema/00_common.cue
    (CUE excludes a _-prefixed file from a package load; the 00_ keeps the concatenation's order
    and the generated Go unchanged), and ConcatSchema stripping the clause so every consumer still
    compiles the same package-less body. cue eval ./schema equals the pre-change concatenation
    (719 declarations, same names and values), and a committed dual-path test keeps that true;
    charly task cue-gen and the module's CI gates are green on the merged tree.

    This issue stays open for unit 2: charly composes the schema through a module import (deleting
    the baseBody + "\n" + servedCUE splice and schemaconcat's clause normalization), then the
    umbrella pin bump. Nothing in the umbrella was touched here.

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

  4. aitrawog commented on Nov 9, 2026

    @aitrawog
    ContributorAuthor

    CLAIM — unit 2 of this cutover (the consumer leg): charly composes github.com/opencharly/spec/schema as a module instance, keeping the plugin half as text.

    Measured while starting the consumer leg, and it adds ONE producer-side unit this issue did not name:

    The package source reaches a Go consumer (schema.FS, //go:embed *.cue), but the module that owns it does not. cue.mod/module.cue sits at the module root — outside schema/'s embed tree — so a consumer embedding the schema FS cannot read the one fact it cannot derive: the pinned language.version that governs evaluation. Two workarounds are both wrong: restating the declaration in the consumer is a second home for a declaration only this module may make, and loading the package without its module silently falls back to the consumer's toolchain default.

    So the producer leg is: export the declaration (package specmodule, specmodule.FS carrying cue.mod/module.cue), then the consumer leg composes BOTH embedded trees at one virtual module root and loads ./schema from there. Opening that leg as a PR now; the charly PR follows on the tag.

    Status will be posted here at each milestone.

    Agent: charly (DeepSeek Harness)

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

  5. aitrawog commented on Nov 9, 2026

    @aitrawog
    ContributorAuthor

    STATUS — the producer unit is MERGED and TAGGED: #296 → d29dc52d2810dd1b4056024a8a5598e81e65c925, tag v0.2026313.48. package specmodule (specmodule.FS = cue.mod/module.cue) is now the consumer-visible declaration; schema.FS is unchanged.

    Consumer leg in progress: charly bumps github.com/opencharly/spec to v0.2026313.48, composes ./schema as a module instance from schema.FS + specmodule.FS over an in-memory overlay, and keeps the plugin half as served text (unified onto the composed base). The parity proof is value equality — every top-level field of the concatenated base against the composed package — and it reports 719 fields identical on the tagged spec.

    This issue stays open until that PR merges.

    Agent: charly (DeepSeek Harness)

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

  6. aitrawog commented on Nov 9, 2026

    @aitrawog
    ContributorAuthor

    RESOLVED — unit 2 (the consumer leg) is MERGED AND TAGGED: opencharly/charly#1114 → squash 500a0a6828694b559e805616ca482a20971f3414, tag v2026.313.0209.

    What landed, against this issue's unit-2 text — and the one clause the measurement corrected:

    • charly composes github.com/opencharly/spec/schema as a module import. sharedCueSchema overlays schema.FS at <root>/schema/ and specmodule.FS at <root>/cue.mod/module.cue, loads ./schema with load.Instances, and refuses a load that is not a module or that declares no language.version. The module's pinned v0.16.1 governs evaluation.
    • The baseBody + "\n" + servedCUE text splice is DELETED. A plugin's served schema is still TEXT and is still unified with the base, but as a VALUE (base & served) — sound because the load gate already requires every served schema to compile standalone. schemaconcat has no runtime caller in charly any more.
    • The package-stripping path in schemaconcat did NOT go, and should not have. That clause assumed the generator stops concatenating too. It does not: internal/schemagen -mode=params still builds a package-less body to re-head with package spec + @go(spec), so the stripping is what keeps the generated Go byte-identical. The stripping now serves the generator, and charly's parity oracle in the consumer repo keeps the two forms equal.
    • The producer leg this issue did not name: cue.mod/module.cue is unreachable from a Go consumer — it sits outside schema/'s //go:embed *.cue tree — so feat(cuemodule): export the CUE module declaration to Go consumers #296 exported it as specmodule.FS before charly could import it.

    Proof on the merged tree: the parity test composes the base BOTH ways and compares every top-level field — 719 identical, 0 differences — with a sensitivity arm that reports 8 differences when one file is dropped from the overlay; the R10 bed check-local-vm passed 11 of 11 steps with a fresh charly update rebuild and zero skips; charly box validate validated this repo's own 604 candies / 122 boxes / 49 deploys with 0 warnings.

    What this issue does NOT cover, unchanged and still open in opencharly/opencharly#950: ONE unit per consuming plugin repo (its own cue.mod/module.cue, an import of github.com/opencharly/spec/schema, the local copy deleted, the parity test retired).

    Closing this issue as delivered; the per-repo units continue under #950.

    Agent: charly (DeepSeek Harness)

    Assisted-by: DeepSeek Harness deepseek-v4.1-flash (fully tested and validated)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions