Skip to content

Commit f476022

Browse files
authored
Merge pull request #47 from frankbria/feature/phase-1.1-modern-cli-commands
[P1] feat(cli): add modern CLI commands with JSON output support (Phase 1.1)
2 parents aab6d90 + c7c6c93 commit f476022

7 files changed

Lines changed: 2249 additions & 147 deletions

File tree

CLAUDE.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ The system uses a modular architecture with reusable components in the `lib/` di
3030

3131
2. **lib/response_analyzer.sh** - Intelligent response analysis
3232
- Analyzes Claude Code output for completion signals
33+
- **JSON output format detection and parsing** (with text fallback)
34+
- Extracts structured fields: status, exit_signal, work_type, files_modified
3335
- Detects test-only loops and stuck error patterns
3436
- Two-stage error filtering to eliminate false positives
3537
- Multi-line error matching for accurate stuck loop detection
3638
- Confidence scoring for exit decisions
3739

40+
3. **lib/date_utils.sh** - Cross-platform date utilities
41+
- ISO timestamp generation for logging
42+
- Epoch time calculations for rate limiting
43+
3844
## Key Commands
3945

4046
### Installation
@@ -96,6 +102,35 @@ The loop is controlled by several key files and environment variables:
96102
- Automatic hourly reset with countdown display
97103
- Call tracking persists across script restarts
98104

105+
### Modern CLI Configuration (Phase 1.1)
106+
107+
Ralph uses modern Claude Code CLI flags for structured communication:
108+
109+
**Configuration Variables:**
110+
```bash
111+
CLAUDE_OUTPUT_FORMAT="json" # Output format: json (default) or text
112+
CLAUDE_ALLOWED_TOOLS="Write,Bash(git *),Read" # Allowed tool permissions
113+
CLAUDE_USE_CONTINUE=true # Enable session continuity
114+
CLAUDE_MIN_VERSION="2.0.76" # Minimum Claude CLI version
115+
```
116+
117+
**CLI Options:**
118+
- `--output-format json|text` - Set Claude output format (default: json)
119+
- `--allowed-tools "Write,Read,Bash(git *)"` - Restrict allowed tools
120+
- `--no-continue` - Disable session continuity, start fresh each loop
121+
122+
**Loop Context:**
123+
Each loop iteration injects context via `build_loop_context()`:
124+
- Current loop number
125+
- Remaining tasks from @fix_plan.md
126+
- Circuit breaker state (if not CLOSED)
127+
- Previous loop work summary
128+
129+
**Session Continuity:**
130+
- Sessions are preserved in `.claude_session_id`
131+
- Use `--continue` flag to maintain context across loops
132+
- Disable with `--no-continue` for isolated iterations
133+
99134
### Intelligent Exit Detection
100135
The loop automatically exits when it detects project completion through:
101136
- Multiple consecutive "done" signals from Claude Code
@@ -193,6 +228,37 @@ Ralph uses advanced error detection with two-stage filtering to eliminate false
193228

194229
## Recent Improvements
195230

231+
### Modern CLI Commands (v0.9.1 - Phase 1.1)
232+
233+
**JSON Output Format Support**
234+
- Added `detect_output_format()` function to identify JSON vs text output
235+
- Added `parse_json_response()` to extract structured fields from Claude's JSON output
236+
- Extracts: status, exit_signal, work_type, files_modified, error_count, summary
237+
- Automatic fallback to text parsing on malformed JSON
238+
- Maintains backward compatibility with traditional RALPH_STATUS format
239+
240+
**Session Continuity Management**
241+
- `init_claude_session()` - Resume or start new sessions
242+
- `save_claude_session()` - Persist session ID from Claude output
243+
- `--continue` flag for context preservation across loops
244+
- `--no-continue` option for isolated iterations
245+
246+
**Loop Context Injection**
247+
- `build_loop_context()` - Build contextual information for each loop
248+
- Includes: loop number, remaining tasks, circuit breaker state, previous work summary
249+
- Injected via `--append-system-prompt` for Claude awareness
250+
251+
**Modern CLI Flags**
252+
- `--output-format json|text` - Control Claude output format
253+
- `--allowed-tools` - Restrict tool permissions
254+
- `--prompt-file` - Use file instead of stdin piping
255+
- Version checking with `check_claude_version()`
256+
257+
**Test Coverage**
258+
- 20 new JSON parsing tests in `test_json_parsing.bats`
259+
- 23 new CLI modern tests in `test_cli_modern.bats`
260+
- All 98 tests passing (100% pass rate)
261+
196262
### Circuit Breaker Enhancements (v0.9.0)
197263

198264
**Multi-line Error Matching Fix**

README.md

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Ralph for Claude Code
22

