返回 DeepSeek-Reasonix
check-cache-impact.sh
根目录 / scripts / check-cache-impact.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3
4 usage() {
5 cat <<'USAGE'
6 Usage: scripts/check-cache-impact.sh [changed-file ...]
7
8 Checks that PRs touching cache-sensitive prompt or tool surfaces include an
9 explicit cache-impact note and guard-test note in the pull request body.
10
11 Inputs:
12 CACHE_IMPACT_PR_BODY or PR_BODY Pull request body text.
13 CACHE_IMPACT_PR_BODY_FILE File containing the pull request body.
14 CACHE_IMPACT_CHANGED_FILES Newline-separated changed files.
15 CACHE_IMPACT_CHANGED_FILES_FILE File containing newline-separated changed files.
16 CACHE_IMPACT_BASE_SHA / BASE_SHA Diff base when files are not supplied.
17 CACHE_IMPACT_HEAD_SHA / HEAD_SHA Diff head when files are not supplied.
18 USAGE
19 }
20
21 if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
22 usage
23 exit 0
24 fi
25
26 body="${CACHE_IMPACT_PR_BODY:-${PR_BODY:-}}"
27 if [[ -n "${CACHE_IMPACT_PR_BODY_FILE:-}" ]]; then
28 body="$(cat "$CACHE_IMPACT_PR_BODY_FILE")"
29 fi
30
31 changed_input=""
32 if [[ "$#" -gt 0 ]]; then
33 changed_input="$(printf '%s\n' "$@")"
34 elif [[ -n "${CACHE_IMPACT_CHANGED_FILES_FILE:-}" ]]; then
35 changed_input="$(cat "$CACHE_IMPACT_CHANGED_FILES_FILE")"
36 elif [[ -n "${CACHE_IMPACT_CHANGED_FILES:-}" ]]; then
37 changed_input="$CACHE_IMPACT_CHANGED_FILES"
38 else
39 base="${CACHE_IMPACT_BASE_SHA:-${BASE_SHA:-}}"
40 head="${CACHE_IMPACT_HEAD_SHA:-${HEAD_SHA:-HEAD}}"
41 if [[ -z "$base" ]]; then
42 base="$(git merge-base origin/main-v2 "$head" 2>/dev/null || git merge-base main-v2 "$head")"
43 fi
44 diff_base="$base"
45 if merge_base="$(git merge-base "$base" "$head" 2>/dev/null)"; then
46 diff_base="$merge_base"
47 fi
48 changed_input="$(git diff --name-only "$diff_base" "$head")"
49 fi
50
51 changed_files=()
52 while IFS= read -r file; do
53 [[ -z "$file" ]] && continue
54 changed_files+=("$file")
55 done <<< "$changed_input"
56
57 cache_sensitive=()
58 system_prompt_sensitive=()
59 standing_instruction_changed=()
60
61 for file in "${changed_files[@]:-}"; do
62 case "$file" in
63 REASONIX.md|AGENTS.md|CLAUDE.md|\
64 REASONIX.local.md|AGENTS.local.md|CLAUDE.local.md|\
65 */REASONIX.md|*/AGENTS.md|*/CLAUDE.md|\
66 */REASONIX.local.md|*/AGENTS.local.md|*/CLAUDE.local.md)
67 standing_instruction_changed+=("$file")
68 cache_sensitive+=("$file")
69 system_prompt_sensitive+=("$file")
70 ;;
71 desktop/session_prompt.go|\
72 internal/agent/agent.go|\
73 internal/agent/ask.go|\
74 internal/agent/cache*|\
75 internal/agent/compact*|\
76 internal/agent/goal_display.go|\
77 internal/agent/parallel_tasks.go|\
78 internal/agent/planner_registry.go|\
79 internal/agent/prune*|\
80 internal/agent/subagent_registry*|\
81 internal/agent/subagent_identity.go|\
82 internal/agent/task.go|\
83 internal/boot/*|\
84 internal/command/slashtool.go|\
85 internal/config/config.go|\
86 internal/config/system_prompt*|\
87 internal/control/goal.go|\
88 internal/control/input.go|\
89 internal/control/turn_orchestrator.go|\
90 internal/environment/*|\
91 internal/goaleval/*|\
92 internal/history/tool.go|\
93 internal/installsource/*|\
94 internal/lsp/tool.go|\
95 internal/memory/*|\
96 internal/outputstyle/*|\
97 internal/plugin/*|\
98 internal/provider/*|\
99 internal/skill/*|\
100 internal/taskintent/*|\
101 internal/tool/*|\
102 scripts/cache-guard.sh|\
103 scripts/check-cache-impact.sh)
104 cache_sensitive+=("$file")
105 ;;
106 esac
107
108 case "$file" in
109 desktop/session_prompt.go|\
110 internal/agent/task.go|\
111 internal/boot/*|\
112 internal/config/config.go|\
113 internal/config/system_prompt*|\
114 internal/environment/*|\
115 internal/memory/*|\
116 internal/outputstyle/*|\
117 internal/skill/*)
118 system_prompt_sensitive+=("$file")
119 ;;
120 esac
121 done
122
123 if [[ "${#cache_sensitive[@]}" -eq 0 ]]; then
124 echo "No cache-sensitive prompt/tool files changed."
125 exit 0
126 fi
127
128 failures=()
129
130 trim() {
131 local s="$1"
132 s="${s#"${s%%[![:space:]]*}"}"
133 s="${s%"${s##*[![:space:]]}"}"
134 printf '%s' "$s"
135 }
136
137 field_value() {
138 local label="$1"
139 local line
140 line="$(printf '%s\n' "$body" | grep -Eim1 "^[[:space:]>#*_-]*${label}[[:space:]]*:" || true)"
141 [[ -z "$line" ]] && return 1
142 trim "${line#*:}"
143 }
144
145 require_field() {
146 local label="$1"
147 local value
148 if ! value="$(field_value "$label")"; then
149 failures+=("missing ${label}: line")
150 return
151 fi
152 if [[ -z "$value" || "$value" =~ ^[Tt][Oo][Dd][Oo]($|[[:space:]:-]) || "$value" =~ ^[Tt][Bb][Dd]($|[[:space:]:-]) ]]; then
153 failures+=("${label}: must be filled out")
154 fi
155 }
156
157 require_review_field() {
158 local label="$1"
159 local value
160 if ! value="$(field_value "$label")"; then
161 failures+=("missing ${label}: line")
162 return
163 fi
164 local lower
165 lower="$(printf '%s' "$value" | tr '[:upper:]' '[:lower:]')"
166 if [[ -z "$value" || "$lower" =~ ^todo($|[[:space:]:-]) || "$lower" =~ ^tbd($|[[:space:]:-]) || "$lower" =~ ^n/?a($|[[:space:]:-]) || "$lower" =~ ^none($|[[:space:]:-]) ]]; then
167 failures+=("${label}: must name the explicit system-prompt review/approval")
168 fi
169 }
170
171 require_field "Cache-impact"
172 require_field "Cache-guard"
173
174 if [[ "${#standing_instruction_changed[@]}" -gt 0 ]]; then
175 cache_impact="$(field_value "Cache-impact" || true)"
176 cache_impact_lower="$(printf '%s' "$cache_impact" | tr '[:upper:]' '[:lower:]')"
177 if [[ "$cache_impact_lower" =~ ^none($|[[:space:]:-]) ]]; then
178 failures+=("Cache-impact: cannot be none when standing instruction files change")
179 fi
180 fi
181
182 if [[ "${#system_prompt_sensitive[@]}" -gt 0 ]]; then
183 require_review_field "System-prompt-review"
184 fi
185
186 if [[ "${#failures[@]}" -gt 0 ]]; then
187 {
188 echo "Cache impact check failed."
189 echo
190 echo "Cache-sensitive files changed:"
191 printf ' - %s\n' "${cache_sensitive[@]}"
192 if [[ "${#system_prompt_sensitive[@]}" -gt 0 ]]; then
193 echo
194 echo "System-prompt-sensitive files changed:"
195 printf ' - %s\n' "${system_prompt_sensitive[@]}"
196 fi
197 echo
198 echo "Required PR body lines:"
199 echo " Cache-impact: <none|low|medium|high> - <reason>"
200 echo " Cache-guard: <focused guard test/command or existing guard rationale>"
201 if [[ "${#system_prompt_sensitive[@]}" -gt 0 ]]; then
202 echo " System-prompt-review: <reviewer/approval note>"
203 fi
204 echo
205 echo "Failures:"
206 printf ' - %s\n' "${failures[@]}"
207 } >&2
208 exit 1
209 fi
210
211 echo "Cache impact check passed."
212 echo "Cache-sensitive files:"
213 printf ' - %s\n' "${cache_sensitive[@]}"
214
214 lines BASH