# RepoMirror Implementation Plan

## PRIORITY 0: fix critical bugs ✅
- [x] sync-forever doesn't exit on ctrl+c ✅
  - Fixed signal handling in sync-forever command for both legacy ralph.sh and new approach
  - Added proper subprocess management with SIGINT/SIGTERM handlers
- [x] check other commands for ctrl+c handling as well ✅
  - Added signal handling to sync command
  - Added signal handling to init command (Claude SDK query)
  - Added signal handling to issue-fixer command (Claude SDK query)
  - Added signal handling to pull command (for both sync and sync-forever)
  - Added signal handling to visualize command
  - All long-running commands now properly handle Ctrl+C

## Priority 1: Core Infrastructure ✅
- [x] Create implementation plan
- [x] Initialize npm project structure
- [x] Create basic CLI entry point

## Priority 2: Init Command ✅
- [x] Implement `npx repomirror init` command
- [x] Generate transformation prompt using Claude SDK
- [x] Perform preflight checks (git, claude, directories)
- [x] Create .repomirror/ directory with scripts
- [x] Ensure all preflight checks have verbose output
- [x] Ensure all prompts/cli flags are stashed to a repomirror.yaml during setup, and defaults are populated from the yaml file if present (instead of core defaults)
- [x] FIX CRITICAL BUG: `npx repomirror init` hangs in generateTransformationPrompt function
  - The Claude SDK async iterator needs proper handling to avoid infinite loops
  - Must break after receiving result (currently only breaks on non-error results)
  - Must handle ALL message types, not just "result" type
  - See updated spec.md for correct implementation pattern
- [x] improve the cli init output to match the spec ✅
  - Updated output format to match spec exactly (removed bullet points, added file list)
  - Fixed typo "repositorty" → "repository" in prompt examples
- [x] update transformation prompt to match the spec ✅

## Priority 3: Sync Commands ✅
- [x] Implement `sync` command to run sync.sh
- [x] Implement `sync-one` command (alias for sync)
- [x] Implement `sync-forever` command to run ralph.sh
- [x] Implement `visualize` command for output formatting

## Priority 4: Advanced Features
- [x] Add comprehensive tests for all commands ✅
- [x] Add remote repo support (push/pull) ✅
  - Implemented `remote` command for managing remote repositories
  - Implemented `push` command with auto-commit and multi-remote support
  - Implemented `pull` command with source sync integration
  - Enhanced sync commands with auto-push capabilities
- [x] Add validation script for init command ✅
  - Created `hack/ralph-validate.sh` for automated testing
  - Added SKIP_CLAUDE_TEST environment variable for testing mode
- [x] GitHub Actions integration ✅
  - Implemented `github-actions` command for workflow generation
  - Creates customizable GitHub Actions workflow for automated syncing
  - Supports scheduled runs, manual triggers, and push-triggered syncs
  - Fixed linting error with escaped characters in workflow template
- [x] Issue fixer functionality ✅
  - Implemented `issue-fixer` command for automatic issue detection and fixing
  - Detects build, test, lint, and type checking issues across multiple languages
  - Supports Node/TypeScript, Python, and Go projects
  - Uses Claude SDK to intelligently fix detected issues
  - Interactive mode for selective issue fixing
  - Comprehensive test suite with 268 passing tests

## Priority 5: GitHub Actions PR Sync Features ✅
- [x] Implement `setup-github-pr-sync` command ✅
  - Creates GitHub Actions workflow for PR-triggered syncing
  - Configurable loop iterations (1-10 times) for sync-one command
  - Persists settings to repomirror.yaml for future use
  - Overwrite protection with user confirmation
  - Creates `.github/workflows/repomirror.yml` workflow file
  - Comprehensive test coverage (8 tests)
- [x] Implement `dispatch-sync` command ✅
  - Dispatches workflow runs using GitHub CLI
  - Automatic repository detection from git remotes
  - User confirmation with `--yes` flag to skip
  - Quiet mode with `--quiet` flag (requires `--yes`)
  - Comprehensive error handling for missing prerequisites
  - Full test coverage (17 tests)

## Current Status
✅ **FULLY IMPLEMENTED** - All planned features completed successfully:
- All CLI commands implemented and working
- Init command creates proper .repomirror/ structure
- Sync commands execute shell scripts correctly
- Visualize command provides colored output
- Remote repository management (add/list/remove remotes)
- Push command with intelligent commit messages and multi-remote support
- Pull command with auto-sync integration
- Auto-push capability after sync operations
- Validation script for testing init command functionality
- Test mode support with SKIP_CLAUDE_TEST environment variable
- GitHub Actions workflow generation for CI/CD
- Issue fixer command for automatic issue detection and resolution
- GitHub Actions PR sync commands (`setup-github-pr-sync` and `dispatch-sync`)
- Comprehensive test suite with 293 tests passing (2 skipped for interactive mode)
- TypeScript build passing with full type safety
- All linting checks passing
- **Ready for production usage with complete feature set**

## Known Issues & Critical Fixes Needed

### 1. Init Command Hangs (CRITICAL) - FIXED ✅
**Problem**: The `repomirror init` command was hanging forever during prompt generation.
**Root Cause**: The `generateTransformationPrompt` function (src/commands/init.ts:256-318) was using an async iterator incorrectly, not handling error cases properly.

**Fix Applied**: Updated the async iterator loop to properly handle both error and success cases:
- Now throws an error immediately when Claude SDK returns an error
- Properly breaks the loop after receiving ANY result type
- Added more descriptive error messages for debugging

**Testing Completed**:
- All 230 tests passing (comprehensive test coverage added)
- TypeScript build successful
- Ready for production use

## Testing Instructions

For testing the init command without calling Claude SDK:
- Set `SKIP_CLAUDE_TEST=true` environment variable
- This will skip the Claude Code preflight check and use a test prompt template
- The validation script `hack/ralph-validate.sh` uses this flag for automated testing
