diff --git a/README.md b/README.md index fc97f61..769063f 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,54 @@ # Maximum Direct shared schemas Language-neutral contracts for shared domain inputs. Author information once in -YAML or JSON, validate the completed document, and let each consumer derive the -view required by its task. +YAML or JSON and validate the completed document. Consumers own task-specific +interpretations and projections. -| Document | Contract | Semantics | Schema | +| Schema | Initial version | Document generation | Contract | | --- | --- | --- | --- | -| Party | `maximumdirect.rpg.party.v1` | [Party](rpg/party/v0.1.0/semantics.md) | [party.schema.json](rpg/party/v0.1.0/schema.json) | -| Campaign | `maximumdirect.rpg.campaign.v1` | [Campaign](rpg/campaign/v0.1.0/semantics.md) | [campaign.schema.json](rpg/campaign/v0.1.0/schema.json) | -| Glossary | `maximumdirect.glossary.v1` | [Glossary](glossary/v0.1.0/semantics.md) | [glossary.schema.json](glossary/v0.1.0/schema.json) | +| Glossary | 0.1.0 | `maximumdirect.glossary.v1` | [Schema](glossary/v0.1.0/schema.json), [semantics](glossary/v0.1.0/semantics.md), [examples](glossary/v0.1.0/examples/) | +| RPG party | 0.1.0 | `maximumdirect.rpg.party.v1` | [Schema](rpg/party/v0.1.0/schema.json), [semantics](rpg/party/v0.1.0/semantics.md), [examples](rpg/party/v0.1.0/examples/) | +| RPG campaign | 0.1.0 | `maximumdirect.rpg.campaign.v1` | [Schema](rpg/campaign/v0.1.0/schema.json), [semantics](rpg/campaign/v0.1.0/semantics.md), [examples](rpg/campaign/v0.1.0/examples/) | -Start with the synthetic [examples](examples). Every standalone document has a -`schema_version`. Glossaries contain named collections under `collections`. -Additional fields are permitted; consumers define which extensions they support. -Application settings, prompts, credentials, and reference vocabulary belong in -their respective repositories. +[Catalog](catalog.json) lists exact versions; [catalog format](docs/catalog.md) +defines its fields. These are unpublished candidates. A schema's URL mirrors its +repository path, such as +`https://schemas.maximumdirect.net/glossary/v0.1.0/schema.json`. +Hosting serves raw content from `main`; visibility does not establish publication. +Published CalVer tags and their inventories identify released versions. ## Validate -Install Go 1.27 or later and prepare the pinned dependencies: +Use Go 1.27 or later and prepare pinned dependencies: ```sh go mod download -go run ./cmd/validate examples/party.yml examples/campaign.yml examples/glossary.yml +go run ./cmd/validate -schema rpg/party@0.1.0 rpg/party/v0.1.0/examples/party.yml +go run ./cmd/validate -schema glossary@0.1.0 glossary/v0.1.0/examples/weather.yml go test ./... ``` -[Validation](docs/validation.md) defines the YAML profile, command, and semantic -checks. ConfigKit owns composition before the completed-document boundary. -The Go harness is a development tool, not a consumer SDK. +[Validation](docs/validation.md) defines the YAML profile and error boundaries. +ConfigKit owns composition before the completed-document handoff. The harness +is a development tool, not a consumer SDK. ## Select a distribution -`VERSION` identifies the schema-set candidate, initially `v1.0.0`. Publication is -separate from implementation. Select an immutable tag using the -[release procedure](docs/release.md), then bundle the complete `schemas/` -directory and [semantic documentation](docs/compatibility.md) for offline use. -For example, after publication: +Repository snapshots use CalVer `YYYY.MM.MICRO`. Schemas have independent full +SemVer versions; document markers identify independent contract generations. +See [compatibility](docs/compatibility.md) and the [release procedure](docs/release.md). +The internal Go module is only tooling and has no schema-version semantics. -```text -https://forge.maximumdirect.net/eric/schemas/archive/v1.0.0.tar.gz -https://forge.maximumdirect.net/eric/schemas/raw/tag/v1.0.0/schemas/glossary.schema.json -``` +Select a published archive, for example +`https://forge.maximumdirect.net/eric/schemas/archive/2026.11.0.tar.gz` +after publication. Record that distribution and the exact selected schema versions. +Bundle those directories, their referenced dependencies, and semantic documents +for offline use. An unrelated schema update need not trigger a consumer upgrade. -The raw URL is also that schema's `$id`. Its tag identifies the schema-set -release; document headers carry only the major contract version. Existing -applications require their own adoption work. See the -[consumer compatibility inventory](docs/compatibility.md#existing-consumers). - -Contributors start with [development](docs/development.md). +Application settings, prompts, credentials, and vocabulary remain in their own +repositories. [Existing consumers](docs/compatibility.md#existing-consumers) +require separately planned adoption. Contributors start with +[development](docs/development.md). Original material is dedicated to the public domain under [CC0 1.0](COPYRIGHT). diff --git a/VERSION b/VERSION index 0ec25f7..d6484a6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v1.0.0 +2026.11.0 diff --git a/cmd/check-published/main.go b/cmd/check-published/main.go new file mode 100644 index 0000000..d074d70 --- /dev/null +++ b/cmd/check-published/main.go @@ -0,0 +1,24 @@ +// check-published verifies immutable versions before an explicitly requested release. +package main + +import ( + "flag" + "fmt" + "forge.maximumdirect.net/eric/schemas/internal/publication" + "os" +) + +func main() { + repo := flag.String("repo", ".", "repository containing the committed candidate") + remote := flag.String("remote", "origin", "authoritative publication remote (already fetched)") + flag.Parse() + if flag.NArg() != 0 { + flag.Usage() + os.Exit(2) + } + if err := publication.CheckRemote(*repo, *remote); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } + fmt.Println("Published contract directories are unchanged.") +} diff --git a/docs/compatibility.md b/docs/compatibility.md index 90a825f..82cc11d 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -1,57 +1,78 @@ # Compatibility -The initial candidate is the `v1.0.0` schema set. Publication status is established -by the immutable upstream tag, not by this candidate's `VERSION` file. Contracts -jointly comprise their JSON Schemas and semantic documents. +Contracts comprise their versioned JSON Schema and adjacent semantic document. +The initial candidates are glossary, RPG party, and RPG campaign at `0.1.0`. +No published shared-schema release is assumed. -## Version identities +## Independent identities -Schema-set releases use Semantic Versioning and ship together. Contract markers -`maximumdirect.rpg.party.v1`, `maximumdirect.rpg.campaign.v1`, and -`maximumdirect.glossary.v1` identify major domain contracts. A compatible schema -release does not require editing operator document headers. +- Repository distribution: CalVer `YYYY.MM.MICRO`, with UTC year, zero-padded + month, and a publication counter starting at zero each month. The counter + conveys no compatibility guarantee. +- Schema version: full SemVer, independently selected per schema, represented + by its `v/` directory. +- Document generation: `maximumdirect.glossary.v1`, + `maximumdirect.rpg.party.v1`, or `maximumdirect.rpg.campaign.v1`. +- Canonical schema identity: `https://schemas.maximumdirect.net/` plus the exact + repository-relative schema path. It stays unchanged across repository snapshots. -- Major: incompatible structure, validation, or meaning. -- Minor: compatible additions that preserve interpretation of existing data. -- Patch: compatible corrections. A tighter validation rule that rejects previously - valid documents is not automatically a patch fix. +A compatible schema update retains its document marker. Incompatible structure +or meaning changes the affected marker, including during pre-stable development. +Independent stable schemas use SemVer: major for incompatibility, minor for +compatible additions, patch for compatible corrections. Pre-stable versions +express developing maturity; `1.0.0` is selected when adoption establishes a +stable contract. Document generation is not derived from schema or Go module major. -Each release pins absolute `$id` values to its immutable raw tag URLs. These are -schema resource identities, distinct from the operator's contract marker. -Vocabulary, schema-set, and consumer application versions evolve independently. +## Published contracts -## Both directions matter +Published version directories, including semantics and examples, remain available +byte-for-byte. A change requires a new schema version. Retain old records in +[catalog.json](../catalog.json). Later CalVer snapshots may add versions without +changing unrelated schemas. Exact publication dates belong in release notes. -A new consumer should accept old documents within its claimed major contract. -An older consumer can accept and preserve new optional extension fields without -claiming their meaning. Additional fields are compatible only when ignoring -them preserves interpretation of the known data. A field changing that -interpretation needs a new major contract or an explicitly selected extension -contract with its own documented semantics. +Hosting exposes raw repository files directly from `main`, including candidates. +Only published tags and their inventories establish released versions. A source +release completes at successful upstream publication; live URL inspection is +optional delivery verification. Hosting selection and consumer adoption are +independent of source publication. -Consumers forwarding or republishing shared documents should preserve extensions; -task-specific projections may omit them. Extensions cannot redefine a standard -field. Consumers can require additional data for a task without claiming that -every shared document must contain it. +## Consumer selection and compatibility -Contract changes include a compatibility assessment, updated schema and semantics, -examples and focused fixtures, and migration guidance for incompatible changes. -Retain representative valid documents from supported releases in `tests/valid/` -as compatibility evidence. A schema diff alone does not detect changed meanings. -The initial release has no earlier shared-schema releases to compare against. +Select a published CalVer archive and exact `name@version` entries from its +[catalog](catalog.md). For example, select `glossary@0.1.0` from `2026.11.0` +after that distribution is published. Bundle `glossary/v0.1.0/` with its schema, +semantic document, and any exact-version dependency directories referenced by +the schema. Register canonical IDs against bundled files for offline resolution. +No Go module dependency is required. + +For an update, review that schema's compatibility and migration notes, replace +the selected bundled directories, test application behavior, and commit the +selected schema versions and source distribution. Unrelated schema updates can +be ignored. Migration is explicit, with no automatic conversion or legacy reader. + +A new consumer reads supported older documents. An older consumer may preserve +new optional extensions without interpreting them. Additions are compatible only +when ignoring them preserves known meanings; otherwise select a new contract +generation or an explicitly selected extension contract. Forwarded documents +preserve extensions; task-specific projections may omit them. Consumers may +require more data for a particular operation than schema conformance requires. + +Each contract change includes compatibility assessment, updated semantics, +examples and focused fixtures, and migration guidance where needed. Retain valid +supported-release fixtures as evidence. Schema diffs alone cannot establish +unchanged meaning. ## Existing consumers -No existing application is declared compatible by this repository's initial -release. Adoption requires explicit implementation and verification. +No current application is declared compatible by this repository's readiness. -| Consumer | Current gap / later adoption responsibility | +| Consumer | Later adoption responsibility | | --- | --- | -| Narratio | Uses `narratio.party.v1`, stricter roster requirements, and the wrapperless glossary schema. Separate shared domain documents from operational campaign configuration and adopt the shared marker, alias spelling, and extension semantics. | -| Audita v4.2.0 | Runtime glossary input is wrapperless and can contain task instructions. Adopt the shared envelope and obtain instructions through application configuration. | -| Notarius v0.9.0 | Spell recognition consumes a strict JSON overlay with separate catalog and ruleset semantics. Reconcile its embedded catalog, merges, and ambiguity rules with shared spell entries and provenance; recognize names and aliases without asking operators to duplicate the source vocabulary. | -| Scriptorium prompts | Adopt shared party and glossary structures in the prompt input contracts that need them; no generic application compatibility is implied. | -| Reference catalog | Retains a wrapperless glossary and partial authoring format. Adopt shared completed envelopes while leaving composition to ConfigKit and vocabulary distribution independent. | +| Narratio | Adopt the RPG party marker, plural aliases, optional attributes, and shared glossary envelope; separate campaign context from operational configuration. | +| Audita v4.2.0 | Adopt the glossary envelope and obtain task instructions from application configuration. | +| Notarius v0.9.0 | Reconcile shared spell entries and provenance with embedded vocabulary, recognition, merges, and ambiguity policy. | +| Scriptorium prompts | Adopt the shared structures required by individual prompt input contracts. | +| Reference catalog | Adopt shared completed envelopes while leaving composition to ConfigKit and vocabulary releases independent. | -The [inventory](inventory.md) identifies source baselines and the deliberate -differences. Consumer release order and conversion code belong to later work. +[Inventory](inventory.md) records the source baselines and deliberate differences. +Consumer adoption order and implementation remain separate work. diff --git a/docs/development.md b/docs/development.md index 51804d9..d0e3aab 100644 --- a/docs/development.md +++ b/docs/development.md @@ -25,17 +25,20 @@ original checkout so missing files and accidental outside references are caught. ## Layout and changes -- `schemas/`: language-neutral Draft 2020-12 contracts. -- `docs/{party,campaign,glossary}.md`: field meanings and semantic rules. -- `examples/`: complete authoring examples, including equivalent YAML and JSON. +- `glossary/v/` and `rpg/{party,campaign}/v/`: independent + schemas, adjacent `semantics.md`, and complete `examples/`. +- `catalog.json`: exact schema-version inventory; see [catalog format](catalog.md). - `tests/valid/`: valid compatibility fixtures. - `tests/invalid/`: focused invalid documents; prefixes identify failure phase. - `internal/validation/`: local YAML profile, schema registration, semantic check. -- `cmd/validate/`: developer CLI; no application SDK or configuration loader. +- `cmd/validate/`: exact-version developer CLI; no consumer SDK. +- `internal/publication/` and `cmd/check-published/`: separate Git history checks + used only in explicitly requested release preparation. Implement a contract change in its schema, semantics, and relevant examples and fixtures together. Test observable acceptance and rejection, extension retention, and semantic boundaries. Avoid duplicating the upstream libraries' own suites. +Published version directories are immutable; additions use a new version. New standard fields need a compatibility assessment. Routine editing does not publish a release or upgrade any consumer. diff --git a/docs/oss/attribution.md b/docs/oss/attribution.md index 074ce24..217703a 100644 --- a/docs/oss/attribution.md +++ b/docs/oss/attribution.md @@ -2,7 +2,7 @@ ## Narratio reference catalog -Material: `schemas/glossary.schema.json`, adapted from the catalog's glossary-v1 +Material: `glossary/v0.1.0/schema.json`, adapted from the catalog's glossary-v1 schema at `a1a87edafd59a1de545a1c0b4efe5feeb80348e0`. The unmodified source is retained in `docs/origins/reference-catalog-glossary-v1.schema.json`. The shared envelope, defined fields, provenance, and structural extension behavior were changed. diff --git a/docs/release.md b/docs/release.md index 89412d7..9b3403e 100644 --- a/docs/release.md +++ b/docs/release.md @@ -1,85 +1,78 @@ # Release procedure -This is a source-only schema distribution. The authoritative remote is `origin` -at `ssh://git@forge.maximumdirect.net:22222/eric/schemas.git`, branch `main`. -Publication requires an explicit release request. Implementing the repository -does not publish the initial candidate. +This repository publishes source-only CalVer distributions. The authoritative +remote is `origin`, `ssh://git@forge.maximumdirect.net:22222/eric/schemas.git`; +the release branch is `main`. Publication requires an explicit release request. +ReleaseKit adoption is deferred. -## Prepare the candidate +## Prepare -1. Select a fresh Semantic Versioning tag under the [compatibility rules](compatibility.md). -2. Update `VERSION`, each schema's raw-tag `$id`, release-specific README examples, - and references between schemas to that version. Contract markers change only - when their major domain contract changes. -3. Write `docs/releases/.md` with the changes, compatibility assessment, - and migration instructions where needed. Include links to COPYRIGHT, LICENSE, - and ATTRIBUTION at the intended immutable tag. The initial candidate note is - [v1.0.0](releases/v1.0.0.md). -4. Prepare Go 1.27.4 and `go mod download`. Commit the intended source with a - short descriptive message. Review the diff for unintended data or credentials. +Select a fresh `YYYY.MM.MICRO` tag using the UTC publication year and month, +with a counter starting at zero each month. Check existing authoritative tags; +the current candidate `2026.11.0` reserves no date or counter. Re-evaluate it +when publication is requested. -Run `sh scripts/check.sh` on that committed candidate. It performs the same checks -as CI, including offline compilation and validation from the unpacked tagged-source -archive format. Validation dependencies are prepared separately; tests need no -network, consumer applications, provider credentials, or LLM calls. +Update `VERSION` and `docs/releases/.md`. Record the exact UTC +publication date in that note during actual release preparation. Identify changed +schema versions and compatibility/migration information. Unchanged schema +directories, IDs, and markers stay unchanged. A schema change gets a new +independent version and inventory record under [compatibility](compatibility.md). +Keep all published version directories and records. -## Distribution +Prepare Go 1.27.4 and `go mod download`. Review and commit the intended source. +Run `GOTOOLCHAIN=go1.27.4 sh scripts/check.sh` for that exact candidate. +The command validates locally and from an unpacked committed source archive. +Prepare dependencies separately; normal tests are offline. -The forge's immutable tagged source archive is the distribution: +## Publication guards -```text -https://forge.maximumdirect.net/eric/schemas/archive/v1.0.0.tar.gz +Before creating a tag: + +1. Confirm a clean worktree and index on `main`, with HEAD unchanged since + validation, and a version-matched release note. +2. Fetch authoritative branch and tag state: `git fetch origin main --tags`. +3. Confirm `git merge-base --is-ancestor origin/main HEAD` succeeds. +4. Confirm the chosen tag is absent locally and on origin using + `git tag --list 2026.11.0` and + `git ls-remote --tags origin refs/tags/2026.11.0`. Stop if either lists it. +5. Run `GOTOOLCHAIN=go1.27.4 go run ./cmd/check-published -remote origin`. + It reads authoritative CalVer tags, verifies fetched tag identities, and + compares their inventories and every retained directory file against HEAD. + Additions outside those directories are allowed. The initial release has + no published baseline. This history/network check is separate from offline + archive checks. + +For the example version, after every guard passes: + +```sh +git tag -a 2026.11.0 -F docs/releases/2026.11.0.md +git push --atomic origin HEAD:refs/heads/main refs/tags/2026.11.0 ``` -It contains the complete schema directory, semantic documentation, examples, -license and attribution, release note, and pinned optional Go harness and fixtures. -A consumer can bundle the schemas and semantic documents, register each `$id` -against its local file, and resolve all references offline. The harness is not a -runtime dependency. No binaries or separate registry are published. +Publish only those refs. Publication completes when the push succeeds; CI, +consumer installs, and live website tests are not completion gates. On an +ambiguous result inspect the exact remote branch and tag before retrying. +Published tags and contents are immutable; corrections use a new version. -To inspect the candidate distribution locally before publication: +## Source distribution and hosting + +The forge supplies the immutable archive, for example after publication: +`https://forge.maximumdirect.net/eric/schemas/archive/2026.11.0.tar.gz`. +It includes the catalog, complete versioned contracts with semantics/examples, +license/attribution, and optional pinned Go tools and fixtures. + +A local preview of the validated committed candidate is: ```sh mkdir -p dist -git archive --format=tar.gz --prefix=schemas-v1.0.0/ \ - --output=dist/schemas-v1.0.0.tar.gz HEAD +git archive --format=tar.gz --prefix=schemas-2026.11.0/ \ + --output=dist/schemas-2026.11.0.tar.gz HEAD ``` -Individual schema/editor URLs use the raw tag route, for example: - -```text -https://forge.maximumdirect.net/eric/schemas/raw/tag/v1.0.0/schemas/glossary.schema.json -``` - -The forge's raw-commit route was checked against the initial repository revision; -the public raw-tag JSON route was checked against a released sibling JSON document. -The exact URLs above become available only after this tag is published. Optional -post-publication inspection can use `curl --fail` on them and decode the response -as JSON, not an HTML forge page. It does not delay source-release completion. - -## Publish when requested - -Start from a clean `main` whose HEAD is the validated candidate. Fetch `origin` -and verify that advancing `origin/main` to HEAD is fast-forward. Check that the -selected tag is absent locally and on `origin`. Publish only the intended branch -and fresh annotated tag. For the initial candidate: - -```sh -git fetch origin main --tags -git merge-base --is-ancestor origin/main HEAD -git status --short -git tag --list v1.0.0 -git ls-remote --tags origin refs/tags/v1.0.0 -git tag -a v1.0.0 -F docs/releases/v1.0.0.md -git push --atomic origin HEAD:refs/heads/main refs/tags/v1.0.0 -``` - -The status and tag checks must be empty before creating the tag. Stop if the -branch is not `main`, the candidate changed, the worktree is dirty, the version -is already used, or validation failed. Publication completes when the push -succeeds; do not wait for CI. The forge supplies the tagged source archive. - -Published tags and contents are immutable. A defect is corrected in a new -version. On an ambiguous push result, inspect the exact upstream branch and tag -before reporting success or retrying. Preserve already-published tags. Routine -releases do not require installed-consumer checks or a new external approval gate. +Hosting serves raw repository paths from `main` without a release selector. +For example, glossary's canonical ID and hosted path are +`https://schemas.maximumdirect.net/glossary/v0.1.0/schema.json`. +Candidates may be visible before publication. Tags and their catalogs establish +release status. Local static-serving tests verify path/byte correspondence; +optional inspection of live URLs after publication verifies delivery. +Hosting provisioning and backend changes remain separately maintained. diff --git a/docs/releases/2026.11.0.md b/docs/releases/2026.11.0.md new file mode 100644 index 0000000..d150a71 --- /dev/null +++ b/docs/releases/2026.11.0.md @@ -0,0 +1,20 @@ +# Maximum Direct shared schemas 2026.11.0 + +Unpublished candidate. Select the actual UTC publication date and CalVer counter +when a release is explicitly requested. + +## Initial schema versions + +- `glossary@0.1.0`: `maximumdirect.glossary.v1`. +- `rpg/party@0.1.0`: `maximumdirect.rpg.party.v1`. +- `rpg/campaign@0.1.0`: `maximumdirect.rpg.campaign.v1`. + +Versioned contracts contain schemas, semantics, and synthetic examples. The catalog +identifies exact versions for offline selection. Distribution dates, schema +SemVer, document generations, and canonical IDs are independent. + +This replaces the unpublished flat candidate layout and party/campaign markers. +Existing applications require separately planned adoption; no conversion shims +or application compatibility claims are supplied. See [compatibility](../compatibility.md). + +[COPYRIGHT](https://forge.maximumdirect.net/eric/schemas/src/tag/2026.11.0/COPYRIGHT) | [LICENSE](https://forge.maximumdirect.net/eric/schemas/src/tag/2026.11.0/LICENSE) | [ATTRIBUTION](https://forge.maximumdirect.net/eric/schemas/src/tag/2026.11.0/docs/oss/attribution.md) diff --git a/docs/releases/v1.0.0.md b/docs/releases/v1.0.0.md deleted file mode 100644 index 0fcaa08..0000000 --- a/docs/releases/v1.0.0.md +++ /dev/null @@ -1,18 +0,0 @@ -# Maximum Direct shared schemas v1.0.0 - -Initial shared party, campaign, and general glossary contracts, identified by -`maximumdirect.rpg.party.v1`, `maximumdirect.rpg.campaign.v1`, and -`maximumdirect.glossary.v1`. - -The distribution includes Draft 2020-12 schemas, semantic documentation, -synthetic YAML/JSON examples, compatibility rules, and an optional offline Go -validation harness. Objects support extensions; semantic validation checks -glossary entry IDs within collections. Glossaries use a versioned envelope and -keep task instructions in consumer configuration. - -This is a new independent contract set. Existing Narratio, Audita, Notarius, -Scriptorium prompt, and reference catalog formats require separately planned -adoption. See [compatibility](../compatibility.md#existing-consumers) for the -initial differences. There is no earlier shared release to migrate. - -[COPYRIGHT](https://forge.maximumdirect.net/eric/schemas/src/tag/v1.0.0/COPYRIGHT) | [LICENSE](https://forge.maximumdirect.net/eric/schemas/src/tag/v1.0.0/LICENSE) | [ATTRIBUTION](https://forge.maximumdirect.net/eric/schemas/src/tag/v1.0.0/docs/oss/attribution.md) diff --git a/docs/validation.md b/docs/validation.md index 6d8624b..fe64b40 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -12,7 +12,8 @@ source archive: ```sh go mod download -go run ./cmd/validate examples/party.yml examples/campaign.yml examples/glossary.yml +go run ./cmd/validate -schema rpg/party@0.1.0 rpg/party/v0.1.0/examples/party.yml +go run ./cmd/validate -schema glossary@0.1.0 glossary/v0.1.0/examples/weather.yml ``` Dependencies are pinned in `go.mod` and `go.sum`. Once prepared, validation is @@ -20,12 +21,15 @@ offline. A built tool can select another unpacked distribution: ```sh go build -o /tmp/schemas-validate ./cmd/validate -/tmp/schemas-validate -root /path/to/schemas-v1.0.0 /path/to/completed-glossary.yml +/tmp/schemas-validate -root /path/to/distribution -schema glossary@0.1.0 /path/to/completed-glossary.yml ``` +Select exactly `name@version` from [catalog.json](../catalog.json). All supplied +documents are validated against that definition, including their document marker. +Separate invocations select different schemas. Success reports the selected version. Flags precede filenames. All files are checked even if an earlier file fails. Exit 0 means all documents passed; 1 means a document could not be read or -validated; 2 means invalid command usage or an unusable schema set. Errors identify +validated; 2 means invalid command usage, missing/unknown selection, or an unusable distribution. Errors identify the document and distinguish `decode`, `structure`, and `semantic`. Decoding errors include field paths and source positions where the YAML library or node profile provides them. Structural errors include JSON instance locations. @@ -93,14 +97,15 @@ can use the document for a particular operation. ## Offline schema use and editors -Every schema declares Draft 2020-12 and an immutable release `$id`. The harness +Every schema declares Draft 2020-12 and an exact versioned canonical `$id`. The harness registers the bundled schemas under those IDs before compiling them and rejects unresolved resource loads. The schema engine supplies the standard meta-schema; ordinary validation performs no network requests. Other validators can likewise register local files under their `$id` values. -Keep the complete schema directory from one release together. Configure editors -externally to associate document paths with a local schema or its immutable raw +Bundle the selected version directories and their exact referenced dependencies +from one selected CalVer snapshot, with their adjacent semantic documents. Configure editors +externally to associate document paths with a local schema or its canonical versioned URL. Operator documents use `schema_version`; they do not need a `$schema` field. Schema validation supplies editor feedback for known fields. Optional tooling can warn about likely misspellings without rejecting extensions. diff --git a/internal/publication/history.go b/internal/publication/history.go new file mode 100644 index 0000000..08a2965 --- /dev/null +++ b/internal/publication/history.go @@ -0,0 +1,104 @@ +// Package publication checks retained contracts against authoritative release tags. +// It is separate from offline schema-distribution validation. +package publication + +import ( + "encoding/json" + "fmt" + "os/exec" + "regexp" + "strings" + + "forge.maximumdirect.net/eric/schemas/internal/validation" +) + +var calver = regexp.MustCompile(`^[0-9]{4}\.(0[1-9]|1[0-2])\.(0|[1-9][0-9]*)$`) + +func git(repo string, args ...string) ([]byte, error) { + out, err := exec.Command("git", append([]string{"-C", repo}, args...)...).CombinedOutput() + if err != nil { + return nil, fmt.Errorf("git %s: %w: %s", strings.Join(args, " "), err, out) + } + return out, nil +} + +// CheckRemote reads the authoritative tag list after the caller has fetched it. +// It neither fetches nor changes any refs and never checks CI or hosting. +func CheckRemote(repo, remote string) error { + out, err := git(repo, "ls-remote", "--tags", "--refs", remote) + if err != nil { + return err + } + for _, line := range strings.Split(strings.TrimSpace(string(out)), "\n") { + fields := strings.Fields(line) + if len(fields) != 2 { + continue + } + tag := strings.TrimPrefix(fields[1], "refs/tags/") + if !calver.MatchString(tag) { + continue + } + // Verify the fetched tag is the authoritative object, not a same-named local ref. + local, err := git(repo, "rev-parse", "refs/tags/"+tag) + if err != nil { + return err + } + if strings.TrimSpace(string(local)) != fields[0] { + return fmt.Errorf("tag %s differs from %s; fetch authoritative tags before checking", tag, remote) + } + if err := CheckTag(repo, tag); err != nil { + return err + } + } + return nil +} + +// CheckTag compares catalog records and every file in each published directory +// with the committed candidate at HEAD. New version directories remain allowed. +func CheckTag(repo, tag string) error { + readCatalog := func(revision string) (validation.Catalog, error) { + data, err := git(repo, "show", revision+":catalog.json") + var catalog validation.Catalog + if err != nil { + return catalog, err + } + if err := json.Unmarshal(data, &catalog); err != nil { + return catalog, fmt.Errorf("%s catalog: %w", revision, err) + } + if catalog.FormatVersion != 1 { + return catalog, fmt.Errorf("%s: unsupported catalog format %d", revision, catalog.FormatVersion) + } + return catalog, nil + } + previous, err := readCatalog(tag) + if err != nil { + return err + } + current, err := readCatalog("HEAD") + if err != nil { + return err + } + records := make(map[string]validation.Record) + for _, record := range current.Schemas { + records[record.Name+"@"+record.Version] = record + } + for _, record := range previous.Schemas { + key := record.Name + "@" + record.Version + if records[key] != record { + return fmt.Errorf("%s: published inventory record %s changed or disappeared", tag, key) + } + directory := strings.TrimSuffix(record.Path, "/schema.json") + "/" + before, err := git(repo, "ls-tree", "-r", "--format=%(objectname) %(path)", tag, "--", directory) + if err != nil { + return err + } + after, err := git(repo, "ls-tree", "-r", "--format=%(objectname) %(path)", "HEAD", "--", directory) + if err != nil { + return err + } + if len(before) == 0 || string(before) != string(after) { + return fmt.Errorf("%s: published directory %s changed or disappeared", tag, directory) + } + } + return nil +} diff --git a/internal/publication/history_test.go b/internal/publication/history_test.go new file mode 100644 index 0000000..a4dadfc --- /dev/null +++ b/internal/publication/history_test.go @@ -0,0 +1,97 @@ +package publication + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "forge.maximumdirect.net/eric/schemas/internal/validation" +) + +func TestPublishedDirectories(t *testing.T) { + repo := t.TempDir() + run := func(args ...string) { + t.Helper() + if _, err := git(repo, args...); err != nil { + t.Fatal(err) + } + } + run("init", "-b", "main") + run("config", "user.name", "Schema Test") + run("config", "user.email", "schemas@example.invalid") + write := func(file, body string) { + t.Helper() + target := filepath.Join(repo, file) + if err := os.MkdirAll(filepath.Dir(target), 0755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(target, []byte(body), 0644); err != nil { + t.Fatal(err) + } + } + commit := func() { t.Helper(); run("add", "."); run("commit", "-m", "Synthetic fixture") } + record := validation.Record{Name: "glossary", Version: "0.1.0", Contract: "maximumdirect.glossary.v1", ID: "https://schemas.maximumdirect.net/glossary/v0.1.0/schema.json", Path: "glossary/v0.1.0/schema.json"} + catalog := validation.Catalog{FormatVersion: 1, Schemas: []validation.Record{record}} + writeCatalog := func() { + t.Helper() + data, err := json.Marshal(catalog) + if err != nil { + t.Fatal(err) + } + write("catalog.json", string(data)) + } + writeCatalog() + write(record.Path, "{}") + write("glossary/v0.1.0/semantics.md", "Original semantics") + write("glossary/v0.1.0/examples/sample.yml", "example: original") + write("VERSION", "2026.10.0") + commit() + run("tag", "2026.10.0") + if err := CheckRemote(repo, repo); err != nil { + t.Fatal(err) + } + for _, file := range []string{record.Path, "glossary/v0.1.0/semantics.md", "glossary/v0.1.0/examples/sample.yml"} { + t.Run(file, func(t *testing.T) { + original, err := os.ReadFile(filepath.Join(repo, file)) + if err != nil { + t.Fatal(err) + } + write(file, "Changed") + commit() + if err := CheckTag(repo, "2026.10.0"); err == nil { + t.Fatal("published modification accepted") + } + if err := os.Remove(filepath.Join(repo, file)); err != nil { + t.Fatal(err) + } + commit() + if err := CheckTag(repo, "2026.10.0"); err == nil { + t.Fatal("published removal accepted") + } + write(file, string(original)) + commit() + }) + } + catalog.Schemas = nil + writeCatalog() + commit() + if err := CheckTag(repo, "2026.10.0"); err == nil { + t.Fatal("removed catalog record accepted") + } + catalog.Schemas = []validation.Record{record} + writeCatalog() + commit() + next := record + next.Version = "0.2.0" + next.Path = "glossary/v0.2.0/schema.json" + next.ID = "https://schemas.maximumdirect.net/" + next.Path + catalog.Schemas = append(catalog.Schemas, next) + writeCatalog() + write(next.Path, "{}") + write("VERSION", "2026.11.0") + commit() + if err := CheckRemote(repo, repo); err != nil { + t.Fatalf("new schema/distribution changed no published bytes: %v", err) + } +}