@cratis/pi 7.170.12 → 7.172.0

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.
@@ -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
@@ -76,7 +76,8 @@ named reference before applying one.
76
76
  tests run serially or several jobs each rebuild. Default: one job builds in
77
77
  `Release`, uploads the output with `actions/upload-artifact`, and a matrix of shard jobs downloads it and runs
78
78
  each built spec executable; only VSTest projects use `dotnet test <project> --no-build`. Pitfall: a shard whose filter matches nothing still
79
- passes, so assert that every shard ran tests. Read
79
+ passes, so assert that every shard ran tests. Each build tuple has one analyzer
80
+ owner (section "One analyzer owner per build tuple"). Read
80
81
  `references/build-once-and-shard.md` when applying or reviewing this.
81
82
 
82
83
  **Fewer, bigger jobs.** Fits queue-bound workflows: every job pays a scheduler
@@ -144,7 +145,10 @@ handle it. Pitfall: without `merge_group` the required check never reports in th
144
145
  queue. Read `references/required-checks-and-path-filters.md`.
145
146
 
146
147
  **Compile once, analyze once.** Fits any workflow where one push compiles the same
147
- code several times. Default: build the spec path without analyzers
148
+ code several times. Exactly one build owns the analyzers per build tuple, never
149
+ zero: by default a parallel required job on the same tuple, while the spec path is
150
+ built by a non-owner; a repository may instead let the shared spec build own them by
151
+ its own decision record. Default: build the spec path without analyzers
148
152
  (`-p:RunAnalyzers=false`) and reuse the output; enforce every analyzer with warnings
149
153
  as errors in one parallel **required** job that fails early on compile and analyzer
150
154
  errors, while the local fast loop may skip analyzers and the pre-push gate runs them.
@@ -4,6 +4,9 @@
4
4
 
5
5
  - When it fits
6
6
  - Shape
7
+ - One analyzer owner per build tuple
8
+ - Order of steps
9
+ - Specs from built executables
7
10
  - Decisions
8
11
  - Pitfalls
9
12
  - Fewer, bigger jobs
@@ -77,7 +80,8 @@ jobs:
77
80
  - run: tar --zstd -xf build-output.tar.zst
78
81
  # Example assumes each xUnit v3 mtp-off AssemblyName matches its directory.
79
82
  # Use evaluated TargetPath for custom outputs; TUnit/native runners need their own report flags.
80
- # Only VSTest uses dotnet test <project> --no-build --configuration Release with --logger/--results-directory.
83
+ # Only VSTest projects use dotnet test <project> --no-build --configuration Release with --logger/--results-directory.
84
+ # The executable must come from the same tuple (configuration, TFM, RID) the build job produced.
81
85
  - name: Test the shard's projects
82
86
  env:
83
87
  PROJECTS: ${{ matrix.projects }}
@@ -122,8 +126,64 @@ To balance, read each shard job's median duration from the slowest-jobs table of
122
126
  re-measure; stop when the spread is within the job start cost. Balance by
123
127
  measured wall time, and confirm the new split on one real CI run before merging it.
124
128
 
129
+ ## One analyzer owner per build tuple
130
+
131
+ A build tuple is the configuration, target framework, runtime identifier and every
132
+ build-affecting property. Every tuple that is built, tested or shipped has
133
+ **exactly one** owning build that runs the analyzers with warnings as errors:
134
+ never zero, and a second owner only repeats the cost.
135
+
136
+ - **Default owner: a parallel required job.** It builds the same tuple as the spec
137
+ build with the analyzers on and warnings as errors, and fails early on compile and
138
+ analyzer errors. The spec build is a non-owner and passes `-p:RunAnalyzers=false`.
139
+ The owning job is a required check: never leave it out of branch protection, and
140
+ the pre-push gate runs the analyzers too (see
141
+ [analyzer cost](test-setup-cost.md#analyzer-cost)).
142
+ - **Alternative owner: the shared spec build.** A repository may choose, by its own
143
+ decision record, that the build feeding the specs owns the analyzers, so the specs
144
+ run on analyzed output. Then no separate analyzer job exists for that tuple.
145
+ - **Non-owners** pass `-p:RunAnalyzers=false` (and `-p:EnforceCodeStyleInBuild=false`
146
+ where code style runs in the build). Use `RunAnalyzers`/`RunAnalyzersDuringBuild`
147
+ as the owner switch: `EnableNETAnalyzers=false` only turns off the .NET SDK's own
148
+ analyzers and leaves other analysis running, so it is not an owner switch. Never
149
+ remove `Analyzer` items either: generators are delivered as analyzer references,
150
+ so the output would lose its generated code.
151
+ - **Check generators survived.** Assert that a known generated file or type is in a
152
+ non-owner build's output before trusting it.
153
+ - **A tuple that is packed or published is always owned**, so shipped binaries were
154
+ analyzed by some build.
155
+ - **Match tuples.** A shard that builds Release/net10.0 after an owner built Debug
156
+ compiles again and leaves its own tuple unowned. Reuse the owner's output, or make
157
+ the second tuple own its analyzers.
158
+
159
+ ## Order of steps
160
+
161
+ 1. Restore once.
162
+ 2. Build the owning tuple.
163
+ 3. Later builds use `--no-restore`.
164
+ 4. Run the specs from the built executables.
165
+ 5. Pack with `--no-build`.
166
+
167
+ Publish and native AOT are separate builds with their own tuple; do not run
168
+ `dotnet publish` nested inside a spec step. Do not split projects to speed up the
169
+ build: measure with `-bl` and `ReportAnalyzer=true` first (see the `msbuild` skill's
170
+ build performance references).
171
+
172
+ ## Specs from built executables
173
+
174
+ xUnit v3 projects are executables: run the built file from the build tuple's output
175
+ directory instead of `dotnet test`, which rebuilds implicitly. Native filters are
176
+ owned by [running-specs](../../cratis-specifications-csharp/references/running-specs.md);
177
+ do not restate the syntax here. Fail closed on counts:
178
+
179
+ - every shard reports executed > 0;
180
+ - the total across shards equals the spec count before the change;
181
+ - repositories with unmigrated v3 consumers track them in their own migration issue.
182
+
125
183
  ## Decisions
126
184
 
185
+ - **Cache dependencies only.** Cache restored packages and installed dependencies,
186
+ never build output; build output travels as an artifact.
127
187
  - **Artifact, not cache, between jobs of one run.** A cache keyed on the commit
128
188
  SHA is immutable: one failed save poisons the key for every later attempt and a
129
189
  rerun cannot recover. An artifact belongs to the run and is the intended
@@ -143,7 +203,8 @@ measured wall time, and confirm the new split on one real CI run before merging
143
203
 
144
204
  ## Pitfalls
145
205
 
146
- - A filter or project list that matches nothing passes `dotnet test`. End every
206
+ - A filter or project list that matches nothing passes: an executable with a
207
+ filter matching nothing exits 0, and so does VSTest `dotnet test`. End every
147
208
  shard with a check that each assigned project or namespace ran at least one test,
148
209
  and print the counts. Zero tests is a failed shard.
149
210
  - Shards balance by test time, not by project count (see the balancing steps
@@ -21,11 +21,13 @@ references/binlog-failure-analysis.md:
21
21
  - Render unimported binlog-failure-analysis routing reference as plain topic text.
22
22
 
23
23
  references/build-perf-baseline.md:
24
+ - Add a labelled Cratis note on analyzer ownership, local incremental measurement and gate scripts.
24
25
  - Render unimported build-perf-baseline routing reference as plain topic text.
25
26
  - Qualify analyzer/warning suppression as timing-only; require the real gate restored.
26
27
  - Add or normalize the top Contents list from existing headings; preserve section content.
27
28
 
28
29
  references/build-perf-diagnostics.md:
30
+ - Add a labelled Cratis note on analyzer ownership per build tuple and keeping generators running.
29
31
  - Render unimported build-perf-diagnostics routing reference as plain topic text.
30
32
  - Qualify analyzer/warning suppression as timing-only; require the real gate restored.
31
33
  - Add or normalize the top Contents list from existing headings; preserve section content.
@@ -418,6 +418,13 @@ Use matching configuration/TFM/RID and restore-affecting properties in each stag
418
418
  `--no-restore` requires current assets; `--no-build` requires successfully built
419
419
  matching test outputs. Keep restore-inclusive and build-only timings separate.
420
420
 
421
+ > **Cratis:** the build that owns a configuration/TFM/RID/property tuple is the one
422
+ > that runs its analyzers; other builds of that tuple reuse its output. Measure local
423
+ > no-op and one-file-edit incremental builds, using `-bl` to see which targets rerun
424
+ > with nothing changed. Gate scripts follow the same one-owner structure. The inner
425
+ > loop may use `-p:RunAnalyzers=false`, but the analyzer-owning gate build is
426
+ > mandatory before push. Report local and CI numbers separately.
427
+
421
428
  ### Skip Unnecessary Targets
422
429
 
423
430
  For an explicitly agreed development scenario where these outputs/checks are
@@ -106,6 +106,14 @@ Use these as investigation hints, not universal budgets or proof of a cause:
106
106
  - **Source generators:** do not assume `RunAnalyzers=false` disables or measures
107
107
  every generator. Preserve required generated code and inspect generator-specific
108
108
  evidence.
109
+
110
+ > **Cratis:** in CI, non-owning builds use `RunAnalyzers`/`RunAnalyzersDuringBuild`,
111
+ > not `EnableNETAnalyzers` (it only disables the .NET SDK's own analyzers, so it is
112
+ > not an owner switch), and never delete `Analyzer` items, which would also remove
113
+ > generators. Each configuration/TFM/RID/property tuple has exactly one analyzer-owning
114
+ > build (see `cratis-ci-pipeline-performance`, `references/build-once-and-shard.md`).
115
+ > Measure with `-bl` and `ReportAnalyzer=true` before and after.
116
+
109
117
  - **GlobalPackageReference:** examine the project, `Directory.Build.props`,
110
118
  `Directory.Packages.props`, and package imports. Active global analyzer
111
119
  references can affect production and test projects; a declaration alone does
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.170.12",
3
+ "version": "7.172.0",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [