@cratis/pi 7.101.0 → 7.103.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/harnesses/copilot/instructions/github-actions.instructions.md +17 -0
- package/package/corpus/harnesses/copilot/instructions/profiles.instructions.md +10 -1
- package/package/corpus/harnesses/copilot/instructions/pull-requests.instructions.md +2 -0
- package/package/corpus/harnesses/copilot/instructions/secrets.instructions.md +4 -0
- package/package/corpus/hooks/README.md +11 -1
- package/package/corpus/hooks/scripts/cratis-check-pr.mjs +12 -1
- package/package/corpus/hooks/scripts/cratis-guard-secrets.sh +79 -23
- package/package/corpus/hooks/scripts/cratis-guard-writes.sh +145 -40
- package/package/corpus/rules/github-actions.md +17 -0
- package/package/corpus/rules/profiles.md +10 -1
- package/package/corpus/rules/pull-requests.md +2 -0
- package/package/corpus/rules/secrets.md +4 -0
- package/package/corpus/skills/analyzing-dotnet-performance/LICENSE +23 -0
- package/package/corpus/skills/analyzing-dotnet-performance/NOTICE +36 -0
- package/package/corpus/skills/analyzing-dotnet-performance/SKILL.md +214 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/async-patterns.md +122 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/collections-and-linq.md +220 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/critical-patterns.md +291 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/io-and-serialization.md +135 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/memory-and-strings.md +219 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/regex-patterns.md +95 -0
- package/package/corpus/skills/analyzing-dotnet-performance/references/structural-patterns.md +38 -0
- package/package/corpus/skills/binlog-generation/LICENSE +23 -0
- package/package/corpus/skills/binlog-generation/NOTICE +22 -0
- package/package/corpus/skills/binlog-generation/SKILL.md +129 -0
- package/package/corpus/skills/check-bin-obj-clash/LICENSE +23 -0
- package/package/corpus/skills/check-bin-obj-clash/NOTICE +27 -0
- package/package/corpus/skills/check-bin-obj-clash/SKILL.md +127 -0
- package/package/corpus/skills/check-bin-obj-clash/references/common-causes-and-fixes.md +206 -0
- package/package/corpus/skills/coverage-analysis/LICENSE +23 -0
- package/package/corpus/skills/coverage-analysis/NOTICE +32 -0
- package/package/corpus/skills/coverage-analysis/SKILL.md +198 -0
- package/package/corpus/skills/coverage-analysis/references/guidelines.md +68 -0
- package/package/corpus/skills/coverage-analysis/references/output-format.md +91 -0
- package/package/corpus/skills/coverage-analysis/references/report-generation.md +58 -0
- package/package/corpus/skills/coverage-analysis/references/setup-discovery.md +307 -0
- package/package/corpus/skills/coverage-analysis/scripts/Compute-CrapScores.ps1 +80 -0
- package/package/corpus/skills/coverage-analysis/scripts/CoverageData.ps1 +272 -0
- package/package/corpus/skills/coverage-analysis/scripts/Extract-MethodCoverage.ps1 +65 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/LICENSE +2 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/SKILL.md +201 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/build-once-and-shard.md +158 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/caching.md +86 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/flaky-and-hung-jobs.md +70 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/publish-pipelines.md +67 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/required-checks-and-path-filters.md +117 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/runner-sizing-and-images.md +65 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/security-and-pinning.md +73 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/sources.md +33 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/references/test-setup-cost.md +82 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/ci-timings.sh +356 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1003.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1007.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/jobs/1010.json +79 -0
- package/package/corpus/skills/cratis-ci-pipeline-performance/scripts/fixtures/runs.json +102 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/LICENSE +2 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/SKILL.md +244 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/docker-images.md +86 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/dotnet-nuget.md +87 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/go-jvm-python-elixir.md +83 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/npm-yarn.md +78 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/other-environments.md +60 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/references/worked-examples.md +97 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/scripts/cratis-local-packages.sh +778 -0
- package/package/corpus/skills/cratis-engineering-local-cross-repo-verification/scripts/npm-restore-check.cjs +109 -0
- package/package/corpus/skills/csharp-refactoring/LICENSE +23 -0
- package/package/corpus/skills/csharp-refactoring/NOTICE +22 -0
- package/package/corpus/skills/csharp-refactoring/SKILL.md +175 -0
- package/package/corpus/skills/csharp-refactoring/references/operation-catalog.md +37 -0
- package/package/corpus/skills/directory-build-organization/LICENSE +23 -0
- package/package/corpus/skills/directory-build-organization/NOTICE +21 -0
- package/package/corpus/skills/directory-build-organization/SKILL.md +205 -0
- package/package/corpus/skills/directory-build-organization/references/common-patterns.md +56 -0
- package/package/corpus/skills/directory-build-organization/references/multi-level-examples.md +167 -0
- package/package/corpus/skills/directory-build-organization/references/targetframework-props-pitfall.md +54 -0
- package/package/corpus/skills/dotnet-aot-compat/LICENSE +23 -0
- package/package/corpus/skills/dotnet-aot-compat/NOTICE +18 -0
- package/package/corpus/skills/dotnet-aot-compat/SKILL.md +265 -0
- package/package/corpus/skills/dotnet-aot-compat/references/polyfills.md +43 -0
- package/package/corpus/skills/dotnet-trace-collect/LICENSE +23 -0
- package/package/corpus/skills/dotnet-trace-collect/NOTICE +65 -0
- package/package/corpus/skills/dotnet-trace-collect/SKILL.md +116 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-monitor.md +97 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-trace-collect-linux.md +84 -0
- package/package/corpus/skills/dotnet-trace-collect/references/dotnet-trace-collect.md +91 -0
- package/package/corpus/skills/dotnet-trace-collect/references/perfcollect.md +200 -0
- package/package/corpus/skills/dotnet-trace-collect/references/perfview.md +141 -0
- package/package/corpus/skills/dotnet-trace-collect/references/tool-selection.md +160 -0
- package/package/corpus/skills/dump-collect/LICENSE +23 -0
- package/package/corpus/skills/dump-collect/NOTICE +40 -0
- package/package/corpus/skills/dump-collect/SKILL.md +97 -0
- package/package/corpus/skills/dump-collect/references/container-dumps.md +412 -0
- package/package/corpus/skills/dump-collect/references/coreclr-dumps.md +108 -0
- package/package/corpus/skills/dump-collect/references/nativeaot-dumps.md +280 -0
- package/package/corpus/skills/eliminate-redundant-restores/LICENSE +23 -0
- package/package/corpus/skills/eliminate-redundant-restores/NOTICE +19 -0
- package/package/corpus/skills/eliminate-redundant-restores/SKILL.md +112 -0
- package/package/corpus/skills/extension-points/LICENSE +23 -0
- package/package/corpus/skills/extension-points/NOTICE +18 -0
- package/package/corpus/skills/extension-points/SKILL.md +248 -0
- package/package/corpus/skills/filter-syntax/LICENSE +23 -0
- package/package/corpus/skills/filter-syntax/NOTICE +17 -0
- package/package/corpus/skills/filter-syntax/SKILL.md +179 -0
- package/package/corpus/skills/including-generated-files/LICENSE +23 -0
- package/package/corpus/skills/including-generated-files/NOTICE +17 -0
- package/package/corpus/skills/including-generated-files/SKILL.md +139 -0
- package/package/corpus/skills/microbenchmarking/LICENSE +23 -0
- package/package/corpus/skills/microbenchmarking/NOTICE +36 -0
- package/package/corpus/skills/microbenchmarking/SKILL.md +131 -0
- package/package/corpus/skills/microbenchmarking/references/bdn-internals-and-tuning.md +143 -0
- package/package/corpus/skills/microbenchmarking/references/comparison-strategies.md +200 -0
- package/package/corpus/skills/microbenchmarking/references/diagnosers-and-exporters.md +150 -0
- package/package/corpus/skills/microbenchmarking/references/project-setup-and-running.md +189 -0
- package/package/corpus/skills/microbenchmarking/references/writing-benchmarks.md +310 -0
- package/package/corpus/skills/msbuild/LICENSE +23 -0
- package/package/corpus/skills/msbuild/NOTICE +55 -0
- package/package/corpus/skills/msbuild/SKILL.md +117 -0
- package/package/corpus/skills/msbuild/references/antipatterns/additional-antipatterns.md +291 -0
- package/package/corpus/skills/msbuild/references/antipatterns/incremental-build-inputs-outputs.md +57 -0
- package/package/corpus/skills/msbuild/references/antipatterns/private-assets.md +29 -0
- package/package/corpus/skills/msbuild/references/binlog-failure-analysis.md +85 -0
- package/package/corpus/skills/msbuild/references/binlog-generation.md +69 -0
- package/package/corpus/skills/msbuild/references/build-perf-baseline.md +493 -0
- package/package/corpus/skills/msbuild/references/build-perf-diagnostics.md +268 -0
- package/package/corpus/skills/msbuild/references/copy-to-output-directory.md +183 -0
- package/package/corpus/skills/msbuild/references/eval-performance.md +190 -0
- package/package/corpus/skills/msbuild/references/extension-points.md +281 -0
- package/package/corpus/skills/msbuild/references/incremental-build.md +365 -0
- package/package/corpus/skills/msbuild/references/msbuild-antipatterns.md +401 -0
- package/package/corpus/skills/orleans/LICENSE +21 -0
- package/package/corpus/skills/orleans/NOTICE +64 -0
- package/package/corpus/skills/orleans/SKILL.md +140 -0
- package/package/corpus/skills/orleans/references/anti-patterns.md +660 -0
- package/package/corpus/skills/orleans/references/configuration-api.md +933 -0
- package/package/corpus/skills/orleans/references/examples.md +66 -0
- package/package/corpus/skills/orleans/references/grain-api.md +784 -0
- package/package/corpus/skills/orleans/references/grains.md +75 -0
- package/package/corpus/skills/orleans/references/hosting.md +71 -0
- package/package/corpus/skills/orleans/references/implementation.md +591 -0
- package/package/corpus/skills/orleans/references/official-docs-index.md +250 -0
- package/package/corpus/skills/orleans/references/patterns.md +811 -0
- package/package/corpus/skills/orleans/references/persistence-api.md +495 -0
- package/package/corpus/skills/orleans/references/primitive-selection.md +35 -0
- package/package/corpus/skills/orleans/references/scheduling-and-services.md +295 -0
- package/package/corpus/skills/orleans/references/serialization-api.md +299 -0
- package/package/corpus/skills/orleans/references/streaming-api.md +396 -0
- package/package/corpus/skills/orleans/references/testing-patterns.md +210 -0
- package/package/corpus/skills/platform-detection/LICENSE +23 -0
- package/package/corpus/skills/platform-detection/NOTICE +17 -0
- package/package/corpus/skills/platform-detection/SKILL.md +230 -0
- package/package/corpus/skills/platform-detection/references/command-mode.md +27 -0
- package/package/corpus/skills/profiling/LICENSE +21 -0
- package/package/corpus/skills/profiling/NOTICE +50 -0
- package/package/corpus/skills/profiling/SKILL.md +144 -0
- package/package/corpus/skills/profiling/references/commands.md +439 -0
- package/package/corpus/skills/profiling/references/patterns.md +586 -0
- package/package/corpus/skills/profiling/references/profiling.md +190 -0
- package/package/corpus/skills/run-tests/LICENSE +23 -0
- package/package/corpus/skills/run-tests/NOTICE +19 -0
- package/package/corpus/skills/run-tests/SKILL.md +305 -0
- package/package/corpus/skills/target-authoring/LICENSE +23 -0
- package/package/corpus/skills/target-authoring/NOTICE +17 -0
- package/package/corpus/skills/target-authoring/SKILL.md +165 -0
- package/package/corpus/skills/vectorization/LICENSE +23 -0
- package/package/corpus/skills/vectorization/NOTICE +17 -0
- package/package/corpus/skills/vectorization/SKILL.md +189 -0
- package/package/profile-catalog.json +87 -1
- package/package.json +3 -2
|
@@ -18,23 +18,74 @@ set -euo pipefail
|
|
|
18
18
|
|
|
19
19
|
# SCRIPTDIR, not a path relative to the caller: shellcheck resolves a plain relative `source=`
|
|
20
20
|
# against the current working directory, and these hooks are linted from wherever CI happens to run.
|
|
21
|
+
script_directory="${BASH_SOURCE[0]%/*}"
|
|
22
|
+
[ "$script_directory" != "${BASH_SOURCE[0]}" ] || script_directory=.
|
|
21
23
|
# shellcheck source=SCRIPTDIR/hook-lib.sh
|
|
22
|
-
. "$
|
|
24
|
+
. "$script_directory/hook-lib.sh"
|
|
23
25
|
|
|
24
26
|
[ "${CRATIS_HOOKS_ALLOW_PROTECTED_WRITES:-0}" = "1" ] && exit 0
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
# This guard runs before every write, so it avoids subprocesses where a builtin does the same job:
|
|
29
|
+
# the helpers below return through REPLY instead of printing into a command substitution.
|
|
30
|
+
# Read stdin with the read builtin: opening /dev/stdin fails with ENXIO when stdin is a socket (Linux, Node pipes).
|
|
31
|
+
input=""
|
|
32
|
+
IFS= read -r -d '' input || true
|
|
27
33
|
[ -n "$input" ] || exit 0
|
|
28
34
|
hook_have jq || exit 0
|
|
29
35
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
# One jq call reads every field the guard uses. Fields are NUL-terminated (embedded NULs are dropped,
|
|
37
|
+
# as a command substitution would drop them); a missing, null, false or unreadable path is empty.
|
|
38
|
+
cwd="" file="" notebook="" new_content="" new_string=""
|
|
39
|
+
{
|
|
40
|
+
IFS= read -r -d '' cwd
|
|
41
|
+
IFS= read -r -d '' file
|
|
42
|
+
IFS= read -r -d '' notebook
|
|
43
|
+
IFS= read -r -d '' new_content
|
|
44
|
+
IFS= read -r -d '' new_string
|
|
45
|
+
} < <(jq -j '
|
|
46
|
+
def field(path): ([try (path // empty) catch empty] | first // "")
|
|
47
|
+
| if type == "string" then . else tojson end
|
|
48
|
+
| gsub("\u0000"; "");
|
|
49
|
+
[field(.cwd), field(.tool_input.file_path), field(.tool_input.notebook_path),
|
|
50
|
+
field(.tool_input.content), field(.tool_input.new_string)]
|
|
51
|
+
| .[] | ., "\u0000"
|
|
52
|
+
' <<<"$input" 2>/dev/null) || true
|
|
53
|
+
# Command substitution stripped trailing newlines from each field; keep that behaviour.
|
|
54
|
+
for field_name in cwd file notebook new_content new_string; do
|
|
55
|
+
while [[ "${!field_name}" == *$'\n' ]]; do printf -v "$field_name" '%s' "${!field_name%$'\n'}"; done
|
|
56
|
+
done
|
|
33
57
|
|
|
34
|
-
|
|
35
|
-
[ -n "$file" ] || file="$
|
|
58
|
+
[ -n "$cwd" ] || cwd="$(hook_repo_root)"
|
|
59
|
+
[ -n "$file" ] || file="$notebook"
|
|
36
60
|
[ -n "$file" ] || exit 0
|
|
37
61
|
|
|
62
|
+
# dir_of / base_of / relative_to mirror dirname, basename and hook_relpath for the absolute,
|
|
63
|
+
# normalized paths used here. abspath mirrors hook_abspath. All return through REPLY.
|
|
64
|
+
dir_of() {
|
|
65
|
+
REPLY="${1%/*}"
|
|
66
|
+
[ -n "$REPLY" ] || REPLY=/
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
base_of() {
|
|
70
|
+
REPLY="${1##*/}"
|
|
71
|
+
[ -n "$REPLY" ] || REPLY=/
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
abspath() {
|
|
75
|
+
case "$1" in
|
|
76
|
+
/*) REPLY="$1" ;;
|
|
77
|
+
*) REPLY="${2%/}/$1" ;;
|
|
78
|
+
esac
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
relative_to() {
|
|
82
|
+
local root="${2%/}"
|
|
83
|
+
case "$1" in
|
|
84
|
+
"$root"/*) REPLY="${1#"$root"/}" ;;
|
|
85
|
+
*) REPLY="$1" ;;
|
|
86
|
+
esac
|
|
87
|
+
}
|
|
88
|
+
|
|
38
89
|
# Lexically normalize before any Git lookup or parent walk, including nonexistent segments.
|
|
39
90
|
# Component parsing preserves spaces and glob characters without depending on realpath.
|
|
40
91
|
normalize_target_path() {
|
|
@@ -52,17 +103,22 @@ normalize_target_path() {
|
|
|
52
103
|
*) normalized="$normalized/$component" ;;
|
|
53
104
|
esac
|
|
54
105
|
done
|
|
55
|
-
|
|
106
|
+
REPLY="${normalized:-/}"
|
|
56
107
|
}
|
|
57
108
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
base="$(basename "$file")"
|
|
109
|
+
abspath "$file" "$cwd"
|
|
110
|
+
normalize_target_path "$REPLY"
|
|
111
|
+
file="$REPLY"
|
|
112
|
+
base_of "$file"
|
|
113
|
+
base="$REPLY"
|
|
64
114
|
|
|
65
115
|
block() {
|
|
116
|
+
# Pi can run the bundled script in a consumer checkout; this root is only for diagnostics,
|
|
117
|
+
# so it is looked up only when a write is actually refused.
|
|
118
|
+
local root rel
|
|
119
|
+
root="$(git -C "$cwd" rev-parse --show-toplevel 2>/dev/null || printf '%s\n' "$cwd")"
|
|
120
|
+
relative_to "$file" "$root"
|
|
121
|
+
rel="$REPLY"
|
|
66
122
|
printf 'BLOCKED by cratis-guard-writes: %s\n\n%s\n\n%s\n' "$rel" "$1" "$2" >&2
|
|
67
123
|
exit 2
|
|
68
124
|
}
|
|
@@ -70,36 +126,70 @@ block() {
|
|
|
70
126
|
# Check both the addressed path and its physical destination: settings may be symlinks to
|
|
71
127
|
# templates, and an innocently named link may target a protected file. Preserve missing suffixes.
|
|
72
128
|
physical_target_path() {
|
|
73
|
-
local target="$1" directory suffix="" link hops=0
|
|
129
|
+
local target="$1" directory suffix="" link hops=0 start="$PWD"
|
|
130
|
+
physical_file=""
|
|
74
131
|
while [ -L "$target" ]; do
|
|
75
132
|
hops=$((hops + 1))
|
|
76
133
|
[ "$hops" -le 40 ] || return 1
|
|
77
134
|
link="$(readlink "$target")" || return 1
|
|
78
|
-
|
|
135
|
+
dir_of "$target"
|
|
136
|
+
abspath "$link" "$REPLY"
|
|
137
|
+
target="$REPLY"
|
|
79
138
|
done
|
|
80
|
-
|
|
81
|
-
|
|
139
|
+
dir_of "$target"
|
|
140
|
+
directory="$REPLY"
|
|
141
|
+
base_of "$target"
|
|
142
|
+
suffix="/$REPLY"
|
|
82
143
|
while [ ! -d "$directory" ]; do
|
|
83
144
|
[ "$directory" != "/" ] || return 1
|
|
84
|
-
|
|
85
|
-
|
|
145
|
+
base_of "$directory"
|
|
146
|
+
suffix="/$REPLY$suffix"
|
|
147
|
+
dir_of "$directory"
|
|
148
|
+
directory="$REPLY"
|
|
86
149
|
done
|
|
87
|
-
|
|
88
|
-
|
|
150
|
+
cd -P "$directory" 2>/dev/null || return 1
|
|
151
|
+
directory="$PWD"
|
|
152
|
+
cd "$start" 2>/dev/null || true
|
|
153
|
+
physical_file="${directory%/}$suffix"
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
# The origin URL, looked up once per repository per run.
|
|
157
|
+
origin_cache_root=""
|
|
158
|
+
origin_cache_value=""
|
|
159
|
+
repository_origin() {
|
|
160
|
+
if [ "$origin_cache_root" != "$1" ]; then
|
|
161
|
+
origin_cache_value="$(git -C "$1" remote get-url origin 2>/dev/null || true)"
|
|
162
|
+
origin_cache_root="$1"
|
|
163
|
+
fi
|
|
164
|
+
REPLY="$origin_cache_value"
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Case-insensitive ASCII match of the origin URL, equivalent to grep -Eiq on a single line.
|
|
168
|
+
origin_matches() {
|
|
169
|
+
# C locale, as the grep it replaced ran: a non-ASCII letter (the Kelvin sign) must not match [a-z].
|
|
170
|
+
local LC_ALL=C pattern="$1" matched=1
|
|
171
|
+
shopt -s nocasematch
|
|
172
|
+
# shellcheck disable=SC2034
|
|
173
|
+
[[ "$REPLY" =~ $pattern ]] && matched=0
|
|
174
|
+
shopt -u nocasematch
|
|
175
|
+
return "$matched"
|
|
89
176
|
}
|
|
90
177
|
|
|
91
178
|
# ── 4. Agent controls and installed managed trees ─────────────────────────────
|
|
92
179
|
agent_control_target() {
|
|
93
|
-
local target="$1" directory policy_root target_rel
|
|
94
|
-
|
|
180
|
+
local target="$1" directory policy_root target_rel
|
|
181
|
+
dir_of "$target"
|
|
182
|
+
directory="$REPLY"
|
|
95
183
|
# Keep the addressed spelling here, even when an adapter directory is a symlink.
|
|
96
184
|
# .git is a directory in a checkout and a file in a linked worktree.
|
|
97
185
|
while [ ! -e "$directory/.git" ]; do
|
|
98
186
|
[ "$directory" != "/" ] || return 1
|
|
99
|
-
|
|
187
|
+
dir_of "$directory"
|
|
188
|
+
directory="$REPLY"
|
|
100
189
|
done
|
|
101
190
|
policy_root="$directory"
|
|
102
|
-
|
|
191
|
+
relative_to "$target" "$policy_root"
|
|
192
|
+
target_rel="$REPLY"
|
|
103
193
|
if [ -f "$policy_root/.cratis/ai.manifest.json" ]; then
|
|
104
194
|
case "$target_rel" in
|
|
105
195
|
.cratis/ai/*) return 0 ;;
|
|
@@ -122,8 +212,8 @@ agent_control_target() {
|
|
|
122
212
|
esac
|
|
123
213
|
else
|
|
124
214
|
# The corpus is authored source in Cratis/AI, not a managed installation.
|
|
125
|
-
|
|
126
|
-
if
|
|
215
|
+
repository_origin "$policy_root"
|
|
216
|
+
if origin_matches '^(https://github\.com/|git@github\.com:|ssh://git@github\.com(:[0-9]+)?/)cratis/ai(\.git)?/?$'; then
|
|
127
217
|
return 1
|
|
128
218
|
fi
|
|
129
219
|
fi
|
|
@@ -134,7 +224,7 @@ agent_control_target() {
|
|
|
134
224
|
return 1
|
|
135
225
|
}
|
|
136
226
|
|
|
137
|
-
|
|
227
|
+
physical_target_path "$file" || physical_file=""
|
|
138
228
|
if agent_control_target "$file" || { [ -n "$physical_file" ] && agent_control_target "$physical_file"; }; then
|
|
139
229
|
block \
|
|
140
230
|
"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." \
|
|
@@ -146,19 +236,30 @@ fi
|
|
|
146
236
|
# Merely *mentioning* the string — documentation, a rule file, this corpus — is not a match.
|
|
147
237
|
marker='^[[:space:]]*(//|/\*|#|<!--)[[:space:]]*@generated by Cratis'
|
|
148
238
|
|
|
239
|
+
# True when one of the first five lines of stdin carries the marker (head -n 5 | grep -E, without forks).
|
|
240
|
+
first_lines_carry_marker() {
|
|
241
|
+
local LC_ALL=C line count=0
|
|
242
|
+
while [ "$count" -lt 5 ] && { IFS= read -r line || [ -n "$line" ]; }; do
|
|
243
|
+
count=$((count + 1))
|
|
244
|
+
# shellcheck disable=SC2034
|
|
245
|
+
[[ "$line" =~ $marker ]] && return 0
|
|
246
|
+
done
|
|
247
|
+
return 1
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
# The cheap in-shell header test runs first; grep -I then confirms the file is text, as before.
|
|
149
251
|
if [ -f "$file" ] \
|
|
150
|
-
&&
|
|
151
|
-
&&
|
|
252
|
+
&& first_lines_carry_marker 2>/dev/null <"$file" \
|
|
253
|
+
&& LC_ALL=C grep -Iq . "$file" 2>/dev/null; then
|
|
152
254
|
block \
|
|
153
255
|
"This file is generated output (its header marks it as generated by Cratis). Rule 15 [contract] in .cratis/ai/rules/general.md: never edit a generated file — the next build overwrites it." \
|
|
154
256
|
"Instead: change the C# source it is generated from (the [Command] / [ReadModel] record) and rebuild with 'dotnet build -c Debug' to regenerate the proxy."
|
|
155
257
|
fi
|
|
156
258
|
|
|
157
259
|
# The same guard for authoring a *new* file that pretends to be generated output.
|
|
158
|
-
new_content
|
|
159
|
-
[ -n "$new_content" ] || new_content="$(hook_json "$input" '.tool_input.new_string')"
|
|
260
|
+
[ -n "$new_content" ] || new_content="$new_string"
|
|
160
261
|
if [ -n "$new_content" ] \
|
|
161
|
-
&&
|
|
262
|
+
&& first_lines_carry_marker <<<"$new_content"; then
|
|
162
263
|
block \
|
|
163
264
|
"The content being written opens with a Cratis generated-file header. Proxies are produced by the Cratis proxy generator, never hand-written." \
|
|
164
265
|
"Instead: write the C# source and run 'dotnet build -c Debug' to generate the proxy."
|
|
@@ -166,16 +267,20 @@ fi
|
|
|
166
267
|
|
|
167
268
|
# ── 2. Dependency manifests, lockfiles, SDK and NuGet configuration ───────────
|
|
168
269
|
manifest_writes_allowed() {
|
|
169
|
-
local setting=""
|
|
270
|
+
local setting="" directory policy_root start="$PWD"
|
|
170
271
|
# Authorization belongs to the write target, which may be outside the session's checkout.
|
|
171
272
|
# New files can have nonexistent parents; find their nearest existing directory first.
|
|
172
|
-
|
|
273
|
+
dir_of "$file"
|
|
274
|
+
directory="$REPLY"
|
|
173
275
|
while [ ! -d "$directory" ]; do
|
|
174
276
|
[ "$directory" != "/" ] || return 1
|
|
175
|
-
|
|
277
|
+
dir_of "$directory"
|
|
278
|
+
directory="$REPLY"
|
|
176
279
|
done
|
|
177
280
|
# Follow existing directory symlinks before asking Git which repository owns the target.
|
|
178
|
-
|
|
281
|
+
cd -P "$directory" 2>/dev/null || return 1
|
|
282
|
+
directory="$PWD"
|
|
283
|
+
cd "$start" 2>/dev/null || true
|
|
179
284
|
policy_root="$(git -C "$directory" rev-parse --show-toplevel 2>/dev/null)" || return 1
|
|
180
285
|
if [ -f "$policy_root/.cratis/ai.json" ]; then
|
|
181
286
|
# Only actual booleans override the default; jq's `// empty` would discard false.
|
|
@@ -185,9 +290,9 @@ manifest_writes_allowed() {
|
|
|
185
290
|
true) return 0 ;;
|
|
186
291
|
false) return 1 ;;
|
|
187
292
|
esac
|
|
188
|
-
|
|
293
|
+
repository_origin "$policy_root"
|
|
189
294
|
# Anchor host, owner and the single repository segment; never infer ownership from profiles.
|
|
190
|
-
|
|
295
|
+
origin_matches '^(https://github\.com/|git@github\.com:|ssh://git@github\.com(:[0-9]+)?/)cratis/[a-z0-9_.-]+/?$'
|
|
191
296
|
}
|
|
192
297
|
|
|
193
298
|
case "$base" in
|
|
@@ -44,6 +44,23 @@ paths:
|
|
|
44
44
|
`cancel-in-progress: true`, keyed `${{ github.workflow }}-${{ github.ref }}`.
|
|
45
45
|
**Never** cancel-in-progress on publish, release, or deploy workflows — a cancelled
|
|
46
46
|
half-publish is worse than a queued one.
|
|
47
|
+
- **Publish and release workflows never cancel** (`cancel-in-progress: false`) and set
|
|
48
|
+
`queue: max`. A group holds one running and one pending run; a newer arrival replaces
|
|
49
|
+
the pending one. Merges into the default branch share a group (a push, a repository-wide
|
|
50
|
+
key, or `github.ref` on a merged `pull_request` `closed` event, which is the base
|
|
51
|
+
branch), so without `queue: max` a newer merge replaces the older pending release.
|
|
52
|
+
`queue: max` keeps up to 100 pending runs, processed in order, and applies only while
|
|
53
|
+
`cancel-in-progress` is false or unset. Keep a single pending slot only for a documented
|
|
54
|
+
design where each run releases everything since the last release, so a replaced run
|
|
55
|
+
loses nothing; say so in a comment beside the `concurrency` block.
|
|
56
|
+
- **A required check must not be skippable by `paths:` alone.** A workflow that never
|
|
57
|
+
starts never reports, and the pull request hangs. Gate jobs on a change-detection job
|
|
58
|
+
and require one always-run aggregator job (`if: always()`, checks every `needs.*.result`).
|
|
59
|
+
- **Pin third-party actions by full commit SHA** (version in a comment) and set minimal
|
|
60
|
+
`permissions:` on each job. Run `zizmor` locally on edited workflows: its `unpinned-uses`
|
|
61
|
+
and `excessive-permissions` audits check exactly this. `actionlint` checks syntax,
|
|
62
|
+
expressions and embedded shell, not pinning. Do not assume CI runs either tool.
|
|
63
|
+
- To make a workflow faster, use the `cratis-ci-pipeline-performance` skill.
|
|
47
64
|
|
|
48
65
|
## Matrices and operating systems
|
|
49
66
|
|
|
@@ -86,11 +86,20 @@ profile includes neither Screenplay nor Stage.
|
|
|
86
86
|
| Profile ID | Description | Automatically Includes |
|
|
87
87
|
|---|---|---|
|
|
88
88
|
| `cratis/engineering` | Engineering conventions and workflows | `cratis/engineering/core`, `cratis/engineering/csharp`, `cratis/engineering/elixir`, `cratis/engineering/go`, `cratis/engineering/kotlin`, `cratis/engineering/react`, `cratis/engineering/typescript` |
|
|
89
|
-
| `cratis/engineering/csharp` | C# engineering conventions and framework Orleans jobs (`cratis-orleans-jobs`, alongside `orleans.md`) | `cratis/engineering/core` |
|
|
89
|
+
| `cratis/engineering/csharp` | C# engineering conventions, .NET engineering skills, and framework Orleans jobs (`cratis-orleans-jobs`, alongside `orleans.md`) | `cratis/engineering/core`, `cratis/engineering/dotnet` |
|
|
90
|
+
| `cratis/engineering/dotnet` | Upstream .NET engineering workflows | `cratis/engineering/dotnet/performance`, `cratis/engineering/dotnet/diagnostics`, `cratis/engineering/dotnet/msbuild`, `cratis/engineering/dotnet/orleans`, `cratis/engineering/dotnet/testing`, `cratis/engineering/dotnet/refactoring` |
|
|
91
|
+
| `cratis/engineering/dotnet/performance` | Microbenchmarking, performance patterns, SIMD, and profiling | (no child profiles) |
|
|
92
|
+
| `cratis/engineering/dotnet/diagnostics` | Trace and crash-dump collection | (no child profiles) |
|
|
93
|
+
| `cratis/engineering/dotnet/msbuild` | MSBuild troubleshooting, build authoring, output paths, and binlogs | (no child profiles) |
|
|
94
|
+
| `cratis/engineering/dotnet/orleans` | Orleans primitives, hosting, persistence, and runtime behavior | (no child profiles) |
|
|
95
|
+
| `cratis/engineering/dotnet/testing` | Test-platform detection, runner commands, filters, and coverage | (no child profiles) |
|
|
96
|
+
| `cratis/engineering/dotnet/refactoring` | Behavior-preserving C# refactoring and AOT compatibility | (no child profiles) |
|
|
90
97
|
| `cratis/engineering/go` | Go framework parity and immutable module releases | `cratis/engineering/core`, `cratis/language/go` |
|
|
91
98
|
| `cratis/engineering/typescript` | TypeScript engineering conventions | `cratis/engineering/core` |
|
|
92
99
|
| `cratis/engineering/react` | React engineering conventions | `cratis/engineering/core` |
|
|
93
100
|
|
|
101
|
+
The `cratis/engineering/dotnet` profiles carry upstream skills under MIT, with attribution and changes in each skill's NOTICE. Cratis rules and the `cratis-*` skills win where they differ.
|
|
102
|
+
|
|
94
103
|
The `cratis/engineering` profile also carries [issue-assignment.md](./issue-assignment.md): when an agent starts work on a numbered issue in a known repository and nobody is assigned, it assigns the current `gh` user.
|
|
95
104
|
|
|
96
105
|
### Language Profiles
|
|
@@ -8,6 +8,8 @@ applyTo: "**/*"
|
|
|
8
8
|
|
|
9
9
|
**The PR description is published verbatim as the GitHub release. In repositories released by `cratis/release-action`, it also closes every issue written as `(#n)`; elsewhere, follow the repository's own release and issue-closing process.** Write the note the person upgrading should read, not a development write-up. The same contract applies to release notes typed into a manual workflow run or written straight into a release. Where it is installed, the `policy / verify` check enforces it on release-bound PRs into the default branch carrying `major`/`minor`/`patch` (it re-runs when the label is added); its release-note step warns on `no-release` and unlabelled PRs, which must still be written this way because any of them may become releasable. `release-action` does not run for a `no-release` PR, so `(#n)` closes nothing there. Editing the description re-runs the check. HTML comments are not shown on the release page and the check ignores them for headings, keywords and placeholders, and `release-action` removes them before publishing, so a `(#n)` only inside a comment closes nothing; the check fails it, so never put an issue reference in a comment. The template's own comment can stay: its `(#123)` examples are inline code, and the comment is not published.
|
|
10
10
|
|
|
11
|
+
**A change to a hook script or its wiring (`.cratis/ai/hooks/**`) needs a release-note line that tells consumers to run `cratis ai update`; a hook fix does not reach a repository until they do.**
|
|
12
|
+
|
|
11
13
|
### Allowed shape
|
|
12
14
|
|
|
13
15
|
- Follow the repository's pull request template (`.github/pull_request_template.md`) within this contract.
|
|
@@ -20,6 +20,10 @@ Every line is tagged **[contract]** (binding) per the Three Levels of Authority
|
|
|
20
20
|
- **[contract] Project the field you need and say which one:** `-o jsonpath='{.spec.containers[*].image}'`,
|
|
21
21
|
`-o custom-columns=…`, `kubectl get … -o name`, status fields, `kubectl logs`, `docker inspect --format`.
|
|
22
22
|
Read a `.env.example`, never the `.env`.
|
|
23
|
+
- **[contract] The hook reads command text only.** It cannot see a command piped into a shell
|
|
24
|
+
(`… | sh`, `bash -c "$(…)"`), a recursive search with no named file (`grep -r PASSWORD .`), or a
|
|
25
|
+
value reached through a variable, alias or script. These stay your rule to keep; output redaction
|
|
26
|
+
is the only backstop.
|
|
23
27
|
|
|
24
28
|
## Values
|
|
25
29
|
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) .NET Foundation and Contributors
|
|
4
|
+
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
.NET Performance Patterns
|
|
2
|
+
Copyright (c) .NET Foundation and Contributors
|
|
3
|
+
Licensed under the MIT License. See LICENSE.
|
|
4
|
+
|
|
5
|
+
Upstream source: https://github.com/dotnet/skills/blob/a6bf43ab61967c30919334986515163ab24d7635/plugins/dotnet-diag/skills/analyzing-dotnet-performance/SKILL.md
|
|
6
|
+
|
|
7
|
+
Changes made by Cratis:
|
|
8
|
+
|
|
9
|
+
LICENSE:
|
|
10
|
+
- Copy upstream MIT license and copyright verbatim.
|
|
11
|
+
|
|
12
|
+
SKILL.md:
|
|
13
|
+
- Replace "I/O" with "input/output" in the description to satisfy the neutral-voice rule.
|
|
14
|
+
- Normalize frontmatter serialization, add MIT license where absent; preserve name and description.
|
|
15
|
+
- Add marked modification/source comment and applicability/Cratis precedence line.
|
|
16
|
+
- Rewrite the description to the Cratis shape (what it does, Use when, Not for) and drop references to skills that are not part of this corpus.
|
|
17
|
+
|
|
18
|
+
references/structural-patterns.md:
|
|
19
|
+
- Qualify sealing advice to preserve published framework/library public API compatibility.
|
|
20
|
+
|
|
21
|
+
references/async-patterns.md:
|
|
22
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
23
|
+
|
|
24
|
+
references/collections-and-linq.md:
|
|
25
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
26
|
+
|
|
27
|
+
references/critical-patterns.md:
|
|
28
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
29
|
+
|
|
30
|
+
references/io-and-serialization.md:
|
|
31
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
32
|
+
|
|
33
|
+
references/memory-and-strings.md:
|
|
34
|
+
- Add or normalize the top Contents list from existing headings; preserve section content.
|
|
35
|
+
|
|
36
|
+
NOTICE: Add this attribution, change list, and any download/execution disclosure.
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: analyzing-dotnet-performance
|
|
3
|
+
description: 'Scans .NET code for about 50 performance anti-patterns across async, memory, strings, collections, LINQ, regex, serialization, and input/output, with tiered severity. Use when analyzing .NET code for optimization opportunities, reviewing hot paths, or auditing allocation-heavy patterns. Not for measuring or profiling a running process (use profiling or microbenchmarking) or for SIMD work (use vectorization).'
|
|
4
|
+
license: MIT
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
<!-- Modified by Cratis from dotnet's original (MIT): frontmatter, applicability, navigation and the changes listed in NOTICE. Upstream: https://github.com/dotnet/skills (plugins/dotnet-diag/skills/analyzing-dotnet-performance/SKILL.md; see NOTICE) -->
|
|
8
|
+
|
|
9
|
+
# .NET Performance Patterns
|
|
10
|
+
|
|
11
|
+
Cratis rules in `.cratis/ai/rules/` (including `csharp.md`, `specs.csharp.md`, and `orleans.md`) and the `cratis-*` skills win where they differ.
|
|
12
|
+
|
|
13
|
+
Scan C#/.NET code for performance anti-patterns and produce prioritized findings with concrete fixes. Patterns sourced from the official .NET performance blog series, distilled to customer-actionable guidance.
|
|
14
|
+
|
|
15
|
+
## When to Use
|
|
16
|
+
|
|
17
|
+
- Reviewing C#/.NET code for performance optimization opportunities
|
|
18
|
+
- Auditing hot paths for allocation-heavy or inefficient patterns
|
|
19
|
+
- Systematic scan of a codebase for known anti-patterns before release
|
|
20
|
+
- Second-opinion analysis after manual performance review
|
|
21
|
+
|
|
22
|
+
## When Not to Use
|
|
23
|
+
|
|
24
|
+
- **Algorithmic complexity analysis** — this skill targets API usage patterns, not algorithm design
|
|
25
|
+
- **Code not on a hot path** with no performance requirements — avoid premature optimization
|
|
26
|
+
|
|
27
|
+
## Inputs
|
|
28
|
+
|
|
29
|
+
| Input | Required | Description |
|
|
30
|
+
|-------|----------|-------------|
|
|
31
|
+
| Source code | Yes | C# files, code blocks, or repository paths to scan |
|
|
32
|
+
| Hot-path context | Recommended | Which code paths are performance-critical |
|
|
33
|
+
| Target framework | Recommended | .NET version (some patterns require .NET 8+) |
|
|
34
|
+
| Scan depth | Optional | `critical-only`, `standard` (default), or `comprehensive` |
|
|
35
|
+
|
|
36
|
+
## Workflow
|
|
37
|
+
|
|
38
|
+
### Step 1: Load Critical Reference
|
|
39
|
+
|
|
40
|
+
Resolve bundled paths from the directory that contains this `SKILL.md`, not from the user's workspace. Load this reference file first:
|
|
41
|
+
|
|
42
|
+
- `references/critical-patterns.md`
|
|
43
|
+
|
|
44
|
+
If a direct read fails, list this skill's `references/` directory once and retry only when the listing shows the expected file. Do not use workspace file or text search to locate the skill installation.
|
|
45
|
+
|
|
46
|
+
### Step 2: Detect Code Signals and Select Topic Recipes
|
|
47
|
+
|
|
48
|
+
Scan the code for signals that indicate which pattern categories to check. Use the `## Detection` section from the critical reference when available and the inline recipes in Step 3 for initial signal detection.
|
|
49
|
+
|
|
50
|
+
After detecting signals, load only the topic-specific references selected by scan depth:
|
|
51
|
+
|
|
52
|
+
- `critical-only`: No additional references (use only `critical-patterns.md`)
|
|
53
|
+
- `standard` (default): Load references matching detected signals from this list:
|
|
54
|
+
- `references/async-patterns.md` — async/Task/ValueTask signals
|
|
55
|
+
- `references/memory-and-strings.md` — Span/Memory/string allocation signals
|
|
56
|
+
- `references/regex-patterns.md` — Regex signals
|
|
57
|
+
- `references/collections-and-linq.md` — Dictionary/List/LINQ signals
|
|
58
|
+
- `references/io-and-serialization.md` — JsonSerializer/HttpClient/Stream signals
|
|
59
|
+
- `references/structural-patterns.md` — always loaded (unsealed classes checked regardless)
|
|
60
|
+
- `comprehensive`: Load all six topic-specific references above
|
|
61
|
+
|
|
62
|
+
For coverage reporting, the selected references are `references/critical-patterns.md` plus only the topic-specific references selected above. If any selected reference remains unavailable after retry, use the inline recipes in Step 3 for the missing coverage. Include `Reference coverage: reduced; unavailable: <paths>; used inline recipes for missing references.` in the final report, with `<paths>` replaced by the missing relative paths of the selected references only.
|
|
63
|
+
|
|
64
|
+
Use the `## Detection` sections from loaded reference files and the inline recipes in Step 3 for categories whose reference files are unavailable.
|
|
65
|
+
|
|
66
|
+
| Signal in Code | Topic |
|
|
67
|
+
|----------------|-------|
|
|
68
|
+
| `async`, `await`, `Task`, `ValueTask` | Async patterns |
|
|
69
|
+
| `Span<`, `Memory<`, `stackalloc`, `ArrayPool`, `string.Substring`, `.Replace(`, `.ToLower()`, `+=` in loops, `params` | Memory & strings |
|
|
70
|
+
| `Regex`, `[GeneratedRegex]`, `Regex.Match`, `RegexOptions.Compiled` | Regex patterns |
|
|
71
|
+
| `Dictionary<`, `List<`, `.ToList()`, `.Where(`, `.Select(`, LINQ methods, `static readonly Dictionary<` | Collections & LINQ |
|
|
72
|
+
| `JsonSerializer`, `HttpClient`, `Stream`, `FileStream` | I/O & serialization |
|
|
73
|
+
|
|
74
|
+
Always check structural patterns (unsealed classes) regardless of signals.
|
|
75
|
+
|
|
76
|
+
**Scan depth controls scope:**
|
|
77
|
+
- `critical-only`: Only critical patterns (deadlocks, >10x regressions)
|
|
78
|
+
- `standard` (default): Critical + detected topic patterns
|
|
79
|
+
- `comprehensive`: All pattern categories
|
|
80
|
+
|
|
81
|
+
### Step 3: Scan and Report
|
|
82
|
+
|
|
83
|
+
**For files under 500 lines, read the entire file first** — you'll spot most patterns faster than running individual grep recipes. Use grep to confirm counts and catch patterns you might miss visually.
|
|
84
|
+
|
|
85
|
+
For each relevant pattern category, run the detection recipes below. Report exact counts, not estimates.
|
|
86
|
+
|
|
87
|
+
**Core scan recipes** (run these when reference files aren't available):
|
|
88
|
+
```
|
|
89
|
+
# Strings & memory
|
|
90
|
+
grep -n '\.IndexOf(\"' FILE # Missing StringComparison
|
|
91
|
+
grep -n '\.Substring(' FILE # Substring allocations
|
|
92
|
+
grep -En '\.(StartsWith|EndsWith|Contains)\s*\(' FILE # Missing StringComparison
|
|
93
|
+
grep -n '\.ToLower()\|\.ToUpper()' FILE # Culture-sensitive + allocation
|
|
94
|
+
grep -n '\.Replace(' FILE # Chained Replace allocations
|
|
95
|
+
grep -n 'params ' FILE # params array allocation
|
|
96
|
+
|
|
97
|
+
# Collections & LINQ
|
|
98
|
+
grep -n '\.Select\|\.Where\|\.OrderBy\|\.GroupBy' FILE # LINQ on hot path
|
|
99
|
+
grep -n '\.All\|\.Any' FILE # LINQ on string/char
|
|
100
|
+
grep -n 'new Dictionary<\|new List<' FILE # Per-call allocation
|
|
101
|
+
grep -n 'static readonly Dictionary<' FILE # FrozenDictionary candidate
|
|
102
|
+
|
|
103
|
+
# Regex
|
|
104
|
+
grep -n 'RegexOptions.Compiled' FILE # Compiled regex budget
|
|
105
|
+
grep -n 'new Regex(' FILE # Per-call regex
|
|
106
|
+
grep -n 'GeneratedRegex' FILE # Positive: source-gen regex
|
|
107
|
+
|
|
108
|
+
# Structural
|
|
109
|
+
grep -n 'public class \|internal class ' FILE # Unsealed classes
|
|
110
|
+
grep -n 'sealed class' FILE # Already sealed
|
|
111
|
+
grep -n ': IEquatable' FILE # Positive: struct equality
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Rules:**
|
|
115
|
+
- Run every relevant recipe for the detected pattern categories
|
|
116
|
+
- **Emit a scan execution checklist** before classifying findings — list each recipe and the hit count
|
|
117
|
+
- A result of **0 hits** is valid and valuable (confirms good practice)
|
|
118
|
+
- If reference files were loaded, also run their `## Detection` recipes
|
|
119
|
+
|
|
120
|
+
**Verify-the-Inverse Rule:** For absence patterns, always count both sides and report the ratio (e.g., "N of M classes are sealed"). The ratio determines severity — 0/185 is systematic, 12/15 is a consistency fix.
|
|
121
|
+
|
|
122
|
+
### Step 3b: Cross-File Consistency Check
|
|
123
|
+
|
|
124
|
+
If an optimized pattern is found in one file, check whether sibling files (same directory, same interface, same base class) use the un-optimized equivalent. Flag as 🟡 Moderate with the optimized file as evidence.
|
|
125
|
+
|
|
126
|
+
### Step 3c: Compound Allocation Check
|
|
127
|
+
|
|
128
|
+
After running scan recipes, look for these multi-allocation patterns that single-line recipes miss:
|
|
129
|
+
|
|
130
|
+
1. **Branched `.Replace()` chains:** Methods that call `.Replace()` across multiple `if/else` branches — report total allocation count across all branches, not just per-line.
|
|
131
|
+
2. **Cross-method chaining:** When a public method delegates to another method that itself allocates intermediates (e.g., A calls B which does 3 regex replaces, then A calls C), report the total chain cost as one finding.
|
|
132
|
+
3. **Compound `+=` with embedded allocating calls:** Lines like `result += $"...{Foo().ToLower()}"` are 2+ allocations (interpolation + ToLower + concatenation) — flag the compound cost, not just the `.ToLower()`.
|
|
133
|
+
4. **`string.Format` specificity:** Distinguish resource-loaded format strings (not fixable) from compile-time literal format strings (fixable with interpolation). Enumerate the actionable sites.
|
|
134
|
+
|
|
135
|
+
### Step 4: Classify and Prioritize Findings
|
|
136
|
+
|
|
137
|
+
Assign each finding a severity:
|
|
138
|
+
|
|
139
|
+
| Severity | Criteria | Action |
|
|
140
|
+
|----------|----------|--------|
|
|
141
|
+
| 🔴 **Critical** | Deadlocks, crashes, security vulnerabilities, >10x regression | Must fix |
|
|
142
|
+
| 🟡 **Moderate** | 2-10x improvement opportunity, best practice for hot paths | Should fix on hot paths |
|
|
143
|
+
| ℹ️ **Info** | Pattern applies but code may not be on a hot path | Consider if profiling shows impact |
|
|
144
|
+
|
|
145
|
+
**Prioritization rules:**
|
|
146
|
+
1. If the user identified hot-path code, elevate all findings in that code to their maximum severity
|
|
147
|
+
2. If hot-path context is unknown, report 🔴 Critical findings unconditionally; report 🟡 Moderate findings with a note: _"Impactful if this code is on a hot path"_
|
|
148
|
+
3. Never suggest micro-optimizations on code that is clearly not performance-sensitive
|
|
149
|
+
|
|
150
|
+
**Scale-based severity escalation:**
|
|
151
|
+
When the same pattern appears across many instances, escalate severity:
|
|
152
|
+
- 1-10 instances of the same anti-pattern → report at the pattern's base severity
|
|
153
|
+
- 11-50 instances → escalate ℹ️ Info patterns to 🟡 Moderate
|
|
154
|
+
- 50+ instances → escalate to 🟡 Moderate with elevated priority; flag as a codebase-wide systematic issue
|
|
155
|
+
|
|
156
|
+
Always report exact counts (from scan recipes), not estimates or agent summaries.
|
|
157
|
+
|
|
158
|
+
### Step 5: Generate Findings
|
|
159
|
+
|
|
160
|
+
**Keep findings compact.** Each finding is one short block — not an essay. Group by severity (🔴 → 🟡 → ℹ️), not by file.
|
|
161
|
+
|
|
162
|
+
Format per finding:
|
|
163
|
+
|
|
164
|
+
```
|
|
165
|
+
#### ID. Title (N instances)
|
|
166
|
+
**Impact:** one-line impact statement
|
|
167
|
+
**Files:** file1.cs:L1, file2.cs:L2, ... (list locations, don't build tables)
|
|
168
|
+
**Fix:** one-line description of the change (e.g., "Add `StringComparison.Ordinal` parameter")
|
|
169
|
+
**Caveat:** only if non-obvious (version requirement, correctness risk)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Rules for compact output:**
|
|
173
|
+
- **No ❌/✅ code blocks** for trivial fixes (adding a keyword, parameter, or type change). A one-line fix description suffices.
|
|
174
|
+
- **Only include code blocks** for non-obvious transformations (e.g., replacing a LINQ chain with a foreach loop, or hoisting a closure).
|
|
175
|
+
- **File locations as inline comma-separated list**, not a table. Use `File.cs:L42` format.
|
|
176
|
+
- **No explanatory prose** beyond the Impact line — the severity icon already conveys urgency.
|
|
177
|
+
- **Merge related findings** that share the same fix (e.g., all `.ToLower()` calls go in one finding, not split by file).
|
|
178
|
+
- **Positive findings** in a bullet list, not a table. One line per pattern: `✅ Pattern — evidence`.
|
|
179
|
+
|
|
180
|
+
End with a summary table and disclaimer:
|
|
181
|
+
|
|
182
|
+
```markdown
|
|
183
|
+
| Severity | Count | Top Issue |
|
|
184
|
+
|----------|-------|-----------|
|
|
185
|
+
| 🔴 Critical | N | ... |
|
|
186
|
+
| 🟡 Moderate | N | ... |
|
|
187
|
+
| ℹ️ Info | N | ... |
|
|
188
|
+
|
|
189
|
+
> ⚠️ **Disclaimer:** These results are generated by an AI assistant and are non-deterministic. Findings may include false positives, miss real issues, or suggest changes that are incorrect for your specific context. Always verify recommendations with benchmarks and human review before applying changes to production code.
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
## Validation
|
|
193
|
+
|
|
194
|
+
Before delivering results, verify:
|
|
195
|
+
|
|
196
|
+
- [ ] All critical patterns were checked (from reference files or inline recipes)
|
|
197
|
+
- [ ] Topic-specific recipes run only when matching signals detected
|
|
198
|
+
- [ ] Each finding includes a concrete code fix
|
|
199
|
+
- [ ] Scan execution checklist is complete (all recipes run)
|
|
200
|
+
- [ ] Summary table included at end
|
|
201
|
+
|
|
202
|
+
## Common Pitfalls
|
|
203
|
+
|
|
204
|
+
| Pitfall | Correct Approach |
|
|
205
|
+
|---------|-----------------|
|
|
206
|
+
| Flagging every `Dictionary` as needing `FrozenDictionary` | Only flag if the dictionary is never mutated after construction |
|
|
207
|
+
| Suggesting `Span<T>` in async methods | Use `Memory<T>` in async code; `Span<T>` only in sync hot paths |
|
|
208
|
+
| Reporting LINQ outside hot paths | Only flag LINQ in identified hot paths or tight loops; LINQ is acceptable in code that runs infrequently. Since .NET 7, LINQ Min/Max/Sum/Average are vectorized — blanket bans on LINQ are misguided |
|
|
209
|
+
| Suggesting `ConfigureAwait(false)` in app code | Only applicable in library code; not primarily a performance concern |
|
|
210
|
+
| Recommending `ValueTask` everywhere | Only for hot paths with frequent synchronous completion |
|
|
211
|
+
| Flagging `new HttpClient()` in DI services | Check if `IHttpClientFactory` is already in use |
|
|
212
|
+
| Suggesting `[GeneratedRegex]` for dynamic patterns | Only flag when the pattern string is a compile-time literal |
|
|
213
|
+
| Suggesting `CollectionsMarshal.AsSpan` broadly | Only for ultra-hot paths with benchmarked evidence; adds complexity and fragility |
|
|
214
|
+
| Suggesting `unsafe` code for micro-optimizations | Avoid `unsafe` except where absolutely necessary — do not recommend it for micro-optimizations that don't matter. Safe alternatives like `Span<T>`, `stackalloc` in safe context, and `ArrayPool` cover the vast majority of performance needs |
|