@cratis/pi 7.171.0 → 7.172.1

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 (19) hide show
  1. package/package/corpus/harnesses/copilot/instructions/application-profile.instructions.md +1 -1
  2. package/package/corpus/harnesses/copilot/instructions/vertical-slices.instructions.md +1 -1
  3. package/package/corpus/hooks/README.md +2 -1
  4. package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +107 -12
  5. package/package/corpus/hooks/scripts/cratis-guard-writes.sh +89 -12
  6. package/package/corpus/prompts/add-business-rule.prompt.md +1 -1
  7. package/package/corpus/rules/application-profile.md +1 -1
  8. package/package/corpus/rules/vertical-slices.md +1 -1
  9. package/package/corpus/skills/cratis-arc-command/references/decisions-and-routing.md +10 -6
  10. package/package/corpus/skills/cratis-arc-command/references/read-model-injection.md +2 -2
  11. package/package/corpus/skills/cratis-arc-command-validation/SKILL.md +6 -4
  12. package/package/corpus/skills/cratis-arc-configuration/SKILL.md +1 -1
  13. package/package/corpus/skills/cratis-arc-configuration/references/data-and-protection-keys.md +3 -1
  14. package/package/corpus/skills/cratis-chronicle-decision-reads/SKILL.md +3 -2
  15. package/package/corpus/skills/cratis-chronicle-decision-reads/references/choosing-how-a-rule-holds.md +40 -11
  16. package/package/corpus/skills/cratis-code-review/SKILL.md +3 -1
  17. package/package/corpus/skills/cratis-screenplay-command-surface/references/protected-reads.md +1 -1
  18. package/package/corpus/skills/cratis-screenplay-streams-and-consistency/references/consistency-and-concurrency.md +1 -1
  19. package/package.json +1 -1
@@ -67,7 +67,7 @@ Tagged **[contract]** (framework-enforced) or **[convention]** (house default).
67
67
 
68
68
  ## Implementation Workflow
69
69
 
70
- - **Starting a brand-new application:** scaffold it instead of hand-writing the skeleton: `dotnet new install Cratis.Templates`, then `dotnet new cratis -n MyApp -o MyApp` (`--language Kotlin|Java`, `--Database MongoDB|PostgreSQL|MsSql|SQLite`; `cratis-aspire` for Aspire; `cratis-chronicle-console` or `cratis-chronicle-web` for a Chronicle client only). Non-interactive runs need `--allow-scripts yes`; the .NET templates target `net10.0`. The template writes `.cratis/ai.json`; run `cratis ai update` afterwards. Its `SomeModule/SomeFeature/Registration/` slice is the house shape. There is no Go, Python or Elixir template (verified at Cratis.Templates `v1.8.1`). Since 1.8.0 the `cratis` and `cratis-aspire` .NET app projects emit `<CratisReadProtection>On</CratisReadProtection>`: read models supplied to commands and validators guard the append. Existing apps are not changed by reinstalling the templates.
70
+ - **Starting a brand-new application:** scaffold it instead of hand-writing the skeleton: `dotnet new install Cratis.Templates`, then `dotnet new cratis -n MyApp -o MyApp` (`--language Kotlin|Java`, `--Database MongoDB|PostgreSQL|MsSql|SQLite`; `cratis-aspire` for Aspire; `cratis-chronicle-console` or `cratis-chronicle-web` for a Chronicle client only). Non-interactive runs need `--allow-scripts yes`; the .NET templates target `net10.0`. The template writes `.cratis/ai.json`; run `cratis ai update` afterwards. Its `SomeModule/SomeFeature/Registration/` slice is the house shape. There is no Go, Python or Elixir template (verified at Cratis.Templates `v1.8.1`). Since 1.8.0 the `cratis` and `cratis-aspire` .NET app projects emit `<CratisReadProtection>On</CratisReadProtection>` (redundant on Arc 23+, where `On` is the default; leave it unset in hand-written projects): read models supplied to commands and validators guard the append. Existing apps are not changed by reinstalling the templates.
71
71
  - **Phase 0 — Find the contract / choose the level.** Before writing slice code, find what the code must match, and choose the level once for the whole scope.
