Skip to content

feat(cedar): scaffold + serializer — the lexicon exists (#1649) - #1656

Merged
lex00 merged 2 commits into
mainfrom
cedar/scaffold-serializer
Aug 10, 2026
Merged

lex00 merged 2 commits into
mainfrom
cedar/scaffold-serializer

Conversation

@lex00

@lex00 lex00 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Part of #1645 (cedar lexicon epic). Closes #1649.

chant init lexicon cedar produced the tree; this replaces the stubs that #1649 owns and leaves the rest for the sub-issues that own them.

Scope

  • src/serializer.ts — the real serializer, replacing the scaffold's JSON placeholder. Name cedar, rulePrefix CED.
  • src/serializer.test.ts — the 12-case checklist from the serializer guide plus cedar-specific cases (forbid with unless, annotations and their escaping, the JSON file, entity-UID parsing). 29 tests.
  • src/plugin.test.ts — plugin shape: valid LexiconPlugin, name, the serializer it exposes, the lifecycle methods core dispatches through, LSP providers, and that every lint rule id sits under CED.
  • src/codegen/package.ts + src/package-cli.ts — packaging through core's packagePipeline, with a manifest carrying name/version/chantVersion. npm run bundle writes a real dist/manifest.json.
  • package.json — routes exports["."].default at ./src/index.ts and deletes emitted JS in build, copied from lexicons/docker/package.json. Tier 1 checks both.

generate(), validate() and coverage() stay the scaffold's compiling TODO stubs — they are #1650 and #1651.

The policy entity model

Pre-codegen, one entity type carries a policy. Schema-driven generate() (#1650) emits typed entity and action classes onto this same shape, so the serializer does not change when it lands.

entityType: "Cedar::Policy", with props:

Prop Meaning
effect "permit" or "forbid"; defaults to permit
principal, action, resource scope constraints — {} for any, or { eq }, { in } (string or array), { is } (optionally with in)
when, unless Cedar expression strings, one clause each
annotations Record<string, string>, emitted as @key("value")

Policy id comes from the export's logical name (allowAdminRead → allow-admin-read) unless annotations.id sets one.

Output

Canonical .cedar policy text is the primary output; the Cedar JSON policy set lands beside it as policies.cedar.json via SerializerResult.files. The JSON is built from the same structured model rather than by re-parsing the text, because #1653 reads it back for import.

@id("deny-unless-mfa")
forbid (
  principal is User in Group::"contractors",
  action in [Action::"delete", Action::"purge"],
  resource
)
when { resource.classification == "restricted" }
unless { context.mfaAuthenticated };

Condition bodies are expression ASTs in the JSON format, and the model carries expression text until #1650 makes them typed, so they go out under Cedar's own __expr escape rather than a private key. Property names pass through verbatim; references resolve through walkValue + a SerializerVisitor over a reverse Declarable → logical-name map built before the walk.

KNOWN_FAILURES

Two tier-1 checks fail for cedar, both belonging to named open sub-issues after this one. Nothing this PR delivers is allowlisted — the plugin export, serializer, rule prefix, manifest, chantVersion, packaging shape, plugin/serializer tests and docs reachability all pass unallowlisted.

Check Entry
postSynthChecks() returns at least 1 check #1651 (cedar 4/8) — the checks worth writing run policies through cedar-wasm and span policies and the resources they govern; both need #1650's typed classes
Every shipped example builds #1650 (cedar 3/8) — examples/getting-started is still chant init lexicon's placeholder; a policy set can only be authored against schema-derived classes

npx tsx scripts/check-lexicons.ts exits 0: cedar at 19/21, every other lexicon 21/21, no untracked failures.

Deviations from the issue

The lexicon stays private: true, and is not added to the root package.json dependency list. packages/core/src/codegen/lexicon-wiring.test.ts asserts the root dependency list equals the set of publishable lexicons — private !== true — so listing a private lexicon there fails it, and the test passes as-is. Going the other way (dropping private, adding the entry) would make scripts/publish-packages.sh pick cedar up on the next just release, and a package with no npm trusted-publisher record publishes as a bare ENEEDAUTH — the exact failure that stranded @intentius/chant-k8s-client and @intentius/chant-lexicon-fountain and turned the release pipeline red for days. Publishing onboarding is #1655, which flips private, adds the root dependency, and patches publish.yml and both smoke Dockerfiles together. lexicons/cedar is still resolvable everywhere via the workspaces: ["lexicons/*"] glob.

Only two KNOWN_FAILURES entries, not three. The LSP/docs/skills tier-1 surface (#1654) already passes on the scaffold — completion and hover providers are registered, the docs site has a reachable page — so an entry for it would be a stale one, and check-lexicons.ts prints an INFO line asking for exactly that to be deleted.

src/codegen/generate-cli.ts reports the unimplemented state and exits 0. just _ensure-gen runs npm run generate for every lexicon that declares one before the bundle step, under set -e. Letting the stub's throw escape takes just check-lexicons down entirely for a phase that has not shipped. generate() itself is untouched and still throws; #1650 makes the catch unreachable.

Examples are not added to root workspaces. No lexicon's examples are — the glob is packages/* and lexicons/* only — and lexicon-wiring.test.ts does not look at examples.

Minor additions the scaffold missed: src/codegen/docs-cli.ts (the generated package.json referenced a file chant init lexicon never wrote) and test/bundle recipes in the justfile.

Verification

  • npx tsc --noEmit -p lexicons/cedar/tsconfig.build.json — clean
  • npx vitest run lexicons/cedar — 37 tests across 4 files, all passing
  • npm run build -w @intentius/chant-lexicon-cedar — clean
  • npx tsx scripts/check-lexicons.ts — exit 0, only the two tracked entries
  • npx vitest run packages/core/src/codegen/lexicon-wiring.test.ts — passing
  • npx eslint packages/ — no new findings

🤖 Generated with Claude Code

https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ

lex00 and others added 2 commits August 10, 2026 10:33
`chant init lexicon cedar` produced the tree; this replaces the stubs
that #1649 owns and leaves the rest to the sub-issues that own them.

The policy entity model is hand-shaped for now: one `Cedar::Policy`
entity whose props carry an effect, three scope constraints, optional
`when`/`unless` guards and annotations. Schema-driven codegen (#1650)
generates typed entity and action classes onto exactly this shape, so
the serializer does not change when it lands.

Canonical `.cedar` policy text is the primary output; the Cedar JSON
policy set lands beside it as `policies.cedar.json`. The JSON is built
from the same structured model rather than by re-parsing the text,
because #1653 reads it back for import. Condition bodies are expression
ASTs in that format and the model carries expression text until #1650
makes them typed, so they go out under Cedar's own `__expr` escape.

Two tier-1 checks are tracked in KNOWN_FAILURES rather than fixed here —
`postSynthChecks()` (#1651) and "every shipped example builds" (#1650) —
both belonging to named open sub-issues. Nothing #1649 delivers is
allowlisted.

The lexicon stays `private: true` and is absent from the root dependency
list: `lexicon-wiring.test.ts` equates that list with the *publishable*
lexicons, and dropping `private` would have `publish-packages.sh` pick
cedar up on the next `just release` with no npm trusted-publisher record
behind it. Publishing onboarding is #1655.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ
`dist/` is gitignored, so a clean CI checkout has no
`lexicons/cedar/dist/manifest.json` and the completeness contract failed
two tier-1 checks that pass locally. Every other lexicon avoids this by
having its `prepack` run in chant.yml's "Generate lexicon artifacts"
step; cedar was missing from both copies of that list.

The packaging path itself needed no change — `packageLexicon` already
falls back to an empty registry when the `generate()` stub throws, so a
clean tree produces a valid manifest.

The test job's copy is not load-bearing today (the full suite passes
with `lexicons/cedar/dist` removed), but both blocks list every lexicon,
and an entry present in one copy and absent from the other is how three
lexicons drifted out of the root dependency list. publish.yml and the
smoke Dockerfiles stay untouched — that is #1655, and cedar is private
until then.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ
@lex00

lex00 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

CI caught a real gap in this PR: the completeness contract failed on dist/manifest.json exists and dist/manifest.json declares a chantVersion. dist/ is gitignored, I had built it locally, and CI runs a clean checkout. Every other lexicon passes because .github/workflows/chant.yml runs its prepack before the gate.

The fix

One line in each of the two Generate lexicon artifacts blocks in chant.yml — the check job (which runs scripts/check-lexicons.ts) and the test job:

# cedar's prepack is bundle + build, with no generate step — its
# codegen input is the user's own schema and lands in #1650 (#1649).
npm run --prefix lexicons/cedar prepack

publish.yml, test/Dockerfile.smoke and test/Dockerfile.smoke-npm stay untouched — that is #1655's onboarding, and cedar is still private: true so publish-packages.sh skips it either way.

Two notes on scope:

  • The test job line is not load-bearing today. I removed lexicons/cedar/dist and ran the full suite: 928 files, 11378 passing, nothing reaches cedar's dist/meta.json yet. It is there because both blocks list every lexicon, and a list where one entry appears in one copy and not the other is how fly/forgejo/fountain drifted out of the root dependency list in the first place.
  • The validate job is deliberately skipped. Its steps are named "Generate and validate <lexicon>", and cedar's prepack is bundle && build with no validate — validate() needs the generated registry from cedar 3/8: schema-driven generate() + configSchema #1650. A step there would claim work that does not happen.

Clean-state proof

$ rm -rf lexicons/cedar/dist lexicons/cedar/src/generated
$ npm run --prefix lexicons/cedar prepack

> @intentius/chant-lexicon-cedar@0.44.7 bundle
> tsx src/package-cli.ts
Running generation pipeline...
Fetching schemas...
cedar generate() is not implemented yet (#1650) — packaging an empty registry: TODO: implement fetchSchemas — download your upstream spec
Building manifest...
Package assembled: 1 rules, 0 skills
dist/ written to lexicons/cedar/dist

> @intentius/chant-lexicon-cedar@0.44.7 build
> tsc -p tsconfig.build.json && tsc-alias ... && find dist ... -delete

$ cat lexicons/cedar/dist/manifest.json
{
  "name": "cedar",
  "version": "0.44.7",
  "chantVersion": ">=0.1.0",
  "namespace": "Cedar",
  "intrinsics": [],
  "pseudoParameters": {}
}

The packaging path never needed generated artifacts — packageLexicon already falls back to an empty registry when the generate() stub throws, which is why this produces a valid manifest from a clean tree with no code change.

Re-verified

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.

cedar 2/8: scaffold + serializer

1 participant