@cratis/pi 7.3.1 → 7.3.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.
@@ -340,10 +340,26 @@ script. A consuming repository customises all three without forking anything:
340
340
  | `scripts/cratis-store-mutations.json` | the store-mutation guard's read-only allowlist and known-mutating list, each entry with its reason or effect, and the CLI options it skips; its header `$comment` documents every field and the CLI version the lists were derived from |
341
341
  | `scripts/cratis-store-mutations.local.json` | optional; its lists are appended to the above. It can classify a command a newer CLI adds, or list a shipped read-only command as mutating (a command on the mutating list always blocks); only a replacement file can make a known mutation read-only |
342
342
 
343
- A gate whose `requires.commands` are not on `PATH`, whose `requires.paths` do not exist, or whose
344
- `workingDirectoryFrom` matches nothing in the repository, is a **no-op with a message on stderr**
343
+ A gate whose `requires.commands` are not on `PATH`, whose `requires.paths` do not exist, whose
344
+ `requires.packageScripts` are not defined in the `package.json` of its working directory (a `g:`
345
+ script may instead be defined in the root `package.json` — this assumes Yarn Berry, where a
346
+ root-defined `g:` script runs from every workspace, and no workspace `package.json` is inspected), or whose `workingDirectoryFrom` matches
347
+ nothing in the repository, is a **no-op with a message on stderr**
345
348
  rather than a failure — that is how a repository with no .NET solution or no frontend stays quiet.
346
349
 
350
+ An override in `.cratis/ai/quality-gates.project.json` is merged shallowly: a field it states
351
+ replaces the managed one. The one exception is `requires.packageScripts`: an override that sets
352
+ `command` without stating `requires` drops the managed gate's `packageScripts`, because they guard
353
+ the managed command (`yarn g:compile`), not the replacement. Without that, a repository replacing
354
+ `command` would silently turn the gate into a no-op whenever it lacks the managed script. An
355
+ override that does state `requires` replaces it whole, so list `packageScripts` again if the new
356
+ command needs them.
357
+
358
+ Every shipped gate ignores the managed corpus and adapter trees (`.cratis/**`, `.pi/**`,
359
+ `.claude/**`) through `excludeChanged`, so a `cratis ai update` never runs a repository's application
360
+ gates. A repository whose own source lives there, like this corpus, restates `excludeChanged` for the
361
+ gates it needs in `.cratis/ai/quality-gates.project.json`.
362
+
347
363
  **No shipped gate names a product's file.** A default that did would activate in exactly one
348
364
  repository and silently no-op in every other, which is the worst of both: it looks configured and
349
365
  checks nothing. So the .NET and frontend gates state *what kind of project* they build and let the
@@ -47,6 +47,11 @@ jq -e . "$config" >/dev/null 2>&1 || {
47
47
  # quality-gates.json mixes project facts into Cratis-owned content, so the next managed update
48
48
  # either reports drift or silently discards the repository's own configuration. The override
49
49
  # states only what differs, keyed by gate id, and nothing here needs a script fork.
50
+ #
51
+ # The merge is shallow (a patch field replaces the base field), with one exception: a patch that
52
+ # replaces `command` but does not state `requires` also drops the base gate's
53
+ # requires.packageScripts. Those scripts guard the base command; keeping them would make the
54
+ # overriding repository's own command a silent NO-OP whenever it lacks e.g. g:compile.
50
55
  overrides="$root/.cratis/ai/quality-gates.project.json"
51
56
  if [ -f "$overrides" ]; then
52
57
  if jq -e . "$overrides" >/dev/null 2>&1; then
@@ -54,11 +59,16 @@ if [ -f "$overrides" ]; then
54
59
  if jq -s '
55
60
  .[0] as $base | .[1] as $over
56
61
  | ($over.gates // []) as $gates
57
- | $base
62
+ | def patched($gate; $patch):
63
+ ($gate + ($patch | del(.id))) as $m
64
+ | if ($patch | has("command")) and (($patch | has("requires")) | not) and ($m.requires != null)
65
+ then $m | .requires |= del(.packageScripts)
66
+ else $m end;
67
+ $base
58
68
  + ($over | del(.gates))
59
69
  + { gates: [ $base.gates[] as $gate
60
70
  | ($gates | map(select(.id == $gate.id)) | first) as $patch
61
- | if $patch == null then $gate else $gate + ($patch | del(.id)) end ] }
71
+ | if $patch == null then $gate else patched($gate; $patch) end ] }
62
72
  ' "$config" "$overrides" >"$merged" 2>/dev/null; then
