Fix set -e bug causing silent exit after valid input

- Replace all `[[ condition ]] && die` with `if/fi` — the && pattern
  exits silently when the condition is false under set -e
- Removed -e from set flags (kept -uo pipefail), all error paths are
  now explicit
- Declare `input` as local in ask/ask_yn/ask_choice to prevent leakage
- Use `read -r input || true` to handle EOF safely
- Fix ask_choice arithmetic to avoid (()) triggering exit on false

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Eli 2026-03-09 12:11:31 +01:00
commit 431e5493fc
3 changed files with 24 additions and 22 deletions

View file

@ -2,7 +2,7 @@
# ╔══════════════════════════════════════════════════════════════════╗
# ║ Context Studio Wizard — Project Setup ║
# ╚══════════════════════════════════════════════════════════════════╝
set -euo pipefail
set -uo pipefail
WIZARD_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@ -17,17 +17,17 @@ collect_project_info() {
header "Project Details"
ask PROJECT_NAME "Project name" ""
[[ -z "$PROJECT_NAME" ]] && die "Project name is required."
if [[ -z "$PROJECT_NAME" ]]; then die "Project name is required."; fi
local default_dir="$HOME/projects/$(slugify "$PROJECT_NAME")"
ask PROJECT_DIR "Project location" "$default_dir"
[[ -z "$PROJECT_DIR" ]] && die "Project location is required."
if [[ -z "$PROJECT_DIR" ]]; then die "Project location is required."; fi
PROJECT_DIR="${PROJECT_DIR/#\~/$HOME}"
if [[ -e "$PROJECT_DIR" ]]; then
warn "Directory already exists: $PROJECT_DIR"
ask_yn _continue "Continue anyway?" "n"
[[ "$_continue" != "y" ]] && die "Aborted."
if [[ "$_continue" != "y" ]]; then die "Aborted."; fi
fi
}
@ -41,14 +41,13 @@ collect_workflow_info() {
if [[ "$WORKFLOW_SOURCE" == "Clone from existing repo" ]]; then
ask WORKFLOW_REPO "Workflow repo URL" ""
[[ -z "$WORKFLOW_REPO" ]] && die "Repo URL is required."
if [[ -z "$WORKFLOW_REPO" ]]; then die "Repo URL is required."; fi
else
ask PROJECT_DESC "Project description" "A software project"
ask TECH_STACK "Tech stack (e.g. Node.js, Rust, Python)" "Node.js"
ask_choice AGENT_PRESET "Agent preset" \
"minimal (5 agents: coordinator, 2 coders, researcher, tester)" \
"standard (9 agents: 2 coordinators, 3 coders, 2 researchers, tester, reviewer)"
# Normalize to short key
case "$AGENT_PRESET" in
minimal*) AGENT_PRESET="minimal" ;;
*) AGENT_PRESET="standard" ;;
@ -63,15 +62,15 @@ confirm_summary() {
echo -e " ${BOLD}Location${RESET} : $PROJECT_DIR"
echo -e " ${BOLD}Core${RESET} : $CS_CORE_DIR"
if [[ "${WORKFLOW_SOURCE:-}" == "Clone from existing repo" ]]; then
echo -e " ${BOLD}Workflow${RESET} : clone $WORKFLOW_REPO"
echo -e " ${BOLD}Workflow${RESET} : clone ${WORKFLOW_REPO:-}"
else
echo -e " ${BOLD}Workflow${RESET} : generate ($AGENT_PRESET preset)"
echo -e " ${BOLD}Workflow${RESET} : generate (${AGENT_PRESET:-minimal} preset)"
echo -e " ${BOLD}Description${RESET} : ${PROJECT_DESC:-}"
echo -e " ${BOLD}Tech stack${RESET} : ${TECH_STACK:-}"
fi
echo ""
ask_yn _ok "Create project?" "y"
[[ "$_ok" != "y" ]] && die "Aborted."
if [[ "$_ok" != "y" ]]; then die "Aborted."; fi
}
# ── Build ──────────────────────────────────────────────────────────────────
@ -82,15 +81,14 @@ build_project() {
create_devcontainer "$PROJECT_DIR" "$PROJECT_NAME"
if [[ "${WORKFLOW_SOURCE:-}" == "Clone from existing repo" ]]; then
clone_workflow "$PROJECT_DIR" "$WORKFLOW_REPO"
clone_workflow "$PROJECT_DIR" "${WORKFLOW_REPO:-}"
else
generate_workflow "$PROJECT_DIR" "$PROJECT_NAME" \
"${PROJECT_DESC:-A software project}" \
"${TECH_STACK:-Node.js}" \
"$AGENT_PRESET"
"${AGENT_PRESET:-minimal}"
fi
# Init git repo
git -C "$PROJECT_DIR" init -q
git -C "$PROJECT_DIR" add .
git -C "$PROJECT_DIR" commit -q -m "Initial project setup via Context Studio Wizard"