@intentius/chant-lexicon-cedar 0.44.8 → 0.44.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +106 -2
  2. package/dist/agentcore/embed.d.ts +189 -0
  3. package/dist/agentcore/embed.d.ts.map +1 -0
  4. package/dist/agentcore/enforcement.d.ts +76 -0
  5. package/dist/agentcore/enforcement.d.ts.map +1 -0
  6. package/dist/agentcore/scan.d.ts +46 -0
  7. package/dist/agentcore/scan.d.ts.map +1 -0
  8. package/dist/codegen/docs-dogwood.d.ts +21 -0
  9. package/dist/codegen/docs-dogwood.d.ts.map +1 -0
  10. package/dist/codegen/docs.d.ts.map +1 -1
  11. package/dist/codegen/package.d.ts.map +1 -1
  12. package/dist/config.d.ts +25 -0
  13. package/dist/config.d.ts.map +1 -1
  14. package/dist/dogwood/cli.d.ts +247 -0
  15. package/dist/dogwood/cli.d.ts.map +1 -0
  16. package/dist/dogwood/event-schema.d.ts +161 -0
  17. package/dist/dogwood/event-schema.d.ts.map +1 -0
  18. package/dist/dogwood/index.d.ts +39 -0
  19. package/dist/dogwood/index.d.ts.map +1 -0
  20. package/dist/dogwood/macros.d.ts +96 -0
  21. package/dist/dogwood/macros.d.ts.map +1 -0
  22. package/dist/dogwood/policy.d.ts +120 -0
  23. package/dist/dogwood/policy.d.ts.map +1 -0
  24. package/dist/dogwood/replay-activity.d.ts +196 -0
  25. package/dist/dogwood/replay-activity.d.ts.map +1 -0
  26. package/dist/dogwood/replay-op.d.ts +165 -0
  27. package/dist/dogwood/replay-op.d.ts.map +1 -0
  28. package/dist/dogwood/scan.d.ts +109 -0
  29. package/dist/dogwood/scan.d.ts.map +1 -0
  30. package/dist/dogwood/serialize.d.ts +66 -0
  31. package/dist/dogwood/serialize.d.ts.map +1 -0
  32. package/dist/dogwood/temporal.d.ts +259 -0
  33. package/dist/dogwood/temporal.d.ts.map +1 -0
  34. package/dist/dogwood/trace.d.ts +215 -0
  35. package/dist/dogwood/trace.d.ts.map +1 -0
  36. package/dist/dogwood/upstream.d.ts +41 -0
  37. package/dist/dogwood/upstream.d.ts.map +1 -0
  38. package/dist/dogwood/window.d.ts +73 -0
  39. package/dist/dogwood/window.d.ts.map +1 -0
  40. package/dist/index.d.ts +12 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/integrity.json +15 -3
  43. package/dist/lint/audit-catalog.d.ts.map +1 -1
  44. package/dist/lint/post-synth/dogwood-helpers.d.ts +63 -0
  45. package/dist/lint/post-synth/dogwood-helpers.d.ts.map +1 -0
  46. package/dist/lint/post-synth/dwdc010.d.ts +25 -0
  47. package/dist/lint/post-synth/dwdc010.d.ts.map +1 -0
  48. package/dist/lint/post-synth/dwdc011.d.ts +19 -0
  49. package/dist/lint/post-synth/dwdc011.d.ts.map +1 -0
  50. package/dist/lint/post-synth/dwdc012.d.ts +21 -0
  51. package/dist/lint/post-synth/dwdc012.d.ts.map +1 -0
  52. package/dist/lint/post-synth/dwdc013.d.ts +33 -0
  53. package/dist/lint/post-synth/dwdc013.d.ts.map +1 -0
  54. package/dist/lint/post-synth/dwde010.d.ts +32 -0
  55. package/dist/lint/post-synth/dwde010.d.ts.map +1 -0
  56. package/dist/lint/post-synth/dwde011.d.ts +33 -0
  57. package/dist/lint/post-synth/dwde011.d.ts.map +1 -0
  58. package/dist/lint/post-synth/dwds010.d.ts +24 -0
  59. package/dist/lint/post-synth/dwds010.d.ts.map +1 -0
  60. package/dist/lint/post-synth/index.d.ts.map +1 -1
  61. package/dist/manifest.json +1 -1
  62. package/dist/okf/index.md +7 -0
  63. package/dist/okf/rules/DWDC010.md +11 -0
  64. package/dist/okf/rules/DWDC011.md +11 -0
  65. package/dist/okf/rules/DWDC012.md +11 -0
  66. package/dist/okf/rules/DWDC013.md +15 -0
  67. package/dist/okf/rules/DWDE010.md +11 -0
  68. package/dist/okf/rules/DWDE011.md +11 -0
  69. package/dist/okf/rules/DWDS010.md +11 -0
  70. package/dist/okf/types/Policy.md +1 -0
  71. package/dist/op/activities/index.d.ts +18 -0
  72. package/dist/op/activities/index.d.ts.map +1 -0
  73. package/dist/plugin.d.ts.map +1 -1
  74. package/dist/policy-text.d.ts +53 -0
  75. package/dist/policy-text.d.ts.map +1 -0
  76. package/dist/rules/dogwood-helpers.ts +139 -0
  77. package/dist/rules/dwdc010.ts +62 -0
  78. package/dist/rules/dwdc011.ts +61 -0
  79. package/dist/rules/dwdc012.ts +46 -0
  80. package/dist/rules/dwdc013.ts +64 -0
  81. package/dist/rules/dwde010.ts +130 -0
  82. package/dist/rules/dwde011.ts +108 -0
  83. package/dist/rules/dwds010.ts +46 -0
  84. package/dist/serializer.d.ts +10 -18
  85. package/dist/serializer.d.ts.map +1 -1
  86. package/dist/skills/chant-cedar-authoring.md +180 -0
  87. package/dist/skills/chant-cedar-avp-embedding.md +125 -0
  88. package/dist/skills/chant-cedar-dogwood.md +327 -0
  89. package/dist/skills/chant-cedar-meta-policy.md +119 -0
  90. package/package.json +7 -2
  91. package/src/agentcore/embed.test.ts +254 -0
  92. package/src/agentcore/embed.ts +399 -0
  93. package/src/agentcore/enforcement.test.ts +43 -0
  94. package/src/agentcore/enforcement.ts +92 -0
  95. package/src/agentcore/scan.ts +119 -0
  96. package/src/codegen/docs-dogwood.ts +1119 -0
  97. package/src/codegen/docs.ts +66 -1
  98. package/src/codegen/package.ts +3 -2
  99. package/src/config.test.ts +12 -0
  100. package/src/config.ts +28 -0
  101. package/src/dogwood/cli.test.ts +513 -0
  102. package/src/dogwood/cli.ts +666 -0
  103. package/src/dogwood/event-schema.test.ts +218 -0
  104. package/src/dogwood/event-schema.ts +318 -0
  105. package/src/dogwood/index.ts +271 -0
  106. package/src/dogwood/macros.test.ts +104 -0
  107. package/src/dogwood/macros.ts +229 -0
  108. package/src/dogwood/policy.test.ts +94 -0
  109. package/src/dogwood/policy.ts +141 -0
  110. package/src/dogwood/replay-activity.test.ts +481 -0
  111. package/src/dogwood/replay-activity.ts +506 -0
  112. package/src/dogwood/replay-op.ts +242 -0
  113. package/src/dogwood/scan.ts +287 -0
  114. package/src/dogwood/serialize.test.ts +331 -0
  115. package/src/dogwood/serialize.ts +246 -0
  116. package/src/dogwood/temporal.test.ts +272 -0
  117. package/src/dogwood/temporal.ts +592 -0
  118. package/src/dogwood/testdata/custom-kinds.dwschema +17 -0
  119. package/src/dogwood/testdata/default-macros.dw +23 -0
  120. package/src/dogwood/testdata/lowered-read-after-login.json +13 -0
  121. package/src/dogwood/testdata/max-window-raised.dwschema +25 -0
  122. package/src/dogwood/testdata/pinned.dwschema +31 -0
  123. package/src/dogwood/testdata/read-after-login.cedarschema +20 -0
  124. package/src/dogwood/testdata/read-after-login.dw +17 -0
  125. package/src/dogwood/testdata/temporal-policies.dw +53 -0
  126. package/src/dogwood/trace.test.ts +231 -0
  127. package/src/dogwood/trace.ts +471 -0
  128. package/src/dogwood/upstream.ts +41 -0
  129. package/src/dogwood/window.ts +124 -0
  130. package/src/index.ts +76 -0
  131. package/src/lint/audit-catalog.ts +64 -0
  132. package/src/lint/post-synth/dogwood-helpers.ts +139 -0
  133. package/src/lint/post-synth/dwd-post-synth.test.ts +374 -0
  134. package/src/lint/post-synth/dwdc010.ts +62 -0
  135. package/src/lint/post-synth/dwdc011.ts +61 -0
  136. package/src/lint/post-synth/dwdc012.ts +46 -0
  137. package/src/lint/post-synth/dwdc013.ts +64 -0
  138. package/src/lint/post-synth/dwde-post-synth.test.ts +368 -0
  139. package/src/lint/post-synth/dwde010.ts +130 -0
  140. package/src/lint/post-synth/dwde011.ts +108 -0
  141. package/src/lint/post-synth/dwds010.ts +46 -0
  142. package/src/lint/post-synth/index.ts +14 -0
  143. package/src/lint/post-synth/post-synth.test.ts +7 -3
  144. package/src/op/activities/index.ts +27 -0
  145. package/src/plugin.test.ts +3 -2
  146. package/src/plugin.ts +30 -0
  147. package/src/policy-text.ts +128 -0
  148. package/src/serializer.ts +71 -109
  149. package/src/skills/chant-cedar-dogwood.md +327 -0