63
73
  unknown="$(jq -r --slurpfile base "$config" '[.gates // [] | .[].id] - [$base[0].gates[].id] | .[]' "$overrides" 2>/dev/null || true)"
64
74
  [ -n "$unknown" ] && printf 'cratis-quality-gate: %s overrides unknown gate(s): %s\n' \
@@ -151,9 +161,16 @@ EOF
151
161
  return 1
152
162
  }
153
163
 
154
- # Report the first unmet requirement, or nothing when the gate can run here.
164
+ # Does the package.json at $1 define the script named $2? A missing file or a file that is not
165
+ # valid JSON defines nothing.
166
+ package_defines_script() {
167
+ [ -f "$1" ] && jq -e --arg s "$2" '.scripts[$s] != null' "$1" >/dev/null 2>&1
168
+ }
169
+
170
+ # Report the first unmet requirement, or nothing when the gate can run here. $2 is the directory,
171
+ # relative to the repository root, the gate runs in.
155
172
  gate_unmet() {
156
- local idx="$1" c p
173
+ local idx="$1" dir="$2" c p s
157
174
  while IFS= read -r c; do
158
175
  [ -n "$c" ] || continue
159
176
  hook_have "$c" || { printf "command '%s' is not on PATH" "$c"; return 0; }
@@ -165,6 +182,22 @@ EOF
165
182
  [ -e "$root/$p" ] || { printf "'%s' does not exist in this repository" "$p"; return 0; }
166
183
  done <<EOF
167
184
  $(jq -r --argjson i "$idx" '.gates[$i].requires.paths // [] | .[]' "$config")
185
+ EOF
186
+ # A package.json script a gate invokes must exist, or yarn fails with "Couldn't find a script"
187
+ # instead of the gate being a NO-OP. A global script (g:) may live in the root package.json
188
+ # that the workspace's own package.json defers to. That fallback assumes Yarn Berry, where
189
+ # a g: script defined at the root is runnable from every workspace; no workspace package.json
190
+ # is inspected.
191
+ while IFS= read -r s; do
192
+ [ -n "$s" ] || continue
193
+ package_defines_script "$root/$dir/package.json" "$s" && continue
194
+ case "$s" in
195
+ g:*) package_defines_script "$root/package.json" "$s" && continue ;;
196
+ esac
197
+ printf "script '%s' is not defined in %s" "$s" "$dir/package.json"
198
+ return 0
199
+ done <<EOF
200
+ $(jq -r --argjson i "$idx" '.gates[$i].requires.packageScripts // [] | .[]' "$config")
168
201
  EOF
169
202
  return 0
170
203
  }
@@ -199,7 +232,7 @@ while [ "$idx" -lt "$gate_count" ]; do
199
232
  fi
200
233
  [ -n "$wd" ] || wd="."
201
234
 
202
- unmet="$(gate_unmet "$idx")"
235
+ unmet="$(gate_unmet "$idx" "$wd")"
203
236
  if [ -n "$unmet" ]; then
204
237
  printf 'cratis-quality-gate: NO-OP %-24s — %s. Configure it in %s.\n' \
205
238
  "$id" "$unmet" "${config#"$root"/}" >&2
@@ -16,6 +16,11 @@
16
16
  " excludeChanged globs that never count as a relevant change",
17
17
  " requires.commands executables that must be on PATH",
18
18
  " requires.paths repo-relative literal paths that must all exist (no globbing)",
19
+ " requires.packageScripts package.json scripts that must be defined in the gate's working directory",
20
+ " (a g: script may instead be defined in the repository root package.json, which assumes",
21
+ " Yarn Berry, where a root-defined g: script runs from every workspace; no workspace",
22
+ " package.json is inspected); a missing script makes the gate a NO-OP instead of a",
23
+ " \"Couldn't find a script\" failure",
19
24
  " workingDirectory repo-relative directory the command runs in",
