moflo 4.7.8 → 4.8.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 (47) hide show
  1. package/bin/hooks.mjs +23 -20
  2. package/bin/session-start-launcher.mjs +88 -3
  3. package/package.json +1 -1
  4. package/src/@claude-flow/cli/dist/src/commands/daemon.js +42 -95
  5. package/src/@claude-flow/cli/dist/src/commands/doctor.js +11 -5
  6. package/src/@claude-flow/cli/dist/src/config/moflo-config.d.ts +5 -0
  7. package/src/@claude-flow/cli/dist/src/config/moflo-config.js +16 -0
  8. package/src/@claude-flow/cli/dist/src/init/executor.js +74 -0
  9. package/src/@claude-flow/cli/dist/src/services/daemon-lock.d.ts +39 -0
  10. package/src/@claude-flow/cli/dist/src/services/daemon-lock.js +213 -0
  11. package/src/@claude-flow/cli/package.json +1 -1
  12. package/.claude/helpers/README.md +0 -97
  13. package/.claude/helpers/adr-compliance.sh +0 -186
  14. package/.claude/helpers/aggressive-microcompact.mjs +0 -36
  15. package/.claude/helpers/auto-commit.sh +0 -178
  16. package/.claude/helpers/checkpoint-manager.sh +0 -251
  17. package/.claude/helpers/context-persistence-hook.mjs +0 -1979
  18. package/.claude/helpers/daemon-manager.sh +0 -252
  19. package/.claude/helpers/ddd-tracker.sh +0 -144
  20. package/.claude/helpers/github-safe.js +0 -106
  21. package/.claude/helpers/github-setup.sh +0 -28
  22. package/.claude/helpers/guidance-hook.sh +0 -13
  23. package/.claude/helpers/guidance-hooks.sh +0 -102
  24. package/.claude/helpers/health-monitor.sh +0 -108
  25. package/.claude/helpers/learning-hooks.sh +0 -329
  26. package/.claude/helpers/learning-optimizer.sh +0 -127
  27. package/.claude/helpers/learning-service.mjs +0 -1211
  28. package/.claude/helpers/memory.cjs +0 -84
  29. package/.claude/helpers/metrics-db.mjs +0 -492
  30. package/.claude/helpers/patch-aggressive-prune.mjs +0 -184
  31. package/.claude/helpers/pattern-consolidator.sh +0 -86
  32. package/.claude/helpers/perf-worker.sh +0 -160
  33. package/.claude/helpers/quick-start.sh +0 -19
  34. package/.claude/helpers/router.cjs +0 -62
  35. package/.claude/helpers/security-scanner.sh +0 -127
  36. package/.claude/helpers/session.cjs +0 -125
  37. package/.claude/helpers/setup-mcp.sh +0 -18
  38. package/.claude/helpers/standard-checkpoint-hooks.sh +0 -189
  39. package/.claude/helpers/swarm-comms.sh +0 -353
  40. package/.claude/helpers/swarm-hooks.sh +0 -761
  41. package/.claude/helpers/swarm-monitor.sh +0 -211
  42. package/.claude/helpers/sync-v3-metrics.sh +0 -245
  43. package/.claude/helpers/update-v3-progress.sh +0 -166
  44. package/.claude/helpers/v3-quick-status.sh +0 -58
  45. package/.claude/helpers/v3.sh +0 -111
  46. package/.claude/helpers/validate-v3-config.sh +0 -216
  47. package/.claude/helpers/worker-manager.sh +0 -170
