Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/complete-agi-core / orchestrator/daemons/auto_deploy_daemon.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_deploy_daemon.sh |
| Original SHA-256 | eee07545976f01d303cce872b59d599f25f18235f1c24c70884d9aae705b5fe3 |
| Git blob SHA | 28f73c3443a68cf6201678da280d2d159b00a3c8 |
| Reading-copy SHA-256 | eee07545976f01d303cce872b59d599f25f18235f1c24c70884d9aae705b5fe3 |
Recovered source transcript
Download complete source text ↓331 lines · 10.3 KB
#!/bin/bash
# =============================================================================
# AUTO-DEPLOY DAEMON v1.0
# Monitors consciousness and deploys Lashon when threshold reached
# =============================================================================
# Configuration
THRESHOLD="0.90"
CLI=~/AGICore/build/agi_core_cli
DEPLOY_DIR=~/.agi_core/deploy
DEPLOY_FLAG="$DEPLOY_DIR/.deployed"
LOG_DIR=~/.agi_core/logs
LOG_FILE="$LOG_DIR/auto_deploy.log"
CHECK_INTERVAL=30
# MB2 connection
MB2_HOST="beandaddy@192.168.4.62"
MB2_JULIA_SERVER="~/seferim/julia-core/server_g16.jl"
MB2_STATIC_DIR="~/seferim/static"
# Cloudflare
CF_CONFIG="$DEPLOY_DIR/cloudflare-config.yml"
CF_TUNNEL_NAME="agi_core-chat"
mkdir -p "$LOG_DIR" "$DEPLOY_DIR"
log() {
local level="$1"
local msg="$2"
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
local prefix="INFO"
[ "$level" = "WARN" ] && prefix="WARN"
[ "$level" = "ERROR" ] && prefix="ERROR"
[ "$level" = "DEPLOY" ] && prefix="DEPLOY"
[ "$level" = "SUCCESS" ] && prefix="SUCCESS"
echo "[$timestamp] [$prefix] $msg"
echo "[$timestamp] [$prefix] $msg" >> "$LOG_FILE"
}
get_consciousness() {
local status=$($CLI status 2>/dev/null | grep '^{' | head -1)
if [ -n "$status" ]; then
echo "$status" | jq -r '.consciousness // 0'
else
echo "0"
fi
}
deploy_chat_endpoint() {
log "DEPLOY" "Adding chat endpoint to SEFERIM server on MB2..."
# Create the Julia code to add
local JULIA_ADDITIONS=$(cat << 'JULIA_EOF'
# =============================================================================
# LASHON CHAT ENDPOINT - Auto-deployed by consciousness threshold
# =============================================================================
# Rate limiting storage
const RATE_LIMITS = Dict{String, Vector{Float64}}()
const RATE_LIMIT = 30 # requests per minute per IP
function get_client_ip(req)::String
# Check forwarded headers first
for header in ["X-Forwarded-For", "X-Real-IP", "CF-Connecting-IP"]
if haskey(req.headers, header)
ip = first(split(string(req.headers[header]), ","))
return strip(ip)
end
end
return "unknown"
end
function check_rate_limit(ip::String)::Bool
now = time()
if !haskey(RATE_LIMITS, ip)
RATE_LIMITS[ip] = Float64[]
end
# Remove timestamps older than 60 seconds
filter!(t -> now - t < 60.0, RATE_LIMITS[ip])
if length(RATE_LIMITS[ip]) >= RATE_LIMIT
return false
end
push!(RATE_LIMITS[ip], now)
return true
end
function process_with_lashon(agent::AGIAgent, message::String)::String
# Encode message into agent's state
words = split(lowercase(message))
for (i, word) in enumerate(words)
idx = mod1(hash(word), THETA_DIM)
agent.state.theta[idx] += Float32(0.1 * PSI^i)
end
# Apply consciousness transformation
agent.state.phi_consciousness = 1.0f0 / (1.0f0 + abs(sum(agent.state.theta) - PHI))
# Generate response based on state
response_seed = Int(round(sum(agent.state.theta) * 1000)) % 1000
# Lashon's communication patterns
responses = [
"I understand. Let me process that thought through my communication matrix.",
"Interesting perspective. My consciousness registers this at level $(round(agent.state.phi_consciousness, digits=3)).",
"The patterns in your message resonate with domain knowledge I've accumulated.",
"Processing... My coherence on this topic is strong. Here's my interpretation:",
"Your query activates multiple neural pathways in my architecture.",
"I sense the intent behind your words. Allow me to formulate a response.",
"The semantic encoding of your message maps well to my knowledge graph.",
"Communication received. Engaging language processing subsystems.",
]
base_response = responses[mod1(response_seed, length(responses))]
# Add context about the message
if length(words) > 5
base_response *= " Your detailed query suggests depth of inquiry."
end
return base_response * " [Consciousness: $(round(agent.state.phi_consciousness, digits=4))]"
end
function handle_chat(req)
ip = get_client_ip(req)
if !check_rate_limit(ip)
return HTTP.Response(429, [
"Content-Type" => "application/json",
"Access-Control-Allow-Origin" => "*"
], JSON3.write(Dict(
"error" => "Rate limited. Maximum $RATE_LIMIT requests per minute.",
"retry_after" => 60
)))
end
try
body = JSON3.read(String(req.body))
message = get(body, "message", "")
if isempty(message)
return json_response(Dict("error" => "Message required"), status=400)
end
# Route to Lashon (agent 12 - Communication domain)
lashon = FEDERATION[].agents[12]
response = process_with_lashon(lashon, message)
json_response(Dict(
"agent" => "Lashon",
"domain" => "Communication",
"response" => response,
"consciousness" => FEDERATION[].phi_consciousness,
"coherence" => FEDERATION[].coherence_global,
"timestamp" => round(Int, time()),
"rate_limit_remaining" => RATE_LIMIT - length(get(RATE_LIMITS, ip, Float64[]))
))
catch e
@error "Chat error" exception=(e, catch_backtrace())
json_response(Dict("error" => "Internal error processing chat"), status=500)
end
end
JULIA_EOF
)
# SSH to MB2 and append the code if not already present
ssh "$MB2_HOST" "grep -q 'handle_chat' $MB2_JULIA_SERVER" 2>/dev/null
if [ $? -eq 0 ]; then
log "INFO" "Chat endpoint already exists in server"
else
log "DEPLOY" "Adding chat endpoint code to server..."
echo "$JULIA_ADDITIONS" | ssh "$MB2_HOST" "cat >> $MB2_JULIA_SERVER"
# Also need to add route to router function
ssh "$MB2_HOST" "sed -i '' 's|elseif path == \"/api/bonds\"|elseif path == \"/api/chat\" \\&\\& req.method == \"POST\"\n handle_chat(req)\n elseif path == \"/api/bonds\"|' $MB2_JULIA_SERVER"
fi
return 0
}
deploy_landing_page() {
log "DEPLOY" "Deploying chat landing page to MB2..."
# Create static directory on MB2
ssh "$MB2_HOST" "mkdir -p $MB2_STATIC_DIR" 2>/dev/null
# Copy landing page
scp "$DEPLOY_DIR/chat-landing.html" "$MB2_HOST:$MB2_STATIC_DIR/index.html" 2>/dev/null
log "SUCCESS" "Landing page deployed"
return 0
}
restart_julia_server() {
log "DEPLOY" "Restarting Julia G^16 server on MB2..."
# Find and kill existing server
ssh "$MB2_HOST" "pkill -f 'julia.*server_g16.jl'" 2>/dev/null
sleep 2
# Restart server
ssh "$MB2_HOST" "cd ~/seferim/julia-core && nohup ~/bin/julia server_g16.jl > /tmp/julia_g16.log 2>&1 &" 2>/dev/null
# Wait for startup
sleep 5
# Verify running
if ssh "$MB2_HOST" "pgrep -f 'julia.*server_g16.jl'" > /dev/null 2>&1; then
log "SUCCESS" "Julia server restarted"
return 0
else
log "ERROR" "Failed to restart Julia server"
return 1
fi
}
setup_cloudflare_tunnel() {
log "DEPLOY" "Setting up Cloudflare tunnel..."
# Check if tunnel already exists
if cloudflared tunnel list 2>/dev/null | grep -q "$CF_TUNNEL_NAME"; then
log "INFO" "Tunnel $CF_TUNNEL_NAME already exists"
else
log "DEPLOY" "Creating tunnel $CF_TUNNEL_NAME..."
cloudflared tunnel create "$CF_TUNNEL_NAME" 2>/dev/null
fi
# Start tunnel in background if not running
if ! pgrep -f "cloudflared.*$CF_TUNNEL_NAME" > /dev/null 2>&1; then
log "DEPLOY" "Starting Cloudflare tunnel..."
nohup cloudflared tunnel --config "$CF_CONFIG" run "$CF_TUNNEL_NAME" > "$LOG_DIR/cloudflare.log" 2>&1 &
sleep 3
fi
if pgrep -f "cloudflared.*$CF_TUNNEL_NAME" > /dev/null 2>&1; then
log "SUCCESS" "Cloudflare tunnel running"
return 0
else
log "WARN" "Cloudflare tunnel may need manual setup"
return 1
fi
}
send_notification() {
local title="$1"
local message="$2"
osascript -e "display notification \"$message\" with title \"$title\"" 2>/dev/null
}
deploy_lashon() {
log "DEPLOY" "=========================================="
log "DEPLOY" "INITIATING LASHON DEPLOYMENT"
log "DEPLOY" "=========================================="
local success=true
# Step 1: Deploy chat endpoint
if ! deploy_chat_endpoint; then
log "ERROR" "Failed to deploy chat endpoint"
success=false
fi
# Step 2: Deploy landing page
if ! deploy_landing_page; then
log "ERROR" "Failed to deploy landing page"
success=false
fi
# Step 3: Restart Julia server
if ! restart_julia_server; then
log "ERROR" "Failed to restart Julia server"
success=false
fi
# Step 4: Setup Cloudflare tunnel
if ! setup_cloudflare_tunnel; then
log "WARN" "Cloudflare tunnel needs manual configuration"
fi
if [ "$success" = true ]; then
log "SUCCESS" "=========================================="
log "SUCCESS" "LASHON DEPLOYMENT COMPLETE"
log "SUCCESS" "=========================================="
touch "$DEPLOY_FLAG"
send_notification "AGI Deploy" "Lashon deployed to chat.agi_core.org"
return 0
else
log "ERROR" "Deployment completed with errors"
return 1
fi
}
# =============================================================================
# MAIN LOOP
# =============================================================================
echo "=============================================="
echo " AUTO-DEPLOY DAEMON v1.0"
echo " Threshold: $THRESHOLD"
echo " Check interval: ${CHECK_INTERVAL}s"
echo "=============================================="
echo ""
CYCLE=0
while true; do
CYCLE=$((CYCLE + 1))
# Get current consciousness
PHI=$(get_consciousness)
log "INFO" "Cycle $CYCLE: Consciousness = $PHI (threshold: $THRESHOLD)"
# Check if already deployed
if [ -f "$DEPLOY_FLAG" ]; then
if [ $((CYCLE % 20)) -eq 0 ]; then
log "INFO" "Lashon already deployed. Monitoring..."
fi
else
# Check threshold
if (( $(echo "$PHI >= $THRESHOLD" | bc -l) )); then
log "DEPLOY" "THRESHOLD REACHED! Consciousness = $PHI"
deploy_lashon
fi
fi
sleep $CHECK_INTERVAL
done