Skip to content

feat(cedar): dogwood temporal dialect — typed builders, .dw serialization, event schemas (#1658) - #1672

Merged
lex00 merged 1 commit into
mainfrom
dogwood/dialect
Aug 10, 2026
Merged

lex00 merged 1 commit into
mainfrom
dogwood/dialect

Conversation

@lex00

@lex00 lex00 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1658. Part of epic #1646.

Rebased onto chant-v0.44.8 (65ecd4c) — the hold is lifted and this is ready for review. It sits on top of #1667, #1668 and #1669; the reconciliation notes are at the bottom.

What this is

The dogwood surface, inside lexicons/cedar under extraRulePrefixes: ["DWD"]. New code lives in src/dogwood/; the touches elsewhere are the serializer hook, the audit-catalog entries, the regenerated post-synth barrel, and one shared-helper extraction.

Built against the corrections on #1646 and the empirical report on #1657, re-verified against upstream at the pinned revision (the three .pest grammars, default_macros.dw, pinned.dwschema and four example bundles were read directly while writing this, not recalled).

Surface

Typed temporal builders (src/dogwood/temporal.ts) targeting the parser primitives, which is the whole point of the correction: formerly, previous, since (window mandatory, units s|m|h|d), exists, tp(), count for … where, sum … for … where, plus predicates, comparisons, &&, !, and the term forms. count_within, sum_within and count_distinct_within are macro calls (dogwood.countWithin(…)), never operators — a caller passing --macros replaces the default library wholesale, so a first-class builder for them would emit a name that may not exist at the far end. dogwood.defaultMacroLibrary() emits upstream's four definitions so a project can stop assuming.

The renderer parenthesises rather than trusting the reader to know the grammar: an && chain in atom position, a since on the left of another since, an exists inside a conjunction (it binds maximally right), an aggregate in comparison position (its where body is greedy). Each has a test naming the rule it protects.

def-macro authoring (src/dogwood/macros.ts) for both def cedar and def temporal, with ?param and $binder validated at definition time — upstream's well-formedness pass rejects sigils outside a macro body, so macroWindow/macroCondition/macroTerm are the three positions they legally appear in.

Dogwood::TemporalPolicy (src/dogwood/policy.ts) — Cedar::Policy's props plus whenTemporal/unlessTemporal and whenGuardrails/unlessGuardrails, matching upstream's cond rule. Also Dogwood::EventSchema and Dogwood::MacroLibrary.

The .dw serializer leg runs inside the cedar serializer and emits policies.dw, events.dwschema and macros.dw alongside the cedar outputs when the build holds temporal entities; a cedar-only build is byte-identical to before. The policy head, scope forms and when/unless bodies come from a new src/policy-text.ts that every renderer imports — extracted, not duplicated, so a change to how a scope constraint is written moves all three.

Event schemas (src/dogwood/event-schema.ts) typed against the 136-line .dwschema grammar: the max_window directive, [decision] event <A>::kind { … }, ...inputs(A)/...outputs(A) spreads, selector/record/concrete field types, and pin … = principal|resource|context.<path>. defaultEventSchema() carries pin callerPrincipal = principal; opting out takes { pinCallerPrincipal: false }, which also stamps the reasoning into the emitted file — supplying any schema opts out of upstream's default wholesale, so an unpinned schema widens every predicate in the set.

Walls

Four DWD checks, auto-discovered, catalogued, none of them shelling to anything:

id severity what
DWDC010 error a temporal predicate names an event kind the emitted .dwschema never declares
DWDC011 error a window past the schema's max_window, or upstream's 24h default when there is none
DWDC012 error formerly/previous/since with no within
DWDS010 warning an emitted event schema that pins nothing

DWDC012 is unrepresentable through the builders — the window is a required argument — and the check reads the serialized text anyway, because raw() exists, a .dw can come from any other tool, and chant audit runs over files chant never wrote.

Deviations, called out

DWDC010 checks the event kind, not the action. The issue asks for "an event kind or action absent from the emitted event schema", but the .dwschema grammar declares events against a symbolic action binder (decision event <A>::request) and names no actions at all — there is nothing in the file to check an action against. The action half of upstream's error comes from the Cedar action schema via --policy-schema, which is #1659's CLI-gated leg. Implementing a .cedarschema scan here would have been dead code with no emitter behind it.

DWDS010 is a fourth check the issue did not list. It is how "emitting a schema that opts out of the pin must be a deliberate, documented choice" becomes visible in a build rather than only in the source.

src/policy-text.ts is a new file outside src/dogwood/. The issue asked to extract shared helpers rather than duplicate; keeping them in serializer.ts and importing them from the dialect would have made a module cycle. serializer.ts re-exports everything it used to export, so no caller changes.

Filenames are policies.dw / events.dwschema / macros.dw, plural to match policies.cedar.json; upstream's examples use the singular. Both are overridable per entity.

Rebase notes (post-0.44.8)

Gates

  • tsc -p lexicons/cedar/tsconfig.build.json — clean
  • npm run build -w @intentius/chant-lexicon-cedar — clean
  • npx vitest run lexicons/cedar — 498 passed / 31 files (was 456 / 26 on main)
  • npx vitest run packages/core — 4242 passed / 288 files, including the audit-catalog coverage tests that now see the four DWD entries
  • npx tsx scripts/check-lexicons.ts — cedar 21/21 tier-1, including the rule-prefix check that the DWD family exists to satisfy
  • npx tsx scripts/typecheck.ts — 85 known failures, no regressions
  • node scripts/depcheck.mjs — no undeclared runtime dependencies

Nothing in gating CI executes the dogwood binary, per the epic.

Not in scope

CLI-gated full validation and the wasm check of the non-temporal body (#1659), the AgentCore embedding (#1660), PolicyReplayOp (#1661), and the docs page in the cedar sidebar (#1662) — the README gains a section saying the dialect exists and is pre-release, and no more. #1677 stacks on this.

Attribution

Fixtures under src/dogwood/testdata/ are adapted from dogwood-policy/dogwood (Apache-2.0) at 5063bcc2d6d6cf5024d1b0498e6cc8ef52cbcf0c; each file names its upstream source in a header comment. The pin and its narrow content hashes are recorded in src/dogwood/upstream.ts.

🤖 Generated with Claude Code

https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ

…tion, event schemas (#1658)

Dogwood ships as a dialect inside the cedar lexicon under
extraRulePrefixes: ["DWD"], not as a sibling lexicon: a .dw file stripped of
Cedar semantics is meaningless, and a .dw policy's head is a Cedar policy's
head byte for byte.

The builders target the parser primitives, per the correction on #1646 and the
count for … where and sum … for … where are the only temporal keywords in
upstream's grammar; count_within, sum_within and count_distinct_within are
macros in a default library a --macros flag replaces wholesale, so they are
expressible as calls and never as operators. def-macro authoring covers both
kinds and both sigils.

The .dw leg runs inside the cedar serializer and shares its rendering through
a new src/policy-text.ts rather than a copy. Event schemas are typed against
upstream's 136-line .dwschema grammar, with the callerPrincipal pin on by
default — dropping it takes a named argument and stamps its reasoning into
the file.

Four DWD walls, all answerable without the dogwood binary: an undeclared event
kind (DWDC010), a window past max_window or the 24h default (DWDC011), a
windowless past-only operator (DWDC012, which the builders already make
unrepresentable), and an event schema that pins nothing (DWDS010, report-only).
Nothing here shells to the CLI; that is #1659's.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018FAMfgpQTVDnsnqJzyHasZ
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.

dogwood 2/6: dialect surface

1 participant