72
72
  1. **Look for a Screenplay model** under the model root (opted in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs` for the decision, root and drafts) for the slice, command, event and read-model names.
73
73
  2. **Model level** — an accepted model under the root covers the scope, or the repository is opted in and this scope has no model yet. The `.play` slice and its specs are the contract: change the model first (new behavior starts in discovery), verify it (V1–V3), get an independent review, then render with Stage or gap-fill by hand only what the renderer rejects. Hand-written code stays checked against the model (**cratis-application-slice-conformance**). Never edit Stage-managed output, never implement behavior the model does not state, never change the model to match existing code, never weaken protection to make it compile or render. Start with **cratis-screenplay-event-modeling** (decision rule), then **cratis-screenplay-modeling-lifecycle**. If the Screenplay skills are not installed, say so; do not author `.play` from memory.
@@ -183,7 +183,7 @@ Three attributes scope an append broad→narrow, and each one *also* (only with
183
183
 
184
184
  Each attribute always tags the appended events (visible in `EventContext`). **Only when the command also carries `concurrency: true`** does each dimension join the server-side `ConcurrencyScope` (plus the event source id), with the optimistic strategy supplying the expected tail sequence number. A command **without** `concurrency: true` contributes no scope of its own, and the append falls to whatever concurrency strategy the event sequence is configured with — by default the optimistic one, scoped to the event source. So the attribute chooses *which dimensions* bound the check, not whether a check happens at all. Reach for it on high-contention state transitions where a stale read would let two commands both "win" — it narrows the boundary so appends that are genuinely independent stop colliding (concurrency failures surface on `CommandResult`/`AppendResult`). Adopt it deliberately per behavior, not as a blanket default.
185
185
 
186
- Read protection `On` is the default from Arc 23; on Arc 22 (22.106.0 or later) set `<CratisReadProtection>On</CratisReadProtection>`. A project that sets the property keeps its mode.
186
+ Read protection `On` is the default from Arc 23: leave `<CratisReadProtection>` unset (the `On` default comes from `Cratis.Arc.Chronicle`'s build props, `Source/DotNET/Chronicle/build/Cratis.Arc.Chronicle.props`; a project not importing them has no default) and never add `[ReadProtection(ReadProtectionMode.On)]` to a command. Opt out only where needed, narrowest first, each with a stated reason: `[Unprotected("why")]` on a read-model parameter, model type or method (one advisory read; the method form covers only raw reads in the body, never injected read-model parameters, and mixing it with protected read-model parameters raises ARCCHR0034, so put it on the parameter); `[Unprotected("why")]` or `[ReadProtection(ReadProtectionMode.Off)]` on one command; project-level `Off` or `Measure` only as a temporary adoption step. For a key computed at runtime, `IDecisionReads.Get<T>(key)` in `Provide` or a validator is a protected read; method-level `[Unprotected]` is only for reads the guard cannot cover (joins, children, other sequences, raw event store, external stores) and its reason names what guards the append. Arc 23 key metadata is strict by default (`CommandReadModelKeysMissing`, `ReadProtection:RequireGeneratedMetadata`, `ProtectedReadModelKeyOptions.Strict`). A project that sets the property keeps its mode. Legacy (Arc 22.106.0 and later 22.x only): the default was `Off`, so set `<CratisReadProtection>On</CratisReadProtection>`; remove it on upgrading to Arc 23.
187
187
  Under `On`, a read-model parameter of `Handle()` or of a `CommandValidator<T>`
188
188
  constructor is read fresh and guards the append; the state rule goes in the
189
189
  validator. Two entities: two parameters, `[LookUpBy(nameof(Cmd.Prop))]` on the
@@ -374,7 +374,8 @@ for protected references, including nested strings, heredoc bodies and option va
374
374
  removes simple quoting/escapes, checks case-insensitive spellings, and asks the write guard's
375
375
  `--references` batch mode to classify candidate paths relative to the hook cwd. Original
376
376
  spellings are retained too so existing generated headers can be checked on case-sensitive
377
- filesystems. Glob/bracket patterns are checked against that same policy; brace patterns
377
+ filesystems. The lowercase alias of a path is dropped only where the original path exists and its
378
+ lowercase spelling provably does not (a case-sensitive lookup); any doubt keeps it. Glob/bracket patterns are checked against that same policy; brace patterns
378
379
  are conservative. A directory containing owned controls/managed paths also counts, such as
379
380
  `.claude`, `.pi/extensions` or installed `.cratis/ai`; no second tree list lives in the shell
380
381
  guard. Other trees, including `.github/workflows`, count only if the write policy protects them.
@@ -49,21 +49,28 @@ if [[ "$command_text" =~ ^[[:space:]]*(cratis|ln)[[:space:]] ]] && command -v no
49
49
  fi
50
50
 
51
51
  IFS= read -r -d '' program <<'AWK' || true
52
- function candidate(s) {
52
+ # `origin` is empty for a real candidate and the original spelling for its lowercase alias. In targets mode
53
+ # an alias is printed as \001origin\001alias so the shell can drop it where it provably names no path.
54
+ # A real candidate is never hidden by an earlier alias with the same text (seen: 1 alias, 2 real).
55
+ function candidate(s, origin, prior, marker) {
53
56
  if (checking_marker) return
54
57
  if (s == "" || s ~ /[\n\r\t]/) return
58
+ marker = ENVIRON["GSW_MODE"] == "targets"
55
59
  if (collecting) {
56
60
  if (s in collected) return
57
61
  if (++collected_count > 256 || length(s) > 4096) exit 2
58
62
  collected[s] = 1
59
63
  } else {
60
- if (s in seen) return
64
+ if (origin == "" && marker && index(s, "\001")) exit 2
65
+ prior = (s in seen) ? seen[s] : 0
66
+ if (prior && (origin != "" || prior == 2)) return
61
67
  if (++candidates > 256 || length(s) > 4096) exit 2
62
- seen[s] = 1; print s
68
+ seen[s] = (origin == "") ? 2 : 1
69
+ if (origin != "" && marker) print "\001" origin "\001" s; else print s
63
70
  }
64
- if (s != tolower(s)) candidate(tolower(s))
71
+ if (s != tolower(s)) candidate(tolower(s), s)
65
72
  # A generic attached option prefix must not hide a path spelling (-t.pi/...).
66
- if (s ~ /^-/ && match(s, /[.\/]/) && RSTART > 1) candidate(substr(s, RSTART))
73
+ if (s ~ /^-/ && match(s, /[.\/]/) && RSTART > 1) candidate(substr(s, RSTART), (origin == "") ? "" : substr(origin, RSTART))
67
74
  }
68
75
  # An extended-glob group (`@(a|b)`, `*(x)`) is also read as one star, so `.e@(n)v` meets `.env`.
69
76
  # A word with a brace span and quoting or expansion syntax is also kept whole, so the classifier sees it unsplit.
@@ -268,11 +275,16 @@ function short_flags(w, flags, k) {
268
275
  return 1
269
276
  }
270
277
  function number(s) { return s ~ /^[+-]?[0-9]+$/ }
271
- function options_allowed(verb, first, i, w, filters, patterns) {
278
+ function options_allowed(verb, first, i, w, filters, patterns, ended) {
272
279
  for (i = first; i <= argc; i++) {
273
280
  w = W[i]
274
- if (w == "--") return 1
275
- if (w !~ /^-/ || w == "-") { patterns++; continue }
281
+ if (!ended && w == "--") { if (verb !~ /^(sort|uniq)$/) return 1; ended = 1; continue }
282
+ if (ended || w !~ /^-/ || w == "-") {
283
+ # Admit sort/uniq only as stdin filters. File operands, including after
284
+ # --, retain whole-command classification and every existing refusal.
285
+ if (verb ~ /^(sort|uniq)$/) return 0
286
+ patterns++; continue
287
+ }
276
288
  if ((verb, w) in long_options) continue
277
289
  if (verb == "head" || verb == "tail" || verb == "git log") {
278
290
  if (w == "-n" || (verb != "git log" && w == "-c")) {
@@ -709,11 +721,48 @@ function readonly(s, i, c, c2, sq, dq) {
709
721
  (directory_only && (nonconditional_separator || (has_pipeline && changed_index)))) fail()
710
722
  return !bad
711
723
  }
724
+ # Only a complete, top-level literal cat heredoc is data. A quote, substitution,
725
+ # comment, backslash or previous heredoc before its opening leaves the whole text
726
+ # unclassified: the apparent cat might otherwise be inside another shell construct.
727
+ # Reference extraction always uses the original text, including every body. Only
728
+ # the read-only check reduces a proven heredoc to cat and its output redirection.
729
+ # Protected bodies may be printed but never materialized to a file. Never execute text.
730
+ function strip_data_heredocs(text, lines, count, i, j, line, before, after, delimiter, quoted, body, prefix, out) {
731
+ count = split(text, lines, "\n")
732
+ for (i = 1; i <= count; i++) {
733
+ line = lines[i]
734
+ if (prefix !~ /[\047"\\$`#<>]/ &&
735
+ line ~ /^[ \t]*cat[ \t]+((>|>>)[ \t]*[-.\/A-Za-z0-9_]+[ \t]+)?<<[ \t]*(\047[A-Za-z_][A-Za-z0-9_]*\047|"[A-Za-z_][A-Za-z0-9_]*"|[A-Za-z_][A-Za-z0-9_]*)[ \t]*((>|>>)[ \t]*[-.\/A-Za-z0-9_]+)?[ \t]*$/) {
736
+ before = substr(line, 1, index(line, "<<") - 1)
737
+ after = substr(line, index(line, "<<") + 2)
738
+ if (!(index(before, ">") && index(after, ">"))) {
739
+ sub(/^[ \t]+/, "", after); sub(/[ \t]*(>|>>).*$/, "", after); sub(/[ \t]+$/, "", after)
740
+ quoted = after ~ /^[\047"]/
741
+ delimiter = after; gsub(/[\047"]/, "", delimiter)
742
+ body = ""
743
+ for (j = i + 1; j <= count && lines[j] != delimiter; j++) body = body lines[j] "\n"
744
+ if (j <= count && (quoted || body !~ /[$`\\]/)) {
745
+ if (index(before, ">") || index(line, ">")) heredoc_writes = 1
746
+ sub(/<<[ \t]*(\047[A-Za-z_][A-Za-z0-9_]*\047|"[A-Za-z_][A-Za-z0-9_]*"|[A-Za-z_][A-Za-z0-9_]*)/, "", line)
747
+ out = out (i > 1 ? "\n" : "") line
748
+ for (; i < j; i++) prefix = prefix lines[i] "\n"
749
+ prefix = prefix lines[i] "\n"
750
+ continue
751
+ }
752
+ }
753
+ }
754
+ out = out (i > 1 ? "\n" : "") line
755
+ prefix = prefix line "\n"
756
+ }
757
+ return out
758
+ }
712
759
  BEGIN {
713
760
  policy("cat", "nAvetsb", "")
714
761
  policy("head", "", ""); policy("tail", "", "")
715
762
  policy("wc", "lwcm", ""); policy("ls", "laA1hdRtrF", "")
716
763
  policy("rg", "nli", "--files")
764
+ policy("sort", "nrufb", "--numeric-sort --reverse --unique --ignore-case --ignore-leading-blanks")
765
+ policy("uniq", "cdui", "--count --repeated --unique --ignore-case")
717
766
  policy("grep", "nirRlLcvwxFEHhoqs", "")
718
767
  policy("egrep", "nirRlLcvwxFEHhoqs", ""); policy("fgrep", "nirRlLcvwxFEHhoqs", "")
719
768
  policy("echo", "neE", "")
@@ -743,13 +792,17 @@ BEGIN {
743
792
  match_rewrite_safe = !index(text, MATCH_MARKER) && !index(decoded, MATCH_MARKER)
744
793
  if (ENVIRON["GSW_MODE"] == "references") { emit_text(text); exit 0 }
745
794
  if (ENVIRON["GSW_MODE"] == "targets") {
746
- readonly(text)
747
- if (unparsed) emit_text(text)
795
+ reduced = strip_data_heredocs(text)
796
+ readonly(reduced)
797
+ # Reducing data must never erase a protected reference and skip the final
798
+ # read-only check, even when the reduced command itself has no targets.
799
+ if (unparsed || reduced != text) emit_text(text)
748
800
  else for (i = 1; i <= emitted_count; i++) emit_text(emitted[i])
749
801
  exit 0
750
802
  }
751
803
  n = split(ENVIRON["GSW_PROTECTED"], a, "\n"); for (i = 1; i <= n; i++) protected_paths[a[i]] = 1
752
- exit readonly(text) ? 0 : 1
804
+ reduced = strip_data_heredocs(text)
805
+ exit (readonly(reduced) && !heredoc_writes) ? 0 : 1
753
806
  }
754
807
  AWK
755
808
  # This stage is independent of the readonly/reference grammar above. Prefix syntax is
@@ -1500,8 +1553,50 @@ glob_shell_safe=1
1500
1553
  if [[ -n "${BASH_ENV+x}" || -n "${ENV+x}" || -n "${GLOBIGNORE+x}" ]]; then glob_shell_safe=0; fi
1501
1554
  candidates_text="$(GSW_COMMAND="$command_text" GSW_CWD="$cwd" GSW_GLOB_SAFE="$glob_shell_safe" GSW_MODE=targets LC_ALL=C awk "$program" </dev/null)" || parser_failed
1502
1555
  [ -n "$candidates_text" ] || exit 0
1556
+ # The lowercase alias of a mixed-case path serves case-insensitive file systems. Drop it only where the
1557
+ # longest existing prefix of the original spelling exists and its lowercase spelling provably does not
1558
+ # (a case-sensitive lookup that names nothing). Any doubt keeps the alias (return 0).
1559
+ alias_needed() {
1560
+ local original="$1" base="" prefix lower parent
1561
+ case "$original" in *[A-Z]*) ;; *) return 0 ;; esac
1562
+ [ -d "$cwd" ] || return 0
1563
+ case "$original" in /*) ;; *) base="$cwd/" ;; esac
1564
+ # A `..` component (also in the working directory) is resolved by the classifier lexically before symlinks.
1565
+ case "/$base$original/" in */../*) return 0 ;; esac
1566
+ prefix="$original"
1567
+ while :; do
1568
+ while [ "${#prefix}" -gt 1 ] && [ "${prefix%/}" != "$prefix" ]; do prefix="${prefix%/}"; done
1569
+ case "$prefix" in "" | /) return 0 ;; esac
1570
+ if [ -e "$base$prefix" ] || [ -L "$base$prefix" ]; then break; fi
1571
+ case "$prefix" in */*) prefix="${prefix%/*}" ;; *) return 0 ;; esac
1572
+ done
1573
+ case "$prefix" in *[A-Z]*) ;; *) return 0 ;; esac
1574
+ lower="${2:0:${#prefix}}"
1575
+ [ "${#lower}" -eq "${#prefix}" ] || return 0
1576
+ if [ -e "$base$lower" ] || [ -L "$base$lower" ]; then return 0; fi
1577
+ # Absence only counts when the nearest existing ancestor of that spelling is a searchable directory
1578
+ # (the lookup then ends in "no such entry", not in a permission or other lookup error).
1579
+ parent="$lower"
1580
+ while :; do
1581
+ case "$parent" in */*) parent="${parent%/*}" ;; *) parent="" ;; esac
1582
+ [ -n "$parent" ] || [ "${lower#/}" = "$lower" ] || parent="/"
1583
+ if [ -z "$parent" ]; then parent="${base:-/}"; break; fi
1584
+ if [ -e "$base$parent" ] || [ -L "$base$parent" ]; then parent="$base$parent"; break; fi
1585
+ done
1586
+ [ -d "$parent" ] && [ -x "$parent" ] || return 0
1587
+ return 1
1588
+ }
1503
1589
  candidates=()
1504
- while IFS= read -r candidate; do candidates[${#candidates[@]}]="$candidate"; done <<<"$candidates_text"
1590
+ while IFS= read -r candidate; do
1591
+ case "$candidate" in
1592
+ $'\001'*)
1593
+ alias_rest="${candidate#?}"
1594
+ if alias_needed "${alias_rest%%$'\001'*}" "${alias_rest#*$'\001'}"; then candidates[${#candidates[@]}]="${alias_rest#*$'\001'}"; fi
1595
+ ;;
1596
+ *) candidates[${#candidates[@]}]="$candidate" ;;
1597
+ esac
1598
+ done <<<"$candidates_text"
1599
+ [ "${#candidates[@]}" -gt 0 ] || exit 0
1505
1600
  classifier="$script_directory/cratis-guard-writes.sh"
1506
1601
  [ -f "$classifier" ] || {
1507
1602
  printf '%s\n' 'BLOCKED by cratis-guard-shell-writes: could not check references (write guard is missing).' >&2
@@ -126,6 +126,62 @@ normalize_target_path() {
126
126
  REPLY="${normalized:-/}"
127
127
  }
128
128
 
129
+ # Resolution changes directory in this shell (no per-path fork); a directory that cannot be restored is undeterminable.
130
+ working_directory_lost() {
131
+ printf 'BLOCKED by cratis-guard-writes: the working directory could not be restored while resolving a path.\n' >&2
132
+ exit 2
133
+ }
134
+
135
+ # Whether $1 cannot be resolved for a reason other than being absent: the nearest existing ancestor is a
136
+ # non-directory, a symlink that does not resolve (dangling or looping), or a directory that is not searchable.
137
+ # A genuinely missing path is not an error. Builtins only.
138
+ path_resolution_error() {
139
+ local candidate="$1"
140
+ while :; do
141
+ if [ -d "$candidate" ]; then
142
+ [ -x "$candidate" ] && return 1
143
+ return 0
144
+ fi
145
+ if [ -e "$candidate" ] || [ -L "$candidate" ]; then return 0; fi
146
+ candidate="${candidate%/*}"
147
+ [ -n "$candidate" ] || candidate=/
148
+ done
149
+ }
150
+
151
+ # The path the kernel opens: each directory before a parent reference is resolved physically
152
+ # (symlinks followed) before the reference applies. A missing prefix keeps the lexical result; a prefix
153
+ # that fails to resolve for another reason sets kernel_strict so the caller fails closed (it is also set by
154
+ # physical_target_path). Returns through REPLY.
155
+ kernel_strict=0
156
+ kernel_target_path() {
157
+ local remaining="$1" resolved="" component start="$PWD"
158
+ kernel_strict=0
159
+ while [ -n "$remaining" ]; do
160
+ component="${remaining%%/*}"
161
+ if [ "$remaining" = "$component" ]; then
162
+ remaining=""
163
+ else
164
+ remaining="${remaining#*/}"
165
+ fi
166
+ case "$component" in
167
+ "" | .) ;;
168
+ ..)
169
+ if cd -P -- "${resolved:-/}" 2>/dev/null; then
170
+ resolved="$PWD"
171
+ cd "$start" 2>/dev/null || working_directory_lost
172
+ elif path_resolution_error "${resolved:-/}"; then
173
+ kernel_strict=1
174
+ fi
175
+ resolved="${resolved%/*}"
176
+ ;;
177
+ *)
178
+ resolved="$resolved/$component"
179
+ ;;
180
+ esac
181
+ done
182
+ REPLY="${resolved:-/}"
183
+ }
184
+
129
185
  block() {
130
186
  # Pi can run the bundled script in a consumer checkout; this root is only for diagnostics,
131
187
  # so it is looked up only when a write is actually refused.
@@ -144,8 +200,9 @@ physical_target_path() {
144
200
  physical_file=""
145
201
  while [ -L "$target" ]; do
146
202
  hops=$((hops + 1))
147
- [ "$hops" -le 40 ] || return 1
148
- link="$(readlink "$target")" || return 1
203
+ # A loop or an unreadable link is an error, not a missing destination.
204
+ [ "$hops" -le 40 ] || { kernel_strict=1; return 1; }
205
+ link="$(readlink "$target")" || { kernel_strict=1; return 1; }
149
206
  dir_of "$target"
150
207
  abspath "$link" "$REPLY"
151
208
  target="$REPLY"
@@ -154,6 +211,7 @@ physical_target_path() {
154
211
  directory="$REPLY"
155
212
  base_of "$target"
156
213
  suffix="/$REPLY"
214
+ if [ ! -d "$directory" ] && path_resolution_error "$directory"; then kernel_strict=1; return 1; fi
157
215
  while [ ! -d "$directory" ]; do
158
216
  [ "$directory" != "/" ] || return 1
159
217
  base_of "$directory"
@@ -161,9 +219,9 @@ physical_target_path() {
161
219
  dir_of "$directory"
162
220
  directory="$REPLY"
163
221
  done
164
- cd -P "$directory" 2>/dev/null || return 1
222
+ cd -P "$directory" 2>/dev/null || { kernel_strict=1; return 1; }
165
223
  directory="$PWD"
166
- cd "$start" 2>/dev/null || true
224
+ cd "$start" 2>/dev/null || working_directory_lost
167
225
  physical_file="${directory%/}$suffix"
168
226
  }
169
227
 
@@ -411,12 +469,15 @@ session_manifests_allowed() {
411
469
  return "$session_manifest_policy"
412
470
  }
413
471
 
472
+ # Whether the repository owning $1 (an absolute path) permits manifest writes; the session decides first.
414
473
  manifest_writes_allowed() {
415
- local directory policy_root start="$PWD"
474
+ local target="$1" directory policy_root start="$PWD"
475
+ # A prefix that cannot be resolved is never trusted.
476
+ [ "$kernel_strict" != 1 ] || return 1
416
477
  # The session decides first; the target is only consulted to tighten it.
417
478
  session_manifests_allowed || return 1
418
479
  # New files can have nonexistent parents; find their nearest existing directory first.
419
- dir_of "$file"
480
+ dir_of "$target"
420
481
  directory="$REPLY"
421
482
  while [ ! -d "$directory" ]; do
422
483
  [ "$directory" != "/" ] || return 1
@@ -426,15 +487,14 @@ manifest_writes_allowed() {
426
487
  # Follow existing directory symlinks before asking Git which repository owns the target.
427
488
  cd -P "$directory" 2>/dev/null || return 1
428
489
  directory="$PWD"
429
- cd "$start" 2>/dev/null || true
490
+ cd "$start" 2>/dev/null || working_directory_lost
430
491
  policy_root="$(git -C "$directory" rev-parse --show-toplevel 2>/dev/null)" || return 1
431
492
  repository_manifest_policy "$policy_root"
432
493
  }
433
494
 
434
- # Return the category, leaving normal Write/Edit diagnostics unchanged below.
435
- classify_file() {
436
- local reference_pattern="${2:-0}" physical_base=""
437
- abspath "$1" "$cwd"; normalize_target_path "$REPLY"; file="$REPLY"
495
+ # Judge $file (already absolute and normalized) and its physical destination.
496
+ classify_resolved() {
497
+ local physical_base=""
438
498
  base_of "$file"; base="$REPLY"
439
499
  physical_target_path "$file" || physical_file=""
440
500
  if [ -n "$physical_file" ]; then base_of "$physical_file"; physical_base="$REPLY"; fi
@@ -442,7 +502,8 @@ classify_file() {
442
502
  classification=controls; return 0
443
503
  fi
444
504
  if names_match "$base" "${manifest_patterns[@]}" || names_match "$physical_base" "${manifest_patterns[@]}"; then
445
- if manifest_writes_allowed; then
505
+ # The addressed and the fully resolved destination are both authorized; either may refuse.
506
+ if manifest_writes_allowed "$file" && { [ -z "$physical_file" ] || manifest_writes_allowed "$physical_file"; }; then
446
507
  # Preserve reference-pattern policy when resolution leaves the basename unchanged.
447
508
  [ "$base" != "$physical_base" ] || return 1
448
509
  else
@@ -455,6 +516,22 @@ classify_file() {
455
516
  return 1
456
517
  }
457
518
 
519
+ # Return the category, leaving normal Write/Edit diagnostics unchanged below. A path with parent references is
520
+ # judged on its lexical form and on the form the kernel opens; either may refuse it.
521
+ classify_file() {
522
+ # reference_pattern is read by names_match and control_match through dynamic scope.
523
+ local raw reference_pattern="${2:-0}"
524
+ abspath "$1" "$cwd"; raw="$REPLY"
525
+ normalize_target_path "$raw"; file="$REPLY"
526
+ kernel_strict=0
527
+ if classify_resolved; then return 0; fi
528
+ case "$raw" in */.. | */../*) ;; *) return 1 ;; esac
529
+ kernel_target_path "$raw"
530
+ [ "$REPLY" != "$file" ] || [ "$kernel_strict" = 1 ] || return 1
531
+ file="$REPLY"
532
+ classify_resolved
533
+ }
534
+
458
535
  if [ "$reference_mode" = 1 ]; then
459
536
  reference_root="$cwd"
460
537
  while [ ! -e "$reference_root/.git" ]; do
@@ -16,7 +16,7 @@ Enforce a new rule on an existing command. Invoke the **cratis-arc-command-valid
16
16
  - Reusable value invariant → `ConceptValidator<T>`.
17
17
  - Command-input / cross-field / pre-handler rule → `CommandValidator<T>`.
18
18
  - Handler needs fetched data first → `Provide()`.
19
- - State rule that must hold **under concurrency** → read protection `On` (the default from Arc 23; on Arc 22 set `<CratisReadProtection>On</CratisReadProtection>`): the read model is a `CommandValidator<T>` constructor parameter and `Handle()` returns the events; add `[LookUpBy]` for a second entity, a per-stream read model or `IStreamReads`/`StreamDecision` for one stream. `[ProtectedDecision]` with `DecisionRead<T>` is the older per-command opt-in. Under `Off` (set explicitly, or the Arc 22 behavior) a validator over a plain read is a hint, and `Result<TEvent, ValidationResult>` alone adds no guard. Specify the business decision by calling `Handle()` or the validator directly with supplied read-model state. Follow `.cratis/ai/rules/specs.scenarios.csharp.md`: keep one cheap assembly-level shape-admission spec; the platform's concurrency/guard matrix belongs only in Arc/Chronicle specs.
19
+ - State rule that must hold **under concurrency** → read protection `On` (the default from Arc 23: leave `<CratisReadProtection>` unset, no per-command `On`; opt out only with `[Unprotected("why")]`; legacy Arc 22 defaulted to `Off` and needed `<CratisReadProtection>On</CratisReadProtection>`): the read model is a `CommandValidator<T>` constructor parameter and `Handle()` returns the events; add `[LookUpBy]` for a second entity, a per-stream read model or `IStreamReads`/`StreamDecision` for one stream. `[ProtectedDecision]` with `DecisionRead<T>` is the older per-command opt-in. Under `Off` (set explicitly, or the Arc 22 behavior) a validator over a plain read is a hint, and `Result<TEvent, ValidationResult>` alone adds no guard. Specify the business decision by calling `Handle()` or the validator directly with supplied read-model state. Follow `.cratis/ai/rules/specs.scenarios.csharp.md`: keep one cheap assembly-level shape-admission spec; the platform's concurrency/guard matrix belongs only in Arc/Chronicle specs.
20
20
  - Uniqueness → `[Unique]` / `IConstraint`.
21
21
 
22
22
  > **Never throw for normal business rejection** — a throw is HTTP 500, not a validation error. Recoverable rejection is a `ValidationResult` / `Result<,>`. Add a direct-call failure spec; a pipeline validation spec asserts both not-successful and has-validation-errors. The skill carries the detail; don't duplicate it here.
@@ -66,7 +66,7 @@ Tagged **[contract]** (framework-enforced) or **[convention]** (house default).
66
66
 
67
67
  ## Implementation Workflow
68
68
 
69
- - **Starting a brand-new application:** scaffold it instead of hand-writing the skeleton: `dotnet new install Cratis.Templates`, then `dotnet new cratis -n MyApp -o MyApp` (`--language Kotlin|Java`, `--Database MongoDB|PostgreSQL|MsSql|SQLite`; `cratis-aspire` for Aspire; `cratis-chronicle-console` or `cratis-chronicle-web` for a Chronicle client only). Non-interactive runs need `--allow-scripts yes`; the .NET templates target `net10.0`. The template writes `.cratis/ai.json`; run `cratis ai update` afterwards. Its `SomeModule/SomeFeature/Registration/` slice is the house shape. There is no Go, Python or Elixir template (verified at Cratis.Templates `v1.8.1`). Since 1.8.0 the `cratis` and `cratis-aspire` .NET app projects emit `<CratisReadProtection>On</CratisReadProtection>`: read models supplied to commands and validators guard the append. Existing apps are not changed by reinstalling the templates.
69
+ - **Starting a brand-new application:** scaffold it instead of hand-writing the skeleton: `dotnet new install Cratis.Templates`, then `dotnet new cratis -n MyApp -o MyApp` (`--language Kotlin|Java`, `--Database MongoDB|PostgreSQL|MsSql|SQLite`; `cratis-aspire` for Aspire; `cratis-chronicle-console` or `cratis-chronicle-web` for a Chronicle client only). Non-interactive runs need `--allow-scripts yes`; the .NET templates target `net10.0`. The template writes `.cratis/ai.json`; run `cratis ai update` afterwards. Its `SomeModule/SomeFeature/Registration/` slice is the house shape. There is no Go, Python or Elixir template (verified at Cratis.Templates `v1.8.1`). Since 1.8.0 the `cratis` and `cratis-aspire` .NET app projects emit `<CratisReadProtection>On</CratisReadProtection>` (redundant on Arc 23+, where `On` is the default; leave it unset in hand-written projects): read models supplied to commands and validators guard the append. Existing apps are not changed by reinstalling the templates.
70
70
  - **Phase 0 — Find the contract / choose the level.** Before writing slice code, find what the code must match, and choose the level once for the whole scope.
71
71
  1. **Look for a Screenplay model** under the model root (opted in per `general.md` "Model first"; where `cratis-screenplay-modeling-lifecycle` is installed, run its `scripts/model-first-status.mjs` for the decision, root and drafts) for the slice, command, event and read-model names.
72
72
  2. **Model level** — an accepted model under the root covers the scope, or the repository is opted in and this scope has no model yet. The `.play` slice and its specs are the contract: change the model first (new behavior starts in discovery), verify it (V1–V3), get an independent review, then render with Stage or gap-fill by hand only what the renderer rejects. Hand-written code stays checked against the model (**cratis-application-slice-conformance**). Never edit Stage-managed output, never implement behavior the model does not state, never change the model to match existing code, never weaken protection to make it compile or render. Start with **cratis-screenplay-event-modeling** (decision rule), then **cratis-screenplay-modeling-lifecycle**. If the Screenplay skills are not installed, say so; do not author `.play` from memory.
@@ -182,7 +182,7 @@ Three attributes scope an append broad→narrow, and each one *also* (only with
182
182
 
183
183
  Each attribute always tags the appended events (visible in `EventContext`). **Only when the command also carries `concurrency: true`** does each dimension join the server-side `ConcurrencyScope` (plus the event source id), with the optimistic strategy supplying the expected tail sequence number. A command **without** `concurrency: true` contributes no scope of its own, and the append falls to whatever concurrency strategy the event sequence is configured with — by default the optimistic one, scoped to the event source. So the attribute chooses *which dimensions* bound the check, not whether a check happens at all. Reach for it on high-contention state transitions where a stale read would let two commands both "win" — it narrows the boundary so appends that are genuinely independent stop colliding (concurrency failures surface on `CommandResult`/`AppendResult`). Adopt it deliberately per behavior, not as a blanket default.
184
184
 
185
- Read protection `On` is the default from Arc 23; on Arc 22 (22.106.0 or later) set `<CratisReadProtection>On</CratisReadProtection>`. A project that sets the property keeps its mode.
185
+ Read protection `On` is the default from Arc 23: leave `<CratisReadProtection>` unset (the `On` default comes from `Cratis.Arc.Chronicle`'s build props, `Source/DotNET/Chronicle/build/Cratis.Arc.Chronicle.props`; a project not importing them has no default) and never add `[ReadProtection(ReadProtectionMode.On)]` to a command. Opt out only where needed, narrowest first, each with a stated reason: `[Unprotected("why")]` on a read-model parameter, model type or method (one advisory read; the method form covers only raw reads in the body, never injected read-model parameters, and mixing it with protected read-model parameters raises ARCCHR0034, so put it on the parameter); `[Unprotected("why")]` or `[ReadProtection(ReadProtectionMode.Off)]` on one command; project-level `Off` or `Measure` only as a temporary adoption step. For a key computed at runtime, `IDecisionReads.Get<T>(key)` in `Provide` or a validator is a protected read; method-level `[Unprotected]` is only for reads the guard cannot cover (joins, children, other sequences, raw event store, external stores) and its reason names what guards the append. Arc 23 key metadata is strict by default (`CommandReadModelKeysMissing`, `ReadProtection:RequireGeneratedMetadata`, `ProtectedReadModelKeyOptions.Strict`). A project that sets the property keeps its mode. Legacy (Arc 22.106.0 and later 22.x only): the default was `Off`, so set `<CratisReadProtection>On</CratisReadProtection>`; remove it on upgrading to Arc 23.
186
186
  Under `On`, a read-model parameter of `Handle()` or of a `CommandValidator<T>`
187
187
  constructor is read fresh and guards the append; the state rule goes in the
188
188
  validator. Two entities: two parameters, `[LookUpBy(nameof(Cmd.Prop))]` on the
@@ -16,17 +16,21 @@ Source: Arc. These features require `Cratis.Arc.Chronicle`.
16
16
  ## Pick the guarded read
17
17
 
18
18
  **Idiomatic default:** a state-dependent rule takes the read model as a `Handle()`
19
- (or validator-constructor) parameter, with `[ReadProtection(On)]` where it must hold
20
- under concurrent writers. Do not take `IDecisionReads` in `Handle()`: it is not
19
+ (or validator-constructor) parameter; Arc 23 read protection `On` is the default, so it holds
20
+ under concurrent writers with no attribute. Do not take `IDecisionReads` in `Handle()`: it is not
21
21
  recommended with Arc and is not an investment target. A computed key stays in
22
22
  `Provide()` until a read-model parameter covers it. Direction, not a release claim:
23
23
  Arc will pin protected parameters so the idiomatic shape needs no further ceremony.
24
24
 
25
- Under read protection `On` (`<CratisReadProtection>On</CratisReadProtection>`, or
26
- `[ReadProtection(ReadProtectionMode.On)]` on a command), a read model that is a
25
+ Under read protection `On`, the default from Arc 23 when nothing is set (leave
26
+ `<CratisReadProtection>` unset (the default comes from `Cratis.Arc.Chronicle`'s build props, `Source/DotNET/Chronicle/build/Cratis.Arc.Chronicle.props`; a project not importing them has no default); do not write `On` or `[ReadProtection(ReadProtectionMode.On)]`), a read model that is a
27
27
  parameter of `Handle()` or of a `CommandValidator<T>` constructor is read fresh from
28
- the event log and guards the command's append. `On` is the default from Arc 23 when nothing is
29
- set (`Off` was the Arc 22 behavior); under `Off` and `Measure` those reads are plain, a hint that guards nothing.
28
+ the event log and guards the command's append. Opt out narrowest first, with a reason:
29
+ `[Unprotected("why")]` on the parameter, model type or method (one advisory read; the method form covers only raw reads in the method body, never injected read-model parameters, and combining it with protected read-model parameters raises ARCCHR0034, so put `[Unprotected]` on the specific parameter), then
30
+ `[Unprotected("why")]` or `[ReadProtection(ReadProtectionMode.Off)]` on the command; project-level
31
+ `Off`/`Measure` is a temporary adoption step. Under `Off` and `Measure` those reads are plain, a hint that guards nothing
32
+ (`Off` was the Arc 22 default).
33
+ For a key computed at runtime, `IDecisionReads.Get<T>(key)` in `Provide()` or a validator is a protected read; method-level `[Unprotected]` is only for reads the guard cannot cover (joins, children, other sequences, raw event store, external stores), and its reason names what guards the append. Arc 23 read-model key metadata is strict by default: missing generated metadata fails with `CommandReadModelKeysMissing` (`ReadProtection:RequireGeneratedMetadata`), and `ProtectedReadModelKeyOptions.Strict` requires composite key accessors.
30
34
  A `Result<TEvent, ValidationResult>` rejects a request but does not enroll a guard.
31
35
  Uniqueness and create-once belong to a Chronicle constraint, not to any read. For the
32
36
  routing by rule shape, the matrix and the traps read
@@ -7,8 +7,8 @@
7
7
  - Which provider owns a read model type
8
8
 
9
9
  Source: [read models in commands](https://github.com/Cratis/Arc/blob/main/Documentation/backend/csharp/chronicle/read-models/injecting-into-commands.md).
10
- Under read protection `Off` (set explicitly, or the Arc 22 behavior) and `Measure`, injected models and keyed
11
- reads are plain reads, not concurrency guards. Under `On`, a read-model parameter of
10
+ Under read protection `Off` (Arc 22 default; on Arc 23 only an explicit, reasoned opt-out) and `Measure`, injected models and keyed
11
+ reads are plain reads, not concurrency guards. Under `On`, the Arc 23 default, a read-model parameter of
12
12
  `Handle()` or a validator constructor is guarded; `IReadModels.GetInstanceById` in a
13
13
  command is refused, so read another entity's model with a second parameter and
14
14
  `[LookUpBy(nameof(Cmd.Prop))]`. See [decisions and routing](decisions-and-routing.md)
@@ -175,10 +175,12 @@ public async Task<Result<Customer, ValidationResult>> Provide(IReadModels readMo
175
175
 
176
176
  ## Step 5 — Guard a concurrency-sensitive decision
177
177
 
178
- Read protection `On` is the default from Arc 23; on Arc 22 set
179
- `<CratisReadProtection>On</CratisReadProtection>`
180
- in the project (or `[ReadProtection(ReadProtectionMode.On)]` on one command). Under
181
- `On`, the read-model parameters of `Handle()` and of the validator constructor are
178
+ Read protection `On` is the default from Arc 23: leave `<CratisReadProtection>` unset
179
+ and do not add `[ReadProtection(ReadProtectionMode.On)]`. (Legacy, Arc 22.106.0 and later 22.x:
180
+ the default was `Off`; set `<CratisReadProtection>On</CratisReadProtection>`.) Opt out only
181
+ where needed, narrowest first and with a reason: `[Unprotected("why")]` on one read-model
182
+ parameter, `[Unprotected("why")]` or `[ReadProtection(ReadProtectionMode.Off)]` on one command.
183
+ Under `On`, the read-model parameters of `Handle()` and of the validator constructor are
182
184
  the guard, so the state rule is a validator and `Handle()` returns the events.
183
185
  Requires Arc 22.106.0. Under `Off` (set explicitly, or the Arc 22 behavior) a plain read guards nothing, even
184
186
  inside `Handle()` returning `Result<,>`. Choose the first boundary that fits:
@@ -63,7 +63,7 @@ passed to `AddCratisArc` runs after binding and wins over configuration.
63
63
  ingress that authenticates callers and replaces the identity headers.
64
64
  - **`ReadProtection` keys are root-level.** `Cratis:Arc:ReadProtection:*` has no
65
65
  effect. The protection mode itself is the `CratisReadProtection` build
66
- property, not configuration.
66
+ property, not configuration; on Arc 23 leave it unset (default `On`).
67
67
  - **Do not put connection strings or credentials in committed appsettings.**
68
68
  Use secret configuration or environment variables.
69
69
  - Do not change a setting on a shared or deployed environment without stating
@@ -49,4 +49,6 @@ is `ReadProtection__MaximumMode`. `Cratis:Arc:ReadProtection:*` has no effect.
49
49
  | `ReadProtection:MeasureScanLimit` | 500 events | 1 to 500. |
50
50
 
51
51
  The mode itself is the `CratisReadProtection` MSBuild property, not a
52
- configuration key.
52
+ configuration key. Arc 23 defaults it to `On`: leave it unset. Set `Measure` or
53
+ `Off` only as a temporary adoption step, or `Off` for a justified project-wide opt-out; prefer
54
+ `[Unprotected("why")]` on the read or the command. (Arc 22 defaulted to `Off`.)
@@ -20,8 +20,9 @@ when the question is which mechanism to use, or before writing code that reads
20
20
  state and then appends. It carries the routing by rule shape, the matrix with what
21
21
  not to use, the refusals, rollout with Measure, testing and the traps.
22
22
 
23
- In an Arc application using `Cratis.Arc.Chronicle`, read protection `On` is the default from Arc 23 (on Arc 22 set
24
- `<CratisReadProtection>On</CratisReadProtection>`; `Off` was the Arc 22 behavior). Under `On` the read model is a parameter of `Handle()` or of the
23
+ In an Arc application using `Cratis.Arc.Chronicle`, read protection `On` is the default from Arc 23: leave `<CratisReadProtection>` unset and opt out
24
+ only where needed, with a reason (see choosing-how-a-rule-holds, *Reads under Off, Measure and On*).
25
+ (Legacy: on Arc 22, `Off` was the default; set `<CratisReadProtection>On</CratisReadProtection>`.) Under `On` the read model is a parameter of `Handle()` or of the
25
26
  `CommandValidator<T>` constructor, and the read guards the append; under `Off` and
26
27
  `Measure` a validator over a plain read is a hint that guards nothing. A plain read under
27
28
  `Off`, `Result<,>` and `concurrency: true` are never the guard.
@@ -11,6 +11,7 @@
11
11
  - Refusals
12
12
  - Arc traps
13
13
  - Chronicle-only traps
14
+ - Opting out of read protection
14
15
  - Roll out with Measure
15
16
  - Specify the business decision
16
17
  - Costs
@@ -31,11 +32,13 @@ Published guides this agrees with:
31
32
 
32
33
  ## Defaults
33
34
 
34
- - Read protection is `On` unless the project sets it (the default from Arc 23;
35
- `Off` was the Arc 22 behavior). On Arc 22 set
36
- `<CratisReadProtection>On</CratisReadProtection>` in the project (it
37
- emits `[assembly: ReadProtection(ReadProtectionMode.On)]`; an invalid value
38
- fails the build). Existing code moves `Off` to `Measure` to `On`; see
35
+ - Read protection is `On` unless the project sets it (the default from Arc 23).
36
+ Leave `<CratisReadProtection>` unset (the default comes from `Cratis.Arc.Chronicle`'s build props, `Source/DotNET/Chronicle/build/Cratis.Arc.Chronicle.props`; a project not importing them has no default); do not write `On` or add
37
+ `[ReadProtection(ReadProtectionMode.On)]` per command. Opt out only where
38
+ needed; see [Opting out](#opting-out-of-read-protection). Legacy: on Arc 22 the
39
+ default was `Off`, so new code set `<CratisReadProtection>On</CratisReadProtection>`
40
+ (it emits `[assembly: ReadProtection(ReadProtectionMode.On)]`; an invalid value
41
+ fails the build). A project that pinned `Off` migrates through `Measure`; see
39
42
  [Roll out with Measure](#roll-out-with-measure).
40
43
  - Under `On`, a read model that is a parameter of `Handle()` or of a
41
44
  `CommandValidator<T>` constructor is read fresh from the event log and guards
@@ -108,12 +111,12 @@ append, a reactor, or an `ExpectedRevision` never passed into a scope.
108
111
 
109
112
  | Mode | Read-model parameter, validator constructor | Results and status codes |
110
113
  | --- | --- | --- |
111
- | `Off` (Arc 22 behavior, or set explicitly) | plain read; a hint, guards nothing | as today |
114
+ | `Off` (Arc 22 default; on Arc 23 only an explicit opt-out) | plain read; a hint, guards nothing | as today |
112
115
  | `Measure` | plain read; Arc reports what `On` would do | same as `Off` |
113
116
  | `On` | read fresh from the log; guards the command's append | a lost race is HTTP 400 |
114
117
 
115
- A command overrides the project with `[ReadProtection(ReadProtectionMode.On)]`
116
- (`Cratis.Arc.Commands`); command-level `[Unprotected]` means `Off`. The runtime
118
+ A command overrides the project with `[ReadProtection(ReadProtectionMode.Off)]` or
119
+ `Measure` (`Cratis.Arc.Commands`); command-level `[Unprotected]` means `Off`. The runtime
117
120
  cap `ReadProtection:MaximumMode` only lowers (a missing or invalid value is `On`,
118
121
  no cap); a lowered command logs a startup Warning. With the cap set, the `On`
119
122
  behaviour does not hold.
@@ -282,11 +285,37 @@ return `Commit()` last), `ReadOfSourceWithStagedEvents`, `ExplicitScopeDoesNotCo
282
285
  - Arc has a static class also named `ConcurrencyScopeBuilder`; in an Arc project
283
286
  qualify Chronicle's builder.
284
287
 
288
+ ## Opting out of read protection
289
+
290
+ Only where a read must stay advisory, always with a stated reason, narrowest first
291
+ (Arc 23 source: `Source/DotNET/Arc.Core/Commands/CommandAttributePolicy.cs`,
292
+ `Source/DotNET/Shared/AttributePrecedencePolicy.cs`):
293
+
294
+ 1. `[Unprotected("why")]` on a read-model parameter, the model type, or the method
295
+ (`Cratis.Arc.Chronicle.ReadModels`): that read is advisory.
296
+ The method form covers only raw reads in the method body, never its injected
297
+ read-model parameters; combining it with protected read-model parameters raises
298
+ `ARCCHR0034`, so put `[Unprotected]` on the specific parameter. For a key computed
299
+ at runtime, `IDecisionReads.Get<T>(key)` in `Provide` or a validator is a protected
300
+ read; method-level `[Unprotected]` is only for reads the guard cannot cover (joins,
301
+ children, other sequences, raw event store, external stores) and its reason names
302
+ what guards the append. Arc 23 key metadata is strict by default:
303
+ `CommandReadModelKeysMissing` (`ReadProtection:RequireGeneratedMetadata`) and
304
+ `ProtectedReadModelKeyOptions.Strict`.
305
+ 2. `[Unprotected("why")]` or `[ReadProtection(ReadProtectionMode.Off)]` on one command
306
+ (`Measure` also works there). Command `[Unprotected]` wins over any
307
+ `[ReadProtection]`; an explicit `On`/`Measure` beside it throws
308
+ `ConflictingReadProtection`. Otherwise a command declaration beats the assembly one.
309
+ 3. Project-level `<CratisReadProtection>Off</CratisReadProtection>` or `Measure`: only a
310
+ temporary adoption step, never the end state.
311
+
285
312
  ## Roll out with Measure
286
313
 
287
- Steps: update the packages, set `<CratisReadProtection>Measure</CratisReadProtection>`,
288
- run the application and its tests, read the report, fix or annotate each finding,
289
- then set `On` per project. Behaviour for callers does not change under `Measure`.
314
+ For a project upgraded from Arc 22 that pinned `Off` (or leaves a lot of reads
315
+ unguarded). Steps: update the packages, set `<CratisReadProtection>Measure</CratisReadProtection>`,
316
+ run the application and its tests, read the report, fix each finding or add a
317
+ justified opt-out, then remove the property and any per-command
318
+ `[ReadProtection(ReadProtectionMode.On)]` so the default applies. Behaviour for callers does not change under `Measure`.
290
319
 
291
320
  - The report: meter `Cratis.Arc.ReadProtection`, counter
292
321
  `cratis.arc.read_protection.events` (tags `command`, `category`, `model`,
@@ -84,7 +84,9 @@ there is nothing to review under a red build.
84
84
  - Logging lives in a `*Logging.cs` partial with `[LoggerMessage]`, not inline in
85
85
  domain code.
86
86
  - No shared mutable state between commands.
87
- - Read protection is `On` by default from Arc 23; on Arc 22 new code sets `<CratisReadProtection>On</CratisReadProtection>`.
87
+ - Read protection is `On` by default from Arc 23. Flag an explicit `<CratisReadProtection>On</CratisReadProtection>` or
88
+ `[ReadProtection(ReadProtectionMode.On)]` as redundant, and any `Off`, `Measure` or `[Unprotected]` without a stated reason
89
+ (legacy: on Arc 22 new code had to set `On`).
88
90
  Under `Off` an injected model or validator read is advisory, not a concurrency guard.
89
91
  Under `On`, review that state rules sit in validators or handlers with the model as
90
92
  a parameter and `[Unprotected("why")]` carries a real reason. Apply
@@ -143,7 +143,7 @@ Stage admits ESM v25.
143
143
 
144
144
  Requires Stage 4.138.0 for the Cratis renderer to render protected reads; `cratis render` gets it from the first CLI that bundles it, and CLI 3.75.0 (Stage 4.137.0) and older refuse every protected read with STAGE-ESM-044.
145
145
 
146
- Each command with `reads` becomes an Arc command with `[ReadProtection(On)]`, a
146
+ Each command with `reads` becomes an Arc command (the renderer emits `[ReadProtection(On)]`, redundant on Arc 23, where `On` is the default; do not hand-write it), a
147
147
  nullable read-model `Handle` parameter per read looked up with `[LookUpBy]`, the
148
148
  `<View> '<key>' does not exist.` rejection, and every requirement evaluated in `Handle`
149
149
  after the reads. Generated specifications run protected commands in decision mode.
@@ -108,7 +108,7 @@ another event source) in `Provide()`/`Handle()` and returning a validation resul
108
108
  at commit is reported as a concurrency violation. Equivalently a Chronicle decision-consistency
109
109
  read with a `concurrency` scope on the event source or stream. A passive read is fresh
110
110
  computation, not an atomic read-and-append; a plain materialized view and a validator are
111
- advisory under Arc read protection `Off` (set explicitly, or the Arc 22 behavior); `On` is the default from Arc 23 (Arc 22.106.0 or later can set it) and the read
111
+ advisory under Arc read protection `Off` (an explicit opt-out on Arc 23, or the Arc 22 default); `On` is the default from Arc 23 (legacy: Arc 22.106.0 or later must set it) and the read
112
112
  model parameters of `Handle()` and of a validator constructor are guarded. Protection covers a single
113
113
  projection keyed directly by the event source id (routing key empty or `$eventSourceId`) and an
114
114
  unfiltered reducer without constructor dependencies. Filtered reducers, reducers with dependencies,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.171.0",
3
+ "version": "7.172.1",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [