Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions ralph.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ PROGRESS_FILE="$SCRIPT_DIR/progress.txt"
ARCHIVE_DIR="$SCRIPT_DIR/archive"
LAST_BRANCH_FILE="$SCRIPT_DIR/.last-branch"


# Fail fast on malformed PRDs before starting the agent loop
if [ -f "$SCRIPT_DIR/validator_prd.sh" ]; then
"$SCRIPT_DIR/validator_prd.sh" "$PRD_FILE"
fi



# Archive previous run if branch changed
if [ -f "$PRD_FILE" ] && [ -f "$LAST_BRANCH_FILE" ]; then
CURRENT_BRANCH=$(jq -r '.branchName // empty' "$PRD_FILE" 2>/dev/null || echo "")
Expand Down
60 changes: 60 additions & 0 deletions scripts/validate_prd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
set -e

FILE=${1:-prd.json}

# Ensure PRD file exists
if [ ! -f "$FILE" ]; then
echo "✗ PRD file not found: $FILE"
exit 1
fi

# Ensure jq is available
if ! command -v jq >/dev/null 2>&1; then
echo "✗ jq is required but not installed"
exit 1
fi

# Fields that must exist on each user story
REQUIRED_FIELDS=("id" "title" "priority")
ERROR=0

echo "Validating PRD: $FILE"
echo "-------------------------"

# Ensure userStories exists and is an array
if ! jq -e '.userStories | type == "array"' "$FILE" >/dev/null; then
echo "✗ 'userStories' must be an array"
exit 1
fi

# Collect all user story IDs
IDS=$(jq -r '.userStories[].id' "$FILE")

# Check for duplicate IDs
DUP_IDS=$(echo "$IDS" | sort | uniq -d)
if [ -n "$DUP_IDS" ]; then
echo "✗ Duplicate userStory IDs:"
echo "$DUP_IDS"
ERROR=1
fi

# Validate each user story
COUNT=$(jq '.userStories | length' "$FILE")

for ((i=0; i<COUNT; i++)); do
for FIELD in "${REQUIRED_FIELDS[@]}"; do
EXISTS=$(jq ".userStories[$i] | has(\"$FIELD\")" "$FILE")
if [ "$EXISTS" != "true" ]; then
echo "✗ Missing field '$FIELD' in userStory index $i"
ERROR=1
fi
done
done

if [ "$ERROR" -eq 0 ]; then
echo "✓ PRD is valid"
else
echo "✗ PRD validation failed"
exit 1
fi