@the-bearded-bear/claude-craft 3.0.2 → 3.1.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.
Files changed (30) hide show
  1. package/Dev/i18n/de/Common/agents/ralph-conductor.md +146 -0
  2. package/Dev/i18n/de/Common/commands/ralph-run.md +171 -0
  3. package/Dev/i18n/de/Common/commands/setup-project-context.md +286 -0
  4. package/Dev/i18n/en/Common/agents/ralph-conductor.md +146 -0
  5. package/Dev/i18n/en/Common/commands/ralph-run.md +171 -0
  6. package/Dev/i18n/en/Common/commands/setup-project-context.md +286 -0
  7. package/Dev/i18n/es/Common/agents/ralph-conductor.md +146 -0
  8. package/Dev/i18n/es/Common/commands/ralph-run.md +171 -0
  9. package/Dev/i18n/es/Common/commands/setup-project-context.md +286 -0
  10. package/Dev/i18n/fr/Common/agents/ralph-conductor.md +146 -0
  11. package/Dev/i18n/fr/Common/commands/ralph-run.md +171 -0
  12. package/Dev/i18n/fr/Common/commands/setup-project-context.md +286 -0
  13. package/Dev/i18n/pt/Common/agents/ralph-conductor.md +146 -0
  14. package/Dev/i18n/pt/Common/commands/ralph-run.md +171 -0
  15. package/Dev/i18n/pt/Common/commands/setup-project-context.md +286 -0
  16. package/Tools/Ralph/README.md +303 -0
  17. package/Tools/Ralph/lib/checkpoint.sh +238 -0
  18. package/Tools/Ralph/lib/circuit-breaker.sh +172 -0
  19. package/Tools/Ralph/lib/dod-validator.sh +306 -0
  20. package/Tools/Ralph/lib/loop.sh +232 -0
  21. package/Tools/Ralph/lib/session.sh +234 -0
  22. package/Tools/Ralph/ralph.sh +491 -0
  23. package/Tools/Ralph/templates/ralph.yml.template +178 -0
  24. package/Tools/i18n/ralph/de.sh +147 -0
  25. package/Tools/i18n/ralph/en.sh +147 -0
  26. package/Tools/i18n/ralph/es.sh +147 -0
  27. package/Tools/i18n/ralph/fr.sh +147 -0
  28. package/Tools/i18n/ralph/pt.sh +147 -0
  29. package/cli/index.js +90 -0
  30. package/package.json +1 -1