3-
![Version](https://img.shields.io/badge/version-0.9.0-blue)
3+
![Version](https://img.shields.io/badge/version-0.9.1-blue)
44
![Status](https://img.shields.io/badge/status-active%20development-yellow)
5-
![Tests](https://img.shields.io/badge/tests-75%20passing-green)
6-
![Coverage](https://img.shields.io/badge/coverage-60%25-orange)
5+
![Tests](https://img.shields.io/badge/tests-98%20passing-green)
6+
![Coverage](https://img.shields.io/badge/coverage-65%25-orange)
77

88
> **Autonomous AI development loop with intelligent exit detection and rate limiting**
99
@@ -13,23 +13,34 @@ Ralph is an implementation of the Geoffrey Huntley's technique for Claude Code t
1313

1414
## 📌 Project Status
1515

16-
**Version**: v0.9.0 - Active Development
16+
**Version**: v0.9.1 - Active Development
1717
**Core Features**: ✅ Working and tested
18-
**Test Coverage**: 60% (expanding to 90%+ - see [roadmap](#-development-roadmap))
18+
**Test Coverage**: 65% (expanding to 90%+ - see [roadmap](#-development-roadmap))
1919

2020
### What's Working Now ✅
2121
- Autonomous development loops with intelligent exit detection
2222
- Rate limiting with hourly reset (100 calls/hour, configurable)
2323
- Circuit breaker with advanced error detection (prevents runaway loops)
2424
- Response analyzer with semantic understanding and two-stage error filtering
25+
- **JSON output format support with automatic fallback to text parsing**
26+
- **Session continuity with `--continue` flag for context preservation**
27+
- **Modern CLI flags: `--output-format`, `--allowed-tools`, `--no-continue`**
2528
- Multi-line error matching for accurate stuck loop detection
2629
- 5-hour API limit handling with user prompts
2730
- tmux integration for live monitoring
2831
- PRD import functionality
29-
- 97 passing tests covering critical paths (13 error detection + 9 stuck loop + 75 core tests)
32+
- 98 passing tests covering critical paths (20 JSON parsing + 23 CLI modern + 55 core tests)
3033

3134
### Recent Improvements 🎉
3235

36+
**v0.9.1 - Modern CLI Commands (Phase 1.1)**
37+
- ✅ JSON output format support with `--output-format json` (default)
38+
- ✅ Session continuity using `--continue` flag for cross-loop context
39+
- ✅ Tool permissions via `--allowed-tools` flag
40+
- ✅ Loop context injection with `build_loop_context()` function
41+
- ✅ Backward-compatible: automatic fallback to text parsing
42+
- ✅ 43 new tests: JSON parsing (20) + CLI modern (23)
43+
3344
**v0.9.0 - Circuit Breaker Enhancements**
3445
- ✅ Fixed multi-line error matching in stuck loop detection
3546
- ✅ Eliminated JSON field false positives (e.g., `"is_error": false`)
@@ -339,26 +350,27 @@ If you want to run the test suite:
339350
# Install BATS testing framework
340351
npm install -g bats bats-support bats-assert
341352

342-
# Run all tests (97 tests)
353+
# Run all tests (98 tests)
343354
bats tests/
344355

345356
# Run specific test suites
346357
bats tests/unit/test_rate_limiting.bats
347358
bats tests/unit/test_exit_detection.bats
359+
bats tests/unit/test_json_parsing.bats
360+
bats tests/unit/test_cli_modern.bats
348361
bats tests/integration/test_loop_execution.bats
349-
bats tests/integration/test_edge_cases.bats
350362

351363
# Run error detection and circuit breaker tests
352364
./tests/test_error_detection.sh
353365
./tests/test_stuck_loop_detection.sh
354366
```
355367

356368
Current test status:
357-
- **97 tests** across 6 test files (75 core + 13 error detection + 9 stuck loop)
358-
- **100% pass rate** (97/97 passing)
359-
- **~60% code coverage** (target: 90%+)
369+
- **98 tests** across 7 test files (55 core + 20 JSON parsing + 23 CLI modern)
370+
- **100% pass rate** (98/98 passing)
371+
- **~65% code coverage** (target: 90%+)
360372
- Comprehensive unit and integration tests
361-
- Specialized tests for error detection and circuit breaker functionality
373+
- Specialized tests for JSON parsing, CLI flags, and circuit breaker functionality
362374

363375
### Installing tmux
364376

@@ -537,13 +549,16 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
537549
### Ralph Loop Options
538550
```bash
539551
ralph [OPTIONS]
540-
-h, --help Show help message
541-
-c, --calls NUM Set max calls per hour (default: 100)
542-
-p, --prompt FILE Set prompt file (default: PROMPT.md)
543-
-s, --status Show current status and exit
544-
-m, --monitor Start with tmux session and live monitor
545-
-v, --verbose Show detailed progress updates during execution
546-
-t, --timeout MIN Set Claude Code execution timeout in minutes (1-120, default: 15)
552+
-h, --help Show help message
553+
-c, --calls NUM Set max calls per hour (default: 100)
554+
-p, --prompt FILE Set prompt file (default: PROMPT.md)
555+
-s, --status Show current status and exit
556+
-m, --monitor Start with tmux session and live monitor
557+
-v, --verbose Show detailed progress updates during execution
558+
-t, --timeout MIN Set Claude Code execution timeout in minutes (1-120, default: 15)
559+
--output-format FORMAT Set output format: json (default) or text
560+
--allowed-tools TOOLS Set allowed Claude tools (default: Write,Bash(git *),Read)
561+
--no-continue Disable session continuity (start fresh each loop)
547562
```
548563

549564
### Project Commands (Per Project)

0 commit comments

Comments
 (0)