diff --git a/scripts/post-install.sh b/scripts/post-install.sh index 3f3ac68..b6aa9a4 100755 --- a/scripts/post-install.sh +++ b/scripts/post-install.sh @@ -92,6 +92,9 @@ fi # --------------------------------------------------------------------------- echo "[3/3] Detecting OpenClaw agents ..." +GRAY='\033[0;90m' +RST='\033[0m' + # detect_agents outputs lines of: INDEX|ID|DISPLAY_NAME|WORKSPACE_PATH # Uses python3 to parse openclaw.json; falls back gracefully if unavailable. detect_agents() { @@ -136,19 +139,34 @@ for agent in agents: PYEOF } -# Collect detected agents into arrays +# Collect ALL detected agents (including non-alive) into arrays +ALL_AGENT_IDS=() +ALL_AGENT_NAMES=() +ALL_AGENT_WORKSPACES=() + +if command -v python3 &>/dev/null && [[ -f "$CONFIG_FILE" ]]; then + while IFS='|' read -r idx agent_id agent_name workspace; do + ALL_AGENT_IDS+=("$agent_id") + ALL_AGENT_NAMES+=("$agent_name") + ALL_AGENT_WORKSPACES+=("$workspace") + done < <(detect_agents 2>/dev/null || true) +fi + +# Filter to alive agents (workspace directory exists) AGENT_IDS=() AGENT_NAMES=() AGENT_WORKSPACES=() +SKIPPED=0 -# Read detection output -if command -v python3 &>/dev/null && [[ -f "$CONFIG_FILE" ]]; then - while IFS='|' read -r idx agent_id agent_name workspace; do - AGENT_IDS+=("$agent_id") - AGENT_NAMES+=("$agent_name") - AGENT_WORKSPACES+=("$workspace") - done < <(detect_agents 2>/dev/null || true) -fi +for i in "${!ALL_AGENT_IDS[@]}"; do + if [[ -d "${ALL_AGENT_WORKSPACES[$i]}" ]]; then + AGENT_IDS+=("${ALL_AGENT_IDS[$i]}") + AGENT_NAMES+=("${ALL_AGENT_NAMES[$i]}") + AGENT_WORKSPACES+=("${ALL_AGENT_WORKSPACES[$i]}") + else + SKIPPED=$((SKIPPED + 1)) + fi +done install_skill_to_workspace() { local workspace="$1" @@ -158,8 +176,22 @@ install_skill_to_workspace() { echo " Installed → ${skill_dest}/SKILL.md" } -if [[ ${#AGENT_IDS[@]} -eq 0 ]]; then - # Fallback: no agents detected — ask user for a workspace path +if [[ ${#AGENT_IDS[@]} -eq 0 && ${#ALL_AGENT_IDS[@]} -gt 0 ]]; then + # Config has agents but none are alive + echo "" + echo " Found ${#ALL_AGENT_IDS[@]} agent(s) in config but their workspace directories don't exist yet." + echo " You may need to initialize them first." + echo "" + printf " Enter workspace path to install SKILL.md (or press Enter to skip): " + read -r FALLBACK_WS + if [[ -n "$FALLBACK_WS" ]]; then + FALLBACK_WS="${FALLBACK_WS/#\~/$HOME}" + install_skill_to_workspace "$FALLBACK_WS" + else + echo " Skipped SKILL.md installation." + fi +elif [[ ${#AGENT_IDS[@]} -eq 0 ]]; then + # No agents at all — ask user for a workspace path echo " No agents detected in openclaw.json (file missing or parse error)." echo "" printf " Enter workspace path to install SKILL.md (or press Enter to skip): " @@ -171,17 +203,47 @@ if [[ ${#AGENT_IDS[@]} -eq 0 ]]; then echo " Skipped SKILL.md installation." fi else - # Show numbered list + # Show numbered list — alive agents first, then skipped summary echo "" - echo " Found ${#AGENT_IDS[@]} agent(s):" + echo " Found ${#AGENT_IDS[@]} alive agent(s):" for i in "${!AGENT_IDS[@]}"; do num=$((i + 1)) printf " [%d] %s (%s)\n" "$num" "${AGENT_NAMES[$i]}" "${AGENT_WORKSPACES[$i]}" done + + # Show skipped (non-alive) agents in gray + if [[ $SKIPPED -gt 0 ]]; then + echo "" + printf " ${GRAY}Skipped %d agent(s) with missing workspace directories:${RST}\n" "$SKIPPED" + for i in "${!ALL_AGENT_IDS[@]}"; do + if [[ ! -d "${ALL_AGENT_WORKSPACES[$i]}" ]]; then + printf " ${GRAY} %s (%s)${RST}\n" "${ALL_AGENT_NAMES[$i]}" "${ALL_AGENT_WORKSPACES[$i]}" + fi + done + fi + echo "" - echo " Install to: [A]ll agents / [1,2,...] specific (comma-separated) / [Q]uit" - printf " > " - read -r SELECTION + echo " Install to: [A]ll alive agents (default) / [1,2,...] specific / [Q]uit" + printf " > (10s timeout, Enter or no input = All) " + + # Auto-select All if stdin is not a tty (pipe/CI) or on timeout + if [[ ! -t 0 ]]; then + SELECTION="A" + echo "(non-interactive: auto-selecting All)" + elif read -t 10 -r SELECTION; then + # User provided input (possibly empty = Enter) + : # SELECTION is set + else + # Timeout — default to All + echo "" + echo " (timeout — defaulting to All)" + SELECTION="" + fi + + # Empty input (Enter or timeout) defaults to All + if [[ -z "$SELECTION" ]]; then + SELECTION="A" + fi case "${SELECTION^^}" in A|ALL) diff --git a/scripts/verify.sh b/scripts/verify.sh index d9c6ad7..8e96fbd 100755 --- a/scripts/verify.sh +++ b/scripts/verify.sh @@ -121,6 +121,8 @@ PYEOF } if $ALL_AGENTS; then + GRAY='\033[0;90m' + echo -e "\n${BOLD}memory-continuity — Multi-Agent Verifier${RESET}" echo "────────────────────────────────────────────" @@ -134,10 +136,33 @@ if $ALL_AGENTS; then exit 1 fi + # Filter to alive agents (workspace directory exists) + ALIVE_LINES=() + SKIPPED=0 + for line in "${AGENT_LINES[@]}"; do + IFS='|' read -r agent_id agent_name agent_ws <<< "$line" + if [[ -d "$agent_ws" ]]; then + ALIVE_LINES+=("$line") + else + echo -e " ${GRAY}Skipping ${agent_name} (${agent_id}) — workspace not found: ${agent_ws}${RESET}" + SKIPPED=$((SKIPPED + 1)) + fi + done + + if [[ $SKIPPED -gt 0 ]]; then + echo -e " ${GRAY}Skipped ${SKIPPED} agent(s) with missing workspace directories${RESET}" + fi + + if [[ ${#ALIVE_LINES[@]} -eq 0 ]]; then + echo -e "${YELLOW}All ${#AGENT_LINES[@]} agent(s) in config have missing workspace directories.${RESET}" + echo -e "${YELLOW}You may need to initialize them first.${RESET}" + exit 1 + fi + TOTAL_PASS=0 TOTAL_FAIL=0 - for line in "${AGENT_LINES[@]}"; do + for line in "${ALIVE_LINES[@]}"; do IFS='|' read -r agent_id agent_name agent_ws <<< "$line" echo -e "\n${BOLD}Agent: ${agent_name} (${agent_id})${RESET}" echo -e " Workspace: ${agent_ws}" @@ -194,7 +219,9 @@ if $ALL_AGENTS; then echo "" echo "────────────────────────────────────────────" - echo -e "${BOLD}Summary: ${TOTAL_PASS} passed, ${TOTAL_FAIL} failed (of ${#AGENT_LINES[@]} agents)${RESET}" + SUMMARY_DETAIL="" + [[ $SKIPPED -gt 0 ]] && SUMMARY_DETAIL=", ${SKIPPED} skipped (no workspace)" + echo -e "${BOLD}Summary: ${TOTAL_PASS} passed, ${TOTAL_FAIL} failed (of ${#ALIVE_LINES[@]} alive agents${SUMMARY_DETAIL})${RESET}" [[ $TOTAL_FAIL -gt 0 ]] && exit 1 || exit 0 fi