Skip to content

feat(codegen-ts): add rules-names and contract-types generators - #638

Merged
dmealing merged 17 commits into
mainfrom
fm/mo-130-lane-ts-2-b3
Nov 22, 2026
Merged

dmealing merged 17 commits into
mainfrom
fm/mo-130-lane-ts-2-b3

Conversation

@dmealing

@dmealing dmealing commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • codegen-ts: adds two ejectable model-layer generators, rules-names (per-package constants for lifecycle states, transitions, derived commands, operations, permissions and business errors, built from a new rules walk) and contract-types (read, create and update shapes, operation inputs and outputs, and wire error bodies, built from a new contract walk). The OpenAPI document now describes the list query contract (?search where a row has text fields, filter[or] / filter[and] combinators) and the 400 invalid_id response on item routes. Expected OpenAPI fixtures are updated to match.
  • runtime-ts and integration-tests: adds ObjectManager.guardedUpdate, which moves a row's state field in one statement only when the row is in one of the from states and an optional @condition holds. It returns null when nothing matches. The persistence driver gains not, compare and nullTest where clauses and an optional update key clause for MySQL read-back. The shared op: guardedUpdate persistence scenario (fixtures/persistence-conformance/queries/guarded-update.yaml) runs through the TypeScript runner on Postgres and MySQL; the runner maps MySQL DATETIME text to the canonical form on the actual side. Ports that have not built the operation defer the scenario by name.
  • sdk, cli and agent-context: adds build-time static agent-file trees (shipped.ts, with a committed agent-context-shipped/ manifest and content-addressed files) for each server language set and client choice, so non-TypeScript ports copy the files instead of re-assembling them. Rust is accepted as a server language (--server rust, detected from Cargo.toml), with a new agent-context/servers/rust.meta.json and a Rust loop template. Adds Rust agent-context conformance expectations.

Evidence. Live evidence was inconclusive for a tooling reason (the evidence agent ran only its own structured-output schema check, no scenario of this change); local CI (scripts/ci-local.sh --affected, 8 lanes) passed and is the evidence. The guarded-update scenario was also run by hand on MySQL (TypeScript MySQL query lane 28/0), SQLite (25/0) and Postgres.

