@cratis/pi 7.56.1 → 7.56.3

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.
@@ -63,9 +63,9 @@
63
63
  }
64
64
  ],
65
65
  "synced": {
66
- "version": "22.97.0",
67
- "date": "2026-10-14",
68
- "by": "Cratis/AI#695"
66
+ "version": "22.100.0",
67
+ "date": "2026-10-15",
68
+ "by": "Cratis/AI#710"
69
69
  },
70
70
  "covers": {
71
71
  "skills": [
@@ -98,7 +98,7 @@
98
98
  "vertical-slices.md"
99
99
  ]
100
100
  },
101
- "notes": "Release-tag delta through 22.97.0: scoped completion and routing validation, generated-target freshness, observable scenarios, asynchronous execution scopes, read-model diagnostics and ordered reactor refusal handling. Existing context generation/self-reduction guidance retained; Screenplay extraction deltas handed to its owning lane. No new runtime probe."
101
+ "notes": "Release-tag delta through 22.100.0: scoped completion and routing validation, generated-target freshness (including direct unit-of-work writes and nested commands), observable scenarios, asynchronous execution scopes, read-model diagnostics, ordered reactor refusal handling and ICommandExceptionMapper. Existing context generation/self-reduction guidance retained; Screenplay extraction deltas handed to its owning lane. No new runtime probe."
102
102
  },
