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 <noreply@anthropic.com>
This commit is contained in:
Lex Christopherson
2026-01-16 22:17:51 -06:00
parent 3d9449cd25
commit 567bdd2e2c
3 changed files with 41 additions and 23 deletions

View File

@@ -244,8 +244,9 @@ issue:
Gather verification context from the phase directory and project state. Gather verification context from the phase directory and project state.
```bash ```bash
# Phase directory (provided in prompt) # Normalize phase and find directory
PHASE_DIR=".planning/phases/${PHASE_ARG}" 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 # List all PLAN.md files
ls "$PHASE_DIR"/*-PLAN.md 2>/dev/null ls "$PHASE_DIR"/*-PLAN.md 2>/dev/null

View File

@@ -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) - `--gaps` — Gap closure mode (reads VERIFICATION.md, skips research)
- `--skip-verify` — Skip planner → checker verification loop - `--skip-verify` — Skip planner → checker verification loop
Check for existing research and plans: Normalize phase input in step 2 before any directory lookups.
```bash
ls .planning/phases/${PHASE}-*/*-RESEARCH.md 2>/dev/null
ls .planning/phases/${PHASE}-*/*-PLAN.md 2>/dev/null
```
</context> </context>
<process> <process>
@@ -56,7 +50,7 @@ ls .planning/ 2>/dev/null
**If not found:** Error - user should run `/gsd:new-project` first. **If not found:** Error - user should run `/gsd:new-project` first.
## 2. Parse Arguments ## 2. Parse and Normalize Arguments
Extract from $ARGUMENTS: Extract from $ARGUMENTS:
@@ -68,6 +62,24 @@ Extract from $ARGUMENTS:
**If no phase number:** Detect next unplanned phase from roadmap. **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 ## 3. Validate Phase
```bash ```bash
@@ -79,14 +91,13 @@ grep -A5 "Phase ${PHASE}:" .planning/ROADMAP.md 2>/dev/null
## 4. Ensure Phase Directory Exists ## 4. Ensure Phase Directory Exists
```bash ```bash
# Match both zero-padded (05-*) and unpadded (5-*) folders # PHASE is already normalized (08, 02.1, etc.) from step 2
PADDED_PHASE=$(printf "%02d" ${PHASE}) PHASE_DIR=$(ls -d .planning/phases/${PHASE}-* 2>/dev/null | head -1)
PHASE_DIR=$(ls -d .planning/phases/${PADDED_PHASE}-* .planning/phases/${PHASE}-* 2>/dev/null | head -1)
if [ -z "$PHASE_DIR" ]; then 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 ' ' '-') 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}" mkdir -p ".planning/phases/${PHASE}-${PHASE_NAME}"
PHASE_DIR=".planning/phases/${PADDED_PHASE}-${PHASE_NAME}" PHASE_DIR=".planning/phases/${PHASE}-${PHASE_NAME}"
fi fi
``` ```

View File

@@ -26,17 +26,23 @@ Research how to implement a phase. Spawns gsd-phase-researcher agent with phase
<context> <context>
Phase number: $ARGUMENTS (required) Phase number: $ARGUMENTS (required)
Check for existing research: Normalize phase input in step 1 before any directory lookups.
```bash
ls .planning/phases/${PHASE}-*/*RESEARCH.md 2>/dev/null
```
</context> </context>
<process> <process>
## 1. Parse and Validate Phase ## 1. Normalize and Validate Phase
```bash ```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 grep -A5 "Phase ${PHASE}:" .planning/ROADMAP.md 2>/dev/null
``` ```
@@ -118,7 +124,7 @@ Before declaring complete, verify:
</quality_gate> </quality_gate>
<output> <output>
Write to: .planning/phases/{phase}-{slug}/{phase}-RESEARCH.md Write to: .planning/phases/${PHASE}-{slug}/${PHASE}-RESEARCH.md
</output> </output>
``` ```
@@ -146,7 +152,7 @@ Continue research for Phase {phase_number}: {phase_name}
</objective> </objective>
<prior_state> <prior_state>
Research file: @.planning/phases/{phase}-{slug}/{phase}-RESEARCH.md Research file: @.planning/phases/${PHASE}-{slug}/${PHASE}-RESEARCH.md
</prior_state> </prior_state>
<checkpoint_response> <checkpoint_response>