@cratis/pi 7.3.1 → 7.3.2

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": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cratis/pi",
3
- "version": "7.3.1",
3
+ "version": "7.3.2",
4
4
  "description": "Configuration-aware Cratis AI integration for Pi",
5
5
  "type": "module",
6
6
  "files": [