@@ -0,0 +1,234 @@
1
+ #!/bin/bash
2
+ # =============================================================================
3
+ # Ralph Wiggum - Session Management Module
4
+ # Handles session creation, storage, and retrieval
5
+ # =============================================================================
6
+
7
+ # Session directory (default: .ralph in current directory)
8
+ RALPH_SESSION_BASE="${RALPH_SESSION_BASE:-$PWD/.ralph}"
9
+
10
+ # =============================================================================
11
+ # Session ID Generation
12
+ # =============================================================================
13
+
14
+ generate_session_id() {
15
+ # Generate a unique session ID using timestamp and random string
16
+ local timestamp=$(date +%s)
17
+ local random=$(head -c 4 /dev/urandom | xxd -p)
18
+ echo "ralph-${timestamp}-${random}"
19
+ }
20
+
21
+ # =============================================================================
22
+ # Session Creation
23
+ # =============================================================================
24
+
25
+ create_session() {
26
+ local prompt="$1"
27
+ local session_id=$(generate_session_id)
28
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
29
+
30
+ # Create session directory
31
+ mkdir -p "$session_dir"
32
+
33
+ # Create session state file
34
+ local state_file="$session_dir/state.json"
35
+ cat > "$state_file" <<EOF
36
+ {
37
+ "id": "$session_id",
38
+ "created_at": "$(date -Iseconds)",
39
+ "status": "running",
40
+ "initial_prompt": $(echo "$prompt" | jq -Rs .),
41
+ "current_iteration": 0,
42
+ "metrics": {
43
+ "total_iterations": 0,
44
+ "file_changes": 0,
45
+ "errors": 0,
46
+ "peak_output_length": 0
47
+ },
48
+ "circuit_breaker": {
49
+ "iterations_without_changes": 0,
50
+ "consecutive_errors": 0,
51
+ "last_output_length": 0
52
+ },
53
+ "dod_results": []
54
+ }
55
+ EOF
56
+
57
+ # Create log file
58
+ touch "$session_dir/session.log"
59
+
60
+ # Create metrics file
61
+ echo "[]" > "$session_dir/metrics.json"
62
+
63
+ echo "$session_id"
64
+ }
65
+
66
+ # =============================================================================
67
+ # Session Resume
68
+ # =============================================================================
69
+
70
+ resume_session() {
71
+ local session_id="$1"
72
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
73
+ local state_file="$session_dir/state.json"
74
+
75
+ if [[ ! -f "$state_file" ]]; then
76
+ return 1
77
+ fi
78
+
79
+ # Update status to running
80
+ local tmp_file=$(mktemp)
81
+ jq '.status = "running" | .resumed_at = "'"$(date -Iseconds)"'"' "$state_file" > "$tmp_file"
82
+ mv "$tmp_file" "$state_file"
83
+
84
+ return 0
85
+ }
86
+
87
+ # =============================================================================
88
+ # Session State Management
89
+ # =============================================================================
90
+
91
+ get_session_state() {
92
+ local session_id="$1"
93
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
94
+ local state_file="$session_dir/state.json"
95
+
96
+ if [[ -f "$state_file" ]]; then
97
+ cat "$state_file"
98
+ else
99
+ echo "{}"
100
+ fi
101
+ }
102
+
103
+ update_session_state() {
104
+ local session_id="$1"
105
+ local field="$2"
106
+ local value="$3"
107
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
108
+ local state_file="$session_dir/state.json"
109
+
110
+ if [[ -f "$state_file" ]]; then
111
+ local tmp_file=$(mktemp)
112
+ jq ".$field = $value" "$state_file" > "$tmp_file"
113
+ mv "$tmp_file" "$state_file"
114
+ fi
115
+ }
116
+
117
+ # =============================================================================
118
+ # Session Metrics
119
+ # =============================================================================
120
+
121
+ update_session_metrics() {
122
+ local session_id="$1"
123
+ local iteration="$2"
124
+ local output="$3"
125
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
126
+ local state_file="$session_dir/state.json"
127
+ local metrics_file="$session_dir/metrics.json"
128
+
129
+ if [[ ! -f "$state_file" ]]; then
130
+ return 1
131
+ fi
132
+
133
+ # Calculate metrics
134
+ local output_length=${#output}
135
+ local timestamp=$(date -Iseconds)
136
+
137
+ # Update state file
138
+ local tmp_file=$(mktemp)
139
+ jq --argjson iter "$iteration" --argjson len "$output_length" '
140
+ .current_iteration = $iter |
141
+ .metrics.total_iterations = $iter |
142
+ .metrics.peak_output_length = (if $len > .metrics.peak_output_length then $len else .metrics.peak_output_length end)
143
+ ' "$state_file" > "$tmp_file"
144
+ mv "$tmp_file" "$state_file"
145
+
146
+ # Append to metrics history
147
+ local metric_entry=$(jq -n \
148
+ --arg ts "$timestamp" \
149
+ --argjson iter "$iteration" \
150
+ --argjson len "$output_length" \
151
+ '{timestamp: $ts, iteration: $iter, output_length: $len}')
152
+
153
+ tmp_file=$(mktemp)
154
+ jq ". + [$metric_entry]" "$metrics_file" > "$tmp_file"
155
+ mv "$tmp_file" "$metrics_file"
156
+ }
157
+
158
+ # =============================================================================
159
+ # Session Saving
160
+ # =============================================================================
161
+
162
+ save_session() {
163
+ local session_id="$1"
164
+ local exit_reason="$2"
165
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
166
+ local state_file="$session_dir/state.json"
167
+
168
+ if [[ -f "$state_file" ]]; then
169
+ local tmp_file=$(mktemp)
170
+ jq --arg reason "$exit_reason" '
171
+ .status = "completed" |
172
+ .exit_reason = $reason |
173
+ .completed_at = "'"$(date -Iseconds)"'"
174
+ ' "$state_file" > "$tmp_file"
175
+ mv "$tmp_file" "$state_file"
176
+ fi
177
+ }
178
+
179
+ # =============================================================================
180
+ # Session Listing
181
+ # =============================================================================
182
+
183
+ list_sessions() {
184
+ local sessions_dir="$RALPH_SESSION_BASE/sessions"
185
+
186
+ if [[ ! -d "$sessions_dir" ]]; then
187
+ echo "[]"
188
+ return
189
+ fi
190
+
191
+ local sessions=()
192
+ for dir in "$sessions_dir"/*/; do
193
+ if [[ -d "$dir" ]]; then
194
+ local state_file="$dir/state.json"
195
+ if [[ -f "$state_file" ]]; then
196
+ sessions+=("$(cat "$state_file")")
197
+ fi
198
+ fi
199
+ done
200
+
201
+ # Convert to JSON array
202
+ printf '%s\n' "${sessions[@]}" | jq -s '.'
203
+ }
204
+
205
+ # =============================================================================
206
+ # Session Cleanup
207
+ # =============================================================================
208
+
209
+ cleanup_session() {
210
+ local session_id="$1"
211
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
212
+
213
+ if [[ -d "$session_dir" ]]; then
214
+ rm -rf "$session_dir"
215
+ return 0
216
+ fi
217
+ return 1
218
+ }
219
+
220
+ # =============================================================================
221
+ # Log Writing
222
+ # =============================================================================
223
+
224
+ log_session() {
225
+ local session_id="$1"
226
+ local level="$2"
227
+ local message="$3"
228
+ local session_dir="$RALPH_SESSION_BASE/sessions/$session_id"
229
+ local log_file="$session_dir/session.log"
230
+
231
+ if [[ -f "$log_file" ]]; then
232
+ echo "[$(date -Iseconds)] [$level] $message" >> "$log_file"
233
+ fi
234
+ }