diff --git a/lib/commands.sh b/lib/commands.sh index ae953b1..656c492 100755 --- a/lib/commands.sh +++ b/lib/commands.sh @@ -84,6 +84,23 @@ show_no_slots_menu() { exit 1 } +# Show menu when all slots are currently in use +show_all_slots_running_menu() { + logo_small + echo + cecho "All slots are currently in use" "$YELLOW" + echo + printf "All your container slots are currently running.\n" + echo + printf " ${CYAN}claudebox slots${NC} - View all running slots\n" + printf " ${CYAN}claudebox slot ${NC} - Connect to specific slot\n" + printf " ${CYAN}claudebox create${NC} - Create an additional slot\n" + echo + printf " ${DIM}Tip: Multiple slots let you run parallel Claude sessions.${NC}\n" + echo + exit 1 +} + # Show menu when no ready slots are available show_no_ready_slots_menu() { logo_small diff --git a/lib/project.sh b/lib/project.sh index 060ba05..8234bf3 100755 --- a/lib/project.sh +++ b/lib/project.sh @@ -186,7 +186,7 @@ determine_next_start_container() { dir="$parent/$name" # Skip non-existent slots - they haven't been created yet [ -d "$dir" ] || continue - + # Check if a container with this slot name is running if ! docker ps --format "{{.Names}}" | grep -q "^claudebox-.*-${name}$"; then echo "$name" @@ -196,6 +196,37 @@ determine_next_start_container() { return 1 } +# Check if all slots are currently running (returns 0 if true) +all_slots_running() { + local path="$1" parent max idx name dir + parent=$(get_parent_dir "$path") + max=$(read_counter "$parent") + + # If no slots created yet, return false + [ "$max" -eq 0 ] && return 1 + + local slot_count=0 + local running_count=0 + + for ((idx=1; idx<=max; idx++)); do + name=$(generate_container_name "$path" "$idx") + dir="$parent/$name" + + # Skip non-existent slots + [ -d "$dir" ] || continue + + ((slot_count++)) + + # Check if this slot is running + if docker ps --format "{{.Names}}" | grep -q "^claudebox-.*-${name}$"; then + ((running_count++)) + fi + done + + # Return 0 (true) if we have slots and all are running + [ "$slot_count" -gt 0 ] && [ "$slot_count" -eq "$running_count" ] +} + # Find the first authenticated and inactive slot find_ready_slot() { local path="$1" parent max idx name dir diff --git a/main.sh b/main.sh index d270048..c8b927c 100755 --- a/main.sh +++ b/main.sh @@ -265,11 +265,18 @@ main() { # Get the slot to use (might be empty) project_folder_name=$(get_project_folder_name "$PROJECT_DIR") - + # Early exit if command needs Docker but no slots exist if [[ "$project_folder_name" == "NONE" ]] && [[ "$cmd_requirements" == "docker" ]]; then - show_no_slots_menu - exit 1 + # Check if slots exist but are all running + if all_slots_running "$PROJECT_DIR"; then + show_all_slots_running_menu + exit 1 + else + # No slots exist at all + show_no_slots_menu + exit 1 + fi fi # Always set IMAGE_NAME based on parent folder