20
25
  " workingDirectoryFrom globs identifying the project file this gate builds; the command runs",
21
26
  " in that file's directory, and a repository holding none makes the gate a",
@@ -23,6 +28,9 @@
23
28
  " when workingDirectory is set.",
24
29
  " command argv array \u2014 executed directly, never through a shell (no eval)",
25
30
  "",
31
+ "Managed corpus and adapter trees (.cratis/**, .pi/**, .claude/**) never count as a relevant change:",
32
+ "a corpus update must not run a repository's application gates over files that are not its application.",
33
+ "",
26
34
  "No gate names a product's solution, package or source root \u2014 a default that does would",
27
35
  "silently no-op in every repository except the one it was written for. The .NET and frontend",
28
36
  "gates discover the repository's own solution/package instead, so they activate unchanged in",
@@ -33,7 +41,9 @@
33
41
  "own .cratis/ai/quality-gates.project.json, which the runner merges over this file by gate id",
34
42
  "(a project fact belongs there, never edited into this managed file, or the next managed update",
35
43
  "reports drift or discards it); or it points CRATIS_HOOKS_GATES at a file anywhere. Neither",
36
- "requires a script fork.",
44
+ "requires a script fork. The merge is shallow: a field the override states replaces the managed one.",
45
+ "The one exception: an override that sets \"command\" without \"requires\" also drops this gate's",
46
+ "requires.packageScripts, since those guard the managed command, not the override's.",
37
47
  "",
38
48
  "Example .cratis/ai/quality-gates.project.json, for a repository whose frontend is not at the root:",
39
49
  " { \"gates\": [ { \"id\": \"frontend-lint\", \"workingDirectory\": \"Source/App\" } ] }",
@@ -64,7 +74,10 @@
64
74
  ],
65
75
  "excludeChanged": [
66
76
  "**/obj/**",
67
- "**/bin/**"
77
+ "**/bin/**",
78
+ ".cratis/**",
79
+ ".pi/**",
80
+ ".claude/**"
68
81
  ],