103
103
  {
104
104
  "id": "ai",
@@ -246,7 +246,7 @@ whatever renders it:
246
246
 
247
247
  Read [references/client-contract.md](references/client-contract.md) for the generated proxy members.
248
248
 
249
- Read `references/command-result.md` when branching on a command result or matching validation failures to fields. Branch on the specific flag, not only on `isSuccess`. The exact `CommandResult`
249
+ Read `references/command-result.md` when branching on a command result, matching validation failures to fields, or mapping integration exceptions. Branch on the specific flag, not only on `isSuccess`. The exact `CommandResult`
250
250
  and `ValidationResult` shapes are in
251
251
  [command result](references/command-result.md) — in particular, a validation
252
252
  failure carries `members: string[]` (camelCased) and a numeric `severity`, not a
@@ -3,6 +3,7 @@
3
3
  ## Contents
4
4
 
5
5
  - Server side
6
+ - Map integration exceptions
6
7
  - Severity filtering
7
8
  - Client side
8
9
  - Executing with a severity
@@ -40,6 +41,34 @@ every execution scope has completed and the result is not successful, so a
40
41
  transaction that rolls back after `Handle` returned a value does not leak that
41
42
  value into the error body.
42
43
 
44
+ ## Map integration exceptions
45
+
46
+ Requires Arc 22.100.0 or later for `Cratis.Arc.Commands.ICommandExceptionMapper`.
47
+ Check `dotnet list package --include-transitive`; older Arc has no mapper hook
48
+ and uses `CommandResult.FromException` for unhandled execution exceptions.
49
+
50
+ Implement the interface for an integration's typed failures, not ordinary
51
+ user-correctable rejections (return validation results for those):
52
+
53
+ ```csharp
54
+ bool TryMap(CommandContext context, Exception exception,
55
+ [NotNullWhen(true)] out CommandResult? result);
56
+ ```
57
+
58
+ `NotNullWhen` is from `System.Diagnostics.CodeAnalysis`. Return `true` with a
59
+ non-null **failure** preserving `context.CorrelationId`, or `false` with `null`
60
+ to decline. Match exception types/properties rather than parsing messages.
61
+ Implementations are convention-discovered through `IInstancesOf<ICommandExceptionMapper>`
62
+ (`Cratis.Types`) and resolved from the command's service scope. The first accepting
63
+ mapper wins. Mapping runs for exceptions escaping command execution or response
64
+ processing, before execution scopes complete, so a mapped failure still rolls
65
+ back pending work. If no mapper accepts, the pipeline falls back to
66
+ `CommandResult.FromException`; a throwing mapper produces `CommandResult.Error`
67
+ and scopes still complete with
68
+ failure. This hook does not replace validation-only or scope-completion exception
69
+ handling. Specify accepting, declining and throwing cases and assert rollback
70
+ and correlation preservation, not only the message.
71
+
43
72
  ## Severity filtering
44
73
 
45
74
  `ValidationResultSeverity`: `Unknown = 0`, `Information = 1`, `Warning = 2`,
@@ -3,6 +3,12 @@
3
3
 
4
4
  # Fresh generated append targets
5
5
 
6
+ ## Contents
7
+
8
+ - Direct writes and nested commands
9
+ - Opt out deliberately
10
+ - Specify the collision
11
+
6
12
  Requires Arc 22.95.0 and Chronicle client 19.59.4 for guarded generated targets; deploy a Chronicle kernel 19.40.1 or later for retry-time emptiness checks. Check package references and the deployed kernel version before relying on the guard; older Arc needs an explicit whole-source `BeforeFirst` scope.
7
13
 
8
14
  A `[GeneratedValue]` parameter defaults to `GeneratedValueFreshness.Guarded`.
@@ -10,9 +16,12 @@ When an Arc-owned append targets a validated value generated in that invocation,
10
16
  it requires the **whole event source** to be empty, including other streams and
11
17
  event types. Payload-only and response-only generated values add no scope.
12
18
  Returned events, tuples, wrappers, `EventsWithConcurrencyScopes` and aggregates
13
- acquired for that generated identifier are covered. Direct `IUnitOfWork.AddEvent`,
14
- `AddEvents` and `eventLog.Transactional.Append` calls are not: return events
15
- through Arc or supply the exact emptiness scope explicitly.
19
+ acquired for that generated identifier are covered.
20
+
21
+ Requires Arc 22.100.0 or later and Chronicle client 19.65.2 or later for direct
22
+ unit-of-work writes and redacted enrollment-conflict translation. Check resolved
23
+ versions with `dotnet list package --include-transitive`; older Arc needs returned
24
+ events or an explicit whole-source `BeforeFirst` scope for direct writes.
16
25
 
17
26
  An occupied destination returns `ValidationResultReason.ConcurrencyViolation`
18
27
  with `ReasonDetail` `GeneratedIdentifierCollision`. Arc does not rerun `Handle()`.
@@ -25,6 +34,56 @@ explicit scope, including `ConcurrencyScope.None` or a narrowed scope, fails wit
25
34
  generated source's returned events contiguous; an interleaved shape that would
26
35
  split its guard fails with `GeneratedIdentifierEventsCannotBeSplit`.
27
36
 
37
+ ## Direct writes and nested commands
38
+
39
+ The same guard covers these writes on the **command's actual unit of work**:
40
+
41
+ - `IUnitOfWork.AddEvent`, `AddEventWithNamedTags` and `AddEvents`.
42
+ - `eventLog.Transactional.Append`, `AppendMany`, `AppendWithNamedTags` and
43
+ `AppendManyWithNamedTags`.
44
+
45
+ Returned, aggregate and direct events share one whole-source expectation. An
46
+ occupied generated destination rejects the whole pending unit, including events
47
+ for other sources, with the collision result above. Arbitrary new units and
48
+ external stores are outside this protection.
49
+
50
+ Nested pipeline invocations share the outer unit and leave completion to its
51
+ owner. Guarded captures from every active invocation participate, so a nested
52
+ handler's attribute-derived scope cannot narrow an outer generated guard.
53
+ Propagate nested rejection so the outer command rolls back earlier events.
54
+ An explicit aggregate `Commit()` can still complete the shared unit early.
55
+
56
+ After enrollment, the required scope survives disposal of the invocation's
57
+ contributor; later unscoped writes inherit it. An incompatible supplied scope
58
+ against that recorded generated guard maps to `ConflictingConcurrencyScopes`,
59
+ even if Chronicle rejects it before invoking contributors. Neither collision nor
60
+ scope-conflict messages expose the identifier or scope values. Arc uses typed
61
+ scope properties and recorded guard provenance, not message parsing; unrelated
62
+ enrollment conflicts retain Chronicle's redacted `ConflictingEnrollmentScope`.
63
+ Scope-only `AddEvents` entries preserve existing requirements but do not invoke
64
+ contributors or establish a new generated guard. A completed nested invocation's
65
+ untargeted capture leaves no enrolled requirement.
66
+
67
+ Custom units must support enrollment contributors. A guarded generated parameter
68
+ fails closed with `FreshIdentifierGuardRequiresEnrollmentContributors` if the unit
69
+ cannot register one; no generated parameters or only `Unguarded` parameters do not
70
+ require that support.
71
+
72
+ `AddEvents` checks all destinations before staging that call; a scope conflict
73
+ stages none of its events. Transactional `AppendMany` and
74
+ `AppendManyWithNamedTags` stage per event, so a later rejection can leave earlier
75
+ events pending. Let the exception escape `Handle()` to roll back the unit;
76
+ catching it and succeeding can commit those earlier events.
77
+
78
+ Immediate `eventLog.Append`, `AppendMany` and their named-tag variants bypass
79
+ enrollment, cannot be rolled back and receive **no automatic freshness guard**.
80
+ Prefer returning events. An integration needing direct writes must use the
81
+ command's transactional unit; an immediate caller needs an explicit whole-source
82
+ `BeforeFirst` scope and must inspect the append result, without automatic
83
+ `GeneratedIdentifierCollision` classification.
84
+
85
+ ## Opt out deliberately
86
+
28
87
  Only when appending to an existing generated destination is intentional, use this
29
88
  parameter attribute fragment (imports `Cratis.Arc.Commands.ModelBound` and
30
89
  `Cratis.Arc.Commands`):
@@ -42,8 +101,9 @@ use an appropriate constraint or explicit concurrency scope for them.
42
101
  Use `new CommandScenario<TCommand>().UseDecisionReads()` **before seeding**, then
43
102
  `PinGeneratedValue(name, id)` and `Given.ForEventSource(id).Events(existingEvent)`.
44
103
  Assert the concurrency reason and collision detail, unchanged append tail and
45
- one handler execution. Also cover an empty source receiving two events and an
46
- occupied source whose events belong to another stream.
104
+ one handler execution. Also cover an empty source receiving two events through
105
+ the chosen write API, an occupied source whose events belong to another stream,
106
+ mixed returned/direct writes, and a nested rejection rolling back the outer unit.
47
107
 
48
108
  Requires Arc 22.95.1 for `GeneratedIdentifierCollisionRequiresDecisionReads`:
49
109
  default scenario mode fails fast when given events and a guarded pin share an id.
@@ -47,6 +47,17 @@ not a command-side alternative to returned guarded events. Check the client
47
47
  package version; older custom units throw
48
48
  `UnitOfWorkEnrollmentContributorsNotSupported` when attached.
49
49
 
50
+ Requires Arc 22.100.0 or later with Chronicle client 19.65.2 or later for Arc's
51
+ generated-identifier guard on direct unit-of-work and transactional writes,
52
+ including nested commands. Check `dotnet list package --include-transitive`;
53
+ older Arc needs returned events or an explicit whole-source `BeforeFirst` scope
54
+ for direct writes. A conflict against an enrolled generated guard is reported as
55
+ Arc's `ConflictingConcurrencyScopes`, without identifier or scope values, rather
56
+ than Chronicle's `ConflictingEnrollmentScope`; unrelated enrollment conflicts keep
57
+ the Chronicle failure. Read
58
+ [generated-target freshness](../cratis-arc-command/references/fresh-identifiers.md)
59
+ for the covered APIs, scope lifetime, rollback and immediate-append boundary.
60
+
50
61
  ## Route the work
51
62
 
52
63
  - For Arc `[ProtectedDecision]`, Arc command/handler shapes and Arc `IStreamReads`,
@@ -157,8 +157,8 @@ Adapters and non-renderable scope follow the contract rules of `cratis-applicati
157
157
  - `description` and `documentation` reach rendered code only as XML documentation comments (Stage#178),
158
158
  never as behavior. A rule stated only in prose is unenforced: fallback record entry or target requirement,
159
159
  never "delivered".
160
- - The `cratis run` sandbox enforces neither validation nor authorization on its default engine; it
161
- is no evidence for denial behaviour.
160
+ - The `cratis run` sandbox's default engine enforces only simple literal validation rules and no
161
+ authorization; it is no evidence for denial behaviour or for any other rule.
162
162
  - Never remove `pii`, `secret`, authorization or rules to get a render through; report the gap.
163
163
  - Stop and ask only on a genuine contradiction between model, specs, descriptions and declared
164
164
  contracts, after reading the slice fully (`cratis-screenplay-modeling-lifecycle` `references/stop-or-assume.md`).
@@ -102,7 +102,7 @@ name them as unfinished.
102
102
  matching value. Both are needed. Ownership checks on text, Uuid, Date and DateTime subjects render;
103
103
  other subjects are STAGE-ESM-015: note it.
104
104
  - Traps: `then error` for a denial; a denial spec whose inputs also break a rule (it still
105
- denies, but reads ambiguously); trusting a `cratis run` sandbox answer (the default engine's enforcement is unverified here;
105
+ denies, but reads ambiguously); trusting a `cratis run` sandbox answer (the default engine enforces no authorization;
106
106
  the opt-in semantic engine enforces both but reads forgeable caller headers, so it is no security boundary); counting another command's denial.
107
107
 
108
108
  ## 4. State violation
@@ -185,9 +185,10 @@ Silent fallback to a default screen is a failure, not a partial render.
185
185
  `cratis run [PATH]` (Docker required) starts `cratis/stage` on the folder or file: Stage
186
186
  API on `9090`, Chronicle Workbench on `https://localhost:35000`. It is a **partial,
187
187
  disposable runtime**, not a generated application. The default engine appends modeled
188
- `produces` facts and echoes the payload but enforces no modeled validation or
189
- authorization and no query authorization; `Stage__Runtime__Engine=semantic` opts in to
190
- an engine that does, and refuses what it cannot execute (HTTP 501). The default engine
188
+ `produces` facts and echoes the payload. It refuses missing required properties and
189
+ simple literal `validate` rules on top-level properties, but enforces no other rule, no
190
+ constraint and no command or query authorization; `Stage__Runtime__Engine=semantic` opts
191
+ in to an engine that does, and refuses what it cannot execute (HTTP 501). The default engine
191
192
  also refuses routed models (`STAGE-ESM-030`). Callers are built from unsigned headers, so
192
193
  authorization there is not a security boundary.
193
194
 
@@ -229,8 +230,8 @@ to disk with no managed staging and no safe stale-file removal; a failure can le
229
230
  managed output and never a weakened model.
230
231
  - No file under `.cratis-render/` is staged; managed files carry no local edits.
231
232
  - Stage's plan is deterministic (same bytes and hashes); that is not a review, and Stage never reviews, stages or approves anything.
232
- - Sandbox expectations account for unenforced validation, authorization and query
233
- authorization on the default engine.
233
+ - Sandbox expectations account for the rules, constraints, authorization and query
234
+ authorization the default engine does not enforce.
234
235
  - Runtime screen smoke coverage uses the same model root or workspace export as
235
236
  `cratis render`, names package/image versions, and fails on dropped authored UI
236
237
  or silent default composition.
@@ -13,8 +13,8 @@ V5 evidence.
13
13
  - Docker, and the `cratis/stage` image at the tag `cratis run` would use (by default the
14
14
  Stage version the CLI renders with).
15
15
  - The **semantic engine**. `cratis run` has no `--engine` option and passes no environment
16
- to the container, so it starts the default EventModel engine, which enforces no
17
- validation or authorization and refuses routed models. Start the same image directly:
16
+ to the container, so it starts the default EventModel engine, which enforces only
17
+ simple literal validation rules, no authorization, and refuses routed models. Start the same image directly:
18
18
 
19
19
  ```bash
20
20
  docker run --rm -p 127.0.0.1:9090:9090 -p 127.0.0.1:35000:35000 \
@@ -36,12 +36,12 @@ Two engines:
36
36
 
37
37
  | Engine | Selected by | Behaviour |
38
38
  | --- | --- | --- |
39
- | EventModel (default) | nothing | Commands evaluate their modeled `produces` mappings, append the facts to Chronicle and echo the payload. **Modeled validation, authorization and query authorization are not enforced.** It registers Chronicle projections. Named event sources, streams and routes are refused with `STAGE-ESM-030` (`/stage/status` reports `state: "unsupported"` and `/api/**` answers 501), so a routed model does not run here |
39
+ | EventModel (default) | nothing | Commands evaluate their modeled `produces` mappings, append the facts to Chronicle and echo the payload. **Only part of modeled validation is enforced, and no authorization.** See [What the default engine enforces](#what-the-default-engine-enforces). It registers Chronicle projections. Named event sources, streams and routes are refused with `STAGE-ESM-030` (`/stage/status` reports `state: "unsupported"` and `/api/**` answers 501), so a routed model does not run here |
40
40
  | Semantic | `Stage__Runtime__Engine=semantic` | Evaluates validation, requirements, authorization, conditional production and constraints before accepting a command; appends one batch; denied is HTTP 403, validation or constraint failure HTTP 400, an unsupported command HTTP 501. `GET /stage/semantic/admission` lists what is admitted. Executes routes and event-triggered reactions (including `where`, `runs as`, `from`, productions, invocations and cascades), settling them with the initiating command in one batch. Refuses a model it cannot execute (`state: "unsupported"`, `/api/**` returns 501). Read models are in-process, not Chronicle projections in the Workbench; the history is unbounded, so use it for short sessions |
41
41
 
42
42
  Do not read an answering sandbox as evidence of correct authorization. Callers are
43
43
  built from unsigned `x-ms-client-principal` headers that anyone who can reach the host can
44
- forge, the default engine enforces nothing, and the session should stay private (loopback
44
+ forge, the default engine enforces no authorization, and the session should stay private (loopback
45
45
  ports or an authenticated proxy). Rendered applications use the renderer's admitted Arc
46
46
  authorization instead, which is the thing to test for production behavior (Debug tests
47
47
  of a render, [render-example.md](render-example.md)).
@@ -61,6 +61,38 @@ launch failure, nonzero exit or invalid report is 502. The timeout defaults to 1
61
61
  (1–600, including queue); specifications stay available after a later world-rebuild or
62
62
  registration failure if the model was admitted.
63
63
 
64
+ ### What the default engine enforces
65
+
66
+ When a command that declares at least one `produces` executes, the default engine
67
+ refuses it with a validation result naming the property, and appends nothing, if:
68
+
69
+ - a property the command's schema requires is missing or `null`;
70
+ - a top-level property breaks a declarative `validate` rule with a literal operand:
71
+ `not empty`, `matches "<regex>"`, `length == <n>`, `min <n>` or `max <n>` on text, or
72
+ `>`, `>=`, `<`, `<=` on a number.
73
+
74
+ Some rules are checked with the wrong meaning:
75
+
76
+ - `min` and `max` on a number are checked as the length of the number's text, so
77
+ `quantity min 1` accepts `0` and `quantity min 2` refuses `9`;
78
+ - `not empty` on a nested property (`address.name`) refuses every payload, including a
79
+ valid one, because the dotted path is looked up as a top-level key; other rules on
80
+ nested properties are skipped.
81
+
82
+ Everything else passes unchecked:
83
+
84
+ - `all >` and `all >=` over element paths;
85
+ - `==` and `!=`, `matches email`, `rule <Name>`, and any rule whose operand is another
86
+ property or a value resolved at run time, such as `today`;
87
+ - concept rules, `require` over read models, and uniqueness constraints;
88
+ - command `authorize` and query `authorize`;
89
+ - every check on a command without `produces`, and the `/validate` route, which runs none
90
+ of these checks.
91
+
92
+ A refusal or an acceptance from the default engine therefore proves nothing beyond the
93
+ lists above. Use the semantic engine, or Debug tests of a render, for
94
+ evidence about the rest.
95
+
64
96
  ## Refusals shared by both engines
65
97
 
66
98
  Both engines refuse public events (`STAGE-ESM-032`), foreign or source-event captures
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.56.1",
3
+ "version": "7.56.3",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [