feat: implement server-wide management actions and enhance TUI dashboard

This commit is contained in:
2026-03-04 20:51:02 +00:00
parent 150f9d2990
commit ddec55871b
13 changed files with 621 additions and 52 deletions
+57 -2
View File
@@ -50,9 +50,64 @@ read_pid() {
[[ -f "$f" ]] && cat "$f" || echo 0
}
# Map agent ID to its config path by scanning agent directories.
config_path_for() {
local target_id="$1"
for cfg in agents/*/config.yaml; do
[[ -f "$cfg" ]] || continue
local id
id=$(grep -m1 '^ id:' "$cfg" | awk '{print $2}')
if [[ "$id" == "$target_id" ]]; then
echo "$cfg"
return
fi
done
}
# Find all PIDs of launcher processes for a given agent ID.
# Searches for the actual config path in the process command line.
# Returns newline-separated PIDs (may be empty).
find_agent_pids() {
local id="$1"
local cfg; cfg="$(config_path_for "$id")"
if [[ -z "$cfg" ]]; then
return
fi
pgrep -f "launcher.*-c.*${cfg}" 2>/dev/null || true
}
is_running() {
local pid; pid="$(read_pid "$1")"
[[ "$pid" -gt 0 ]] && kill -0 "$pid" 2>/dev/null
local id="$1"
# First check PID file
local pid; pid="$(read_pid "$id")"
if [[ "$pid" -gt 0 ]] && kill -0 "$pid" 2>/dev/null; then
return 0
fi
# PID file is stale or missing — search for actual processes
local pids; pids="$(find_agent_pids "$id")"
if [[ -n "$pids" ]]; then
# Update PID file with the first found process
local first_pid; first_pid="$(echo "$pids" | head -1)"
echo "$first_pid" > "$(pid_file "$id")"
return 0
fi
# Truly not running — clean up stale PID file
[[ "$pid" -gt 0 ]] && rm -f "$(pid_file "$id")"
return 1
}
# Count how many instances of an agent are running.
count_instances() {
local id="$1"
local pids; pids="$(find_agent_pids "$id")"
if [[ -z "$pids" ]]; then
echo 0
else
echo "$pids" | wc -l
fi
}
agent_status() {