69
82
  "requires": {
70
83
  "commands": [
@@ -95,7 +108,10 @@
95
108
  ],
96
109
  "excludeChanged": [
97
110
  "**/obj/**",
98
- "**/bin/**"
111
+ "**/bin/**",
112
+ ".cratis/**",
113
+ ".pi/**",
114
+ ".claude/**"
99
115
  ],
100
116
  "requires": {
101
117
  "commands": [
@@ -129,7 +145,10 @@
129
145
  ],
130
146
  "excludeChanged": [
131
147
  "**/obj/**",
132
- "**/bin/**"
148
+ "**/bin/**",
149
+ ".cratis/**",
150
+ ".pi/**",
151
+ ".claude/**"
133
152
  ],
134
153
  "requires": {
135
154
  "commands": [
@@ -162,7 +181,10 @@
162
181
  "**/wwwroot/**",
163
182
  "**/dist/**",
164
183
  "**/obj/**",
165
- "**/bin/**"
184
+ "**/bin/**",
185
+ ".cratis/**",
186
+ ".pi/**",
187
+ ".claude/**"
166
188
  ],
167
189
  "requires": {
168
190
  "commands": [
@@ -190,11 +212,17 @@
190
212
  "**/wwwroot/**",
191
213
  "**/dist/**",
192
214
  "**/obj/**",
193
- "**/bin/**"
215
+ "**/bin/**",
216
+ ".cratis/**",
217
+ ".pi/**",
218
+ ".claude/**"
194
219
  ],
195
220
  "requires": {
196
221
  "commands": [
197
222
  "yarn"
223
+ ],
224
+ "packageScripts": [
225
+ "g:compile"
198
226
  ]
199
227
  },
200
228
  "workingDirectoryFrom": [
@@ -218,11 +246,17 @@
218
246
  "**/wwwroot/**",
219
247
  "**/dist/**",
220
248
  "**/obj/**",
221
- "**/bin/**"
249
+ "**/bin/**",
250
+ ".cratis/**",
251
+ ".pi/**",
252
+ ".claude/**"
222
253
  ],
223
254
  "requires": {
224
255
  "commands": [
225
256
  "yarn"
257
+ ],
258
+ "packageScripts": [
259
+ "g:compile:specs"
226
260
  ]
227
261
  },
228
262
  "workingDirectoryFrom": [
@@ -246,7 +280,10 @@
246
280
  "**/wwwroot/**",
247
281
  "**/dist/**",
248
282
  "**/obj/**",
249
- "**/bin/**"
283
+ "**/bin/**",
284
+ ".cratis/**",
285
+ ".pi/**",
286
+ ".claude/**"
250
287
  ],
251
288
  "requires": {
252
289
  "commands": [
@@ -195,7 +195,7 @@ The default is fire-and-forget. When a caller's correctness depends on all obser
195
195
  2. **Use event data directly** — Never query the read model back inside a reactor. The event contains all the information you need.
196
196
  3. **Return events and commands instead of injecting the plumbing** — If the reactor needs to produce new events, return them directly as `Task<TEvent>`, `Task<EventForEventSourceId>`, or a collection thereof. For intent in another slice, return the `[Command]` (Arc executes it; a denied or invalid result fails the partition) — or inject `ICommandPipeline` and inspect the result. Either way the handler is `[OnceOnly]`. Avoid injecting `IEventLog` directly into a reactor.
197
197
  4. **Single responsibility** — Each reactor class should have a focused purpose. Multiple handler methods in one reactor are fine if they serve the same automation concern.
198
- 5. **Failure behavior** — If a reactor throws, *or* a returned side-effect event fails to append (constraint violation, concurrency violation, or error), the failing event-source partition pauses until the issue is resolved. Repeated failures can **quarantine** the observer: once `QuarantineOnFailedPartitionCount`/`QuarantineOnFailedPartitionPercentage` (under `Observers`) is crossed, the observer enters the `Quarantined` state — reminders cancelled, retries stopped, automatic recovery suppressed. **A quarantined observer does NOT auto-resume on reconnect** — an operator must call `ClearObserverQuarantine()`. A periodic watchdog (default 60s, `WatchdogInterval`) re-routes stuck/dead observers but does not rescue quarantined ones. Design for resilience.
198
+ 5. **Failure behavior** — If a reactor throws, *or* a returned side-effect event fails to append (constraint violation, concurrency violation, or error), the failing event-source partition pauses until the issue is resolved. Repeated failures can **quarantine** the observer: once `QuarantineOnFailedPartitionCount`/`QuarantineOnFailedPartitionPercentage` (under `Observers`) is crossed, the observer enters the `Quarantined` state — reminders cancelled, retries stopped, automatic recovery suppressed. **A quarantine ends when an operator clears it (`ClearObserverQuarantine()`), or when the observer is subscribed again** — for an application observer that is when the client connects again, for example after a redeploy; Kernel-owned observers are subscribed again when the Kernel starts. A periodic watchdog (default 60s, `WatchdogInterval`) re-routes stuck/dead observers but does not rescue quarantined ones. Design for resilience.
199
199
  6. **Don't throw to validate malformed inbound events** — reactors are not data-quality validators; invalid payloads must be rejected at the command/append site. When a malformed cross-service fact reaches a consumer, throwing just to reject it pauses the partition and can quarantine the whole observer. Instead append a clear failure/dead-letter event (e.g. `ProvisioningFailed`) or surface it via the operational failure path, and skip partial side effects.
200
200
  7. **No state** — Reactors should be stateless. Inject dependencies via primary constructor, but do not store mutable state on the class.
201
201
  8. **An unattended, irreversible pass reads the log, not the sink — and carries a fuse.** A reactor that deletes, revokes, bills or notifies *because a read model says something is absent* is trusting a materialized sink that is only as current as its observer: a paused partition, a replay in progress or a lagging projection makes "absent" true of the sink and false of the world. Decide from a **`[Passive]`** read model (computed on demand from the events at the moment the reactor runs) or from the events themselves. And the code shape cannot tell an **empty subject set** ("nothing to consider" — fail-safe) from an **empty qualifying set** ("nothing survived the filter" — fail-destructive: every subject is about to be acted on), so an unattended pass states its expected population, refuses when the count is implausible, and caps how many subjects one run may touch — the same discipline as [guards-and-fuses.md](./guards-and-fuses.md), applied to a reactor.
@@ -134,8 +134,12 @@ list|show`, `failed-partitions list|show`, `projections list|show`,
134
134
  from the outside.
135
135
  - **Fix the cause before replaying.** Replaying into an unfixed handler fails the
136
136
  same way and buries the original error under a newer one.
137
- - **A quarantined observer does not resume by itself.** Clearing the quarantine
138
- is an explicit operation, and it is the last step, not the first.
137
+ - **A quarantined observer does not resume by itself.** A quarantine ends when
138
+ an operator clears it, or when the observer is subscribed again — for an
139
+ application observer, when the client reconnects, for example after a
140
+ redeploy. Clearing the quarantine is an explicit operation and the last step,
141
+ not the first. A redeploy that restarts the client can also end the quarantine
142
+ as a side effect, so check the observer's state before and after a redeploy.
139
143
 
140
144
  ## Before you change anything
141
145
 
@@ -140,12 +140,12 @@ credentials (`:57`). Query options: `apiKey`, `auth`, `skipTlsValidation`,
140
140
  from `string` (`:158`) and a `Redacted` form for logging (`:152`).
141
141
 
142
142
  > **Certificate validation is skipped by default, and that is deliberate.** The
143
- > Chronicle server always serves TLS, generating a self-signed certificate on
144
- > every start when none is configured, so a development pair connects with no
145
- > setup — the rationale is written out at `ChronicleClient.cs:141-146`. **A
146
- > production connection string must set `skipTlsValidation=false`** (or
147
- > `Tls.SkipCertificateValidation = false`) against a server whose certificate is
148
- > actually verifiable.
143
+ > development Chronicle images (`latest-development` and `latest-development-slim`)
144
+ > generate a self-signed certificate on every start, so a development pair
145
+ > connects with no setup. The production image does not: it refuses to start with
146
+ > TLS enabled (the default) and no configured certificate. **A production connection string must set
147
+ > `skipTlsValidation=false`** (or `Tls.SkipCertificateValidation = false`)
148
+ > against a server whose certificate is actually verifiable.
149
149
 
150
150
  ### In a host
151
151
 
@@ -214,6 +214,13 @@ storage, configured under `Cratis:Chronicle:Compliance:Encryption`.
214
214
  > migration flag before switching stores, and confirm a known subject still
215
215
  > reads after the switch.
216
216
 
217
+ > **Restore order.** The erasure fence is kept inside the key store, so a key
218
+ > store restored from *before* an erasure brings the key back without its fence
219
+ > and the erased personal data reads again; a key store older than the storage
220
+ > also lacks keys for newer subjects, and their values read as empty. Restore
221
+ > the certificate ring first, then the storage, then the key store to the
222
+ > storage's point in time.
223
+
217
224
  ## Modeling rules that follow from erasure
218
225
 
219
226
  - Prefer **one subject per event stream** for person-level personal data. The
@@ -313,8 +313,10 @@ If a handler throws, or a returned side-effect event fails to append — a
313
313
  constraint violation, a concurrency violation, or an error — the failing
314
314
  event-source partition **pauses** until the cause is resolved. Repeated failures
315
315
  can **quarantine** the observer, which stops retries and suppresses automatic
316
- recovery. **A quarantined observer does not resume on reconnect**; an operator
317
- must clear the quarantine explicitly.
316
+ recovery. **A quarantine ends when an operator clears it
317
+ (`ClearObserverQuarantine()`), or when the observer is subscribed again** — for an
318
+ application observer that is when the client connects again, for example after a
319
+ redeploy; Kernel-owned observers are subscribed again when the Kernel starts.
318
320
 
319
321
  Do not throw to reject a malformed inbound event. A reactor is not a data-quality
320
322
  gate; invalid payloads belong at the command or append site. When a malformed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.3.1",
3
+ "version": "7.3.3",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [