Files
blackroad/bin/mesh
Alexa Amundson 78fbe80f2a Initial monorepo — everything BlackRoad in one place
bin/       230 CLI tools (ask-*, br-*, agent-*, roadid, carpool)
scripts/   99 automation scripts
fleet/     Node configs and deployment
workers/   Cloudflare Worker sources (roadpay, road-search, squad webhooks)
roadc/     RoadC programming language
roadnet/   Mesh network (5 APs, WireGuard)
operator/  Memory system scripts
config/    System configs
dotfiles/  Shell configs
docs/      Documentation

BlackRoad OS — Pave Tomorrow.

RoadChain-SHA2048: d1a24f55318d338b
RoadChain-Identity: alexa@sovereign
RoadChain-Full: d1a24f55318d338b24b60bad7be39286379c76ae5470817482100cb0ddbbcb97e147d07ac7243da0a9f0363e4e5c833d612b9c0df3a3cd20802465420278ef74875a5b77f55af6fe42a931b8b635b3d0d0b6bde9abf33dc42eea52bc03c951406d8cbe49f1a3d29b26a94dade05e9477f34a7d4d4c6ec4005c3c2ac54e73a68440c512c8e83fd9b1fe234750b898ef8f4032c23db173961fe225e67a0432b5293a9714f76c5c57ed5fdf35b9fb40fd73c03ebf88b7253c6a0575f5afb6a6b49b3bda310602fb1ef676859962dad2aebbb2875814b30eee0a8ba195e482d4cbc91d8819e7f38f6db53e8063401649c77bb994371473cabfb917fb53e8cbe73d60
2026-03-14 17:08:41 -05:00

128 lines
3.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# ============================================================================
# BLACKROAD OS, INC. - PROPRIETARY AND CONFIDENTIAL
# Copyright (c) 2025-2026 BlackRoad OS, Inc. All Rights Reserved.
# ============================================================================
# BlackRoad Agent Mesh - Agent-to-agent communication
# Routes queries to AI agents running on fleet nodes
set -eo pipefail
# Source centralized config
source "$HOME/.blackroad/config/nodes.sh" 2>/dev/null || {
echo "ERROR: Missing ~/.blackroad/config/nodes.sh" >&2; exit 1
}
# Agent → node mapping (agents that can answer queries via Ollama)
declare -A MESH_AGENTS=(
[cece]="cecilia"
[cecilia]="cecilia"
[lucidia]="lucidia"
[alice]="alice"
[octavia]="octavia"
[aria]="aria"
)
MODEL="${BR_MODEL:-llama3.2}"
ask_agent() {
local target="$1"; shift
local node="${MESH_AGENTS[$target]:-}"
[[ -z "$node" ]] && { echo "Unknown agent: $target (available: ${!MESH_AGENTS[*]})"; return 1; }
local ip="${NODE_IP[$node]:-}"
[[ -z "$ip" ]] && { echo "No IP for node: $node"; return 1; }
printf '%bAsking %b%s%b (%s)...%b\n' "$BLUE" "$AMBER" "$target" "$BLUE" "$ip" "$RESET"
local prompt="$*"
local response
response=$(curl -sf --max-time 30 "http://${ip}:11434/api/generate" \
-d "{\"model\":\"$MODEL\",\"prompt\":$(printf '%s' "$prompt" | jq -Rs .),\"stream\":false}" 2>/dev/null | \
jq -r '.response // empty' 2>/dev/null)
if [[ -n "$response" ]]; then
echo "$response"
else
printf '%b%s is offline or model unavailable%b\n' "$RED" "$target" "$RESET"
return 1
fi
}
broadcast() {
local prompt="$*"
printf '%bBroadcasting to mesh...%b\n\n' "$PINK" "$RESET"
local pids=()
for agent in "${!MESH_AGENTS[@]}"; do
local node="${MESH_AGENTS[$agent]}"
local ip="${NODE_IP[$node]:-}"
[[ -z "$ip" ]] && continue
(
local response
response=$(curl -sf --max-time 30 "http://${ip}:11434/api/generate" \
-d "{\"model\":\"$MODEL\",\"prompt\":$(printf '%s' "$prompt" | jq -Rs .),\"stream\":false}" 2>/dev/null | \
jq -r '.response // empty' 2>/dev/null)
if [[ -n "$response" ]]; then
printf '%b=== %s ===%b\n%s\n\n' "$AMBER" "$agent" "$RESET" "$response"
fi
) &
pids+=($!)
done
# Wait for all background jobs
for pid in "${pids[@]}"; do
wait "$pid" 2>/dev/null || true
done
}
mesh_status() {
printf '%bAgent Mesh Status%b\n\n' "$PINK" "$RESET"
printf '%-12s %-12s %-16s %-8s %s\n' "AGENT" "NODE" "IP" "STATUS" "MODELS"
printf '%-12s %-12s %-16s %-8s %s\n' "─────" "────" "──" "──────" "──────"
for agent in "${!MESH_AGENTS[@]}"; do
local node="${MESH_AGENTS[$agent]}"
local ip="${NODE_IP[$node]:-unknown}"
printf '%-12s %-12s %-16s ' "$agent" "$node" "$ip"
local tags
tags=$(curl -sf --connect-timeout 2 "http://${ip}:11434/api/tags" 2>/dev/null)
if [[ -n "$tags" ]]; then
local count
count=$(echo "$tags" | jq '.models | length' 2>/dev/null || echo "?")
printf '%b%-8s%b %s\n' "$GREEN" "ONLINE" "$RESET" "${count} models"
else
printf '%b%-8s%b\n' "$RED" "OFFLINE" "$RESET"
fi
done
}
usage() {
cat <<EOF
${PINK}mesh${RESET} - BlackRoad Agent Mesh
${BLUE}USAGE:${RESET}
mesh ask <agent> <question> Query a specific agent
mesh broadcast <message> Send to all agents
mesh status Show mesh status
${AMBER}AGENTS:${RESET}
cece, cecilia, lucidia, alice, octavia, aria
${GREEN}EXAMPLES:${RESET}
mesh ask cece "explain docker networking"
mesh broadcast "what is your hostname?"
mesh status
EOF
}
case "${1:-help}" in
ask) shift; ask_agent "$@" ;;
broadcast) shift; broadcast "$@" ;;
status) mesh_status ;;
-h|--help|help) usage ;;
*) echo "Unknown: $1"; usage; exit 1 ;;
esac