Repository navigation
feat(cedar): scaffold + serializer — the lexicon exists (#1649) - #1656
Conversation
`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
|
CI caught a real gap in this PR: the completeness contract failed on The fixOne line in each of the two # 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
Two notes on scope:
Clean-state proofThe packaging path never needed generated artifacts — Re-verified
|
Part of #1645 (cedar lexicon epic). Closes #1649.
chant init lexicon cedarproduced 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. Namecedar, rulePrefixCED.src/serializer.test.ts— the 12-case checklist from the serializer guide plus cedar-specific cases (forbid withunless, annotations and their escaping, the JSON file, entity-UID parsing). 29 tests.src/plugin.test.ts— plugin shape: validLexiconPlugin, name, the serializer it exposes, the lifecycle methods core dispatches through, LSP providers, and that every lint rule id sits underCED.src/codegen/package.ts+src/package-cli.ts— packaging through core'spackagePipeline, with a manifest carryingname/version/chantVersion.npm run bundlewrites a realdist/manifest.json.package.json— routesexports["."].defaultat./src/index.tsand deletes emitted JS inbuild, copied fromlexicons/docker/package.json. Tier 1 checks both.generate(),validate()andcoverage()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:effect"permit"or"forbid"; defaults topermitprincipal,action,resource{}for any, or{ eq },{ in }(string or array),{ is }(optionally within)when,unlessannotationsRecord<string, string>, emitted as@key("value")Policy id comes from the export's logical name (
allowAdminRead→allow-admin-read) unlessannotations.idsets one.Output
Canonical
.cedarpolicy text is the primary output; the Cedar JSON policy set lands beside it aspolicies.cedar.jsonviaSerializerResult.files. 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 the JSON format, and the model carries expression text until #1650 makes them typed, so they go out under Cedar's own
__exprescape rather than a private key. Property names pass through verbatim; references resolve throughwalkValue+ aSerializerVisitorover a reverseDeclarable→ 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.postSynthChecks() returns at least 1 checkcedar-wasmand span policies and the resources they govern; both need #1650's typed classesEvery shipped example buildsexamples/getting-startedis stillchant init lexicon's placeholder; a policy set can only be authored against schema-derived classesnpx tsx scripts/check-lexicons.tsexits 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 rootpackage.jsondependency list.packages/core/src/codegen/lexicon-wiring.test.tsasserts 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 (droppingprivate, adding the entry) would makescripts/publish-packages.shpick cedar up on the nextjust release, and a package with no npm trusted-publisher record publishes as a bareENEEDAUTH— the exact failure that stranded@intentius/chant-k8s-clientand@intentius/chant-lexicon-fountainand turned the release pipeline red for days. Publishing onboarding is #1655, which flipsprivate, adds the root dependency, and patchespublish.ymland both smoke Dockerfiles together.lexicons/cedaris still resolvable everywhere via theworkspaces: ["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.tsprints an INFO line asking for exactly that to be deleted.src/codegen/generate-cli.tsreports the unimplemented state and exits 0.just _ensure-genrunsnpm run generatefor every lexicon that declares one before the bundle step, underset -e. Letting the stub's throw escape takesjust check-lexiconsdown 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 ispackages/*andlexicons/*only — andlexicon-wiring.test.tsdoes not look at examples.Minor additions the scaffold missed:
src/codegen/docs-cli.ts(the generatedpackage.jsonreferenced a filechant init lexiconnever wrote) andtest/bundlerecipes in the justfile.Verification
npx tsc --noEmit -p lexicons/cedar/tsconfig.build.json— cleannpx vitest run lexicons/cedar— 37 tests across 4 files, all passingnpm run build -w @intentius/chant-lexicon-cedar— cleannpx tsx scripts/check-lexicons.ts— exit 0, only the two tracked entriesnpx vitest run packages/core/src/codegen/lexicon-wiring.test.ts— passingnpx eslint packages/— no new findings🤖 Generated with Claude Code
https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