Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .claude/rules/codegen-architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ one file (#266: a shared artifact rendered from the whole loaded root, like the
`enums.ts`, is emitted by every `entityFile()` instance); also errors on an unknown
target, missing `importBase` for cross-target imports, or any generator throw, (6) writes each file under its target's `outDir`, deciding from
`.metaobjects/.gen-state/` — a three-way merge against the snapshot body when one is
present, else the committed `.hashes.json` (hash matches what we recorded writing ⇒
present, else the committed `.hashes/` (hash matches what we recorded writing ⇒
overwrite; edited or unrecorded ⇒ refused). The `@generated` header is **informational**:
every use of it is an emitter stamping the marker into output, and the overwrite decision
never reads it. Because the snapshot bodies are gitignored while `.hashes.json` is
never reads it. Because the snapshot bodies are gitignored while `.hashes/` is
committed, a fresh clone or CI runner takes the second branch — so a hand-edited generated
file is REFUSED there rather than merged.

Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ import { EntityFetcherProvider, EntityGrid } from "@metaobjectsdev/tanstack";

- **TS runtime**: Bun-first for development (zero-config TS, native test runner). Node-compatible for distribution; users install via npm/pnpm/bun without lock-in to Bun's runtime.
- **Module system**: ESM only. No CommonJS, no transpile step required.
- **Storage format**: JSON files in `metaobjects/meta.<concept>.json` at project root. `.metaobjects/.gen-state/` holds the codegen merge base: the snapshot **bodies are gitignored** (a second full copy of all generated output), but **`.hashes.json` is COMMITTED** — one hash per generated path, and the only thing that lets `meta gen` tell "this file is exactly what I wrote" from "somebody edited this" on a machine that did not generate it. Ignore it and a fresh clone or CI runner silently overwrites hand edits; commit it and an edited file is refused by name instead.
- **Storage format**: JSON files in `metaobjects/meta.<concept>.json` at project root. `.metaobjects/.gen-state/` holds the codegen merge base: the snapshot **bodies are gitignored** (a second full copy of all generated output), but **`.hashes/` (one file per model package) is COMMITTED** — one hash per generated path, and the only thing that lets `meta gen` tell "this file is exactly what I wrote" from "somebody edited this" on a machine that did not generate it. Ignore it and a fresh clone or CI runner silently overwrites hand edits; commit it and an edited file is refused by name instead.
- **Codegen substrate**: the vendored ts-poet printer (`codegen-ts/src/poet.ts`) for greenfield emit, ts-morph for in-place edits, Biome for format pass, `git merge-file --diff3` for hand-edit-preserving regen.
- **Runtime substrate**: Kysely for TS (user-provided connection, async-only).
- **Migration substrate**: Postgres + SQLite for TS v0.3.
Expand Down Expand Up @@ -304,7 +304,7 @@ project-root/
├── .metaobjects/ # HIDDEN — tool state
│ ├── config.json # static project state
│ └── .gen-state/ # codegen merge base
│ ├── .hashes.json # COMMIT THIS — one hash per generated path
│ ├── .hashes/<package>.json # COMMIT THIS — one hash per generated path, one file per package
│ └── <mirrored output> # gitignored (a 2nd copy of all output)
└── metaobjects.config.ts # runtime config
```
Expand Down
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,17 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
`codegen-kotlin` generators ignored a generator's `<filters>` and wrote every object; they now
honour them, as the `codegen-base` generators always did. A pom whose filters were inert
generates fewer files: remove the `<filters>` that no longer describe what you want.
- **The hash manifest is one file per package.** `.metaobjects/.gen-state/.hashes.json` is replaced
by `.metaobjects/.gen-state/.hashes/<package>.json` (and `.root.json` for a path in no package), so
two branches that regenerate files in different packages no longer conflict on one file. Nothing to
do but commit: the first `meta gen` (or `dotnet meta gen`, `mvn metaobjects:generate`,
`metaobjects gen`, `cargo meta gen`) reads the old file, writes the package files, deletes the old
file and adds `!.gen-state/.hashes/` to `.metaobjects/.gitignore` when that file ignores
`.gen-state/*`. A project whose root `.gitignore` excludes `.metaobjects/.gen-state/` should
un-ignore the new directory the way it un-ignored the old file; `meta verify` still names the
rule that is in force. A pipeline that read `.hashes.json` directly reads every file in
`.hashes/` instead. ADR-0064 Amendment 1;
[docs/features/migrations/per-package-hash-manifest.md](docs/features/migrations/per-package-hash-manifest.md).
- **`metamodelVersion` is `1.3`.** Upgrade every port together.

### Security
Expand Down Expand Up @@ -215,6 +226,19 @@ Each item below is described in full under Security, Added, Changed or Fixed; th

### Added

- **The hash manifest is one file per package (ADR-0064 Amendment 1).** Every port that keeps hash
state, TypeScript, C#, Java, Kotlin, Python and Rust, writes `.gen-state/.hashes/<package>.json`
instead of one `.gen-state/.hashes.json`. The file name is the package's `::` segments joined with
`.`, percent-encoding any byte outside `[A-Za-z0-9_-]`. A file is placed by the `sourceNode` the
entry records, else by the model object its file name names (matched by words, so `OrderLine.cs`
and `order_line.py` both find `OrderLine`), else it stays where it was, else it goes in
`.root.json`. Placement only decides which file holds an entry: a reader merges them all, so a
wrong placement costs a merge conflict and nothing else. A write touches only the files whose
bytes change, so a run that changes nothing still writes nothing. The shared vectors are
`fixtures/codegen-skip-conformance/manifests.json`, and a `legacy-manifest` case in that corpus
holds every port to the migration. A test merges two real git branches that change different
packages with no conflict.

- **Business rules: operations, permission names and lifecycles (ADR-0066). Experimental:** the
shape may change in a MINOR, including removals and renames, until generated services run on
it in an adopter estate (`docs/compatibility-policy.md`). The names ADR-0030
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Generated files carry the header:

The header is **informational on this port** — the write decision never reads it. What
the runner overwrites is decided by `.metaobjects/.gen-state/`: the snapshot body if the
machine has one (three-way merge), otherwise the committed `.hashes.json` (byte-for-byte
machine has one (three-way merge), otherwise the committed `.hashes/` (byte-for-byte
what it wrote ⇒ overwrite; anything else ⇒ refused, exit 1). A sibling file you created
(`<Entity>.extra.ts` by convention) is never touched because it is not a path the runner
records — not because of its name, and not because of the header. Locate generated output at the
Expand Down
4 changes: 2 additions & 2 deletions agent-context/skills/metaobjects-codegen/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ You run a `gen` step. The runner:
3. Runs each configured **generator** — most emit one file per entity; some emit a
single shared file (a barrel, a DB-context, an app-config).
4. Decides whether it may overwrite a file, by a committed **hash manifest**
(`.metaobjects/.gen-state/.hashes.json`) on every port. If a file still hashes to what
(`.metaobjects/.gen-state/.hashes/`) on every port. If a file still hashes to what
the generator recorded writing, it is safe to overwrite; if it was edited, or there is
no record of it, the write is **refused by name**. TypeScript additionally
three-way-merges against a snapshot when one is present locally. **Commit the
Expand All @@ -189,7 +189,7 @@ You run a `gen` step. The runner:
write). On Java and Kotlin a refusal is a warning and `mvn metaobjects:verify` is the
gate that fails. The one-time fix for a project that predates the committed manifest
is **`gen --baseline=adopt`**: it records the files you have as the baseline and writes
nothing, so there is finally a `.hashes.json` to commit — then `gen` again, and the
nothing, so there is finally a `.hashes/` to commit — then `gen` again, and the
regeneration lands as its own diff. Adopting DECLARES those files to be generated
output, so an edit already inside one is part of the baseline and that regeneration
replaces it; commit before you run it. (TypeScript additionally has
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,16 +314,16 @@ npx meta gen Author Post # scope to named entities
Generated files carry an `@generated by @metaobjectsdev/codegen-ts` header. It is
**informational** — the write decision never reads it. `.metaobjects/.gen-state/`
decides: the snapshot body if this machine has one (three-way merge), otherwise the
committed `.hashes.json` (byte-for-byte what it wrote ⇒ overwrite; anything else ⇒
committed `.hashes/` (byte-for-byte what it wrote ⇒ overwrite; anything else ⇒
refused, path named, exit 1). So the merge is machine-local: a file you edited and
pushed is REFUSED on a fresh clone or in CI, not merged. Recovery is in
`docs/features/own-your-codegen.md`.

A project with NO manifest at all (it predates the manifest being committed) is a
different case with a different fix: every stale file refuses, and a run where everything
refuses writes no manifest — so "commit `.hashes.json`" has nothing to commit. Run
refuses writes no manifest — so "commit `.hashes/`" has nothing to commit. Run
`meta gen --baseline=adopt` once: it records the files you have as the merge base and
writes nothing, leaving exactly one file to commit; the next `meta gen` is then the
writes nothing, leaving the manifest to commit; the next `meta gen` is then the
regeneration, as its own reviewable diff. Adopting declares those files to BE generated
output, so an edit already inside one is part of the base and that regeneration replaces
it — `--baseline=fresh` + `git checkout` is the sequence that KEEPS an edit.
Expand Down
2 changes: 1 addition & 1 deletion agent-context/skills/metaobjects-verify/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ with `ERR_DEPENDENCY_SNAPSHOT_STALE` naming the fix: run `meta deps sync`.
regen) fails the build. Wire it into CI so a stale `@generated` file fails.
**A hand edit inside a generated file is reported apart from drift** — `meta gen`
three-way-merges hand edits by design, and the Node gate judges the *generated
contribution* against the committed `.metaobjects/.gen-state/.hashes.json`, not the
contribution* against the committed `.metaobjects/.gen-state/.hashes/`, not the
bytes, then lists every generated file carrying a hand edit (count + paths). Whether
that list fails the build is `verify.handEdits` in `.metaobjects/config.json`:
`"fail"` exits 1 (what `meta init` writes for a new project), `"notice"` (and a
Expand Down
2 changes: 1 addition & 1 deletion agent-context/templates/always-on.md.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ is built (never before), a new node for new behaviour.
{{verifySteps}}- `npx meta verify --db <url>` (the live schema matches the metadata).

Commit the metadata, the generated code, `.metaobjects/migrations/` and
`.metaobjects/.gen-state/.hashes.json`.
`.metaobjects/.gen-state/.hashes/`.

## Calling the generated REST API

Expand Down
2 changes: 1 addition & 1 deletion docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/enum-length-conformance/`](../fixtures/enum-length-conformance/) (a string-stored enum's column length: `@maxLength`, else `enums.maxLength`) | 5 cases + 1 overflow + 5 refusals; run by a port that sizes the column | ✓ | ✓ | inherits via Java (one config reader, one resolver) | ✓ | — (sizes no column: emits no DDL or column type; the config reader accepts and shape-checks the `enums` block) |
| [`fixtures/check-constraint-conformance/`](../fixtures/check-constraint-conformance/) (the CHECK constraints `meta migrate` derives: name and expression text per dialect) | 1 model, 5 expected files (postgres, sqlite, d1, and both skip-redundant variants) | ✓ (reference, `migrate-ts`) | — (no CHECK in a generated model) | — (same) | ✓ (the EF context declares them; live-Postgres `EnsureCreated` lane) | — (same) |
| [`fixtures/foreign-key-index-conformance/`](../fixtures/foreign-key-index-conformance/) (the indexes `migrate.foreignKeyIndexes` adds: which foreign keys are uncovered, and each index's name per dialect, a name over 63 bytes cut on Postgres; and the name each declared `identity.secondary` / `index.lookup` is created under) | 1 model, 4 expected files (FK and declared, postgres and sqlite) | ✓ (reference, `migrate-ts`; the Drizzle tables declare the declared names) | — (no index in a generated model) | ✓ (the Exposed tables declare them) | ✓ (the EF context declares them) | — (same as Java) |
| [`fixtures/codegen-skip-conformance/`](../fixtures/codegen-skip-conformance/) (when `gen` may skip and what a local `verify --codegen` may answer, ADR-0064) | one case table in `cases.json` | ✓ | ✓ | ✓ (through the Java runner) | ✓ | ✓ |
| [`fixtures/codegen-skip-conformance/`](../fixtures/codegen-skip-conformance/) (when `gen` may skip and what a local `verify --codegen` may answer, ADR-0064) | one case table in `cases.json`, plus the manifest layout vectors in `manifests.json` (ADR-0064 Amendment 1) | ✓ | ✓ | ✓ (through the Java runner) | ✓ | ✓ |
| [`fixtures/codegen-noop/`](../fixtures/codegen-noop/) (vocabulary with no lowering yet: FR-044 reporting, what is lowered and what stays inert; ADR-0066 business rules, inert everywhere) | 2 model pairs (`reporting/` and `rules/`, each `with` vs `without`) | ✓ (codegen + migrate) | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/cube-model/`](../fixtures/cube-model/) (FR-044 Plan 4 — the `cube-model` generator's golden Cube files, plus the canonical model's golden) | 46 cases (36 trees + 10 errors) + 1 canonical golden | ✓ (the exporter is TypeScript-only, spec R6; its `cube` lane also loads the files into a real Cube) | — | — | — | — |
| [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 41 cases (31 core + 10 TypeScript) | ✓ (the first writer; core and TypeScript dialect) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) |
Expand Down
8 changes: 4 additions & 4 deletions docs/features/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vocabulary everywhere, each port implementing the modes it supports.
| Subverb | What it checks | Touches a DB? |
|---|---|---|
| `verify --db` | **Schema drift** — does the live database (or snapshot) match the metadata? (migrate engine, ADR-0015) | yes |
| `verify --codegen` | **Codegen drift** — regenerate from metadata in memory and fail if it differs from the committed generated output. Catches "metadata changed but `meta gen` wasn't re-run". **A hand-edited generated file** (Node `meta`): `meta gen` three-way-merges hand edits, so the gate compares the *generated contribution* against the committed `.gen-state/.hashes.json` and reports each edited file separately, by path, with how to see the edit and how to drop it. What that report does to the exit code is the `verify.handEdits` key in `.metaobjects/config.json`: `"fail"` exits 1, `"notice"` (and a project without the key, as before 1.3) prints it and exits 0. `meta init` writes `"fail"` for a new project. `--allow-hand-edits` relaxes `fail` to a notice for one run; `--forbid-hand-edits` makes a hand edit fail for one run whatever the key says. The other ports compare the generated files byte for byte, so any edit is drift and fails: `dotnet meta verify --codegen`, `mvn metaobjects:verify` (Java and Kotlin) and `metaobjects verify --codegen` each exit non-zero and name the file. | no |
| `verify --codegen` | **Codegen drift** — regenerate from metadata in memory and fail if it differs from the committed generated output. Catches "metadata changed but `meta gen` wasn't re-run". **A hand-edited generated file** (Node `meta`): `meta gen` three-way-merges hand edits, so the gate compares the *generated contribution* against the committed `.gen-state/.hashes/` and reports each edited file separately, by path, with how to see the edit and how to drop it. What that report does to the exit code is the `verify.handEdits` key in `.metaobjects/config.json`: `"fail"` exits 1, `"notice"` (and a project without the key, as before 1.3) prints it and exits 0. `meta init` writes `"fail"` for a new project. `--allow-hand-edits` relaxes `fail` to a notice for one run; `--forbid-hand-edits` makes a hand edit fail for one run whatever the key says. The other ports compare the generated files byte for byte, so any edit is drift and fails: `dotnet meta verify --codegen`, `mvn metaobjects:verify` (Java and Kotlin) and `metaobjects verify --codegen` each exit non-zero and name the file. | no |
| `verify --templates` | **Template/prompt drift** — `Renderer.verify` checks each `template.*` node's `{{field}}` references against its payload VO (FR-004). A Jinja body (Python and TypeScript, ADR-0061) is checked the same way. | no |
| `verify --docs` | **Removed in 1.1.0** (ADR-0034 Amendment 9). It prints where the check went and exits 2: documentation is written by entries in `generators`, so `verify --codegen` checks it with the rest of the declared output. | — |
| `verify --deps` | **Dependency drift** (FR-023) — re-resolves each declared dependency (its `path`, its installed `npm` / `python` package, or its `maven` / `nuget` package in the local cache) and compares its installed artifact's hash against `.metaobjects/deps.lock.json`, same comparison as `meta deps check`. Needs the publisher reachable, so it is never part of the bare-`verify` default. A `drifted` or `unresolved` dependency fails with `ERR_DEPENDENCY_UPSTREAM_DRIFT`. **Node `meta`; Python (`metaobjects verify --deps`, plus `metaobjects deps check`), C# (`dotnet meta verify --deps`), and Java and Kotlin (`-Dmeta.verify.mode=deps`) have the `path`-only counterpart.** See [`metadata-dependencies.md`](metadata-dependencies.md). | no |
Expand Down Expand Up @@ -289,7 +289,7 @@ ships. When `verify` renders, it compares in memory: no temp tree is written.
## `gen` refuses rather than guesses — and `--baseline` is how you answer it

Every port's `gen` decides per file whether it may overwrite, from a committed hash
manifest (`.metaobjects/.gen-state/.hashes.json`). A file that still hashes to what the
manifest (`.metaobjects/.gen-state/.hashes/`). A file that still hashes to what the
generator recorded writing is safe to overwrite; one that was edited, or that no record
covers, is **refused by name and left exactly as it is**.

Expand Down Expand Up @@ -324,10 +324,10 @@ Syntax per port, and the orphan rule both follow:
[own-your-codegen](own-your-codegen.md#handedits-keep-or-discard-edits-to-one-generators-files).

**`adopt` exists because the refusal's own remedy was unreachable.** It told you to commit
`.hashes.json` — but nothing writes a manifest until a `gen` succeeds, and a run where
`.hashes/` — but nothing writes a manifest until a `gen` succeeds, and a run where
every file refuses writes none, so there was nothing to commit and the next run refused
identically. `adopt` breaks that loop: it records what is on disk, writes not one byte of
output, and leaves exactly one file to commit. Then `gen` again, and the regeneration
output, and leaves the manifest to commit. Then `gen` again, and the regeneration
arrives as its own reviewable diff.

**What adopting declares** — say this out loud before running it: that the files you have
Expand Down
Loading
Loading