@@ -1,108 +0,0 @@
1
- #!/bin/bash
2
- # RuFlo V3 - Health Monitor Worker
3
- # Checks disk space, memory pressure, process health
4
-
5
- set -euo pipefail
6
-
7
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9
- METRICS_DIR="$PROJECT_ROOT/.claude-flow/metrics"
10
- HEALTH_FILE="$METRICS_DIR/health.json"
11
- LAST_RUN_FILE="$METRICS_DIR/.health-last-run"
12
-
13
- mkdir -p "$METRICS_DIR"
14
-
15
- should_run() {
16
- if [ ! -f "$LAST_RUN_FILE" ]; then return 0; fi
17
- local last_run=$(cat "$LAST_RUN_FILE" 2>/dev/null || echo "0")
18
- local now=$(date +%s)
19
- [ $((now - last_run)) -ge 300 ] # 5 minutes
20
- }
21
-
22
- check_health() {
23
- echo "[$(date +%H:%M:%S)] Running health check..."
24
-
25
- # Disk usage
26
- local disk_usage=$(df -h "$PROJECT_ROOT" 2>/dev/null | awk 'NR==2 {print $5}' | tr -d '%')
27
- local disk_free=$(df -h "$PROJECT_ROOT" 2>/dev/null | awk 'NR==2 {print $4}')
28
-
29
- # Memory usage
30
- local mem_total=$(free -m 2>/dev/null | awk '/Mem:/ {print $2}' || echo "0")
31
- local mem_used=$(free -m 2>/dev/null | awk '/Mem:/ {print $3}' || echo "0")
32
- local mem_pct=$((mem_used * 100 / (mem_total + 1)))
33
-
34
- # Process counts
35
- local node_procs=$(pgrep -c node 2>/dev/null || echo "0")
36
- local agentic_procs=$(ps aux 2>/dev/null | grep -c "agentic-flow" | grep -v grep || echo "0")
37
-
38
- # CPU load
39
- local load_avg=$(cat /proc/loadavg 2>/dev/null | awk '{print $1}' || echo "0")
40
-
41
- # File descriptor usage
42
- local fd_used=$(ls /proc/$$/fd 2>/dev/null | wc -l || echo "0")
43
-
44
- # Determine health status
45
- local status="healthy"
46
- local warnings=""
47
-
48
- if [ "$disk_usage" -gt 90 ]; then
49
- status="critical"
50
- warnings="$warnings disk_full"
51
- elif [ "$disk_usage" -gt 80 ]; then
52
- status="warning"
53
- warnings="$warnings disk_high"
54
- fi
55
-
56
- if [ "$mem_pct" -gt 90 ]; then
57
- status="critical"
58
- warnings="$warnings memory_full"
59
- elif [ "$mem_pct" -gt 80 ]; then
60
- [ "$status" != "critical" ] && status="warning"
61
- warnings="$warnings memory_high"
62
- fi
63
-
64
- # Write health metrics
65
- cat > "$HEALTH_FILE" << EOF
66
- {
67
- "status": "$status",
68
- "timestamp": "$(date -Iseconds)",
69
- "disk": {
70
- "usage_pct": $disk_usage,
71
- "free": "$disk_free"
72
- },
73
- "memory": {
74
- "total_mb": $mem_total,
75
- "used_mb": $mem_used,
76
- "usage_pct": $mem_pct
77
- },
78
- "processes": {
79
- "node": $node_procs,
80
- "agentic_flow": $agentic_procs
81
- },
82
- "load_avg": $load_avg,
83
- "fd_used": $fd_used,
84
- "warnings": "$(echo $warnings | xargs)"
85
- }
86
- EOF
87
-
88
- echo "[$(date +%H:%M:%S)] ✓ Health: $status | Disk: ${disk_usage}% | Memory: ${mem_pct}% | Load: $load_avg"
89
-
90
- date +%s > "$LAST_RUN_FILE"
91
-
92
- # Return non-zero if unhealthy
93
- [ "$status" = "healthy" ] && return 0 || return 1
94
- }
95
-
96
- case "${1:-check}" in
97
- "run") check_health ;;
98
- "check") should_run && check_health || echo "[$(date +%H:%M:%S)] Skipping (throttled)" ;;
99
- "force") rm -f "$LAST_RUN_FILE"; check_health ;;
100
- "status")
101
- if [ -f "$HEALTH_FILE" ]; then
102
- jq -r '"Status: \(.status) | Disk: \(.disk.usage_pct)% | Memory: \(.memory.usage_pct)% | Load: \(.load_avg)"' "$HEALTH_FILE"
103
- else
104
- echo "No health data available"
105
- fi
106
- ;;
107
- *) echo "Usage: $0 [run|check|force|status]" ;;
108
- esac
@@ -1,329 +0,0 @@
1
- #!/bin/bash
2
- # RuFlo V3 - Learning Hooks
3
- # Integrates learning-service.mjs with session lifecycle
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
7
- LEARNING_SERVICE="$SCRIPT_DIR/learning-service.mjs"
8
- LEARNING_DIR="$PROJECT_ROOT/.claude-flow/learning"
9
- METRICS_DIR="$PROJECT_ROOT/.claude-flow/metrics"
10
-
11
- # Ensure directories exist
12
- mkdir -p "$LEARNING_DIR" "$METRICS_DIR"
13
-
14
- # Colors
15
- GREEN='\033[0;32m'
16
- YELLOW='\033[1;33m'
17
- CYAN='\033[0;36m'
18
- RED='\033[0;31m'
19
- DIM='\033[2m'
20
- RESET='\033[0m'
21
-
22
- log() { echo -e "${CYAN}[Learning] $1${RESET}"; }
23
- success() { echo -e "${GREEN}[Learning] ✓ $1${RESET}"; }
24
- warn() { echo -e "${YELLOW}[Learning] ⚠ $1${RESET}"; }
25
- error() { echo -e "${RED}[Learning] ✗ $1${RESET}"; }
26
-
27
- # Generate session ID
28
- generate_session_id() {
29
- echo "session_$(date +%Y%m%d_%H%M%S)_$$"
30
- }
31
-
32
- # =============================================================================
33
- # Session Start Hook
34
- # =============================================================================
35
- session_start() {
36
- local session_id="${1:-$(generate_session_id)}"
37
-
38
- log "Initializing learning service for session: $session_id"
39
-
40
- # Check if better-sqlite3 is available
41
- if ! npm list better-sqlite3 --prefix "$PROJECT_ROOT" >/dev/null 2>&1; then
42
- log "Installing better-sqlite3..."
43
- npm install --prefix "$PROJECT_ROOT" better-sqlite3 --save-dev --silent 2>/dev/null || true
44
- fi
45
-
46
- # Initialize learning service
47
- local init_result
48
- init_result=$(node "$LEARNING_SERVICE" init "$session_id" 2>&1)
49
-
50
- if [ $? -eq 0 ]; then
51
- # Parse and display stats
52
- local short_term=$(echo "$init_result" | grep -o '"shortTermPatterns":[0-9]*' | cut -d: -f2)
53
- local long_term=$(echo "$init_result" | grep -o '"longTermPatterns":[0-9]*' | cut -d: -f2)
54
-
55
- success "Learning service initialized"
56
- echo -e " ${DIM}├─ Short-term patterns: ${short_term:-0}${RESET}"
57
- echo -e " ${DIM}├─ Long-term patterns: ${long_term:-0}${RESET}"
58
- echo -e " ${DIM}└─ Session ID: $session_id${RESET}"
59
-
60
- # Store session ID for later hooks
61
- echo "$session_id" > "$LEARNING_DIR/current-session-id"
62
-
63
- # Update metrics
64
- cat > "$METRICS_DIR/learning-status.json" << EOF
65
- {
66
- "sessionId": "$session_id",
67
- "initialized": true,
68
- "shortTermPatterns": ${short_term:-0},
69
- "longTermPatterns": ${long_term:-0},
70
- "hnswEnabled": true,
71
- "timestamp": "$(date -Iseconds)"
72
- }
73
- EOF
74
-
75
- return 0
76
- else
77
- warn "Learning service initialization failed (non-critical)"
78
- echo "$init_result" | head -5
79
- return 1
80
- fi
81
- }
82
-
83
- # =============================================================================
84
- # Session End Hook
85
- # =============================================================================
86
- session_end() {
87
- log "Consolidating learning data..."
88
-
89
- # Get session ID
90
- local session_id=""
91
- if [ -f "$LEARNING_DIR/current-session-id" ]; then
92
- session_id=$(cat "$LEARNING_DIR/current-session-id")
93
- fi
94
-
95
- # Export session data
96
- local export_result
97
- export_result=$(node "$LEARNING_SERVICE" export 2>&1)
98
-
99
- if [ $? -eq 0 ]; then
100
- # Save export
101
- echo "$export_result" > "$LEARNING_DIR/session-export-$(date +%Y%m%d_%H%M%S).json"
102
-
103
- local patterns=$(echo "$export_result" | grep -o '"patterns":[0-9]*' | cut -d: -f2)
104
- log "Session exported: $patterns patterns"
105
- fi
106
-
107
- # Run consolidation
108
- local consolidate_result
109
- consolidate_result=$(node "$LEARNING_SERVICE" consolidate 2>&1)
110
-
111
- if [ $? -eq 0 ]; then
112
- local removed=$(echo "$consolidate_result" | grep -o '"duplicatesRemoved":[0-9]*' | cut -d: -f2)
113
- local pruned=$(echo "$consolidate_result" | grep -o '"patternsProned":[0-9]*' | cut -d: -f2)
114
- local duration=$(echo "$consolidate_result" | grep -o '"durationMs":[0-9]*' | cut -d: -f2)
115
-
116
- success "Consolidation complete"
117
- echo -e " ${DIM}├─ Duplicates removed: ${removed:-0}${RESET}"
118
- echo -e " ${DIM}├─ Patterns pruned: ${pruned:-0}${RESET}"
119
- echo -e " ${DIM}└─ Duration: ${duration:-0}ms${RESET}"
120
- else
121
- warn "Consolidation failed (non-critical)"
122
- fi
123
-
124
- # Get final stats
125
- local stats_result
126
- stats_result=$(node "$LEARNING_SERVICE" stats 2>&1)
127
-
128
- if [ $? -eq 0 ]; then
129
- echo "$stats_result" > "$METRICS_DIR/learning-final-stats.json"
130
-
131
- local total_short=$(echo "$stats_result" | grep -o '"shortTermPatterns":[0-9]*' | cut -d: -f2)
132
- local total_long=$(echo "$stats_result" | grep -o '"longTermPatterns":[0-9]*' | cut -d: -f2)
133
- local avg_search=$(echo "$stats_result" | grep -o '"avgSearchTimeMs":[0-9.]*' | cut -d: -f2)
134
-
135
- log "Final stats:"
136
- echo -e " ${DIM}├─ Short-term: ${total_short:-0}${RESET}"
137
- echo -e " ${DIM}├─ Long-term: ${total_long:-0}${RESET}"
138
- echo -e " ${DIM}└─ Avg search: ${avg_search:-0}ms${RESET}"
139
- fi
140
-
141
- # Clean up session file
142
- rm -f "$LEARNING_DIR/current-session-id"
143
-
144
- return 0
145
- }
146
-
147
- # =============================================================================
148
- # Store Pattern (called by post-edit hooks)
149
- # =============================================================================
150
- store_pattern() {
151
- local strategy="$1"
152
- local domain="${2:-general}"
153
- local quality="${3:-0.7}"
154
-
155
- if [ -z "$strategy" ]; then
156
- error "No strategy provided"
157
- return 1
158
- fi
159
-
160
- # Escape quotes in strategy
161
- local escaped_strategy="${strategy//\"/\\\"}"
162
-
163
- local result
164
- result=$(node "$LEARNING_SERVICE" store "$escaped_strategy" "$domain" 2>&1)
165
-
166
- if [ $? -eq 0 ]; then
167
- local action=$(echo "$result" | grep -o '"action":"[^"]*"' | cut -d'"' -f4)
168
- local id=$(echo "$result" | grep -o '"id":"[^"]*"' | cut -d'"' -f4)
169
-
170
- if [ "$action" = "created" ]; then
171
- success "Pattern stored: $id"
172
- else
173
- log "Pattern updated: $id"
174
- fi
175
- return 0
176
- else
177
- warn "Pattern storage failed"
178
- return 1
179
- fi
180
- }
181
-
182
- # =============================================================================
183
- # Search Patterns (called by pre-edit hooks)
184
- # =============================================================================
185
- search_patterns() {
186
- local query="$1"
187
- local k="${2:-3}"
188
-
189
- if [ -z "$query" ]; then
190
- error "No query provided"
191
- return 1
192
- fi
193
-
194
- # Escape quotes
195
- local escaped_query="${query//\"/\\\"}"
196
-
197
- local result
198
- result=$(node "$LEARNING_SERVICE" search "$escaped_query" "$k" 2>&1)
199
-
200
- if [ $? -eq 0 ]; then
201
- local patterns=$(echo "$result" | grep -o '"patterns":\[' | wc -l)
202
- local search_time=$(echo "$result" | grep -o '"searchTimeMs":[0-9.]*' | cut -d: -f2)
203
-
204
- echo "$result"
205
-
206
- if [ -n "$search_time" ]; then
207
- log "Search completed in ${search_time}ms"
208
- fi
209
- return 0
210
- else
211
- warn "Pattern search failed"
212
- return 1
213
- fi
214
- }
215
-
216
- # =============================================================================
217
- # Record Pattern Usage (for promotion tracking)
218
- # =============================================================================
219
- record_usage() {
220
- local pattern_id="$1"
221
- local success="${2:-true}"
222
-
223
- if [ -z "$pattern_id" ]; then
224
- return 1
225
- fi
226
-
227
- # This would call into the learning service to record usage
228
- # For now, log it
229
- log "Recording usage: $pattern_id (success=$success)"
230
- }
231
-
232
- # =============================================================================
233
- # Run Benchmark
234
- # =============================================================================
235
- run_benchmark() {
236
- log "Running HNSW benchmark..."
237
-
238
- local result
239
- result=$(node "$LEARNING_SERVICE" benchmark 2>&1)
240
-
241
- if [ $? -eq 0 ]; then
242
- local avg_search=$(echo "$result" | grep -o '"avgSearchMs":"[^"]*"' | cut -d'"' -f4)
243
- local p95_search=$(echo "$result" | grep -o '"p95SearchMs":"[^"]*"' | cut -d'"' -f4)
244
- local improvement=$(echo "$result" | grep -o '"searchImprovementEstimate":"[^"]*"' | cut -d'"' -f4)
245
-
246
- success "HNSW Benchmark Complete"
247
- echo -e " ${DIM}├─ Avg search: ${avg_search}ms${RESET}"
248
- echo -e " ${DIM}├─ P95 search: ${p95_search}ms${RESET}"
249
- echo -e " ${DIM}└─ Estimated improvement: ${improvement}${RESET}"
250
-
251
- echo "$result"
252
- return 0
253
- else
254
- error "Benchmark failed"
255
- echo "$result"
256
- return 1
257
- fi
258
- }
259
-
260
- # =============================================================================
261
- # Get Stats
262
- # =============================================================================
263
- get_stats() {
264
- local result
265
- result=$(node "$LEARNING_SERVICE" stats 2>&1)
266
-
267
- if [ $? -eq 0 ]; then
268
- echo "$result"
269
- return 0
270
- else
271
- error "Failed to get stats"
272
- return 1
273
- fi
274
- }
275
-
276
- # =============================================================================
277
- # Main
278
- # =============================================================================
279
- case "${1:-help}" in
280
- "session-start"|"start")
281
- session_start "$2"
282
- ;;
283
- "session-end"|"end")
284
- session_end
285
- ;;
286
- "store")
287
- store_pattern "$2" "$3" "$4"
288
- ;;
289
- "search")
290
- search_patterns "$2" "$3"
291
- ;;
292
- "record-usage"|"usage")
293
- record_usage "$2" "$3"
294
- ;;
295
- "benchmark")
296
- run_benchmark
297
- ;;
298
- "stats")
299
- get_stats
300
- ;;
301
- "help"|"-h"|"--help")
302
- cat << 'EOF'
303
- RuFlo V3 Learning Hooks
304
-
305
- Usage: learning-hooks.sh <command> [args]
306
-
307
- Commands:
308
- session-start [id] Initialize learning for new session
309
- session-end Consolidate and export session data
310
- store <strategy> Store a new pattern
311
- search <query> [k] Search for similar patterns
312
- record-usage <id> Record pattern usage
313
- benchmark Run HNSW performance benchmark
314
- stats Get learning statistics
315
- help Show this help
316
-
317
- Examples:
318
- ./learning-hooks.sh session-start
319
- ./learning-hooks.sh store "Fix authentication bug" code
320
- ./learning-hooks.sh search "authentication error" 5
321
- ./learning-hooks.sh session-end
322
- EOF
323
- ;;
324
- *)
325
- error "Unknown command: $1"
326
- echo "Use 'learning-hooks.sh help' for usage"
327
- exit 1
328
- ;;
329
- esac
@@ -1,127 +0,0 @@
1
- #!/bin/bash
2
- # RuFlo V3 - Learning Optimizer Worker
3
- # Runs SONA micro-LoRA optimization on patterns
4
-
5
- set -euo pipefail
6
-
7
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
8
- PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
9
- LEARNING_DIR="$PROJECT_ROOT/.claude-flow/learning"
10
- METRICS_DIR="$PROJECT_ROOT/.claude-flow/metrics"
11
- PATTERNS_DB="$LEARNING_DIR/patterns.db"
12
- LEARNING_FILE="$METRICS_DIR/learning.json"
13
- LAST_RUN_FILE="$METRICS_DIR/.optimizer-last-run"
14
-
15
- mkdir -p "$LEARNING_DIR" "$METRICS_DIR"
16
-
17
- should_run() {
18
- if [ ! -f "$LAST_RUN_FILE" ]; then return 0; fi
19
- local last_run=$(cat "$LAST_RUN_FILE" 2>/dev/null || echo "0")
20
- local now=$(date +%s)
21
- [ $((now - last_run)) -ge 1800 ] # 30 minutes
22
- }
23
-
24
- calculate_routing_accuracy() {
25
- if [ -f "$PATTERNS_DB" ] && command -v sqlite3 &>/dev/null; then
26
- # Calculate based on pattern quality distribution
27
- local high_quality=$(sqlite3 "$PATTERNS_DB" "SELECT COUNT(*) FROM short_term_patterns WHERE quality > 0.7" 2>/dev/null || echo "0")
28
- local total=$(sqlite3 "$PATTERNS_DB" "SELECT COUNT(*) FROM short_term_patterns" 2>/dev/null || echo "1")
29
-
30
- if [ "$total" -gt 0 ]; then
31
- echo $((high_quality * 100 / total))
32
- else
33
- echo "0"
34
- fi
35
- else
36
- echo "0"
37
- fi
38
- }
39
-
40
- optimize_patterns() {
41
- if [ ! -f "$PATTERNS_DB" ] || ! command -v sqlite3 &>/dev/null; then
42
- echo "[$(date +%H:%M:%S)] No patterns to optimize"
43
- return 0
44
- fi
45
-
46
- echo "[$(date +%H:%M:%S)] Running learning optimization..."
47
-
48
- # Boost quality of successful patterns
49
- sqlite3 "$PATTERNS_DB" "
50
- UPDATE short_term_patterns
51
- SET quality = MIN(1.0, quality * 1.05)
52
- WHERE quality > 0.5
53
- " 2>/dev/null || true
54
-
55
- # Cross-pollinate: copy strategies across similar domains
56
- sqlite3 "$PATTERNS_DB" "
57
- INSERT OR IGNORE INTO short_term_patterns (strategy, domain, quality, source)
58
- SELECT strategy, 'general', quality * 0.8, 'cross-pollinated'
59
- FROM short_term_patterns
60
- WHERE quality > 0.8
61
- LIMIT 10
62
- " 2>/dev/null || true
63
-
64
- # Calculate metrics
65
- local short_count=$(sqlite3 "$PATTERNS_DB" "SELECT COUNT(*) FROM short_term_patterns" 2>/dev/null || echo "0")
66
- local long_count=$(sqlite3 "$PATTERNS_DB" "SELECT COUNT(*) FROM long_term_patterns" 2>/dev/null || echo "0")
67
- local avg_quality=$(sqlite3 "$PATTERNS_DB" "SELECT ROUND(AVG(quality), 3) FROM short_term_patterns" 2>/dev/null || echo "0")
68
- local routing_accuracy=$(calculate_routing_accuracy)
69
-
70
- # Calculate intelligence score
71
- local pattern_score=$((short_count + long_count * 2))
72
- [ "$pattern_score" -gt 100 ] && pattern_score=100
73
- local quality_score=$(echo "$avg_quality * 40" | bc 2>/dev/null | cut -d. -f1 || echo "0")
74
- local intel_score=$((pattern_score * 60 / 100 + quality_score))
75
- [ "$intel_score" -gt 100 ] && intel_score=100
76
-
77
- # Write learning metrics
78
- cat > "$LEARNING_FILE" << EOF
79
- {
80
- "timestamp": "$(date -Iseconds)",
81
- "patterns": {
82
- "shortTerm": $short_count,
83
- "longTerm": $long_count,
84
- "avgQuality": $avg_quality
85
- },
86
- "routing": {
87
- "accuracy": $routing_accuracy
88
- },
89
- "intelligence": {
90
- "score": $intel_score,
91
- "level": "$([ $intel_score -lt 25 ] && echo "learning" || ([ $intel_score -lt 50 ] && echo "developing" || ([ $intel_score -lt 75 ] && echo "proficient" || echo "expert")))"
92
- },
93
- "sona": {
94
- "adaptationTime": "0.05ms",
95
- "microLoraEnabled": true
96
- }
97
- }
98
- EOF
99
-
100
- echo "[$(date +%H:%M:%S)] ✓ Learning: Intel ${intel_score}% | Patterns: $short_count/$long_count | Quality: $avg_quality | Routing: ${routing_accuracy}%"
101
-
102
- date +%s > "$LAST_RUN_FILE"
103
- }
104
-
105
- run_sona_training() {
106
- echo "[$(date +%H:%M:%S)] Spawning SONA learning agent..."
107
-
108
- # Use agentic-flow for deep learning optimization
109
- npx agentic-flow@alpha hooks intelligence 2>/dev/null || true
110
-
111
- echo "[$(date +%H:%M:%S)] ✓ SONA training triggered"
112
- }
113
-
114
- case "${1:-check}" in
115
- "run"|"optimize") optimize_patterns ;;
116
- "check") should_run && optimize_patterns || echo "[$(date +%H:%M:%S)] Skipping (throttled)" ;;
117
- "force") rm -f "$LAST_RUN_FILE"; optimize_patterns ;;
118
- "sona") run_sona_training ;;
119
- "status")
120
- if [ -f "$LEARNING_FILE" ]; then
121
- jq -r '"Intel: \(.intelligence.score)% (\(.intelligence.level)) | Patterns: \(.patterns.shortTerm)/\(.patterns.longTerm) | Routing: \(.routing.accuracy)%"' "$LEARNING_FILE"
122
- else
123
- echo "No learning data available"
124
- fi
125
- ;;
126
- *) echo "Usage: $0 [run|check|force|sona|status]" ;;
127
- esac