Skip to content

[Feature] Add ralph-init command for existing projects #121

@paulodearaujo

Description

@paulodearaujo

Summary

Add a new ralph-init command (or extend ralph-setup) to initialize Ralph in an existing project directory without creating a new folder or running git init.

Problem Statement

Currently, both ralph-setup and ralph-import always create a new project directory:

# ralph-setup always creates new folder
mkdir -p "$PROJECT_NAME"
cd "$PROJECT_NAME"
git init  # Dangerous for existing repos!

# ralph-import does the same
ralph-setup "$project_name"
cd "$project_name"

Users with existing projects have no native way to add Ralph. The current workaround is cumbersome:

# Workaround: create temp project and copy .ralph/ folder
ralph-import my-project/prd.md temp-ralph
cp -r temp-ralph/.ralph my-project/
rm -rf temp-ralph

This is a highly requested feature - see issue #85 with 8+ users asking for this capability.

Proposed CLI Interface

# Initialize Ralph in current directory (no new folder, no git init)
cd my-existing-project
ralph-init

# Initialize with PRD conversion
ralph-init --from prd.md

# Initialize in specific directory
ralph-init --dir /path/to/existing/project

# Force overwrite existing .ralph/ folder
ralph-init --force

Expected Behavior

Command Creates folder? Runs git init? Converts PRD?
ralph-setup project Yes Yes No
ralph-import prd.md project Yes Yes Yes
ralph-init No No No
ralph-init --from prd.md No No Yes

Implementation Approach

  1. Create new ralph_init.sh script
  2. Add safety checks:
    • Warn if .ralph/ already exists (require --force to overwrite)
    • Detect if directory is a git repo (skip git init)
    • Verify templates directory exists
  3. Create only .ralph/ structure without touching project root
  4. Optionally run PRD conversion with --from flag
  5. Add ralph-init to install.sh for global availability
  6. Update documentation

Proposed Implementation

#!/bin/bash
# ralph_init.sh - Initialize Ralph in existing project

set -e

TARGET_DIR="${1:-.}"
PRD_FILE=""
FORCE=false

# Parse arguments
while [[ $# -gt 0 ]]; do
    case $1 in
        --from) PRD_FILE="$2"; shift 2 ;;
        --dir) TARGET_DIR="$2"; shift 2 ;;
        --force) FORCE=true; shift ;;
        *) shift ;;
    esac
done

cd "$TARGET_DIR"

# Safety check
if [[ -d ".ralph" && "$FORCE" != "true" ]]; then
    echo "Error: .ralph/ already exists. Use --force to overwrite."
    exit 1
fi

# Create .ralph structure (no git init!)
mkdir -p .ralph/{specs/stdlib,examples,logs,docs/generated}

# Copy templates
cp "$TEMPLATES_DIR/PROMPT.md" .ralph/
cp "$TEMPLATES_DIR/fix_plan.md" .ralph/@fix_plan.md
cp "$TEMPLATES_DIR/AGENT.md" .ralph/@AGENT.md

# Optional PRD conversion
if [[ -n "$PRD_FILE" ]]; then
    # Run conversion logic from ralph_import.sh
    convert_prd "$PRD_FILE"
fi

echo "✅ Ralph initialized in $(pwd)"

Acceptance Criteria

  • ralph-init creates .ralph/ structure in current directory
  • Does NOT create new project folder
  • Does NOT run git init (respects existing repos)
  • --from prd.md converts PRD using Claude Code
  • --dir path allows specifying target directory
  • --force overwrites existing .ralph/ folder
  • Warns if .ralph/ already exists without --force
  • Added to install.sh for global installation
  • Documentation updated in README.md
  • Tests added for new command

Related Issues

Notes

This would significantly improve Ralph's adoption for users with existing codebases, which is likely the majority of real-world use cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions