From 567bdd2e2c3aa1ef25a1a58fb6ecb6af7e6e11cb Mon Sep 17 00:00:00 2001 From: Lex Christopherson Date: Fri, 16 Jan 2026 22:17:51 -0600 Subject: [PATCH] fix: normalize phase input at command entry points Commands accept both padded (08) and unpadded (8) phase numbers. Normalization happens in step 1/2 before any directory lookups. Co-Authored-By: Claude Opus 4.5 --- agents/gsd-plan-checker.md | 5 +++-- commands/gsd/plan-phase.md | 39 ++++++++++++++++++++++------------ commands/gsd/research-phase.md | 20 +++++++++++------ 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/agents/gsd-plan-checker.md b/agents/gsd-plan-checker.md index 1e5f45ca0..a180947a3 100644 --- a/agents/gsd-plan-checker.md +++ b/agents/gsd-plan-checker.md @@ -244,8 +244,9 @@ issue: Gather verification context from the phase directory and project state. ```bash -# Phase directory (provided in prompt) -PHASE_DIR=".planning/phases/${PHASE_ARG}" +# Normalize phase and find directory +PADDED_PHASE=$(printf "%02d" ${PHASE_ARG} 2>/dev/null || echo "${PHASE_ARG}") +PHASE_DIR=$(ls -d .planning/phases/${PADDED_PHASE}-* .planning/phases/${PHASE_ARG}-* 2>/dev/null | head -1) # List all PLAN.md files ls "$PHASE_DIR"/*-PLAN.md 2>/dev/null diff --git a/commands/gsd/plan-phase.md b/commands/gsd/plan-phase.md index 1e5e21a68..44f8df162 100644 --- a/commands/gsd/plan-phase.md +++ b/commands/gsd/plan-phase.md @@ -37,13 +37,7 @@ Phase number: $ARGUMENTS (optional - auto-detects next unplanned phase if not pr - `--gaps` — Gap closure mode (reads VERIFICATION.md, skips research) - `--skip-verify` — Skip planner → checker verification loop -Check for existing research and plans: - -```bash -ls .planning/phases/${PHASE}-*/*-RESEARCH.md 2>/dev/null -ls .planning/phases/${PHASE}-*/*-PLAN.md 2>/dev/null -``` - +Normalize phase input in step 2 before any directory lookups. @@ -56,7 +50,7 @@ ls .planning/ 2>/dev/null **If not found:** Error - user should run `/gsd:new-project` first. -## 2. Parse Arguments +## 2. Parse and Normalize Arguments Extract from $ARGUMENTS: @@ -68,6 +62,24 @@ Extract from $ARGUMENTS: **If no phase number:** Detect next unplanned phase from roadmap. +**Normalize phase to zero-padded format:** + +```bash +# Normalize phase number (8 → 08, but preserve decimals like 2.1 → 02.1) +if [[ "$PHASE" =~ ^[0-9]+$ ]]; then + PHASE=$(printf "%02d" "$PHASE") +elif [[ "$PHASE" =~ ^([0-9]+)\.([0-9]+)$ ]]; then + PHASE=$(printf "%02d.%s" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}") +fi +``` + +**Check for existing research and plans:** + +```bash +ls .planning/phases/${PHASE}-*/*-RESEARCH.md 2>/dev/null +ls .planning/phases/${PHASE}-*/*-PLAN.md 2>/dev/null +``` + ## 3. Validate Phase ```bash @@ -79,14 +91,13 @@ grep -A5 "Phase ${PHASE}:" .planning/ROADMAP.md 2>/dev/null ## 4. Ensure Phase Directory Exists ```bash -# Match both zero-padded (05-*) and unpadded (5-*) folders -PADDED_PHASE=$(printf "%02d" ${PHASE}) -PHASE_DIR=$(ls -d .planning/phases/${PADDED_PHASE}-* .planning/phases/${PHASE}-* 2>/dev/null | head -1) +# PHASE is already normalized (08, 02.1, etc.) from step 2 +PHASE_DIR=$(ls -d .planning/phases/${PHASE}-* 2>/dev/null | head -1) if [ -z "$PHASE_DIR" ]; then - # Create phase directory from roadmap name with zero-padded phase number + # Create phase directory from roadmap name PHASE_NAME=$(grep "Phase ${PHASE}:" .planning/ROADMAP.md | sed 's/.*Phase [0-9]*: //' | tr '[:upper:]' '[:lower:]' | tr ' ' '-') - mkdir -p ".planning/phases/${PADDED_PHASE}-${PHASE_NAME}" - PHASE_DIR=".planning/phases/${PADDED_PHASE}-${PHASE_NAME}" + mkdir -p ".planning/phases/${PHASE}-${PHASE_NAME}" + PHASE_DIR=".planning/phases/${PHASE}-${PHASE_NAME}" fi ``` diff --git a/commands/gsd/research-phase.md b/commands/gsd/research-phase.md index 3920262c3..41b1a8670 100644 --- a/commands/gsd/research-phase.md +++ b/commands/gsd/research-phase.md @@ -26,17 +26,23 @@ Research how to implement a phase. Spawns gsd-phase-researcher agent with phase Phase number: $ARGUMENTS (required) -Check for existing research: -```bash -ls .planning/phases/${PHASE}-*/*RESEARCH.md 2>/dev/null -``` +Normalize phase input in step 1 before any directory lookups. -## 1. Parse and Validate Phase +## 1. Normalize and Validate Phase ```bash +# Normalize phase number (8 → 08, but preserve decimals like 2.1 → 02.1) +if [[ "$ARGUMENTS" =~ ^[0-9]+$ ]]; then + PHASE=$(printf "%02d" "$ARGUMENTS") +elif [[ "$ARGUMENTS" =~ ^([0-9]+)\.([0-9]+)$ ]]; then + PHASE=$(printf "%02d.%s" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}") +else + PHASE="$ARGUMENTS" +fi + grep -A5 "Phase ${PHASE}:" .planning/ROADMAP.md 2>/dev/null ``` @@ -118,7 +124,7 @@ Before declaring complete, verify: -Write to: .planning/phases/{phase}-{slug}/{phase}-RESEARCH.md +Write to: .planning/phases/${PHASE}-{slug}/${PHASE}-RESEARCH.md ``` @@ -146,7 +152,7 @@ Continue research for Phase {phase_number}: {phase_name} -Research file: @.planning/phases/{phase}-{slug}/{phase}-RESEARCH.md +Research file: @.planning/phases/${PHASE}-{slug}/${PHASE}-RESEARCH.md