@the-bearded-bear/claude-craft 4.0.2 → 4.0.3-next.db8034a

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.
Files changed (42) hide show
  1. package/Dev/i18n/de/Common/agents/ralph-conductor.md +46 -134
  2. package/Dev/i18n/de/Common/commands/ralph-run.md +45 -146
  3. package/Dev/i18n/en/Common/agents/ralph-conductor.md +89 -44
  4. package/Dev/i18n/en/Common/commands/ralph-run.md +137 -72
  5. package/Dev/i18n/es/Common/agents/ralph-conductor.md +48 -136
  6. package/Dev/i18n/es/Common/commands/ralph-run.md +51 -140
  7. package/Dev/i18n/fr/Common/agents/ralph-conductor.md +83 -133
  8. package/Dev/i18n/fr/Common/commands/ralph-run.md +131 -106
  9. package/Dev/i18n/pt/Common/agents/ralph-conductor.md +46 -134
  10. package/Dev/i18n/pt/Common/commands/ralph-run.md +52 -153
  11. package/Tools/Ralph/.ralph/hooks/pre-tool-context.sh +100 -0
  12. package/Tools/Ralph/.ralph/hooks/session-restore.sh +118 -0
  13. package/Tools/Ralph/.ralph/hooks/status-injector.sh +147 -0
  14. package/Tools/Ralph/.ralph/hooks/stop-dod-gate.sh +133 -0
  15. package/Tools/Ralph/README.md +308 -19
  16. package/Tools/Ralph/lib/circuit-breaker.sh +320 -13
  17. package/Tools/Ralph/lib/config-generator.sh +561 -0
  18. package/Tools/Ralph/lib/dashboard.sh +392 -0
  19. package/Tools/Ralph/lib/dod-templates.sh +335 -0
  20. package/Tools/Ralph/lib/dod-validator.sh +116 -0
  21. package/Tools/Ralph/lib/health-monitor.sh +416 -0
  22. package/Tools/Ralph/lib/hooks-generator.sh +337 -0
  23. package/Tools/Ralph/lib/metrics-exporter.sh +383 -0
  24. package/Tools/Ralph/lib/project-detector.sh +562 -0
  25. package/Tools/Ralph/lib/session.sh +196 -0
  26. package/Tools/Ralph/ralph.sh +182 -1
  27. package/Tools/Ralph/templates/dod/dotnet.yml +73 -0
  28. package/Tools/Ralph/templates/dod/flutter.yml +70 -0
  29. package/Tools/Ralph/templates/dod/generic.yml +49 -0
  30. package/Tools/Ralph/templates/dod/go.yml +82 -0
  31. package/Tools/Ralph/templates/dod/python.yml +73 -0
  32. package/Tools/Ralph/templates/dod/react.yml +73 -0
  33. package/Tools/Ralph/templates/dod/rust.yml +73 -0
  34. package/Tools/Ralph/templates/dod/symfony.yml +73 -0
  35. package/Tools/Ralph/templates/ralph.yml.template +115 -4
  36. package/Tools/i18n/ralph/de.sh +49 -0
  37. package/Tools/i18n/ralph/en.sh +49 -0
  38. package/Tools/i18n/ralph/es.sh +49 -0
  39. package/Tools/i18n/ralph/fr.sh +49 -0
  40. package/Tools/i18n/ralph/pt.sh +49 -0
  41. package/cli/index.js +11 -1
  42. package/package.json +1 -1
@@ -2,6 +2,7 @@
2
2
  # =============================================================================
3
3
  # Ralph Wiggum - Circuit Breaker Module
4
4
  # Safety mechanism to prevent infinite loops and detect stalls
5
+ # Now with adaptive profiles and learning capabilities (v2.0)
5
6
  # =============================================================================
6
7
 
7
8
  # Circuit breaker thresholds (defaults)
@@ -17,6 +18,52 @@ CB_LAST_OUTPUT_LENGTH=0
17
18
  CB_TRIGGERED=false
18
19
  CB_TRIGGER_REASON=""
19
20
 
21
+ # Adaptive mode settings
22
+ CB_ADAPTIVE_ENABLED="${CB_ADAPTIVE_ENABLED:-false}"
23
+ CB_CURRENT_PROFILE="medium_feature"
24
+ CB_LEARNING_ENABLED="${CB_LEARNING_ENABLED:-true}"
25
+ CB_LEARNING_MIN_SAMPLES=5
26
+
27
+ # =============================================================================
28
+ # Adaptive Profiles
29
+ # =============================================================================
30
+ # Each profile defines thresholds optimized for different task types
31
+
32
+ declare -A CB_PROFILE_QUICK_FIX=(
33
+ ["no_changes"]=2
34
+ ["errors"]=3
35
+ ["max_iterations"]=10
36
+ ["keywords"]="fix bug typo hotfix patch"
37
+ )
38
+
39
+ declare -A CB_PROFILE_SMALL_FEATURE=(
40
+ ["no_changes"]=3
41
+ ["errors"]=4
42
+ ["max_iterations"]=15
43
+ ["keywords"]="add implement small simple"
44
+ )
45
+
46
+ declare -A CB_PROFILE_MEDIUM_FEATURE=(
47
+ ["no_changes"]=4
48
+ ["errors"]=6
49
+ ["max_iterations"]=25
50
+ ["keywords"]="feature create with tests"
51
+ )
52
+
53
+ declare -A CB_PROFILE_LARGE_FEATURE=(
54
+ ["no_changes"]=5
55
+ ["errors"]=8
56
+ ["max_iterations"]=50
57
+ ["keywords"]="refactor migrate complex large"
58
+ )
59
+
60
+ declare -A CB_PROFILE_EXPLORATION=(
61
+ ["no_changes"]=10
62
+ ["errors"]=15
63
+ ["max_iterations"]=100
64
+ ["keywords"]="explore investigate research analyze"
65
+ )
66
+
20
67
  # =============================================================================
21
68
  # Initialization
22
69
  # =============================================================================
@@ -29,33 +76,293 @@ init_circuit_breaker() {
29
76
  CB_TRIGGERED=false
30
77
  CB_TRIGGER_REASON=""
31
78
 
32
- # Load thresholds from config if available (with validation)
79
+ # Load settings from config if available
33
80
  if [[ -n "$CONFIG_FILE" && -f "$CONFIG_FILE" ]] && command -v yq &> /dev/null; then
34
- local no_changes
35
- no_changes=$(yq e '.circuit_breaker.no_file_changes_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
36
- if [[ -n "$no_changes" && "$no_changes" =~ ^[0-9]+$ ]]; then
37
- CB_NO_CHANGES_THRESHOLD=$no_changes
81
+ # Check for adaptive mode
82
+ local adaptive
83
+ adaptive=$(yq e '.circuit_breaker.adaptive // "false"' "$CONFIG_FILE" 2>/dev/null)
84
+ CB_ADAPTIVE_ENABLED="$adaptive"
85
+
86
+ # Load default profile
87
+ local default_profile
88
+ default_profile=$(yq e '.circuit_breaker.default_profile // "medium_feature"' "$CONFIG_FILE" 2>/dev/null)
89
+ CB_CURRENT_PROFILE="$default_profile"
90
+
91
+ # Load learning settings
92
+ local learning
93
+ learning=$(yq e '.circuit_breaker.learning.enabled // "true"' "$CONFIG_FILE" 2>/dev/null)
94
+ CB_LEARNING_ENABLED="$learning"
95
+
96
+ local min_samples
97
+ min_samples=$(yq e '.circuit_breaker.learning.min_samples // "5"' "$CONFIG_FILE" 2>/dev/null)
98
+ if [[ "$min_samples" =~ ^[0-9]+$ ]]; then
99
+ CB_LEARNING_MIN_SAMPLES=$min_samples
38
100
  fi
39
101
 
40
- local errors
41
- errors=$(yq e '.circuit_breaker.repeated_error_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
42
- if [[ -n "$errors" && "$errors" =~ ^[0-9]+$ ]]; then
43
- CB_REPEATED_ERROR_THRESHOLD=$errors
102
+ # Load manual thresholds (used when adaptive is disabled)
103
+ if [[ "$CB_ADAPTIVE_ENABLED" != "true" ]]; then
104
+ local no_changes
105
+ no_changes=$(yq e '.circuit_breaker.no_file_changes_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
106
+ if [[ -n "$no_changes" && "$no_changes" =~ ^[0-9]+$ ]]; then
107
+ CB_NO_CHANGES_THRESHOLD=$no_changes
108
+ fi
109
+
110
+ local errors
111
+ errors=$(yq e '.circuit_breaker.repeated_error_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
112
+ if [[ -n "$errors" && "$errors" =~ ^[0-9]+$ ]]; then
113
+ CB_REPEATED_ERROR_THRESHOLD=$errors
114
+ fi
115
+
116
+ local decline
117
+ decline=$(yq e '.circuit_breaker.output_decline_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
118
+ if [[ -n "$decline" && "$decline" =~ ^[0-9]+$ ]]; then
119
+ CB_OUTPUT_DECLINE_THRESHOLD=$decline
120
+ fi
44
121
  fi
122
+ fi
45
123
 
46
- local decline
47
- decline=$(yq e '.circuit_breaker.output_decline_threshold // ""' "$CONFIG_FILE" 2>/dev/null)
48
- if [[ -n "$decline" && "$decline" =~ ^[0-9]+$ ]]; then
49
- CB_OUTPUT_DECLINE_THRESHOLD=$decline
124
+ # If adaptive mode, detect profile from prompt
125
+ if [[ "$CB_ADAPTIVE_ENABLED" == "true" && -n "$PROMPT" ]]; then
126
+ detect_task_profile "$PROMPT"
127
+ load_profile_thresholds "$CB_CURRENT_PROFILE"
128
+
129
+ # Apply learning adjustments if available
130
+ if [[ "$CB_LEARNING_ENABLED" == "true" ]]; then
131
+ apply_learned_adjustments "$CB_CURRENT_PROFILE"
50
132
  fi
51
133
  fi
52
134
 
53
135
  print_verbose "Circuit breaker initialized:"
136
+ print_verbose " - Adaptive mode: $CB_ADAPTIVE_ENABLED"
137
+ print_verbose " - Profile: $CB_CURRENT_PROFILE"
54
138
  print_verbose " - No changes threshold: $CB_NO_CHANGES_THRESHOLD"
55
139
  print_verbose " - Error threshold: $CB_REPEATED_ERROR_THRESHOLD"
56
140
  print_verbose " - Output decline threshold: ${CB_OUTPUT_DECLINE_THRESHOLD}%"
57
141
  }
58
142
 
143
+ # =============================================================================
144
+ # Profile Detection
145
+ # =============================================================================
146
+
147
+ detect_task_profile() {
148
+ local prompt="$1"
149
+ local prompt_lower
150
+ prompt_lower=$(echo "$prompt" | tr '[:upper:]' '[:lower:]')
151
+
152
+ # Check each profile's keywords
153
+ local profiles=("quick_fix" "small_feature" "medium_feature" "large_feature" "exploration")
154
+
155
+ for profile in "${profiles[@]}"; do
156
+ local keywords
157
+ case "$profile" in
158
+ quick_fix) keywords="${CB_PROFILE_QUICK_FIX["keywords"]}" ;;
159
+ small_feature) keywords="${CB_PROFILE_SMALL_FEATURE["keywords"]}" ;;
160
+ medium_feature) keywords="${CB_PROFILE_MEDIUM_FEATURE["keywords"]}" ;;
161
+ large_feature) keywords="${CB_PROFILE_LARGE_FEATURE["keywords"]}" ;;
162
+ exploration) keywords="${CB_PROFILE_EXPLORATION["keywords"]}" ;;
163
+ esac
164
+
165
+ for keyword in $keywords; do
166
+ if [[ "$prompt_lower" == *"$keyword"* ]]; then
167
+ CB_CURRENT_PROFILE="$profile"
168
+ print_verbose "Detected profile '$profile' from keyword '$keyword'"
169
+ return 0
170
+ fi
171
+ done
172
+ done
173
+
174
+ # Default to medium_feature if no match
175
+ CB_CURRENT_PROFILE="medium_feature"
176
+ print_verbose "No profile match, using default: $CB_CURRENT_PROFILE"
177
+ }
178
+
179
+ # =============================================================================
180
+ # Load Profile Thresholds
181
+ # =============================================================================
182
+
183
+ load_profile_thresholds() {
184
+ local profile="$1"
185
+
186
+ case "$profile" in
187
+ quick_fix)
188
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_QUICK_FIX["no_changes"]}
189
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_QUICK_FIX["errors"]}
190
+ MAX_ITERATIONS=${CB_PROFILE_QUICK_FIX["max_iterations"]}
191
+ ;;
192
+ small_feature)
193
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_SMALL_FEATURE["no_changes"]}
194
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_SMALL_FEATURE["errors"]}
195
+ MAX_ITERATIONS=${CB_PROFILE_SMALL_FEATURE["max_iterations"]}
196
+ ;;
197
+ medium_feature)
198
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_MEDIUM_FEATURE["no_changes"]}
199
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_MEDIUM_FEATURE["errors"]}
200
+ MAX_ITERATIONS=${CB_PROFILE_MEDIUM_FEATURE["max_iterations"]}
201
+ ;;
202
+ large_feature)
203
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_LARGE_FEATURE["no_changes"]}
204
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_LARGE_FEATURE["errors"]}
205
+ MAX_ITERATIONS=${CB_PROFILE_LARGE_FEATURE["max_iterations"]}
206
+ ;;
207
+ exploration)
208
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_EXPLORATION["no_changes"]}
209
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_EXPLORATION["errors"]}
210
+ MAX_ITERATIONS=${CB_PROFILE_EXPLORATION["max_iterations"]}
211
+ ;;
212
+ *)
213
+ # Default to medium_feature
214
+ CB_NO_CHANGES_THRESHOLD=${CB_PROFILE_MEDIUM_FEATURE["no_changes"]}
215
+ CB_REPEATED_ERROR_THRESHOLD=${CB_PROFILE_MEDIUM_FEATURE["errors"]}
216
+ MAX_ITERATIONS=${CB_PROFILE_MEDIUM_FEATURE["max_iterations"]}
217
+ ;;
218
+ esac
219
+
220
+ print_verbose "Loaded thresholds for profile: $profile"
221
+ }
222
+
223
+ # =============================================================================
224
+ # Learning from History
225
+ # =============================================================================
226
+
227
+ apply_learned_adjustments() {
228
+ local profile="$1"
229
+ local history_file="$RALPH_SESSION_BASE/history/circuit-breaker-history.json"
230
+
231
+ if [[ ! -f "$history_file" ]]; then
232
+ return 0
233
+ fi
234
+
235
+ if ! command -v jq &>/dev/null; then
236
+ return 0
237
+ fi
238
+
239
+ # Get historical data for this profile
240
+ local profile_data
241
+ profile_data=$(jq --arg p "$profile" '
242
+ .profiles[$p] // {samples: 0}
243
+ ' "$history_file" 2>/dev/null)
244
+
245
+ local samples
246
+ samples=$(echo "$profile_data" | jq -r '.samples // 0')
247
+
248
+ if [[ $samples -lt $CB_LEARNING_MIN_SAMPLES ]]; then
249
+ print_verbose "Not enough samples for learning ($samples < $CB_LEARNING_MIN_SAMPLES)"
250
+ return 0
251
+ fi
252
+
253
+ # Apply adjustments based on historical success rate
254
+ local success_rate
255
+ success_rate=$(echo "$profile_data" | jq -r '.success_rate // 0')
256
+
257
+ local avg_iterations
258
+ avg_iterations=$(echo "$profile_data" | jq -r '.avg_iterations // 0')
259
+
260
+ # If success rate is low, increase thresholds
261
+ if [[ $success_rate -lt 50 ]]; then
262
+ CB_NO_CHANGES_THRESHOLD=$((CB_NO_CHANGES_THRESHOLD + 1))
263
+ CB_REPEATED_ERROR_THRESHOLD=$((CB_REPEATED_ERROR_THRESHOLD + 2))
264
+ print_verbose "Learning adjustment: increased thresholds due to low success rate ($success_rate%)"
265
+ fi
266
+
267
+ # Adjust max iterations based on historical average
268
+ if [[ $avg_iterations -gt $MAX_ITERATIONS ]]; then
269
+ MAX_ITERATIONS=$((avg_iterations + 5))
270
+ print_verbose "Learning adjustment: increased max_iterations to $MAX_ITERATIONS"
271
+ fi
272
+ }
273
+
274
+ record_circuit_breaker_outcome() {
275
+ local profile="$1"
276
+ local success="$2"
277
+ local iterations="$3"
278
+ local history_file="$RALPH_SESSION_BASE/history/circuit-breaker-history.json"
279
+
280
+ # Ensure history directory exists
281
+ mkdir -p "$(dirname "$history_file")"
282
+
283
+ # Initialize history file if needed
284
+ if [[ ! -f "$history_file" ]]; then
285
+ echo '{"profiles": {}}' > "$history_file"
286
+ fi
287
+
288
+ if ! command -v jq &>/dev/null; then
289
+ return 0
290
+ fi
291
+
292
+ # Update profile history
293
+ local tmp_file="${history_file}.tmp.$$"
294
+ jq --arg p "$profile" \
295
+ --argjson s "$([[ "$success" == "true" ]] && echo 1 || echo 0)" \
296
+ --argjson i "$iterations" '
297
+ .profiles[$p] = (
298
+ .profiles[$p] // {samples: 0, successes: 0, total_iterations: 0}
299
+ | .samples += 1
300
+ | .successes += $s
301
+ | .total_iterations += $i
302
+ | .success_rate = ((.successes / .samples) * 100 | floor)
303
+ | .avg_iterations = ((.total_iterations / .samples) | floor)
304
+ )
305
+ ' "$history_file" > "$tmp_file" 2>/dev/null && mv "$tmp_file" "$history_file"
306
+
307
+ print_verbose "Recorded circuit breaker outcome for profile: $profile"
308
+ }
309
+
310
+ # =============================================================================
311
+ # Get Profile Info
312
+ # =============================================================================
313
+
314
+ get_profile_info() {
315
+ local profile="${1:-$CB_CURRENT_PROFILE}"
316
+
317
+ cat <<EOF
318
+ {
319
+ "profile": "$profile",
320
+ "adaptive": $CB_ADAPTIVE_ENABLED,
321
+ "learning": $CB_LEARNING_ENABLED,
322
+ "thresholds": {
323
+ "no_changes": $CB_NO_CHANGES_THRESHOLD,
324
+ "errors": $CB_REPEATED_ERROR_THRESHOLD,
325
+ "max_iterations": $MAX_ITERATIONS
326
+ }
327
+ }
328
+ EOF
329
+ }
330
+
331
+ list_profiles() {
332
+ echo "Available Circuit Breaker Profiles:"
333
+ echo "-----------------------------------"
334
+ echo ""
335
+ echo "quick_fix:"
336
+ echo " - No changes: ${CB_PROFILE_QUICK_FIX["no_changes"]}"
337
+ echo " - Errors: ${CB_PROFILE_QUICK_FIX["errors"]}"
338
+ echo " - Max iterations: ${CB_PROFILE_QUICK_FIX["max_iterations"]}"
339
+ echo " - Keywords: ${CB_PROFILE_QUICK_FIX["keywords"]}"
340
+ echo ""
341
+ echo "small_feature:"
342
+ echo " - No changes: ${CB_PROFILE_SMALL_FEATURE["no_changes"]}"
343
+ echo " - Errors: ${CB_PROFILE_SMALL_FEATURE["errors"]}"
344
+ echo " - Max iterations: ${CB_PROFILE_SMALL_FEATURE["max_iterations"]}"
345
+ echo " - Keywords: ${CB_PROFILE_SMALL_FEATURE["keywords"]}"
346
+ echo ""
347
+ echo "medium_feature:"
348
+ echo " - No changes: ${CB_PROFILE_MEDIUM_FEATURE["no_changes"]}"
349
+ echo " - Errors: ${CB_PROFILE_MEDIUM_FEATURE["errors"]}"
350
+ echo " - Max iterations: ${CB_PROFILE_MEDIUM_FEATURE["max_iterations"]}"
351
+ echo " - Keywords: ${CB_PROFILE_MEDIUM_FEATURE["keywords"]}"
352
+ echo ""
353
+ echo "large_feature:"
354
+ echo " - No changes: ${CB_PROFILE_LARGE_FEATURE["no_changes"]}"
355
+ echo " - Errors: ${CB_PROFILE_LARGE_FEATURE["errors"]}"
356
+ echo " - Max iterations: ${CB_PROFILE_LARGE_FEATURE["max_iterations"]}"
357
+ echo " - Keywords: ${CB_PROFILE_LARGE_FEATURE["keywords"]}"
358
+ echo ""
359
+ echo "exploration:"
360
+ echo " - No changes: ${CB_PROFILE_EXPLORATION["no_changes"]}"
361
+ echo " - Errors: ${CB_PROFILE_EXPLORATION["errors"]}"
362
+ echo " - Max iterations: ${CB_PROFILE_EXPLORATION["max_iterations"]}"
363
+ echo " - Keywords: ${CB_PROFILE_EXPLORATION["keywords"]}"
364
+ }
365
+
59
366
  # =============================================================================
60
367
  # Circuit Breaker Check
61
368
  # =============================================================================