bmalph 2.2.1 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +162 -48
  2. package/dist/cli.js +14 -0
  3. package/dist/commands/doctor.d.ts +14 -2
  4. package/dist/commands/doctor.js +105 -41
  5. package/dist/commands/implement.d.ts +6 -0
  6. package/dist/commands/implement.js +82 -0
  7. package/dist/commands/init.d.ts +1 -0
  8. package/dist/commands/init.js +74 -7
  9. package/dist/commands/reset.d.ts +7 -0
  10. package/dist/commands/reset.js +81 -0
  11. package/dist/commands/status.js +86 -10
  12. package/dist/commands/upgrade.js +8 -5
  13. package/dist/installer.d.ts +15 -4
  14. package/dist/installer.js +190 -101
  15. package/dist/platform/aider.d.ts +2 -0
  16. package/dist/platform/aider.js +71 -0
  17. package/dist/platform/claude-code.d.ts +2 -0
  18. package/dist/platform/claude-code.js +87 -0
  19. package/dist/platform/codex.d.ts +2 -0
  20. package/dist/platform/codex.js +67 -0
  21. package/dist/platform/copilot.d.ts +2 -0
  22. package/dist/platform/copilot.js +71 -0
  23. package/dist/platform/cursor.d.ts +2 -0
  24. package/dist/platform/cursor.js +71 -0
  25. package/dist/platform/detect.d.ts +7 -0
  26. package/dist/platform/detect.js +23 -0
  27. package/dist/platform/index.d.ts +4 -0
  28. package/dist/platform/index.js +3 -0
  29. package/dist/platform/registry.d.ts +4 -0
  30. package/dist/platform/registry.js +27 -0
  31. package/dist/platform/resolve.d.ts +8 -0
  32. package/dist/platform/resolve.js +24 -0
  33. package/dist/platform/types.d.ts +41 -0
  34. package/dist/platform/types.js +7 -0
  35. package/dist/platform/windsurf.d.ts +2 -0
  36. package/dist/platform/windsurf.js +71 -0
  37. package/dist/reset.d.ts +18 -0
  38. package/dist/reset.js +181 -0
  39. package/dist/transition/artifact-scan.d.ts +27 -0
  40. package/dist/transition/artifact-scan.js +91 -0
  41. package/dist/transition/artifacts.d.ts +1 -0
  42. package/dist/transition/artifacts.js +2 -1
  43. package/dist/transition/context.js +34 -0
  44. package/dist/transition/fix-plan.d.ts +8 -2
  45. package/dist/transition/fix-plan.js +33 -7
  46. package/dist/transition/orchestration.d.ts +2 -2
  47. package/dist/transition/orchestration.js +120 -41
  48. package/dist/transition/preflight.d.ts +6 -0
  49. package/dist/transition/preflight.js +154 -0
  50. package/dist/transition/specs-changelog.js +4 -1
  51. package/dist/transition/specs-index.d.ts +1 -1
  52. package/dist/transition/specs-index.js +24 -1
  53. package/dist/transition/types.d.ts +23 -1
  54. package/dist/utils/config.d.ts +2 -0
  55. package/dist/utils/dryrun.d.ts +1 -1
  56. package/dist/utils/dryrun.js +22 -0
  57. package/dist/utils/validate.js +18 -2
  58. package/package.json +1 -1
  59. package/ralph/drivers/claude-code.sh +118 -0
  60. package/ralph/drivers/codex.sh +81 -0
  61. package/ralph/ralph_import.sh +11 -0
  62. package/ralph/ralph_loop.sh +52 -64
  63. package/ralph/templates/ralphrc.template +7 -0
  64. package/slash-commands/bmalph-doctor.md +16 -0
  65. package/slash-commands/bmalph-implement.md +18 -141
  66. package/slash-commands/bmalph-status.md +15 -0
  67. package/slash-commands/bmalph-upgrade.md +15 -0
@@ -66,7 +66,8 @@ RALPH_SESSION_HISTORY_FILE="$RALPH_DIR/.ralph_session_history" # Session transi
66
66
  CLAUDE_SESSION_EXPIRY_HOURS=${CLAUDE_SESSION_EXPIRY_HOURS:-24}
