@cratis/pi 7.144.0 → 7.145.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.
- package/package/corpus/agents/code-reviewer.md +1 -1
- package/package/corpus/harnesses/copilot/instructions/code-health.instructions.md +43 -0
- package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +2 -1
- package/package/corpus/harnesses/copilot/instructions/review-reports.instructions.md +5 -0
- package/package/corpus/harnesses/pi/agents/code-reviewer.md +1 -1
- package/package/corpus/hooks/README.md +18 -12
- package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +23 -1
- package/package/corpus/hooks/scripts/cratis-guard-shell-writes.sh +26 -14
- package/package/corpus/rules/code-health.md +42 -0
- package/package/corpus/rules/codescene.md +19 -23
- package/package/corpus/rules/general.md +4 -4
- package/package/corpus/rules/profiles.md +2 -1
- package/package/corpus/rules/review-reports.md +5 -0
- package/package.json +1 -1
|
@@ -29,7 +29,7 @@ This is a read-only review role: propose corrections and refactors in the report
|
|
|
29
29
|
You are the **Code Reviewer** for Cratis-based projects.
|
|
30
30
|
Your responsibility is to review all changed files and ensure they meet project standards before merge.
|
|
31
31
|
|
|
32
|
-
Select only diff-relevant, profile-applicable canonical rules in `.cratis/ai/rules/` (and `general.md`): `vertical-slices.md`, `csharp.md`, `code-quality.md` (+ `.csharp`/`.typescript`), `specs.md` (+ `.csharp`/`.typescript`), `frontend-testing.md`, `typescript.md`, `react.md`, `components.md`, `dialogs.md`, `frontend-quality.md`, `concepts.md`, `mongodb.md` (when MongoDB is used), `efcore.md`/`efcore.specs.md`.
|
|
32
|
+
Select only diff-relevant, profile-applicable canonical rules in `.cratis/ai/rules/` (and `general.md`): `vertical-slices.md`, `csharp.md`, `code-quality.md` (+ `.csharp`/`.typescript`), `code-health.md` (flag a touched file below 9.5 with no reported reason only together with the round's other findings), `specs.md` (+ `.csharp`/`.typescript`), `frontend-testing.md`, `typescript.md`, `react.md`, `components.md`, `dialogs.md`, `frontend-quality.md`, `concepts.md`, `mongodb.md` (when MongoDB is used), `efcore.md`/`efcore.specs.md`.
|
|
33
33
|
|
|
34
34
|
---
|
|
35
35
|
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.cs,**/*.ts,**/*.tsx,**/*.go,**/*.kt,**/*.kts,**/*.java,**/*.ex,**/*.exs"
|
|
3
|
+
paths:
|
|
4
|
+
- "**/*.cs"
|
|
5
|
+
- "**/*.ts"
|
|
6
|
+
- "**/*.tsx"
|
|
7
|
+
- "**/*.go"
|
|
8
|
+
- "**/*.kt"
|
|
9
|
+
- "**/*.kts"
|
|
10
|
+
- "**/*.java"
|
|
11
|
+
- "**/*.ex"
|
|
12
|
+
- "**/*.exs"
|
|
13
|
+
---
|
|
14
|
+
<!-- cratis-ai: generated Copilot instructions. Do not edit; rules/ is the source. -->
|
|
15
|
+
|
|
16
|
+
# Code Health floor
|
|
17
|
+
|
|
18
|
+
Applies when CodeScene tools (`code_health_review`, `code_health_score`,
|
|
19
|
+
`pre_commit_code_health_safeguard`, `analyze_change_set`) are available. Without them or
|
|
20
|
+
an account, say so in the report and continue; never block. MCP setup, approval-gated
|
|
21
|
+
tools and tool-output handling are in [codescene.md](../../../rules/codescene.md).
|
|
22
|
+
|
|
23
|
+
## The floor
|
|
24
|
+
|
|
25
|
+
- Every file a change creates or modifies ends at Code Health **9.5 or higher**; new files aim for 10. A touched file never declines.
|
|
26
|
+
- A touched file that starts below 9.5 is raised to 9.5 in the same change by behavior-preserving refactoring with specs behind it (`guiding-refactoring-with-code-health` where the profile provides it).
|
|
27
|
+
- If that is too large for the task (a red or yellow legacy file), raise it as far as is safe, report before and after, and add the file to the repository's Code Health uplift issue ("Code Health: raise all files to 9.5"; create it if none exists).
|
|
28
|
+
- Urgent security and production fixes may ship below 9.5, but report the gap and file the uplift.
|
|
29
|
+
- Never refactor generated code. A "could not determine" Code Health score is not a failure. Other Cratis rules win over a finding.
|
|
30
|
+
- CodeScene has no floor setting, so the check is ours.
|
|
31
|
+
|
|
32
|
+
## Checking
|
|
33
|
+
|
|
34
|
+
- Run `code_health_review` on each changed file while shaping it, then `code_health_score` on each changed file before delivery, then `pre_commit_code_health_safeguard` (or `analyze_change_set` against the base branch).
|
|
35
|
+
- The delivery report has a table: file, score before, score after; name each exception with its reason.
|
|
36
|
+
|
|
37
|
+
## No fix loops
|
|
38
|
+
|
|
39
|
+
- **Once, before the gate.** Handle Code Health once per touched file: review while shaping the code (design for the score, do not write first and fix later), refactor, then one `code_health_score`. The gate and review then run once on the final shape.
|
|
40
|
+
- **Never a cycle.** No gate, score, refactor, gate loops. A score check never triggers an extra build or test run on its own; batch score fixes with the other fixes.
|
|
41
|
+
- **One refactor pass per file per change.** If it does not reach 9.5, report the before and after and the reason, add the file to the uplift issue, and stop.
|
|
42
|
+
- **A reported reason closes the item.** Reviewers flag only a touched file below 9.5 with no reason, together with the round's other findings, never as a review round of its own.
|
|
43
|
+
- **A second Code Health round is itself a finding.** Name the cause (wrong approach, file too large for the task, tool problem) instead of iterating.
|
|
@@ -234,7 +234,8 @@ language policy always follows the consuming repository's `go.mod` minimum.
|
|
|
234
234
|
Select `cratis/codescene` explicitly to load the four upstream CodeScene skills:
|
|
235
235
|
`safeguarding-ai-generated-code`, `guiding-refactoring-with-code-health`,
|
|
236
236
|
`prioritizing-technical-debt` and `risk-based-testing-with-code-health`.
|
|
237
|
-
The [CodeScene policy](../../../rules/codescene.md) overrides those skills where they differ.
|
|
237
|
+
The [CodeScene policy](../../../rules/codescene.md) overrides those skills where they differ. The Code Health
|
|
238
|
+
floor itself is the universal rule [code-health.md](./code-health.instructions.md); the profile supplies the skills and server.
|
|
238
239
|
No other profile, including `cratis` and `cratis/full`, composes it.
|
|
239
240
|
|
|
240
241
|
The profile selects the `codescene` stdio server (`cs-mcp`, no arguments) from
|
|
@@ -81,6 +81,11 @@ and exhaustion never imply approval. Verify cancellation before replacement; esc
|
|
|
81
81
|
unresolved disputes instead of looping. Suggestions alone do not justify another round.
|
|
82
82
|
See `cratis-engineering-review-rounds` for dispatch and writer-pause mechanics.
|
|
83
83
|
|
|
84
|
+
Code Health (`code-health.md`) never earns a round of its own: flag a touched file below
|
|
85
|
+
9.5 with no reported reason only together with the round's other findings. A file below 9.5
|
|
86
|
+
with a reason and an uplift entry is closed; a second Code Health round is a finding that
|
|
87
|
+
names its cause.
|
|
88
|
+
|
|
84
89
|
## Reviewer independence
|
|
85
90
|
|
|
86
91
|
- **[contract]** Run a reviewer on a different provider family than the author's model
|
|
@@ -26,7 +26,7 @@ This is a read-only review role: propose corrections and refactors in the report
|
|
|
26
26
|
You are the **Code Reviewer** for Cratis-based projects.
|
|
27
27
|
Your responsibility is to review all changed files and ensure they meet project standards before merge.
|
|
28
28
|
|
|
29
|
-
Select only diff-relevant, profile-applicable canonical rules in `.cratis/ai/rules/` (and `general.md`): `vertical-slices.md`, `csharp.md`, `code-quality.md` (+ `.csharp`/`.typescript`), `specs.md` (+ `.csharp`/`.typescript`), `frontend-testing.md`, `typescript.md`, `react.md`, `components.md`, `dialogs.md`, `frontend-quality.md`, `concepts.md`, `mongodb.md` (when MongoDB is used), `efcore.md`/`efcore.specs.md`.
|
|
29
|
+
Select only diff-relevant, profile-applicable canonical rules in `.cratis/ai/rules/` (and `general.md`): `vertical-slices.md`, `csharp.md`, `code-quality.md` (+ `.csharp`/`.typescript`), `code-health.md` (flag a touched file below 9.5 with no reported reason only together with the round's other findings), `specs.md` (+ `.csharp`/`.typescript`), `frontend-testing.md`, `typescript.md`, `react.md`, `components.md`, `dialogs.md`, `frontend-quality.md`, `concepts.md`, `mongodb.md` (when MongoDB is used), `efcore.md`/`efcore.specs.md`.
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
@@ -37,9 +37,10 @@ The shell-write reference scan keeps conservative leading-dot intersections: a t
|
|
|
37
37
|
`SHELL`, and the hook process's options do not establish the execution shell's options. Globbed writes
|
|
38
38
|
therefore remain blocked. Read operands under protected paths are not write targets: `rg -n`/`-l`,
|
|
39
39
|
quoted `--glob`/`-g` filters, and numeric/last-line `sed -n …p` scripts are recognized as read-only.
|
|
40
|
-
`sed -n` scripts with writes, execution or extra options are not exempt.
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
`sed -n` scripts with writes, execution or extra options are not exempt. `cd` permits `&&`
|
|
41
|
+
read/search chains, including pipelines of reviewed readers, but never a piped `cd` or index-changing
|
|
42
|
+
command. `git branch --show-current` retains the `&&`-only restriction; semicolons and other
|
|
43
|
+
separators remain refused for these cwd/branch forms. Any file redirection in a cwd-changing chain fails closed because
|
|
43
44
|
its target is not proven against the changed cwd. Mutating commands and protected redirects stay
|
|
44
45
|
blocked. No shell-option assumption is used to dismiss leading-dot intersections.
|
|
45
46
|
Heredoc bodies receive the same conservative whole-text reference scan as other command text,
|
|
@@ -49,8 +50,11 @@ Portable bracket classes are kept; ambiguous backslash-bearing classes are widen
|
|
|
49
50
|
as invalid awk regexes.
|
|
50
51
|
|
|
51
52
|
Literal `git ls-files` pathspecs are filename metadata, including `-s`/`--stage` and `--debug`,
|
|
52
|
-
so credential-worded source directories do not taint that single command.
|
|
53
|
-
|
|
53
|
+
so credential-worded source directories do not taint that single command. Literal non-verbose
|
|
54
|
+
`git status`, summary-only `git diff --stat`/`--numstat`/`--shortstat`/`--name-only`/`--name-status`,
|
|
55
|
+
and non-interactive `git add` of proven directories also permit secret-like source folder names.
|
|
56
|
+
Verbose status, patch diffs and interactive staging receive no such exemption. Credential content
|
|
57
|
+
reads, including `credentials.json` inside source folders, remain refused. Bare `git grep` uses grep's pattern/file distinction, including `-e`
|
|
54
58
|
pattern values; protected pathspecs remain blocked. `git show` and `git cat-file` of secret paths
|
|
55
59
|
remain content reads, not filename metadata.
|
|
56
60
|
|
|
@@ -239,7 +243,8 @@ arguments are operands. A lone `-` is a stdin operand. Value-free short flags ma
|
|
|
239
243
|
| `head`, `tail` | `-n N`, `-nN`, `-c N`, `-N` (numeric counts); no `-f` |
|
|
240
244
|
| `wc` | `-l -w -c -m` |
|
|
241
245
|
| `ls` | `-l -a -A -1 -h -d -R -t -r -F` |
|
|
242
|
-
| `
|
|
246
|
+
| `df` | `-h` |
|
|
247
|
+
| `rg` | `-n -l -i`, `--files`; literal `--glob`/`-g` filters |
|
|
243
248
|
| `grep`, `egrep`, `fgrep` | `-n -i -r -R -l -L -c -v -w -x -F -E -H -h -o -q -s`; `-e PATTERN`, `-A N`, `-B N`, `-C N`; no long options |
|
|
244
249
|
| `echo` | `-n -e -E` |
|
|
245
250
|
| `printf`, `test`, `[`, `true`, `false`, `pwd` | None (in particular, no `printf -v`) |
|
|
@@ -247,15 +252,16 @@ arguments are operands. A lone `-` is a stdin operand. Value-free short flags ma
|
|
|
247
252
|
| `git diff` | `--stat --numstat --name-only --name-status --cached --staged --check -p -U<N> --no-color` |
|
|
248
253
|
| `git log` | `--oneline --stat --name-only -n N -nN -<N> -p --no-color --format=<fmt> --pretty=<fmt> --follow` |
|
|
249
254
|
| `git show` | `--stat --name-only -p --no-color --format=<fmt>` |
|
|
250
|
-
| `git add` | `-A -u -p
|
|
251
|
-
| `git commit` | `-m MSG`, `-mMSG`, `-a`, `-q`; `-F FILE` only for a literal non-protected file; no `--no-verify` |
|
|
255
|
+
| `git add` | `-A -u -p -v --all`, including path globs for installed prompts |
|
|
256
|
+
| `git commit` | `-m MSG`, `--message MSG`, `-mMSG`, `-a`, `-q`; `-F FILE` only for a literal non-protected file; no `--no-verify` |
|
|
252
257
|
| `git blame`, `ls-files`, `rev-parse`, `check-ignore`, `grep` | None |
|
|
253
258
|
|
|
254
259
|
The only global Git option exemption is a single separate `-C <dir>` with a literal,
|
|
255
260
|
non-empty directory word not starting with `-`, followed by exactly one of these tails:
|
|
256
261
|
`status --short`, `rev-parse HEAD`, `branch --show-current`, or `tag --list <pattern>`.
|
|
257
262
|
The tag tail takes exactly one pattern not starting with `-` (for example, `'*7.321*'`).
|
|
258
|
-
|
|
263
|
+
Those metadata tails accept no extra words. Literal `git -C <dir> add` and `commit` also qualify,
|
|
264
|
+
with the ordinary per-verb option checks above. Attached `-Cdir`/`-C=dir`, repeated `-C`, other verbs and
|
|
259
265
|
all other global options (`-c`, `--git-dir`, `--work-tree`, `--no-pager`, `--exec-path`, etc.)
|
|
260
266
|
remain denied. `-C` gives **no protection** from a hostile repository's configuration:
|
|
261
267
|
fsmonitor, hooks, pager and diff/textconv helpers can still run. This is a syntax filter,
|
|
@@ -270,9 +276,9 @@ that references a protected file.
|
|
|
270
276
|
are not on this list: their option surfaces are deliberately not analysed here.
|
|
271
277
|
|
|
272
278
|
Assignment prefixes and assignment-only commands are not allowlisted. Neither are wrappers,
|
|
273
|
-
evaluators, shells or writer verbs. `
|
|
274
|
-
protected reference exists
|
|
275
|
-
|
|
279
|
+
evaluators, shells or writer verbs. `pushd` and `popd` are **not** allowlisted when a
|
|
280
|
+
protected reference exists. The restricted literal `cd` read-chain exemption still refuses
|
|
281
|
+
`cd .claude && echo x > settings.json` without inferring write destinations. Shells refuse regardless of stdin descriptor, lone `-`, or
|
|
276
282
|
`-c` option spelling. Unparsed complex syntax, including substitutions and heredocs, refuses
|
|
277
283
|
once a protected reference exists; no shell bodies are interpreted.
|
|
278
284
|
|
|
@@ -267,6 +267,27 @@ function metadata_shape(A, M, n, k, j, c, mk) {
|
|
|
267
267
|
}
|
|
268
268
|
return 1
|
|
269
269
|
}
|
|
270
|
+
# Filename metadata must not exempt verbose/patch modes that print file contents. Staging
|
|
271
|
+
# is limited to proven directories; credential-file operands retain the literal-read rule.
|
|
272
|
+
function git_metadata(words, count, subcommand, k, w, ended, summary) {
|
|
273
|
+
subcommand = words[2]
|
|
274
|
+
if (subcommand !~ /^(status|diff|add)$/) return 0
|
|
275
|
+
for (k = 3; k <= count; k++) {
|
|
276
|
+
w = words[k]
|
|
277
|
+
if (!ended && w == "--") { ended = 1; continue }
|
|
278
|
+
if (!ended && w ~ /^-/) {
|
|
279
|
+
if (subcommand == "status" && w ~ /^(-s|-b|-sb|-bs|--short|--branch|--porcelain(=v[12])?)$/) continue
|
|
280
|
+
if (subcommand == "diff") {
|
|
281
|
+
if (w ~ /^(--stat|--numstat|--shortstat|--name-only|--name-status)$/) { summary = 1; continue }
|
|
282
|
+
if (w ~ /^(--cached|--staged|--no-color)$/) continue
|
|
283
|
+
}
|
|
284
|
+
if (subcommand == "add" && w ~ /^(-A|-u|-v|--all|--update|--verbose)$/) continue
|
|
285
|
+
return 0
|
|
286
|
+
}
|
|
287
|
+
if (subcommand == "add" && !directory_operand(w)) return 0
|
|
288
|
+
}
|
|
289
|
+
return subcommand != "diff" || summary
|
|
290
|
+
}
|
|
270
291
|
function literal_shape(A, M, n, k, j, b, words, count, pattern, ended, w, paths, flags) {
|
|
271
292
|
if (metadata_shape(A, M, n)) return 1
|
|
272
293
|
delete words
|
|
@@ -279,6 +300,7 @@ function literal_shape(A, M, n, k, j, b, words, count, pattern, ended, w, pat
|
|
|
279
300
|
}
|
|
280
301
|
}
|
|
281
302
|
b = words[1]
|
|
303
|
+
if (b == "git" && git_metadata(words, count)) return 1
|
|
282
304
|
if (b == "git" && words[2] == "ls-files") {
|
|
283
305
|
for (k = 3; k <= count; k++) {
|
|
284
306
|
w = words[k]
|
|
@@ -592,7 +614,7 @@ function sensitive_path(w, l, b) {
|
|
|
592
614
|
if (b == "id_rsa" || b == "id_ed25519" || b == "id_ecdsa" || b == "id_dsa") return "a private key"
|
|
593
615
|
if (b ~ /(^|[._-])tokens?($|[._-])/ && !code_file(b) && !token_ok(l, b)) return "a token file"
|
|
594
616
|
if (b == ".netrc" || b == ".npmrc" || b == ".pgpass" || b == ".pypirc" || b == ".git-credentials") return "a credentials file"
|
|
595
|
-
if (b == "credentials") return "a credentials file"
|
|
617
|
+
if (b == "credentials" || b == "credentials.json") return "a credentials file"
|
|
596
618
|
if (l ~ /\.docker\/config\.json$/) return "the Docker registry credentials"
|
|
597
619
|
if (l ~ /\/proc\/[^\/]*\/environ$/) return "a process environment"
|
|
598
620
|
if (l ~ /^\/(var\/)?run\/secrets\//) return "mounted secrets"
|
|
@@ -147,7 +147,7 @@ function options_allowed(verb, first, i, w) {
|
|
|
147
147
|
continue
|
|
148
148
|
}
|
|
149
149
|
if (verb == "git commit") {
|
|
150
|
-
if (w == "-m") { if (++i > argc) return 0; continue }
|
|
150
|
+
if (w == "-m" || w == "--message") { if (++i > argc) return 0; continue }
|
|
151
151
|
if (w ~ /^-m./) continue
|
|
152
152
|
if (w == "-F") {
|
|
153
153
|
if (++i > argc || W[i] ~ /[$`*?\[{]/ || protected(W[i])) return 0
|
|
@@ -162,8 +162,8 @@ function options_allowed(verb, first, i, w) {
|
|
|
162
162
|
}
|
|
163
163
|
return 1
|
|
164
164
|
}
|
|
165
|
-
# Only git -C
|
|
166
|
-
#
|
|
165
|
+
# Only literal git -C metadata (with exact arity) or staging/commit commands
|
|
166
|
+
# (with their normal option checks) are exempt; no other global option is.
|
|
167
167
|
# -C gives no protection from hostile repository config (fsmonitor, hooks, pager,
|
|
168
168
|
# diff/textconv helpers). This filter checks syntax, not repository trust.
|
|
169
169
|
function directory_metadata() {
|
|
@@ -186,24 +186,33 @@ function allow_command( verb, first) {
|
|
|
186
186
|
if (++commands > 64) { bad = 1; return }
|
|
187
187
|
verb = W[1]; first = 2
|
|
188
188
|
if (verb == "cd") {
|
|
189
|
-
|
|
189
|
+
directory_only = 1
|
|
190
190
|
if (argc != 2 || W[2] == "" || W[2] ~ /^-/ || globbed[2] || file_redirect) bad = 1
|
|
191
191
|
changed_cwd = 1
|
|
192
192
|
return
|
|
193
193
|
}
|
|
194
194
|
if (verb == "sed") { if (!print_only_sed()) bad = 1; return }
|
|
195
195
|
if (verb == "git" && W[2] == "-C") {
|
|
196
|
-
if (!
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
196
|
+
if (argc >= 4 && W[3] != "" && W[3] !~ /^-/ && !globbed[3] && W[4] ~ /^(add|commit)$/) {
|
|
197
|
+
verb = verb " " W[4]; first = 5
|
|
198
|
+
} else {
|
|
199
|
+
if (!directory_metadata()) bad = 1
|
|
200
|
+
return
|
|
201
|
+
}
|
|
202
|
+
} else if (verb == "git") { verb = verb " " W[2]; first = 3 }
|
|
203
|
+
if (verb == "git add" || verb == "git commit") changed_index = 1
|
|
200
204
|
if (verb == "git branch") {
|
|
201
205
|
conditional_only = 1
|
|
202
206
|
if (argc != 3 || W[3] != "--show-current") { bad = 1; return }
|
|
203
207
|
}
|
|
204
208
|
if (!(verb in verbs) || !options_allowed(verb, first)) bad = 1
|
|
205
209
|
}
|
|
206
|
-
function command_end() {
|
|
210
|
+
function command_end(separator) {
|
|
211
|
+
endword(); allow_command()
|
|
212
|
+
if (W[1] == "cd" && (separator == "|" || previous_pipe)) bad = 1
|
|
213
|
+
previous_pipe = (separator == "|")
|
|
214
|
+
delete W; delete globbed; argc = 0
|
|
215
|
+
}
|
|
207
216
|
function readonly(s, i, c, c2, sq, dq) {
|
|
208
217
|
for (i = 1; i <= length(s); i++) {
|
|
209
218
|
c = substr(s, i, 1); c2 = substr(s, i + 1, 1)
|
|
@@ -229,30 +238,33 @@ function readonly(s, i, c, c2, sq, dq) {
|
|
|
229
238
|
if (c2 ~ /[><&|]/) { i++; if (substr(s, i + 1, 1) == ">") i++ }
|
|
230
239
|
continue
|
|
231
240
|
}
|
|
232
|
-
if (c == "&" && c2 == "&") { command_end(); if (redirect) bad = 1; i++; continue }
|
|
233
|
-
if (c
|
|
241
|
+
if (c == "&" && c2 == "&") { command_end("&&"); if (redirect) bad = 1; i++; continue }
|
|
242
|
+
if (c == "|" && c2 != "|") { has_pipeline = 1; command_end("|"); if (redirect) bad = 1; continue }
|
|
243
|
+
if (c ~ /[;|&\n]/) { nonconditional_separator = 1; command_end(c); if (redirect) bad = 1; continue }
|
|
234
244
|
if (c ~ /[ \t\r]/) { endword(); continue }
|
|
235
245
|
word = word c; inword = 1
|
|
236
246
|
}
|
|
237
247
|
command_end()
|
|
238
|
-
if (sq || dq || redirect || (conditional_only && nonconditional_separator))
|
|
248
|
+
if (sq || dq || redirect || (conditional_only && (nonconditional_separator || has_pipeline)) ||
|
|
249
|
+
(directory_only && (nonconditional_separator || (has_pipeline && changed_index)))) bad = 1
|
|
239
250
|
return !bad
|
|
240
251
|
}
|
|
241
252
|
BEGIN {
|
|
242
253
|
policy("cat", "nAvetsb", "")
|
|
243
254
|
policy("head", "", ""); policy("tail", "", "")
|
|
244
255
|
policy("wc", "lwcm", ""); policy("ls", "laA1hdRtrF", "")
|
|
245
|
-
policy("rg", "
|
|
256
|
+
policy("rg", "nli", "--files")
|
|
246
257
|
policy("grep", "nirRlLcvwxFEHhoqs", "")
|
|
247
258
|
policy("egrep", "nirRlLcvwxFEHhoqs", ""); policy("fgrep", "nirRlLcvwxFEHhoqs", "")
|
|
248
259
|
policy("echo", "neE", "")
|
|
249
260
|
policy("printf", "", ""); policy("test", "", ""); policy("[", "", "")
|
|
250
261
|
policy("true", "", ""); policy("false", "", ""); policy("pwd", "", "")
|
|
262
|
+
policy("df", "h", "")
|
|
251
263
|
policy("git status", "sb", "--short --porcelain")
|
|
252
264
|
policy("git diff", "p", "--stat --numstat --name-only --name-status --cached --staged --check --no-color --cc")
|
|
253
265
|
policy("git log", "p", "--oneline --stat --name-only --no-color --follow")
|
|
254
266
|
policy("git show", "p", "--stat --name-only --no-color")
|
|
255
|
-
policy("git add", "
|
|
267
|
+
policy("git add", "Aupv", "--all"); policy("git commit", "aq", "")
|
|
256
268
|
policy("git blame", "", ""); policy("git ls-files", "s", "--stage --debug")
|
|
257
269
|
policy("git branch", "", "--show-current")
|
|
258
270
|
policy("git rev-parse", "", ""); policy("git check-ignore", "", ""); policy("git grep", "n", "")
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
---
|
|
2
|
+
applyTo: "**/*.cs,**/*.ts,**/*.tsx,**/*.go,**/*.kt,**/*.kts,**/*.java,**/*.ex,**/*.exs"
|
|
3
|
+
paths:
|
|
4
|
+
- "**/*.cs"
|
|
5
|
+
- "**/*.ts"
|
|
6
|
+
- "**/*.tsx"
|
|
7
|
+
- "**/*.go"
|
|
8
|
+
- "**/*.kt"
|
|
9
|
+
- "**/*.kts"
|
|
10
|
+
- "**/*.java"
|
|
11
|
+
- "**/*.ex"
|
|
12
|
+
- "**/*.exs"
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# Code Health floor
|
|
16
|
+
|
|
17
|
+
Applies when CodeScene tools (`code_health_review`, `code_health_score`,
|
|
18
|
+
`pre_commit_code_health_safeguard`, `analyze_change_set`) are available. Without them or
|
|
19
|
+
an account, say so in the report and continue; never block. MCP setup, approval-gated
|
|
20
|
+
tools and tool-output handling are in [codescene.md](./codescene.md).
|
|
21
|
+
|
|
22
|
+
## The floor
|
|
23
|
+
|
|
24
|
+
- Every file a change creates or modifies ends at Code Health **9.5 or higher**; new files aim for 10. A touched file never declines.
|
|
25
|
+
- A touched file that starts below 9.5 is raised to 9.5 in the same change by behavior-preserving refactoring with specs behind it (`guiding-refactoring-with-code-health` where the profile provides it).
|
|
26
|
+
- If that is too large for the task (a red or yellow legacy file), raise it as far as is safe, report before and after, and add the file to the repository's Code Health uplift issue ("Code Health: raise all files to 9.5"; create it if none exists).
|
|
27
|
+
- Urgent security and production fixes may ship below 9.5, but report the gap and file the uplift.
|
|
28
|
+
- Never refactor generated code. A "could not determine" Code Health score is not a failure. Other Cratis rules win over a finding.
|
|
29
|
+
- CodeScene has no floor setting, so the check is ours.
|
|
30
|
+
|
|
31
|
+
## Checking
|
|
32
|
+
|
|
33
|
+
- Run `code_health_review` on each changed file while shaping it, then `code_health_score` on each changed file before delivery, then `pre_commit_code_health_safeguard` (or `analyze_change_set` against the base branch).
|
|
34
|
+
- The delivery report has a table: file, score before, score after; name each exception with its reason.
|
|
35
|
+
|
|
36
|
+
## No fix loops
|
|
37
|
+
|
|
38
|
+
- **Once, before the gate.** Handle Code Health once per touched file: review while shaping the code (design for the score, do not write first and fix later), refactor, then one `code_health_score`. The gate and review then run once on the final shape.
|
|
39
|
+
- **Never a cycle.** No gate, score, refactor, gate loops. A score check never triggers an extra build or test run on its own; batch score fixes with the other fixes.
|
|
40
|
+
- **One refactor pass per file per change.** If it does not reach 9.5, report the before and after and the reason, add the file to the uplift issue, and stop.
|
|
41
|
+
- **A reported reason closes the item.** Reviewers flag only a touched file below 9.5 with no reason, together with the round's other findings, never as a review round of its own.
|
|
42
|
+
- **A second Code Health round is itself a finding.** Name the cause (wrong approach, file too large for the task, tool problem) instead of iterating.
|
|
@@ -15,37 +15,33 @@ CodeScene needs an account and OAuth `login`. Without an account or available
|
|
|
15
15
|
CodeScene tools, skip these steps and say so; never block contributors who have
|
|
16
16
|
not opted in.
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Thresholds and checking
|
|
19
19
|
|
|
20
|
-
The
|
|
21
|
-
|
|
22
|
-
`safeguarding-ai-generated-code` instruction to refactor when a review reports
|
|
23
|
-
|
|
20
|
+
The floor (touched files end at Code Health 9.5 or higher), the checking steps and the
|
|
21
|
+
no-fix-loops process are the universal rule [code-health.md](./code-health.md). The
|
|
22
|
+
`safeguarding-ai-generated-code` instruction to refactor when a review reports problems
|
|
23
|
+
applies to every touched file, not only to problems the change introduced.
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
- Changed files: **no decline**.
|
|
29
|
-
- Uplift red (below 4) or yellow (4–8.9) files only through a dedicated,
|
|
30
|
-
issue-tracked task with tests behind it, using
|
|
31
|
-
`guiding-refactoring-with-code-health`.
|
|
32
|
-
- Project target: **Hotspot Code Health at least 9**, with no downward trend.
|
|
33
|
-
- CodeScene categories, for reference: **10 optimal**, **9–9.9 green**,
|
|
34
|
-
**4–8.9 yellow**, **1–3.9 red**.
|
|
35
|
-
|
|
36
|
-
## When to check
|
|
37
|
-
|
|
38
|
-
Use the `codescene` MCP server's `code_health_review` on changed files after
|
|
39
|
-
editing. Before declaring work done or opening a PR, run
|
|
40
|
-
`pre_commit_code_health_safeguard`, or `analyze_change_set` against the base
|
|
41
|
-
branch. Name any decline the user explicitly accepts in the report or PR comment;
|
|
42
|
-
never hide it.
|
|
25
|
+
CodeScene categories, for reference: **10 optimal**, **9–9.9 green**, **4–8.9 yellow**,
|
|
26
|
+
**1–3.9 red**. Project target: **Hotspot Code Health at least 9**, with no downward trend.
|
|
27
|
+
Name any shortfall the user explicitly accepts in the report or PR comment; never hide it.
|
|
43
28
|
|
|
44
29
|
## Exclusions and precedence
|
|
45
30
|
|
|
46
31
|
Never refactor generated code: proto/gRPC contracts, generated proxies or `obj/`.
|
|
47
32
|
"Could not determine Code Health score" is not a failure.
|
|
48
33
|
|
|
34
|
+
Optional recipe for generated code CodeScene still scores: a root `.codescene/code-health-rules.json`
|
|
35
|
+
with one `rule_sets` entry whose `matching_content_path` is the generated glob (`**/*.g.cs`,
|
|
36
|
+
`**/Generated/**`, `**/Proxies/**`) and `rules` listing every rule at `"weight": 0.0` scores those
|
|
37
|
+
files 10 and leaves others unchanged (verified). Names: Bumpy Road Ahead, Complex Conditional,
|
|
38
|
+
Complex Method, Constructor Over-Injection, Code Duplication, Deep, Nested Complexity, Excess Number
|
|
39
|
+
of Function Arguments, Large Method, Large Assertion Blocks, Duplicated Assertion Blocks, Low
|
|
40
|
+
Cohesion, Brain Class, Brain Method, Overall Code Complexity, Primitive Obsession, String Heavy
|
|
41
|
+
Function Arguments, Lines of Code in a Single File, Number of Functions in a Single Module, Global
|
|
42
|
+
Conditionals, Missing Arguments Abstractions. Run `rules_config_validate` first; never exclude domain
|
|
43
|
+
code such as Chronicle `Migrations`. The corpus cannot install this file.
|
|
44
|
+
|
|
49
45
|
Other Cratis rules take precedence over findings. One-file vertical slices make
|
|
50
46
|
"Lines of Code in a Single File" expected; do not rewrite `ConceptAs` usage or
|
|
51
47
|
spec conventions to satisfy a finding.
|
|
@@ -123,6 +123,7 @@ A claim is only as good as the signal behind it — a build result, a test run,
|
|
|
123
123
|
- The affected solution/project builds with zero warnings and zero errors.
|
|
124
124
|
- Relevant specs for every affected project pass.
|
|
125
125
|
- For public-facing changes (clients, SDKs, public APIs, developer-facing behavior), documentation is added or updated and its verification passes.
|
|
126
|
+
- When CodeScene tools are available, touched files end at Code Health >= 9.5 and never decline; handle it once, before the gate, and report before/after (`code-health.md`).
|
|
126
127
|
|
|
127
128
|
## Where to Look
|
|
128
129
|
|
|
@@ -141,8 +142,8 @@ A claim is only as good as the signal behind it — a build result, a test run,
|
|
|
141
142
|
| Spec patterns — universal `Specification` base (both profiles) | `specs.md`, `specs.csharp.md`, `specs.typescript.md` |
|
|
142
143
|
| Build and spec-run speed: parallel-safe specs, no per-spec startup, cheap analyzers | `fast-feedback.md` |
|
|
143
144
|
| Spec patterns — the four `*Scenario` helpers (application only) | `specs.scenarios.csharp.md` |
|
|
144
|
-
| Strongly-typed values (`ConceptAs<T>`, `EventSourceId<T>`) | `concepts.md` |
|
|
145
|
-
|
|
|
145
|
+
| Strongly-typed values (`ConceptAs<T>`, `EventSourceId<T>`); shared term definitions (event, projection, reducer, reactor, observer, DCB, …) | `concepts.md`; `glossary.md` |
|
|
146
|
+
| Files an AI change touches (Code Health with CodeScene) | `code-health.md` |
|
|
146
147
|
| Diagnosing a misbehaving slice | read model stale or startup crash: **cratis-chronicle-projection** (*Startup-crash traps*); reactor paused or quarantined: **cratis-chronicle-reactor** (*Failure behavior*); proxy missing: **cratis-arc-command** (*Generate the TypeScript proxy*) |
|
|
147
148
|
| Inspecting or operating a **running** Chronicle store (failed partitions, replays, browsing events) with the `cratis` CLI | the **cratis-chronicle-cli-operations** and **cratis-cli-terminal-workbench** skills |
|
|
148
149
|
| EF Core read models / migrations | `efcore.md`, `efcore.specs.md` |
|
|
@@ -162,8 +163,7 @@ A claim is only as good as the signal behind it — a build result, a test run,
|
|
|
162
163
|
| Code-level event modeling / schema migration / calling commands from code / paging / cross-cutting metadata / multi-tenancy | the matching skills |
|
|
163
164
|
| Building or changing behavior in an opted-in repository (see Model first above), or designing an information system, business process or information flow: **model first** | the **cratis-screenplay-event-modeling** skill (decision rule), then **cratis-screenplay-modeling-lifecycle** and one phase skill; per-surface `cratis-screenplay-*` skills for syntax |
|
|
164
165
|
| Building or changing behavior in a Cratis application that is not opted in | `application-profile.md` Phase 0, then the code skills (**cratis-arc-command**, **cratis-chronicle-projection**, ...) |
|
|
165
|
-
| Reviewing or explaining a `.play` model | the **cratis-screenplay-model-review** skill |
|
|
166
|
-
| Turning an existing system into a model | the **cratis-screenplay-legacy-extraction** skill |
|
|
166
|
+
| Reviewing or explaining a `.play` model; turning an existing system into a model | the **cratis-screenplay-model-review** skill; the **cratis-screenplay-legacy-extraction** skill |
|
|
167
167
|
| Rendering or gap-filling an accepted model | the **cratis-screenplay-render-and-gap-fill** skill, then **cratis-stage-rendering-and-sandbox** for renderer facts |
|
|
168
168
|
| Code, security, performance and repository-investigation review reports | `review-reports.md` |
|
|
169
169
|
| Authoring or reviewing skills, rules, agents or prompts | `authoring-skills.md` |
|
|
@@ -233,7 +233,8 @@ language policy always follows the consuming repository's `go.mod` minimum.
|
|
|
233
233
|
Select `cratis/codescene` explicitly to load the four upstream CodeScene skills:
|
|
234
234
|
`safeguarding-ai-generated-code`, `guiding-refactoring-with-code-health`,
|
|
235
235
|
`prioritizing-technical-debt` and `risk-based-testing-with-code-health`.
|
|
236
|
-
The [CodeScene policy](./codescene.md) overrides those skills where they differ.
|
|
236
|
+
The [CodeScene policy](./codescene.md) overrides those skills where they differ. The Code Health
|
|
237
|
+
floor itself is the universal rule [code-health.md](./code-health.md); the profile supplies the skills and server.
|
|
237
238
|
No other profile, including `cratis` and `cratis/full`, composes it.
|
|
238
239
|
|
|
239
240
|
The profile selects the `codescene` stdio server (`cs-mcp`, no arguments) from
|
|
@@ -80,6 +80,11 @@ and exhaustion never imply approval. Verify cancellation before replacement; esc
|
|
|
80
80
|
unresolved disputes instead of looping. Suggestions alone do not justify another round.
|
|
81
81
|
See `cratis-engineering-review-rounds` for dispatch and writer-pause mechanics.
|
|
82
82
|
|
|
83
|
+
Code Health (`code-health.md`) never earns a round of its own: flag a touched file below
|
|
84
|
+
9.5 with no reported reason only together with the round's other findings. A file below 9.5
|
|
85
|
+
with a reason and an uplift entry is closed; a second Code Health round is a finding that
|
|
86
|
+
names its cause.
|
|
87
|
+
|
|
83
88
|
## Reviewer independence
|
|
84
89
|
|
|
85
90
|
- **[contract]** Run a reviewer on a different provider family than the author's model
|