package/src/serializer.ts CHANGED
@@ -19,14 +19,28 @@
19
19
  * (#1650) generates typed classes onto exactly this shape, so nothing here
20
20
  * changes when it lands — the guards become typed expressions rather than
21
21
  * the opaque Cedar-expression strings they are today.
22
+ *
23
+ * A third view arrives when the build holds dogwood entities (#1658): `.dw`
24
+ * policy text and its `.dwschema`/`macros.dw` companions, rendered by
25
+ * `./dogwood/serialize.ts` and returned in the same result. Both legs share
26
+ * `./policy-text.ts` rather than a copy of it, because a `.dw` policy's head
27
+ * *is* a Cedar policy's head.
22
28
  */
23
29
 
24
30
  import type { Declarable } from "@intentius/chant/declarable";
25
- import { isPropertyDeclarable, isResourceDeclarable } from "@intentius/chant/declarable";
31
+ import { isPropertyDeclarable } from "@intentius/chant/declarable";
26
32
  import type { Serializer, SerializerResult } from "@intentius/chant/serializer";
27
33
  import type { LexiconOutput } from "@intentius/chant/lexicon-output";
28
34
  import { walkValue, type SerializerVisitor } from "@intentius/chant/serializer-walker";
29
35
  import { policyToJson, splitPolicySet, templateToJson, type PolicyJson } from "./spec/wasm";
36
+ import { serializeDogwood } from "./dogwood/serialize";
37
+ import {
38
+ conditionStrings,
39
+ getProps,
40
+ isRecord,
41
+ renderPolicyHead,
42
+ resolvePolicyId,
43
+ } from "./policy-text";
30
44
 
31
45
  // ── The policy entity model ───────────────────────────────────────
32
46
 
@@ -74,40 +88,22 @@ export interface CedarPolicyProps {
74
88
  }
75
89
 
76
90
  // ── Helpers ───────────────────────────────────────────────────────
77
-
78
- function isRecord(value: unknown): value is Record<string, unknown> {
79
- return typeof value === "object" && value !== null && !Array.isArray(value);
80
- }
81
-
82
- function getProps(entity: Declarable): Record<string, unknown> {
83
- if (isResourceDeclarable(entity) && isRecord(entity.props)) {
84
- return entity.props;
85
- }
86
- return {};
87
- }
88
-
89
- /** Escape a string for a double-quoted Cedar literal. */
90
- export function escapeCedarString(value: string): string {
91
- return value
92
- .replace(/\\/g, "\\\\")
93
- .replace(/"/g, '\\"')
94
- .replace(/\n/g, "\\n")
95
- .replace(/\r/g, "\\r")
96
- .replace(/\t/g, "\\t");
97
- }
98
-
99
- /**
100
- * Derive a policy id from a logical name: `allowAdminRead` → `allow-admin-read`.
101
- * Cedar ids are free-form strings; kebab-case keeps them readable in the
102
- * `@id` annotation and stable across a rename-free refactor.
103
- */
104
- export function policyIdFromLogicalName(name: string): string {
105
- return name
106
- .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
107
- .replace(/([A-Z]+)([A-Z][a-z])/g, "$1-$2")
108
- .replace(/[\s_]+/g, "-")
109
- .toLowerCase();
110
- }
91
+ //
92
+ // Rendering the dogwood dialect shares lives in `./policy-text.ts`, along with
93
+ // `resolvePolicyId` — the one rule linking a chant entity to a policy id, which
94
+ // #1652 extracted for the AVP observation and the `.dw` leg needs for the same
95
+ // reason. Re-exported here so this module stays the one import a caller needs.
96
+
97
+ export {
98
+ conditionStrings,
99
+ escapeCedarString,
100
+ getProps,
101
+ isRecord,
102
+ policyIdFromLogicalName,
103
+ renderPolicyHead,
104
+ renderScope,
105
+ resolvePolicyId,
106
+ } from "./policy-text";
111
107
 
112
108
  // ── Walker visitor ────────────────────────────────────────────────
113
109
 
@@ -131,33 +127,6 @@ const cedarVisitor: SerializerVisitor = {
131
127
 
132
128
  // ── Cedar policy text ─────────────────────────────────────────────
133
129
 
134
- function refText(value: unknown): string {
135
- return String(value);
136
- }
137
-
138
- /** `principal`, `principal == User::"alice"`, `action in [ … ]`, `resource is Photo`. */
139
- function renderScope(variable: string, scope: unknown): string {
140
- if (!isRecord(scope)) return variable;
141
-
142
- const parts = [variable];
143
- if (typeof scope.is === "string") parts.push(`is ${scope.is}`);
144
- if (scope.eq !== undefined) parts.push(`== ${refText(scope.eq)}`);
145
- if (scope.in !== undefined) {
146
- parts.push(
147
- Array.isArray(scope.in)
148
- ? `in [${scope.in.map(refText).join(", ")}]`
149
- : `in ${refText(scope.in)}`,
150
- );
151
- }
152
- return parts.join(" ");
153
- }
154
-
155
- function conditionStrings(value: unknown): string[] {
156
- if (value === undefined || value === null) return [];
157
- if (Array.isArray(value)) return value.map(refText);
158
- return [refText(value)];
159
- }
160
-
161
130
  /**
162
131
  * One policy, as `.cedar` text.
163
132
  *
@@ -165,24 +134,12 @@ function conditionStrings(value: unknown): string[] {
165
134
  * nothing else — `AWS::VerifiedPermissions::Policy` carries its policy as
166
135
  * `Definition.Static.Statement`, a single Cedar policy rather than a set. Two
167
136
  * renderers would be two dialects; there is one.
137
+ *
138
+ * The head comes from `renderPolicyHead`, which the dogwood dialect's `.dw`
139
+ * leg also calls: three surfaces, one rendering of an annotation and a scope.
168
140
  */
169
141
  export function renderPolicyText(id: string, props: Record<string, unknown>): string {
170
- const lines: string[] = [];
171
-
172
- // @id first, then the author's own annotations in declaration order.
173
- const annotations = isRecord(props.annotations) ? props.annotations : {};
174
- lines.push(`@id("${escapeCedarString(id)}")`);
175
- for (const [key, value] of Object.entries(annotations)) {
176
- if (key === "id" || value === undefined || value === null) continue;
177
- lines.push(`@${key}("${escapeCedarString(refText(value))}")`);
178
- }
179
-
180
- const effect = props.effect === "forbid" ? "forbid" : "permit";
181
- lines.push(`${effect} (`);
182
- lines.push(` ${renderScope("principal", props.principal)},`);
183
- lines.push(` ${renderScope("action", props.action)},`);
184
- lines.push(` ${renderScope("resource", props.resource)}`);
185
- lines.push(")");
142
+ const lines = renderPolicyHead(id, props);
186
143
 
187
144
  for (const clause of conditionStrings(props.when)) {
188
145
  lines.push(`when { ${clause} }`);
@@ -257,22 +214,6 @@ export interface CedarPolicyRecord {
257
214
  props: Record<string, unknown>;
258
215
  }
259
216
 
260
- /**
261
- * The Cedar id for a policy: an explicit `annotations.id` when the author gave
262
- * one, else derived from the logical name.
263
- *
264
- * This is the only rule that links a chant entity to a policy in a live AVP
265
- * store (#1652) — the observation resolves the same id from the same props and
266
- * matches it against the `@id` annotation the statement carries. Two copies of
267
- * this rule would be a mapping that drifts silently, so there is one.
268
- */
269
- export function resolvePolicyId(logicalName: string, props: Record<string, unknown>): string {
270
- const explicit = isRecord(props.annotations) ? props.annotations.id : undefined;
271
- return typeof explicit === "string" && explicit.length > 0
272
- ? explicit
273
- : policyIdFromLogicalName(logicalName);
274
- }
275
-
276
217
  /**
277
218
  * Every `Cedar::Policy` in a build, with references walked and ids resolved.
278
219
  *
@@ -304,6 +245,11 @@ export const cedarSerializer: Serializer = {
304
245
  name: "cedar",
305
246
  rulePrefix: "CED",
306
247
 
248
+ // The dogwood temporal dialect ships inside this lexicon (epic #1646): a
249
+ // `.dw` file stripped of Cedar semantics is meaningless, so its checks are
250
+ // this serializer's, under their own published id family.
251
+ extraRulePrefixes: ["DWD"],
252
+
307
253
  serialize(entities: Map<string, Declarable>, _outputs?: LexiconOutput[]): string | SerializerResult {
308
254
  const policyText: string[] = [];
309
255
 
@@ -311,25 +257,41 @@ export const cedarSerializer: Serializer = {
311
257
  policyText.push(renderPolicyText(id, props));
312
258
  }
313
259
 
314
- if (policyText.length === 0) return "";
315
-
316
- const primary = policyText.join("\n\n") + "\n";
317
- const { doc, error } = policySetJSON(primary);
318
-
319
- // A policy set Cedar cannot read is a real defect, but it is the lint and
320
- // post-synth surface's to report (#1651) — the text is still the artifact
321
- // every evaluator consumes, so it is emitted either way, with the module's
322
- // own message carried out as a build warning rather than swallowed.
323
- if (!doc) {
324
- return {
325
- primary,
326
- warnings: [`cedar: the emitted policy text did not parse, so ${CEDAR_JSON_FILENAME} was not written — ${error}`],
327
- };
260
+ // The dogwood dialect's own entities (#1658). Emitted from here rather
261
+ // than from a second serializer because they are one policy set with two
262
+ // halves — the `.dw` text and the `.cedar` text describe the same system,
263
+ // and a project holding only temporal policies still gets its files.
264
+ const dogwood = serializeDogwood(entities);
265
+
266
+ if (policyText.length === 0 && !dogwood) return "";
267
+
268
+ const files: Record<string, string> = {};
269
+ const warnings: string[] = [...(dogwood?.warnings ?? [])];
270
+ let primary = "";
271
+
272
+ if (policyText.length > 0) {
273
+ primary = policyText.join("\n\n") + "\n";
274
+ const { doc, error } = policySetJSON(primary);
275
+
276
+ // A policy set Cedar cannot read is a real defect, but it is the lint and
277
+ // post-synth surface's to report (#1651) — the text is still the artifact
278
+ // every evaluator consumes, so it is emitted either way, with the module's
279
+ // own message carried out as a build warning rather than swallowed.
280
+ if (doc) {
281
+ files[CEDAR_JSON_FILENAME] = JSON.stringify(doc, null, 2) + "\n";
282
+ } else {
283
+ warnings.push(
284
+ `cedar: the emitted policy text did not parse, so ${CEDAR_JSON_FILENAME} was not written — ${error}`,
285
+ );
286
+ }
328
287
  }
329
288
 
289
+ Object.assign(files, dogwood?.files ?? {});
290
+
330
291
  return {
331
292
  primary,
332
- files: { [CEDAR_JSON_FILENAME]: JSON.stringify(doc, null, 2) + "\n" },
293
+ ...(Object.keys(files).length > 0 ? { files } : {}),
294
+ ...(warnings.length > 0 ? { warnings } : {}),
333
295
  };
334
296
  },
335
297
  };
@@ -0,0 +1,327 @@
1
+ ---
2
+ skill: chant-cedar-dogwood
3
+ description: Author dogwood temporal policies with the cedar lexicon's typed builders — the parser primitives, the macro caveat, the validation split, AgentCore embedding, and replay
4
+ user-invocable: true
5
+ ---
6
+
7
+ # Temporal Policies with the Dogwood Dialect
8
+
9
+ ## Read this part first
10
+
11
+ Dogwood is pre-release, and the framing matters more than usual because it
12
+ changes what you should write.
13
+
14
+ Upstream (`dogwood-policy/dogwood`, Apache-2.0) says on its own README, in
15
+ bold, that it is **not intended for production use**. It is a reference
16
+ interpreter with enumerated gaps: no event timestamp validation, no event
17
+ authentication, no trace durability, unsandboxed Rhai in providers, no audit
18
+ logging, no multi-tenancy isolation, and an `http_get` provider with no SSRF
19
+ protection.
20
+
21
+ It also has no versioning story at all. Zero tags, zero releases, no changelog.
22
+ The crate reports `1.0.0` because it is published to an Amazon-internal
23
+ registry, and every future sync will also report `1.0.0`. The repository is a
24
+ read-only mirror: content arrives as squashed "Sync from internal source"
25
+ commits from a publish bot, against a repository nobody outside Amazon can see,
26
+ at a cadence of roughly one sync every three days over its public life.
27
+
28
+ chant pins a git SHA plus the blob hashes of seven files in
29
+ `src/dogwood/upstream.ts`. Do not tell a user this surface is stable. Do tell
30
+ them what is pinned and what a sync can move.
31
+
32
+ ## The one distinction to get right
33
+
34
+ **`formerly`, `previous`, `since`, `exists`, `tp()`, `count for … where` and
35
+ `sum … for … where` are the parser primitives.** They are the entire temporal
36
+ keyword set in upstream's grammar, and they are what the typed builders target.
37
+
38
+ **`count_within`, `sum_within`, `count_distinct_within` and `bind` are macros**
39
+ in a swappable default library (`configuration/default_macros.dw`). A caller
40
+ who passes `--macros` replaces that library wholesale, so a policy built on
41
+ them is built on an assumption about the far end.
42
+
43
+ **`once` does not ship at all.** It appears in upstream's examples as an
44
+ ordinary user-defined macro and is in no library. (The grammar rule behind
45
+ `formerly` is internally named `once_op`, which is where the confusion comes
46
+ from.) If a user asks for `once`, define it as a macro or use `formerly`
47
+ directly — do not emit a bare `once(…)` call and hope.
48
+
49
+ So: the four aggregates are expressible as **calls**
50
+ (`dogwood.countWithin(…)`), never as operators. A missing macro at the far end
51
+ is a comprehensible error. A builder that emits a name the callee's library
52
+ does not define is a mystery.
53
+
54
+ The way to stop assuming is to ship the definitions:
55
+
56
+ ```typescript
57
+ import { TemporalMacroLibrary, dogwood } from "@intentius/chant-lexicon-cedar";
58
+
59
+ // Upstream's four definitions, verbatim, into the project's own macros.dw.
60
+ export const macros = new TemporalMacroLibrary({ macros: dogwood.defaultMacroLibrary() });
61
+ ```
62
+
63
+ With `inline: true` they go at the top of `policies.dw` instead, and a policy
64
+ set's own `def` shadows a same-named library macro — the strongest form,
65
+ because the definitions travel with the policies.
66
+
67
+ ## Authoring
68
+
69
+ ```typescript
70
+ import { TemporalPolicy, TemporalEventSchema, dogwood } from "@intentius/chant-lexicon-cedar";
71
+
72
+ export const events = new TemporalEventSchema({ schema: dogwood.defaultEventSchema() });
73
+
74
+ export const readAfterLogin = new TemporalPolicy({
75
+ annotations: { id: "read_after_login" },
76
+ action: { eq: 'Drupe::Action::"Read"' },
77
+ whenTemporal: [
78
+ dogwood.formerly(
79
+ "1h",
80
+ dogwood.predicate('Drupe::Action::"Login"', "response", {
81
+ "input.user": dogwood.ctx("input.user"),
82
+ }),
83
+ ),
84
+ ],
85
+ });
86
+ ```
87
+
88
+ Emits:
89
+
90
+ ```
91
+ @id("read_after_login")
92
+ permit (
93
+ principal,
94
+ action == Drupe::Action::"Read",
95
+ resource
96
+ )
97
+ when temporal {
98
+ formerly within 1h Drupe::Action::"Login"::response{ input.user: context.input.user }
99
+ };
100
+ ```
101
+
102
+ ### Clause forms
103
+
104
+ | Prop | Emits |
105
+ |---|---|
106
+ | `when` / `unless` | `when { … }` — Cedar expression strings, same as `Cedar::Policy` |
107
+ | `whenGuardrails` / `unlessGuardrails` | `when guardrails { … }` — a Cedar expression with a tag upstream discards when lowering |
108
+ | `whenTemporal` / `unlessTemporal` | `when temporal { … }` — the temporal sub-language |
109
+
110
+ ### Windows
111
+
112
+ `formerly`, `previous` and `since` all take a mandatory window: an integer and
113
+ one of `s`, `m`, `h`, `d`. Nothing else parses. The builders take it as an
114
+ argument, so a windowless operator is unrepresentable — do not reach for
115
+ `dogwood.raw()` to work around a window you do not want, because there is no
116
+ such form.
117
+
118
+ Every operator is past-only. There is no future operator and no way to write
119
+ one. A user asking for "deny if X happens later" needs a different design.
120
+
121
+ ### Terms
122
+
123
+ Numbers and booleans lift. A bare string does not, on purpose: `"alice"` is a
124
+ Cedar string literal and `alice` is a binder reference, and guessing is how a
125
+ policy silently stops matching. Say which:
126
+
127
+ | Builder | Renders |
128
+ |---|---|
129
+ | `dogwood.str("alice")` | `"alice"` |
130
+ | `dogwood.varRef("a")` | `a` |
131
+ | `dogwood.ctx("input.user")` | `context.input.user` |
132
+ | `dogwood.scopeRef("principal", "dept")` | `principal.dept` |
133
+ | `dogwood.entityUid('Drupe::OAuthUser::"alice"')` | `Drupe::OAuthUser::"alice"` |
134
+
135
+ ### An aggregate, from the primitive
136
+
137
+ ```typescript
138
+ export const rateLimited = new TemporalPolicy({
139
+ annotations: { id: "rate_limited" },
140
+ action: { eq: 'Drupe::Action::"Transfer"' },
141
+ whenTemporal: [
142
+ dogwood.compare(
143
+ dogwood.count(
144
+ [dogwood.typedBinder("t", "Timepoint")],
145
+ dogwood.formerly(
146
+ "15m",
147
+ dogwood.and(dogwood.predicate('Drupe::Action::"Transfer"', "request"), dogwood.tp("t")),
148
+ ),
149
+ ),
150
+ "<",
151
+ 5,
152
+ ),
153
+ ],
154
+ });
155
+ ```
156
+
157
+ That is what `count_within` expands to. Writing it directly costs four lines
158
+ and depends on nothing at the far end.
159
+
160
+ ## The event schema, and the pin
161
+
162
+ `.dwschema` is the optional service half of the schema; the required half is
163
+ the Cedar `.cedarschema` the rest of the lexicon already generates from. They
164
+ are two halves of one schema, not competing formats.
165
+
166
+ The default event schema pins `callerPrincipal = principal` on every kind, so
167
+ every temporal predicate is correlated to the deciding request's principal and
168
+ other principals' events are invisible.
169
+
170
+ **Supplying any event schema opts out of upstream's default wholesale.** A
171
+ schema emitted without a pin does not merely fail to add a correlation — it
172
+ removes one the author probably assumed, and every predicate in the set starts
173
+ matching across principals. `dogwood.defaultEventSchema()` carries the pin;
174
+ dropping it is a named argument that stamps a comment into the emitted file:
175
+
176
+ ```typescript
177
+ dogwood.defaultEventSchema({ pinCallerPrincipal: false });
178
+ ```
179
+
180
+ DWDS010 warns about an unpinned emitted schema. That is report-only — chant
181
+ does not know which the author wanted, only that the choice should be visible
182
+ in a diff.
183
+
184
+ `max_window` caps look-back for the whole set; absent, it is 24h — the same 24h
185
+ that applies when no schema is supplied at all.
186
+
187
+ ## Deploying to AgentCore
188
+
189
+ `AWS::BedrockAgentCore::Policy` is the vehicle. Its `Definition` is a two-arm
190
+ `oneOf` — `Cedar.Statement` for plain Cedar, `Policy.Statement` for anything
191
+ else — and a `.dw` policy travels in the second arm.
192
+
193
+ ```typescript
194
+ import { agentCoreStagedPolicy } from "@intentius/chant-lexicon-cedar";
195
+
196
+ new BedrockAgentCorePolicy({
197
+ PolicyEngineId: engine.ref(),
198
+ ...agentCoreStagedPolicy("writeNeedsApproval", writeNeedsApproval, "log-only"),
199
+ });
200
+ ```
201
+
202
+ `agentCorePolicyDefinition(name, policy)` picks the arm from the policy itself.
203
+ Templates are refused — AgentCore's union has no template-linked arm, so a
204
+ statement carrying `?principal` or `?resource` throws at authoring time rather
205
+ than failing at deploy.
206
+
207
+ `EnforcementMode` stages the rollout: `"log-only"` is evaluated on every request
208
+ with its decision observed rather than returned, `"enforce"` binds. Start a
209
+ temporal policy log-only — whether it fires depends on traffic nobody has
210
+ replayed. Promotion is a one-token diff.
211
+
212
+ The resource carries a statement and nothing else, so the event schema is
213
+ registered with the engine separately; DWDC013 warns when temporal text is
214
+ embedded and no `.dwschema` was emitted beside it.
215
+
216
+ ## The validation split
217
+
218
+ Explain this split when a user asks why something did or did not fail.
219
+
220
+ Always, gating, no binary anywhere:
221
+
222
+ | Check | Catches |
223
+ |---|---|
224
+ | DWDC010 | A temporal predicate naming an event kind the emitted `.dwschema` never declares |
225
+ | DWDC011 | A window past `max_window` (or upstream's 24h default) — macro-call intervals count |
226
+ | DWDC012 | A `formerly`/`previous`/`since` with no `within` window |
227
+ | DWDC013 | An AgentCore-embedded temporal statement with no `.dwschema` emitted beside it (warning) |
228
+ | DWDS010 | An emitted event schema that pins nothing (warning) |
229
+
230
+ Only when the `dogwood` binary is present:
231
+
232
+ | Check | Catches |
233
+ |---|---|
234
+ | DWDE010 | Everything `dogwood validate` catches — macro expansion, the temporal type check, the Cedar body against the action schema |
235
+ | DWDE011 | The `dogwood lower` output failing Cedar's own validator via `@cedar-policy/cedar-wasm` |
236
+
237
+ Binary resolution order: an explicit `configureDogwoodCli({ binary })`, then
238
+ `$CHANT_DOGWOOD_BINARY`, then `cedar.dogwood.binary` in a `chant.config.json`,
239
+ then `dogwood` on `PATH`. There is no published build — it is `cargo build
240
+ --release` from the pinned revision.
241
+
242
+ When it is absent, DWDE010 emits exactly one `info` finding naming the binary,
243
+ where chant looked, and the issue. It never silently passes: a check that
244
+ quietly succeeds when it could not run is claiming a guarantee it did not make.
245
+
246
+ Nothing in gating CI runs the binary, by design.
247
+
248
+ ### Do not read exit codes
249
+
250
+ If you write anything that shells to the CLI: exit 2 means both "policy set
251
+ rejected" and clap's usage error for an unknown flag, and upstream's own guide
252
+ claims 1 for the latter. The JSON on stdout decides, in both directions. There
253
+ are two JSON shapes — a validate report (`passed`, `errors[]`, `warnings[]`)
254
+ and a bare fatal error object with the same diagnostic fields flattened plus
255
+ `related[]`. A run that produced neither is "could not be used", never "your
256
+ policy is bad".
257
+
258
+ ## Replay
259
+
260
+ A temporal policy is not decidable from its source — whether `formerly within
261
+ 1h …` fires depends on history nobody has replayed — so the check is a replay
262
+ against recorded traffic. That ships as `PolicyReplayOp`:
263
+
264
+ ```typescript
265
+ import { PolicyReplayOp } from "@intentius/chant-lexicon-cedar";
266
+
267
+ export const { op } = PolicyReplayOp({
268
+ name: "policy-replay",
269
+ policiesPath: "dist/policies.dw",
270
+ policySchemaPath: "schema.cedarschema",
271
+ eventSchemaPath: "dist/events.dwschema",
272
+ tracePath: "trace/read-after-login.log",
273
+ expect: [
274
+ { timestamp: 10, verdict: "allow", determiningRules: [0] },
275
+ { timestamp: 7200, verdict: "deny", note: "the login is two hours stale" },
276
+ ],
277
+ onFinding: "report",
278
+ });
279
+ ```
280
+
281
+ Three phases — Artifacts (`chantBuild`, skippable with `buildScript: false`),
282
+ Replay (`dogwoodReplay`, writes `dist/dogwood-replay.json`), Report
283
+ (`dogwoodReplayReport`, acts on `report | issue | pull-request`).
284
+ `failOnDivergence` defaults to false: an observe-dial Op reports. The composite
285
+ ships from cedar and carries no dependency on the temporal lexicon; a scheduled
286
+ form is a project-side `TemporalSchedule` pairing.
287
+
288
+ Build traces with `dogwood.traceEvent()` rather than by hand. Two traps it
289
+ exists to close, and both are worth naming whenever a user assembles a fixture:
290
+
291
+ 1. **Both bags.** A trace line carries a `request_context(...)` envelope, which
292
+ the Cedar request is built from, and a trailing logged record, which temporal
293
+ predicates match against. A field both halves need must be in both.
294
+ `traceEvent()` writes a `context` group into both by default; getting the
295
+ weaker trace takes an explicit `bags: "record-only"` / `"context-only"`.
296
+ Populate one bag only and nothing errors — the other check silently weakens.
297
+ 2. **Fully-qualified action names.** `Drupe::Action::"Transfer"`, never
298
+ `Transfer`. A bare name still authorizes through Cedar while every temporal
299
+ predicate quietly fails to match. `traceEvent()` rejects one at construction.
300
+
301
+ `dogwood.auditTrace(events)` applies the same checks to a trace chant did not
302
+ build (`single-bag`, `no-request-context`, `empty-record`, `out-of-order`), and
303
+ `dogwood.traceFixture(events)` throws rather than handing back a weakened one.
304
+
305
+ Write expectations against `timestamp`, not `index`: `index` is the position in
306
+ the decision stream, and a history-only event (any kind the schema does not
307
+ mark `decision`) contributes history and no verdict, so the two do not line up.
308
+ `determiningRules` catches a decision that is right for the wrong reason.
309
+
310
+ Replay exits 0 even when every verdict is DENY, so the activity reads the JSON
311
+ rather than the exit status — and a run that could not happen throws instead of
312
+ reporting zero divergences.
313
+
314
+ ## What chant does not do
315
+
316
+ - **No lowering.** `dogwood lower` owns that; a reimplementation would drift on
317
+ the next sync. Where the lowered form is wanted, chant shells to the binary.
318
+ - **No request-time evaluation.** The policy engine in front of the traffic
319
+ decides; chant has no seat there. The offline half is `PolicyReplayOp`, which
320
+ replays recorded history through upstream's interpreter.
321
+ - **No gate.** Dogwood is a target, the same as Cedar. Organizational policy in
322
+ chant is TypeScript post-synth checks.
323
+
324
+ ## Reference
325
+
326
+ Full pages: `/chant/lexicons/cedar/dogwood/`, and from there temporal policies,
327
+ event schemas, validation and replay.