67
67
 
68
68
  # Valid tool patterns for --allowed-tools validation
69
- # Tools can be exact matches or pattern matches with wildcards in parentheses
69
+ # Default: Claude Code tools. Platform driver overwrites via driver_valid_tools() in main().
70
+ # Validation runs in main() after load_platform_driver so the correct patterns are in effect.
70
71
  VALID_TOOL_PATTERNS=(
71
72
  "Write"
72
73
  "Read"
@@ -98,6 +99,9 @@ TEST_PERCENTAGE_THRESHOLD=30 # If more than 30% of recent loops are test-only,
98
99
  RALPHRC_FILE=".ralphrc"
99
100
  RALPHRC_LOADED=false
100
101
 
102
+ # Platform driver (set from .ralphrc or environment)
103
+ PLATFORM_DRIVER="${PLATFORM_DRIVER:-claude-code}"
104
+
101
105
  # load_ralphrc - Load project-specific configuration from .ralphrc
102
106
  #
103
107
  # This function sources .ralphrc if it exists, applying project-specific
@@ -155,6 +159,26 @@ load_ralphrc() {
155
159
  return 0
156
160
  }
157
161
 
162
+ # Source platform driver
163
+ load_platform_driver() {
164
+ local driver_file="$SCRIPT_DIR/drivers/${PLATFORM_DRIVER}.sh"
165
+ if [[ ! -f "$driver_file" ]]; then
166
+ log_status "ERROR" "Platform driver not found: $driver_file"
167
+ log_status "ERROR" "Available drivers: $(ls "$SCRIPT_DIR/drivers/"*.sh 2>/dev/null | xargs -n1 basename | sed 's/.sh$//' | tr '\n' ' ')"
168
+ exit 1
169
+ fi
170
+ # shellcheck source=/dev/null
171
+ source "$driver_file"
172
+
173
+ # Initialize driver-specific tool patterns
174
+ driver_valid_tools
175
+
176
+ # Set CLI binary from driver
177
+ CLAUDE_CODE_CMD="$(driver_cli_binary)"
178
+
179
+ log_status "INFO" "Platform driver: $(driver_display_name) ($(driver_cli_binary))"
180
+ }
181
+
158
182
  # Colors for terminal output
159
183
  RED='\033[0;31m'
160
184
  GREEN='\033[0;32m'
@@ -949,68 +973,11 @@ update_session_last_used() {
949
973
  # Global array for Claude command arguments (avoids shell injection)
950
974
  declare -a CLAUDE_CMD_ARGS=()
951
975
 
952
- # Build Claude CLI command with modern flags using array (shell-injection safe)
976
+ # Build CLI command with platform driver (shell-injection safe)
977
+ # Delegates to the active platform driver's driver_build_command()
953
978
  # Populates global CLAUDE_CMD_ARGS array for direct execution
954
- # Uses -p flag with prompt content (Claude CLI does not have --prompt-file)
955
979
  build_claude_command() {
956
- local prompt_file=$1
957
- local loop_context=$2
958
- local session_id=$3
959
-
960
- # Reset global array
961
- # Note: We do NOT use --dangerously-skip-permissions here. Tool permissions
962
- # are controlled via --allowedTools from CLAUDE_ALLOWED_TOOLS in .ralphrc.
963
- # This preserves the permission denial circuit breaker (Issue #101).
964
- CLAUDE_CMD_ARGS=("$CLAUDE_CODE_CMD")
965
-
966
- # Check if prompt file exists
967
- if [[ ! -f "$prompt_file" ]]; then
968
- log_status "ERROR" "Prompt file not found: $prompt_file"
969
- return 1
970
- fi
971
-
972
- # Add output format flag
973
- if [[ "$CLAUDE_OUTPUT_FORMAT" == "json" ]]; then
974
- CLAUDE_CMD_ARGS+=("--output-format" "json")
975
- fi
976
-
977
- # Add allowed tools (each tool as separate array element)
978
- if [[ -n "$CLAUDE_ALLOWED_TOOLS" ]]; then
979
- CLAUDE_CMD_ARGS+=("--allowedTools")
980
- # Split by comma and add each tool
981
- local IFS=','
982
- read -ra tools_array <<< "$CLAUDE_ALLOWED_TOOLS"
983
- for tool in "${tools_array[@]}"; do
984
- # Trim whitespace
985
- tool=$(echo "$tool" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
986
- if [[ -n "$tool" ]]; then
987
- CLAUDE_CMD_ARGS+=("$tool")
988
- fi
989
- done
990
- fi
991
-
992
- # Add session continuity flag
993
- # IMPORTANT: Use --resume with explicit session ID instead of --continue
994
- # --continue resumes the "most recent session in current directory" which
995
- # can hijack active Claude Code sessions. --resume with a specific session ID
996
- # ensures we only resume Ralph's own sessions. (Issue #151)
997
- if [[ "$CLAUDE_USE_CONTINUE" == "true" && -n "$session_id" ]]; then
998
- CLAUDE_CMD_ARGS+=("--resume" "$session_id")
999
- fi
1000
- # If no session_id, start fresh - Claude will generate a new session ID
1001
- # which we'll capture via save_claude_session() for future loops
1002
-
1003
- # Add loop context as system prompt (no escaping needed - array handles it)
1004
- if [[ -n "$loop_context" ]]; then
1005
- CLAUDE_CMD_ARGS+=("--append-system-prompt" "$loop_context")
1006
- fi
1007
-
1008
- # Read prompt file content and use -p flag
1009
- # Note: Claude CLI uses -p for prompts, not --prompt-file (which doesn't exist)
1010
- # Array-based approach maintains shell injection safety
1011
- local prompt_content
1012
- prompt_content=$(cat "$prompt_file")
1013
- CLAUDE_CMD_ARGS+=("-p" "$prompt_content")
980
+ driver_build_command "$@"
1014
981
  }
1015
982
 
1016
983
  # Main execution function
@@ -1418,6 +1385,14 @@ main() {
1418
1385
  fi
1419
1386
  fi
1420
1387
 
1388
+ # Load platform driver (after .ralphrc so PLATFORM_DRIVER can be overridden)
1389
+ load_platform_driver
1390
+
1391
+ # Validate --allowed-tools now that platform-specific VALID_TOOL_PATTERNS are loaded
1392
+ if [[ "${_CLI_ALLOWED_TOOLS:-}" == "true" ]] && ! validate_allowed_tools "$CLAUDE_ALLOWED_TOOLS"; then
1393
+ exit 1
1394
+ fi
1395
+
1421
1396
  log_status "SUCCESS" "🚀 Ralph loop starting with Claude Code"
1422
1397
  log_status "INFO" "Max calls per hour: $MAX_CALLS_PER_HOUR"
1423
1398
  log_status "INFO" "Logs: $LOG_DIR/ | Docs: $DOCS_DIR/ | Status: $STATUS_FILE"
@@ -1461,6 +1436,21 @@ main() {
1461
1436
  exit 1
1462
1437
  fi
1463
1438
 
1439
+ # Check required dependencies
1440
+ if ! command -v jq &> /dev/null; then
1441
+ log_status "ERROR" "Required dependency 'jq' is not installed."
1442
+ echo ""
1443
+ echo "jq is required for JSON processing in the Ralph loop."
1444
+ echo ""
1445
+ echo "Install jq:"
1446
+ echo " macOS: brew install jq"
1447
+ echo " Ubuntu: sudo apt-get install jq"
1448
+ echo " Windows: choco install jq (or: winget install jqlang.jq)"
1449
+ echo ""
1450
+ echo "After installing, run this command again."
1451
+ exit 1
1452
+ fi
1453
+
1464
1454
  # Initialize session tracking before entering the loop
1465
1455
  init_session_tracking
1466
1456
 
@@ -1750,10 +1740,8 @@ while [[ $# -gt 0 ]]; do
1750
1740
  shift 2
1751
1741
  ;;
1752
1742
  --allowed-tools)
1753
- if ! validate_allowed_tools "$2"; then
1754
- exit 1
1755
- fi
1756
1743
  CLAUDE_ALLOWED_TOOLS="$2"
1744
+ _CLI_ALLOWED_TOOLS=true
1757
1745
  shift 2
1758
1746
  ;;
1759
1747
  --no-continue)
@@ -6,6 +6,13 @@
6
6
  # Values here override global Ralph defaults.
7
7
  # Environment variables override values in this file.
8
8
 
9
+ # =============================================================================
10
+ # PLATFORM DRIVER
11
+ # =============================================================================
12
+
13
+ # Platform driver for Ralph loop (claude-code or codex)
14
+ PLATFORM_DRIVER="${PLATFORM_DRIVER:-claude-code}"
15
+
9
16
  # =============================================================================
10
17
  # PROJECT IDENTIFICATION
11
18
  # =============================================================================
@@ -0,0 +1,16 @@
1
+ # Check Project Health
2
+
3
+ Run diagnostic checks on the bmalph installation and report any issues.
4
+
5
+ ## How to Run
6
+
7
+ Execute the CLI command:
8
+ bmalph doctor
9
+
10
+ ## What It Does
11
+
12
+ - Verifies required directories exist (`_bmad/`, `.ralph/`, `bmalph/`)
13
+ - Checks that slash commands are installed correctly
14
+ - Validates the instructions file contains the BMAD snippet
15
+ - Reports version mismatches between installed and bundled assets
16
+ - Suggests remediation steps for any issues found
@@ -2,151 +2,28 @@
2
2
 
3
3
  Transition from BMAD planning (Phase 3) to Ralph implementation (Phase 4).
4
4
 
5
- ## Prerequisites
5
+ ## How to Run
6
6
 
7
- - bmalph must be initialized (`bmalph/config.json` must exist)
8
- - Stories must exist in `_bmad-output/planning-artifacts/`
7
+ Execute the CLI command:
8
+ bmalph implement
9
9
 
10
- ## Steps
10
+ If pre-flight validation fails and you want to proceed anyway:
11
+ bmalph implement --force
11
12
 
12
- ### 1. Validate Prerequisites
13
+ ## What It Does
13
14
 
14
- Check that:
15
- - `bmalph/config.json` exists
16
- - `.ralph/ralph_loop.sh` exists
17
- - `_bmad-output/planning-artifacts/` exists with story files
15
+ - Validates planning artifacts (PRD, architecture, readiness report)
16
+ - Parses epics and stories into `.ralph/@fix_plan.md`
17
+ - Copies specs to `.ralph/specs/`
18
+ - Generates PROJECT_CONTEXT.md, PROMPT.md, SPECS_INDEX.md
19
+ - Customizes @AGENT.md based on detected tech stack
20
+ - Updates phase state to 4 (implementing)
18
21
 
19
- If any are missing, report the error and suggest running the required commands.
22
+ ## After Running
20
23
 
21
- ### 2. Parse Stories
24
+ Review the CLI output for:
25
+ - **Pre-flight warnings**: Address any issues or acknowledge them
26
+ - **Story count**: Verify all expected stories were parsed
27
+ - **Driver instructions**: Follow the displayed command to start the Ralph loop
22
28
 
23
- Read `_bmad-output/planning-artifacts/stories.md` (or any file matching `*stor*.md` or `*epic*.md`):
24
- - Extract epics: `## Epic N: Title`
25
- - Extract stories: `### Story N.M: Title`
26
- - Parse acceptance criteria (Given/When/Then blocks)
27
-
28
- ### 3. Generate `.ralph/@fix_plan.md`
29
-
30
- Create an ordered list of stories as checkboxes:
31
-
32
- ```markdown
33
- # Ralph Fix Plan
34
-
35
- ## Stories to Implement
36
-
37
- ### [Epic Title]
38
- > Goal: [Epic description]
39
-
40
- - [ ] Story 1.1: [Title]
41
- > [Description line 1]
42
- > AC: Given..., When..., Then...
43
-
44
- ## Completed
45
-
46
- ## Notes
47
- - Follow TDD methodology (red-green-refactor)
48
- - One story per Ralph loop iteration
49
- - Update this file after completing each story
50
- ```
51
-
52
- **Important:** If existing `@fix_plan.md` has completed items `[x]`, preserve their completion status in the new file.
53
-
54
- ### 4. Generate `.ralph/PROJECT_CONTEXT.md`
55
-
56
- Extract from planning artifacts:
57
- - Project goals from PRD (Executive Summary, Vision, Goals sections)
58
- - Success metrics from PRD
59
- - Architecture constraints from architecture document
60
- - Technical risks from architecture document
61
- - Scope boundaries from PRD
62
- - Target users from PRD
63
- - Non-functional requirements from PRD
64
-
65
- Format as:
66
-
67
- ```markdown
68
- # [Project Name] — Project Context
69
-
70
- ## Project Goals
71
- [extracted content]
72
-
73
- ## Success Metrics
74
- [extracted content]
75
-
76
- ## Architecture Constraints
77
- [extracted content]
78
-
79
- ## Technical Risks
80
- [extracted content]
81
-
82
- ## Scope Boundaries
83
- [extracted content]
84
-
85
- ## Target Users
86
- [extracted content]
87
-
88
- ## Non-Functional Requirements
89
- [extracted content]
90
- ```
91
-
92
- ### 5. Copy Specs to `.ralph/specs/`
93
-
94
- Copy the entire `_bmad-output/` tree to `.ralph/specs/`:
95
- - This includes `planning-artifacts/`, `implementation-artifacts/`, etc.
96
- - Preserve directory structure
97
-
98
- If specs existed before, generate `SPECS_CHANGELOG.md`:
99
- ```markdown
100
- # Specs Changelog
101
-
102
- Last updated: [timestamp]
103
-
104
- ## Added
105
- - [new files]
106
-
107
- ## Modified
108
- - [changed files]
109
-
110
- ## Removed
111
- - [deleted files]
112
- ```
113
-
114
- ### 6. Update State
115
-
116
- Update `bmalph/state/current-phase.json`:
117
- ```json
118
- {
119
- "currentPhase": 4,
120
- "status": "implementing",
121
- "startedAt": "[original or now]",
122
- "lastUpdated": "[now]"
123
- }
124
- ```
125
-
126
- ### 7. Report Results
127
-
128
- Output:
129
- - Number of stories found
130
- - Any warnings (missing PRD, architecture, NO-GO status in readiness report)
131
- - Whether fix_plan progress was preserved
132
-
133
- ### 8. Instruct User
134
-
135
- Display:
136
-
137
- ```
138
- Transition complete. To start the Ralph autonomous loop:
139
-
140
- bash .ralph/ralph_loop.sh
141
-
142
- Or in a separate terminal for background execution:
143
-
144
- nohup bash .ralph/ralph_loop.sh > .ralph/logs/ralph.log 2>&1 &
145
- ```
146
-
147
- ## Warnings to Check
148
-
149
- - No PRD document found
150
- - No architecture document found
151
- - Readiness report indicates NO-GO status
152
- - No stories parsed from the epics file
29
+ If there are errors, fix the underlying planning artifacts and re-run.
@@ -0,0 +1,15 @@
1
+ # Project Status
2
+
3
+ Show the current bmalph project status, including phase, Ralph progress, and version info.
4
+
5
+ ## How to Run
6
+
7
+ Execute the CLI command:
8
+ bmalph status
9
+
10
+ ## What It Does
11
+
12
+ - Shows current phase (1-4) and status (planning, implementing, completed)
13
+ - Displays Ralph loop progress (tasks completed / total)
14
+ - Reports installed bmalph version and bundled asset versions
15
+ - Indicates whether updates are available
@@ -0,0 +1,15 @@
1
+ # Upgrade Bundled Assets
2
+
3
+ Update BMAD and Ralph assets to match the currently installed bmalph version.
4
+
5
+ ## How to Run
6
+
7
+ Execute the CLI command:
8
+ bmalph upgrade
9
+
10
+ ## What It Does
11
+
12
+ - Overwrites `_bmad/` with the latest bundled BMAD agents and workflows
13
+ - Overwrites `.ralph/` base files with the latest bundled Ralph loop and libraries
14
+ - Preserves project-specific state (config, fix plan progress, specs)
15
+ - Reports which files were updated