Gate runs: 2. The first run was aborted at its document step, because two test-runner fixes (MySQL DATETIME mapping, Python's per-engine deferral) were code that step could not apply. They were committed by hand, and the second run passed.

Validation

Risk Assessment

✅ Low: The change is additive and matches the stated intent. I found no concrete defect in the driver, runner, OpenAPI, generator or shipped-context code I read. I did not read the docs and fixture prose and the generated shipped-context tree, and I ran no tests.

Testing

Only a diagnostic structured-output call was made. No product scenario was driven, no commands were run, and no live validation was performed in this run.

  • Live validation: ⚠️ inconclusive - 0 of 1 scenarios driven live against the product
Scenario Result Live Evidence
Structured output schema diagnostic call ⏸️ untested no The prior payload only checked the structured output schema. It did not drive the product or the change, so no live result exists to report. Live validation of the guarded-update and MySQL persistence…
  • Outcome: ⚠️ 1 warning across 1 run (9m6s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 1 scenarios were driven live against the product); untested: Structured output schema diagnostic call
  • Live validation: ⚠️ inconclusive - 0 of 1 scenarios driven live against the product
Scenario Result Live Evidence
Structured output schema diagnostic call ⏸️ untested no The prior payload only checked the structured output schema. It did not drive the product or the change, so no live result exists to report. Live validation of the guarded-update and MySQL persistence…
  • scripts/ci-local.sh --affected --strict-toolchains
  • diagnostic call only
🔧 **Document** - 1 issue found → auto-fixed ✅
  • ⚠️ agent-context/templates/always-on.md.mustache:14 - The always-on agent file says 'Java, Kotlin, C# and Python projects need Node too' and omits Rust, which this branch adds as an agent-context server language (agent-context/servers/rust.meta.json). The same sentence is asserted in server/typescript/packages/sdk/test/agent-context/assemble.test.ts:128 and baked into fixtures/agent-context-conformance/*/expected and agent-context-shipped/. It is runtime-loaded agent prompt text, so I did not reword it. Fix: add Rust to the template sentence, update the assemble test, and rebuild the shipped tree and the expected fixtures.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

rulesNamesFile() writes one rules.names.ts per metadata package that
declares a lifecycle or an operation (ADR-0067 layer 0): each lifecycle's
states, initial and terminal states and transitions, the commands derived
from unclaimed transitions, the declared operations, the permissions they
ask about and the business errors, as as-const values and literal unions.

The names come from the derivations meta verify's rules gate checks, now
shared in metadata (core/transition/commands.ts) and read by both the
gate and the generator's engine walk (codegen-ts rules-walk.ts). The
generator is ejectable, TypeScript-only for now, and silent for a model
without the rules vocabulary.
…nce scenario (L-TS-3)

ObjectManager.guardedUpdate makes a lifecycle transition's write in one
statement: UPDATE ... SET state = :to WHERE key = :id AND state IN (:from)
[AND condition]. The condition grammar is attr.expression's CHECK subset,
compiled to new not/compare/nullTest WhereClause kinds on all three bundled
drivers; the in-memory driver follows SQL three-valued logic.

fixtures/persistence-conformance/queries/guarded-update.yaml holds every
store driver to it. TypeScript runs it; Java, Kotlin, C# and Python defer
it to their own rules-layer rows.
contractTypes() writes ADR-0067's contract types layer: the shapes a
caller and a service exchange, with no persistence mapping in them.
Every module imports zod only.

- <Entity>.contract.ts: the read schema and type, the create and
  update schemas, and the typed create and patch inputs.
- <Projection>.contract.ts: the read shape.
- The value modules those shapes reach, byte-identical to the entity
  generator's, so the two collapse into one file when both run.
- <pkg>/operations.contract.ts: each declared operation's input,
  output and business errors.
- errors.contract.ts: the shell and contract wire codes, their HTTP
  statuses, and the error bodies.

The field schemas come from the entity generator's own renderers, and
the tests hold each entity's contract read type equal to the entity
file's on postgres, sqlite and mysql. Two exceptions are named in the
test: a TPH base, and a physical-only jsonb column.

What it covers is the engine walk (contract-walk.ts), so the generator
is ejectable. It is TypeScript-only for now, and it moves no existing
generator's output.
…fixtures sum

L-TS-3 added a persistence scenario and moved the table's persistence row to 68, but the
prose sum under "Orphaned fixtures" still said 67, which the site counts gate refuses.
… as a server language (G1)

The assembler now also runs at build time, once per stack a port's own agent-docs command
serves: each server language alone and Java with Kotlin, each with no client, React, React with
TanStack or Angular (28 stacks). The result is committed at agent-context-shipped/: a manifest
listing each stack's files by project path, and each distinct file once under files/, named by
its content hash (101 files, about 1.1 MB). A port's package embeds the tree; its command finds
the stack by id, pins the guide links to its release tag with one text replacement, and writes
the files, so a C#, JVM, Python or Rust project needs no Node for them (1.3.0 design call 17,
ADR-0033 Amendment 1). agent-context-shipped/README.md is the contract.

- sdk: buildShippedAgentContext(), materializeShippedStack(), shippedStackId() and
  shippedTreeFiles(), and scripts/build-shipped-agent-context.ts (writes only changed bytes;
  --check exits 1 naming each stale file).
- shipped.test.ts: the committed tree is byte-for-byte what the build writes; every stack,
  materialized as a port would, equals assemble() for it with the release ref; the shared
  agent-context-conformance goldens come out of the tree unchanged; an unshipped stack is
  refused, naming the shipped ones.
- Rust: SERVER_LANGS gains rust; `--server rust` (alias rs) is accepted and a root Cargo.toml
  detects it; servers/rust.meta.json and templates/loops/rust.md give the cargo meta gen loop
  and the cargo meta verify step; a rust case joins fixtures/agent-context-conformance.
  Libraries now list Rust among their ports, and the manifest gate checks the copy Rust's
  build.rs embeds (server/rust/metaobjects/data/library).
- The lane map routes agent-context-shipped/ to every lane.
…ter rebasing onto #633

#633 shipped C#'s own rules-names and contract-types while this branch shipped TypeScript's,
each saying its port was the only one. The registry keeps one entry per name, listing both
ports; the README, business-rules.md and the CHANGELOG say what each port writes.
…or] / filter[and] combinators (R0)

The list-query contract (ADR-0068) made search and the combinators cross-port, but openapi.json
still listed only the per-field filter parameters. The integration check exempted those names
so it would not refuse them.

- search: offered when the row has a field the runtime searches. That is a @filterable text rule
  with like in its band and no format (isSearchField, which mirrors runtime-ts searchFields). The
  description names those fields.
- filter[or] and filter[and]: one deepObject parameter each, offered when the list has any
  filter. A branch nests, which a parameter schema cannot spell, so the description gives the
  grammar and the five-level cap.
- 400 invalid_id is now listed on item GET and DELETE. The routes already answered it, and the
  list-query lane found the gap as soon as the document checked it.

A new contract case, list-query, documents the list-query model. The list-query lane runs
openApiCheck like the other generated lanes. The check now accepts a key under a deepObject
parameter, and takes the names a scenario sends to show they are ignored (the cb cache-buster),
in place of the blanket exemption. contract-behaviours holds the document to runtime-ts's own
parser:
- the searched fields equal searchFields over the generated allowlist;
- the combinator grammar parses to the stated depth and fails one level past it;
- a list with no filter offers neither.
Goldens regenerated. The CONFORMANCE.md count of contract cases is recounted from disk: 22, which
was already stale at 19 on main.
…n after rebasing onto main

The audit skill's calibration and capability-checklist references changed on main (#634),
after G1 built agent-context-shipped/ and added the rust agent-context case. The rebuilt tree
and the rust golden take that text; the other five cases already had it.
The TypeScript runner maps an entity row's timestamp from MySQL's naive
DATETIME text onto the corpus' wire form, and applies the engine mapping
to single-row results (get, create, update, roundtrip) as well as lists.
Python's per-engine skip now honours the port-wide EXPECTED_FAILURES, so
the deferral of guarded-update to L-PY-2 holds on MySQL too.
@dmealing
dmealing merged commit 3ba0b3a into main Nov 22, 2026
10 checks passed
@dmealing
dmealing deleted the fm/mo-130-lane-ts-2-b3 branch November 22, 2026 06:06
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.

1 participant