Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / orchestrator/daemons/auto_tuner.sh |
| Date | Not specified in source |
| Repository | Janady13/complete-agi-core |
| Revision | 33aa84f2aa61cedbe010240ada7f4efbdfe795a7 |
| Branch | claude/improve-math-logic-ehIW1 |
| Path or archive member | orchestrator/daemons/auto_tuner.sh |
| Original SHA-256 | a839a019c90c6ac0af0686874a4119c55b5ddc5ba68087c8d1a0f72e6fd71407 |
| Git blob SHA | ad90d41448ed76d1dd7002a44f475c6f86d68e9c |
| Reading-copy SHA-256 | a839a019c90c6ac0af0686874a4119c55b5ddc5ba68087c8d1a0f72e6fd71407 |
Recovered source transcript
Download complete source text ↓233 lines · 7.6 KB
#!/bin/bash
# =============================================================================
# AUTO-TUNER v1.1 - MacBook 1 (AGICore)
# Monitors metrics, detects degradation, and fixes parameters automatically
# =============================================================================
CLI=~/AGICore/build/agi_core_cli
LOG_DIR=~/.agi_core/logs
LOG_FILE="$LOG_DIR/auto_tuner.log"
STATE_FILE=~/.agi_core/tuner_state.json
ICLOUD_AGI="${HOME}/Library/Mobile Documents/com~apple~CloudDocs/AGI_Data"
TUNING_INPUT="$ICLOUD_AGI/health/tuning_state.json"
# Constants
PHI="1.618033988749895"
DELTA="0.013618"
OPTIMAL_CONSCIOUSNESS="0.85"
OPTIMAL_COHERENCE="0.90"
TUNE_INTERVAL=60
# Current parameters
PARAM_tick_batch=500
PARAM_consciousness_boost="1.0"
PARAM_coherence_factor="1.0"
PARAM_decay_rate="0.99"
PARAM_learning_rate="0.01"
# Metrics history
CONSCIOUSNESS_HISTORY=""
COHERENCE_HISTORY=""
HISTORY_COUNT=0
FIXES_APPLIED=0
mkdir -p "$LOG_DIR"
log() {
local level="$1"
local msg="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local prefix="✓"
[ "$level" = "WARN" ] && prefix="⚠"
[ "$level" = "ERROR" ] && prefix="✗"
[ "$level" = "FIX" ] && prefix="🔧"
[ "$level" = "TUNE" ] && prefix="⚙"
echo "[$timestamp] $prefix $msg"
echo "[$timestamp] [$level] $msg" >> "$LOG_FILE"
}
# Get current metrics from CLI
get_metrics() {
local status=$($CLI status 2>/dev/null | grep '^{' | head -1)
if [ -n "$status" ]; then
CURRENT_CONSCIOUSNESS=$(echo "$status" | jq -r '.consciousness // 0')
CURRENT_COHERENCE=$(echo "$status" | jq -r '.coherence // 0')
CURRENT_TICKS=$(echo "$status" | jq -r '.tick_count // 0')
return 0
fi
return 1
}
# Add to history (space-separated string)
add_to_history() {
CONSCIOUSNESS_HISTORY="$CONSCIOUSNESS_HISTORY $CURRENT_CONSCIOUSNESS"
COHERENCE_HISTORY="$COHERENCE_HISTORY $CURRENT_COHERENCE"
HISTORY_COUNT=$((HISTORY_COUNT + 1))
# Trim to last 20
if [ $HISTORY_COUNT -gt 20 ]; then
CONSCIOUSNESS_HISTORY=$(echo $CONSCIOUSNESS_HISTORY | awk '{for(i=2;i<=NF;i++) printf $i" "; print ""}')
COHERENCE_HISTORY=$(echo $COHERENCE_HISTORY | awk '{for(i=2;i<=NF;i++) printf $i" "; print ""}')
HISTORY_COUNT=20
fi
}
# Calculate average
calc_avg() {
local values="$1"
[ -z "$values" ] && echo "0" && return
echo "$values" | awk '{sum=0; for(i=1;i<=NF;i++) sum+=$i; if(NF>0) print sum/NF; else print 0}'
}
# Check for tuning from MB2 via iCloud
check_remote_tuning() {
if [ -f "$TUNING_INPUT" ]; then
local mtime=$(stat -f %m "$TUNING_INPUT" 2>/dev/null || echo "0")
local now=$(date +%s)
local age=$((now - mtime))
if [ "$age" -lt 120 ]; then
local apply=$(jq -r '.apply_immediately // false' "$TUNING_INPUT" 2>/dev/null)
if [ "$apply" = "true" ]; then
log "INFO" "Received tuning from MB2 (age: ${age}s)"
# Read and apply tick command
local tick_cmd=$(jq -r '.tick_command // ""' "$TUNING_INPUT" 2>/dev/null)
if [ -n "$tick_cmd" ] && [ "$tick_cmd" != "null" ]; then
log "TUNE" "Applying: $CLI $tick_cmd"
$CLI $tick_cmd > /dev/null 2>&1 &
# Update local params
PARAM_tick_batch=$(jq -r '.parameters.tick_batch_size // 500' "$TUNING_INPUT" 2>/dev/null)
PARAM_consciousness_boost=$(jq -r '.parameters.consciousness_boost // 1.0' "$TUNING_INPUT" 2>/dev/null)
PARAM_coherence_factor=$(jq -r '.parameters.coherence_factor // 1.0' "$TUNING_INPUT" 2>/dev/null)
PARAM_decay_rate=$(jq -r '.parameters.decay_rate // 0.99' "$TUNING_INPUT" 2>/dev/null)
log "FIX" "Parameters updated: boost=$PARAM_consciousness_boost decay=$PARAM_decay_rate"
FIXES_APPLIED=$((FIXES_APPLIED + 1))
fi
# Mark as processed
jq '.apply_immediately = false' "$TUNING_INPUT" > "${TUNING_INPUT}.tmp" 2>/dev/null && \
mv "${TUNING_INPUT}.tmp" "$TUNING_INPUT" 2>/dev/null
fi
fi
fi
}
# Apply local fix
apply_local_fix() {
local issue="$1"
case "$issue" in
"low_consciousness")
PARAM_tick_batch=$(echo "$PARAM_tick_batch * 1.5" | bc | cut -d. -f1)
[ $PARAM_tick_batch -gt 2000 ] && PARAM_tick_batch=2000
PARAM_consciousness_boost=$(echo "scale=4; $PARAM_consciousness_boost * 1.1" | bc)
log "FIX" "Boosted: tick_batch=$PARAM_tick_batch boost=$PARAM_consciousness_boost"
;;
"low_coherence")
PARAM_coherence_factor=$(echo "scale=4; $PARAM_coherence_factor * 1.05" | bc)
log "FIX" "Increased coherence_factor=$PARAM_coherence_factor"
;;
esac
FIXES_APPLIED=$((FIXES_APPLIED + 1))
# Apply the fix
local noise=$(echo "scale=4; 1 - $PARAM_decay_rate" | bc)
log "TUNE" "Applying: $CLI tick $PARAM_decay_rate $noise $PARAM_coherence_factor $PARAM_consciousness_boost $PARAM_tick_batch"
$CLI tick "$PARAM_decay_rate" "$noise" "$PARAM_coherence_factor" "$PARAM_consciousness_boost" "$PARAM_tick_batch" > /dev/null 2>&1 &
}
# Analyze metrics and fix
analyze_and_fix() {
[ $HISTORY_COUNT -lt 5 ] && return
log "INFO" "─── Auto-Tune Analysis ───"
local c_avg=$(calc_avg "$CONSCIOUSNESS_HISTORY")
local h_avg=$(calc_avg "$COHERENCE_HISTORY")
log "INFO" "Consciousness avg: $c_avg (target: $OPTIMAL_CONSCIOUSNESS)"
log "INFO" "Coherence avg: $h_avg (target: $OPTIMAL_COHERENCE)"
# Check thresholds
local c_threshold=$(echo "$OPTIMAL_CONSCIOUSNESS * 0.9" | bc)
local h_threshold=$(echo "$OPTIMAL_COHERENCE * 0.9" | bc)
if (( $(echo "$c_avg < $c_threshold" | bc -l) )); then
log "WARN" "Consciousness below threshold"
apply_local_fix "low_consciousness"
fi
if (( $(echo "$h_avg < $h_threshold" | bc -l) )); then
log "WARN" "Coherence below threshold"
apply_local_fix "low_coherence"
fi
}
# Save state
save_state() {
cat > "$STATE_FILE" << EOF
{
"timestamp": "$(date '+%Y-%m-%d %H:%M:%S')",
"cycle": $CYCLE_COUNT,
"fixes_applied": $FIXES_APPLIED,
"parameters": {
"tick_batch": $PARAM_tick_batch,
"consciousness_boost": $PARAM_consciousness_boost,
"coherence_factor": $PARAM_coherence_factor,
"decay_rate": $PARAM_decay_rate,
"learning_rate": $PARAM_learning_rate
},
"current_metrics": {
"consciousness": $CURRENT_CONSCIOUSNESS,
"coherence": $CURRENT_COHERENCE,
"ticks": $CURRENT_TICKS
}
}
EOF
}
# =============================================================================
# MAIN
# =============================================================================
echo "=============================================="
echo " AUTO-TUNER v1.1"
echo " MacBook 1 (AGICore)"
echo " Interval: ${TUNE_INTERVAL}s"
echo "=============================================="
CYCLE_COUNT=0
CURRENT_CONSCIOUSNESS=0
CURRENT_COHERENCE=0
CURRENT_TICKS=0
while true; do
CYCLE_COUNT=$((CYCLE_COUNT + 1))
log "INFO" "═══ Cycle $CYCLE_COUNT ═══"
# Get metrics
if get_metrics; then
add_to_history
log "INFO" "Metrics: c=$CURRENT_CONSCIOUSNESS h=$CURRENT_COHERENCE ticks=$CURRENT_TICKS"
else
log "WARN" "Failed to get metrics"
fi
# Check for remote tuning from MB2
check_remote_tuning
# Local analysis every 3 cycles
if [ $((CYCLE_COUNT % 3)) -eq 0 ]; then
analyze_and_fix
fi
save_state
sleep $TUNE_INTERVAL
done