@cratis/pi 7.181.0 → 7.182.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.
@@ -333,6 +333,26 @@ public class ReactorSideEffectHandlers(IInstancesOf<IReactorSideEffectHandler> h
333
333
  - Keep log messages in a separate `<ClassName>Logging.cs` partial static internal class.
334
334
  - Use `[LoggerMessage]` attribute (without `eventId`).
335
335
 
336
+ ## C# 14/15 Language Features
337
+
338
+ Cratis .NET repos build with SDK 11 (C# 15); libraries target `net10.0;net11.0`.
339
+
340
+ Use in new code:
341
+
342
+ - Extension blocks (`extension(T x) { ... }`, C# 14) for new extension APIs; leave existing extension classes as they are.
343
+ - The `field` keyword (C# 14) in property accessors instead of a hand-written backing field.
344
+ - `System.Threading.Lock` for new lock objects instead of `object`.
345
+ - Collection expression arguments `with(...)` (C# 15), e.g. to pass a comparer or capacity.
346
+ - `closed` (C# 15) for new internal class hierarchies.
347
+
348
+ Avoid:
349
+
350
+ - Union types in public APIs of libraries that also target `net10.0` — consumers on C# 14 cannot use them.
351
+ - Adding `closed` to existing public types — it is a breaking change.
352
+ - Runtime-async — it is still preview.
353
+
354
+ Keep `ConceptAs<T>` and the existing result envelopes unchanged.
355
+
336
356
  ## Async
337
357
 
338
358
  - Use `async`/`await` for asynchronous programming.
@@ -553,14 +553,50 @@ and Pi:
553
553
  ```
554
554
 
555
555
  `false` re-enables the manifest block in a Cratis repository; `true` allows manifest writes
556
- in any repository, for targets that do not themselves block (see above). Merge this property into the existing configuration. An absent, malformed,
557
- or non-boolean setting uses the origin-based default. This setting never permits `.env` writes.
556
+ in any repository, for targets that do not themselves block (see above). Merge this property into the existing configuration. An absent
557
+ or non-boolean setting uses the origin-based default (an unparsable file protects the whole repository; see below). This setting never permits `.env` writes.
558
558
  The protected basename list is unchanged; `package.json` is not part of this guard's manifest category.
559
559
 
560
560
  This allowance is not authorization for unrelated upgrades: keep changes task-focused and
561
561
  call out version bumps in the PR description. Other repositories retain the rule requiring
562
562
  an explicit request; their setting is a mechanical opt-out, not a change to that rule.
563
563
 
564
+ #### Repository-declared protected paths
565
+
566
+ A repository can add its own agent-control paths with `protectedPaths` in its `.cratis/ai.json`:
567
+
568
+ ```json
569
+ { "protectedPaths": ["docs/release/*", "RELEASE.md", "deploy/"] }
570
+ ```
571
+
572
+ Both the Write/Edit guard and the shell-write guard treat these exactly like the built-in controls:
573
+ same case-insensitive matching, same symlink and `..` normalisation, same
574
+ deny message and the same `CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1` override. The file read is the
575
+ `.cratis/ai.json` at the root of the repository that owns the target path, not the session's; globs are
576
+ relative to that root.
577
+ The list is additive: it cannot remove or weaken a built-in control, and `.cratis/ai.json` stays protected.
578
+
579
+ A declared entry takes one of three shapes, so exactly the same literal-prefix machinery as the built-in controls
580
+ (`.pi/extensions/*`, `.claude/settings.json`) protects it for every command shape, folder operands included (`rm -rf`,
581
+ `mv`, `rsync --delete`, `cp -r`, `tar -C`, `unzip -d`, `ln -sfn`, `find -delete`, `cd dir && …`):
582
+
583
+ - a literal **file** path: `tools/guard.sh` (a folder operand that contains it is protected too);
584
+ - a literal **folder** with a trailing `/`: `hooks/` (everything under it);
585
+ - a literal folder followed by a whole final segment `*`: `hooks/*` (the same as `hooks/`).
586
+
587
+ Segments use only `A-Z a-z 0-9 . _ - /`; a leading `./` is ignored. A `*` anywhere else is **not accepted**: inside a name
588
+ (`*.sh`, `settings*.json`, `src/*.ts`, `a*/b`), in a leading or middle segment, `**`, or alone. A name wildcard
589
+ crosses `/` for single files but cannot be matched against a folder operand, so it would be enforced for `Write` yet
590
+ missed by `rm -rf src/tests`. Also refused: `..`, `.` segments, empty segments, absolute paths and any other
591
+ character (`( ) | ! @ + ? [ ] { } \`, spaces, quotes, `$`, control or non-ASCII). Declare the folder, or the exact files.
592
+ Every enclosing repository's list applies, so a nested `.git` file or directory never hides the policy of an
593
+ ancestor repository (this holds for the built-in controls too).
594
+
595
+ Fail closed: if `.cratis/ai.json` cannot be read as one JSON object, or `protectedPaths` is not an array of at most 256
596
+ entries of the accepted shapes, the declared intent is unknowable, so **every** path in that repository is protected. The
597
+ deny message names `protectedPaths`, the first offending entry (when it can be found) and the accepted shapes; the
598
+ declaration is rejected rather than ignored so a mistake is noticed. An absent or `null` `protectedPaths` declares nothing.
599
+
564
600
  **Blocked outright** (`PreToolUse` on `Bash`, exit 2): a `cratis chronicle` command that is not
565
601
  read-only. The **cratis-chronicle-cli-operations** skill makes `--yes` the authorization boundary for
566
602
  a live store and says a request to diagnose does not authorize a mutation; this guard enforces that.
@@ -372,6 +372,8 @@ lsof_matches() {
372
372
  # Anonymous-inode names are kernel objects whatever the reported type (for example a
373
373
  # memory-mapped `anon_inode:[io_uring]` is type REG), so the name alone exempts them.
374
374
  if (path ~ /^(anon_inode:)?\[[[:alnum:]_]+(:[0-9]+(,[0-9]+)*)?\]$/) next
375
+ # lsof truncates long names, leaving a digit/comma list ending in `...` with no closing bracket.
376
+ if (path ~ /^(anon_inode:)?\[[[:alnum:]_]+:[0-9,]*\.\.\.$/) next
375
377
  if (type == "a_inode" && path ~ /^(anon_inode:)?[[:alnum:]_]+$/) next
376
378
  if (type == "unix" && path ~ /^type=[[:upper:]]+( \([[:upper:]]+\))?$/) next
377
379
  if (type == "netlink" && path ~ /^[[:upper:]_]+$/) next
@@ -389,29 +389,75 @@ authored_corpus_repository() {
389
389
  return "$authored_cache_status"
390
390
  }
391
391
 
392
- agent_control_target() {
393
- local target="$1" directory policy_root target_rel managed pattern
394
- dir_of "$target"
395
- directory="$REPLY"
396
- if [ "$destructive_mode" = 1 ]; then
397
- [ ! -d "$target" ] || directory="$target"
398
- # A mutation of the repository or any containing directory reaches its controls too.
399
- if [[ -n "$reference_root" && ( "$target" == / || "$reference_root" == "$target" || "$reference_root" == "$target"/* ) ]]; then
400
- directory="$reference_root"
401
- fi
392
+ # protectedPaths of one repository's .cratis/ai.json: globs relative to that root, additive to the built-ins.
393
+ # A declared entry is only (a) a literal file path (tools/guard.sh), (b) a literal folder with a trailing '/' (hooks/),
394
+ # or (c) a literal folder followed by a whole final segment '*' (hooks/*). A '*' anywhere else (inside a name such as
395
+ # *.sh or Source/*.ts, in a leading or middle segment, '**') would need a "could this folder hold a match" rule that
396
+ # folder operands (rm -rf, mv, rsync --delete, tar -C, unzip -d ...) cannot be given, so it is refused. The same literal-prefix
397
+ # machinery as the built-in controls then protects folders for every command shape. Characters: only A-Z a-z 0-9 . _ - /
398
+ # and that '*'. Anything else is refused.
399
+ protected_cache_root=""
400
+ protected_paths=()
401
+ protected_invalid=0
402
+ protected_config_root=""
403
+ protected_bad_entry=""
404
+ # The jq definition of a valid declared glob: the three accepted shapes (see above). Leading './' is
405
+ # dropped first, so the shape is judged on what is matched.
406
+ # shellcheck disable=SC2016
407
+ protected_glob_jq='
408
+ def norm: until(startswith("./") | not; .[2:]);
409
+ def shape: norm | split("/") as $s | ($s | length) as $n | ($s[-1]) as $last
410
+ | all($s[]; . != "." and . != "..") and all($s[:-1][]; length > 0 and (contains("*") | not))
411
+ and (($last | contains("*") | not) or ($last == "*" and $n > 1));
412
+ def valid: type == "string" and length > 0 and (startswith("/") | not)
413
+ and (explode | all(.[]; (. >= 48 and . <= 57) or (. >= 65 and . <= 90) or (. >= 97 and . <= 122) or . == 46 or . == 95 or . == 45 or . == 47 or . == 42))
414
+ and shape;
415
+ '
416
+ load_protected_paths() {
417
+ local root="$1" item index glob config="$1/.cratis/ai.json" items=() last
418
+ [ "$protected_cache_root" != "$root" ] || return 0
419
+ protected_cache_root="$root"
420
+ protected_paths=()
421
+ protected_invalid=0
422
+ protected_bad_entry=""
423
+ [ -e "$config" ] || [ -L "$config" ] || return 0
424
+ if [ -f "$config" ]; then
425
+ while IFS= read -r -d '' item; do items[${#items[@]}]="$item"; done < <(
426
+ jq -j -s "$protected_glob_jq"'
427
+ if length == 1 then .[0] else error("expected one JSON document") end
428
+ | (if type == "object" then .protectedPaths else error("expected an object") end)
429
+ | if . == null then []
430
+ elif type == "array" and length <= 256 and all(.[]; valid) then .
431
+ else error("invalid protectedPaths") end
432
+ | (.[], "ok") | ., "\u0000"' "$config" 2>/dev/null
433
+ )
402
434
  fi
403
- # Keep the addressed spelling here, even when an adapter directory is a symlink.
404
- # .git is a directory in a checkout and a file in a linked worktree.
405
- while [ ! -e "$directory/.git" ]; do
406
- [ "$directory" != "/" ] || return 1
407
- dir_of "$directory"
408
- directory="$REPLY"
435
+ last=$((${#items[@]} - 1))
436
+ if [ "$last" -lt 0 ] || [ "${items[$last]}" != ok ]; then
437
+ protected_invalid=1
438
+ # Best effort: name the first offending entry, when the file is readable enough to find one.
439
+ protected_bad_entry="$(jq -r -s "$protected_glob_jq"'
440
+ first(.[0].protectedPaths[]? | select(valid | not) | tojson | gsub("[^ -~]"; "?")) // empty' "$config" 2>/dev/null | head -c 200)" || protected_bad_entry=""
441
+ return 0
442
+ fi
443
+ for ((index = 0; index < last; index++)); do
444
+ glob="${items[$index]}"
445
+ while [[ "$glob" == ./* ]]; do glob="${glob#./}"; done
446
+ case "$glob" in */) glob="$glob*" ;; esac
447
+ protected_paths[${#protected_paths[@]}]="$glob"
409
448
  done
410
- policy_root="$directory"
449
+ }
450
+
451
+ # Whether the repository at policy_root treats target (absolute) as a control, by its own policy only.
452
+ agent_control_in_root() {
453
+ local target="$1" policy_root="$2" target_rel managed pattern
411
454
  if [[ "$destructive_mode" == 1 && ( "$target" == / || "$policy_root" == "$target" || "$policy_root" == "$target"/* ) ]]; then target_rel='.'
412
455
  else relative_to "$target" "$policy_root"; target_rel="$REPLY"; fi
413
456
  # Policy files remain controls even in the authored corpus repository.
414
457
  if control_match "$target_rel" '.cratis/ai.manifest.json' '.cratis/ai.json'; then return 0; fi
458
+ load_protected_paths "$policy_root"
459
+ if [ "$protected_invalid" = 1 ]; then protected_config_root="$policy_root"; return 0; fi
460
+ if [ "${#protected_paths[@]}" -gt 0 ] && control_match "$target_rel" "${protected_paths[@]}"; then return 0; fi
415
461
  if [ ! -f "$policy_root/.cratis/ai.manifest.json" ] && authored_corpus_repository "$policy_root"; then
416
462
  return 1
417
463
  fi
@@ -435,6 +481,33 @@ agent_control_target() {
435
481
  control_match "$target_rel" "${control_patterns[@]}"
436
482
  }
437
483
 
484
+ # The target is judged by the policy of every enclosing repository, innermost first: a nested .git (a directory in a
485
+ # checkout, a file in a linked worktree) never hides an ancestor's controls. Keep the addressed spelling here, even
486
+ # when an adapter directory is a symlink.
487
+ agent_control_target() {
488
+ local target="$1" directory
489
+ dir_of "$target"
490
+ directory="$REPLY"
491
+ if [ "$destructive_mode" = 1 ]; then
492
+ [ ! -d "$target" ] || directory="$target"
493
+ # A mutation of the repository or any containing directory reaches its controls too.
494
+ if [[ -n "$reference_root" && ( "$target" == / || "$reference_root" == "$target" || "$reference_root" == "$target"/* ) ]]; then
495
+ directory="$reference_root"
496
+ fi
497
+ fi
498
+ while :; do
499
+ while [ ! -e "$directory/.git" ]; do
500
+ [ "$directory" != "/" ] || return 1
501
+ dir_of "$directory"
502
+ directory="$REPLY"
503
+ done
504
+ if agent_control_in_root "$target" "$directory"; then return 0; fi
505
+ [ "$directory" != "/" ] || return 1
506
+ dir_of "$directory"
507
+ directory="$REPLY"
508
+ done
509
+ }
510
+
438
511
  # ── Dependency manifests, lockfiles, SDK and NuGet configuration ──────────────
439
512
  # Policy of one repository root: a boolean allowDependencyManifestWrites wins, else a github.com/Cratis origin.
440
513
  repository_manifest_policy() {
@@ -571,7 +644,11 @@ fi
571
644
  [ -n "$new_content" ] || new_content="$new_string"
572
645
  if ! classify_file "$file"; then exit 0; fi
573
646
  case "$classification" in
574
- controls) block \
647
+ controls)
648
+ if [ -n "$protected_config_root" ]; then block \
649
+ "The repository's .cratis/ai.json is malformed${protected_bad_entry:+ at protectedPaths entry $protected_bad_entry} (protectedPaths must be an array of relative globs of letters, digits, . _ - and /, as a file 'tools/guard.sh', a folder 'locked/', or a folder with a whole final segment 'hooks/*'; a * inside a name is not accepted), so every path in this repository is treated as protected until a person fixes it." \
650
+ "Instead: report the problem; a person must repair .cratis/ai.json. An explicitly authorized protected write requires CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1 in the harness environment. Do not retry through a shell write."; fi
651
+ block \
575
652
  "This target controls the agent's permissions or extensions, or belongs to an installed managed corpus/adapter tree. Agent Write/Edit calls may not alter their own controls or managed instructions." \
576
653
  "Instead: report the intended change. Use 'cratis ai update' for managed files, or let a person change settings. An explicitly authorized protected write requires CRATIS_HOOKS_ALLOW_PROTECTED_WRITES=1 in the harness environment. Do not retry through a shell write." ;;
577
654
  manifest) block \
@@ -332,6 +332,26 @@ public class ReactorSideEffectHandlers(IInstancesOf<IReactorSideEffectHandler> h
332
332
  - Keep log messages in a separate `<ClassName>Logging.cs` partial static internal class.
333
333
  - Use `[LoggerMessage]` attribute (without `eventId`).
334
334
 
335
+ ## C# 14/15 Language Features
336
+
337
+ Cratis .NET repos build with SDK 11 (C# 15); libraries target `net10.0;net11.0`.
338
+
339
+ Use in new code:
340
+
341
+ - Extension blocks (`extension(T x) { ... }`, C# 14) for new extension APIs; leave existing extension classes as they are.
342
+ - The `field` keyword (C# 14) in property accessors instead of a hand-written backing field.
343
+ - `System.Threading.Lock` for new lock objects instead of `object`.
344
+ - Collection expression arguments `with(...)` (C# 15), e.g. to pass a comparer or capacity.
345
+ - `closed` (C# 15) for new internal class hierarchies.
346
+
347
+ Avoid:
348
+
349
+ - Union types in public APIs of libraries that also target `net10.0` — consumers on C# 14 cannot use them.
350
+ - Adding `closed` to existing public types — it is a breaking change.
351
+ - Runtime-async — it is still preview.
352
+
353
+ Keep `ConceptAs<T>` and the existing result envelopes unchanged.
354
+
335
355
  ## Async
336
356
 
337
357
  - Use `async`/`await` for asynchronous programming.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.181.0",
3
+ "version": "7.182.1",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [