feat(date): Add cross-platform date compatibility for macOS and Linux#9
Conversation
Add cross-platform date utility library to handle differences between GNU date (Linux) and BSD date (macOS). Fixes issues with: - ISO 8601 timestamp formatting (-Iseconds flag) - Date arithmetic operations (-d vs -v flags) Changes: - Created lib/date_utils.sh with get_iso_timestamp() and get_next_hour_time() - Updated ralph_loop.sh to use date utilities (2 instances) - Updated lib/circuit_breaker.sh to use date utilities (4 instances) - Updated lib/response_analyzer.sh to use date utilities (1 instance) All date operations now work consistently across both platforms without modification. The utility automatically detects the OS and uses the appropriate date command syntax. Tested on Linux with GNU date - all syntax checks and integration tests pass.
|
Caution Review failedThe pull request is closed. WalkthroughA new cross-platform date utilities library was added and three shell scripts were updated to source it and replace direct Changes
Sequence Diagram(s)(omitted — changes are focused on utility extraction and direct replacements; no new multi-component control flow introduced) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
lib/date_utils.sh (2)
37-41: Document the unused function or consider removing it.The
get_basic_timestamp()function is not currently used by any of the modified scripts in this PR. Consider either documenting its intended future use or removing it to maintain a lean codebase.
7-8: Enhance function documentation to fully comply with coding guidelines.Per coding guidelines, "All bash script functions must include comments documenting their purpose, parameters, and behavior." The current comments document purpose and return format but should explicitly note that these functions take no parameters.
🔎 Proposed documentation enhancement
# Get current timestamp in ISO 8601 format with seconds precision +# Parameters: None # Returns: YYYY-MM-DDTHH:MM:SS+00:00 format get_iso_timestamp() { # Get time component (HH:MM:SS) for one hour from now +# Parameters: None # Returns: HH:MM:SS format get_next_hour_time() { # Get current timestamp in a basic format (fallback) +# Parameters: None # Returns: YYYY-MM-DD HH:MM:SS format get_basic_timestamp() {Based on coding guidelines: "All bash script functions must include comments documenting their purpose, parameters, and behavior"
Also applies to: 22-23, 37-38
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
lib/circuit_breaker.shlib/date_utils.shlib/response_analyzer.shralph_loop.sh
🧰 Additional context used
📓 Path-based instructions (3)
**/*.sh
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.sh: All bash script functions must include comments documenting their purpose, parameters, and behavior
Keep bash script comments current and remove outdated comments immediately when implementation changes
Files:
lib/date_utils.shlib/response_analyzer.shralph_loop.shlib/circuit_breaker.sh
lib/response_analyzer.sh
📄 CodeRabbit inference engine (CLAUDE.md)
Use two-stage error filtering in error detection to eliminate JSON field false positives: Stage 1 filters field patterns like
"is_error": false, Stage 2 detects actual errors via context (Error:, ERROR:, Exception, etc.)
Files:
lib/response_analyzer.sh
lib/circuit_breaker.sh
📄 CodeRabbit inference engine (CLAUDE.md)
Use literal fixed-string matching with
grep -qFfor multi-line error detection to avoid regex edge cases when detecting stuck loops with multiple simultaneous errors
Files:
lib/circuit_breaker.sh
🧠 Learnings (5)
📚 Learning: 2025-12-31T21:28:57.468Z
Learnt from: CR
Repo: frankbria/ralph-claude-code PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-31T21:28:57.468Z
Learning: Applies to lib/response_analyzer.sh : Use two-stage error filtering in error detection to eliminate JSON field false positives: Stage 1 filters field patterns like `"is_error": false`, Stage 2 detects actual errors via context (Error:, ERROR:, Exception, etc.)
Applied to files:
lib/response_analyzer.sh
📚 Learning: 2025-12-31T21:28:57.468Z
Learnt from: CR
Repo: frankbria/ralph-claude-code PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-31T21:28:57.468Z
Learning: Update CLAUDE.md when new commands, exit conditions, thresholds, or Ralph loop behaviors are introduced
Applied to files:
ralph_loop.sh
📚 Learning: 2025-12-31T21:28:57.468Z
Learnt from: CR
Repo: frankbria/ralph-claude-code PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-31T21:28:57.468Z
Learning: Test Ralph loop functionality with new features and verify installation process when applicable before marking features complete
Applied to files:
ralph_loop.sh
📚 Learning: 2025-12-31T21:28:57.468Z
Learnt from: CR
Repo: frankbria/ralph-claude-code PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-31T21:28:57.468Z
Learning: Files prefixed with `@` (e.g., `fix_plan.md`, `AGENT.md`) are Ralph-specific control files; hidden files (e.g., `.call_count`) track loop state; logs are timestamped in `logs/` directory
Applied to files:
ralph_loop.sh
📚 Learning: 2025-12-31T21:28:57.468Z
Learnt from: CR
Repo: frankbria/ralph-claude-code PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-12-31T21:28:57.468Z
Learning: Applies to lib/circuit_breaker.sh : Use literal fixed-string matching with `grep -qF` for multi-line error detection to avoid regex edge cases when detecting stuck loops with multiple simultaneous errors
Applied to files:
lib/circuit_breaker.sh
🧬 Code graph analysis (3)
lib/date_utils.sh (1)
tests/helpers/test_helper.bash (1)
date(194-202)
ralph_loop.sh (1)
lib/date_utils.sh (2)
get_iso_timestamp(8-20)get_next_hour_time(24-35)
lib/circuit_breaker.sh (1)
lib/date_utils.sh (1)
get_iso_timestamp(8-20)
🔇 Additional comments (7)
lib/response_analyzer.sh (2)
5-6: LGTM!The sourcing of date utilities is correctly implemented with proper path resolution using
dirname "${BASH_SOURCE[0]}".
158-158: LGTM!The replacement of
date -Isecondswithget_iso_timestamp()correctly delegates timestamp generation to the cross-platform utility.lib/circuit_breaker.sh (2)
6-7: LGTM!The sourcing of date utilities is correctly implemented with proper path resolution.
42-42: LGTM!All four timestamp generations have been correctly updated to use
get_iso_timestamp()instead of directdate -Isecondsinvocations, ensuring cross-platform compatibility across state initialization, loop result recording, transition logging, and circuit breaker reset operations.Also applies to: 170-170, 202-202, 278-278
ralph_loop.sh (2)
10-10: LGTM!The sourcing of date utilities is correctly placed before other library components that may depend on it.
168-168: LGTM!Both timestamp replacements are correct:
- Line 168:
get_iso_timestamp()provides ISO 8601 format for status tracking- Line 175:
get_next_hour_time()handles date arithmetic for the next reset timeAlso applies to: 175-175
lib/date_utils.sh (1)
22-35: LGTM!The
get_next_hour_time()function correctly implements cross-platform date arithmetic using BSD's-vflag for macOS and GNU's-dflag for Linux. Both use local time consistently.
Add -u flag to GNU date command in get_iso_timestamp() to match the macOS implementation and function documentation. Both platforms now consistently return UTC timestamps in YYYY-MM-DDTHH:MM:SS+00:00 format. Before: date -Iseconds (returned local time on Linux) After: date -u -Iseconds (returns UTC on Linux)
Summary
Adds cross-platform date compatibility to resolve GNU date vs BSD date differences between Linux and macOS systems. This fixes issues where Ralph would fail on macOS due to unsupported date command flags.
Problem
-Isecondsfor ISO 8601 formatting and-dfor date arithmeticSolution
lib/date_utils.shwith cross-platform date utility functionsget_iso_timestamp()- Auto-detects OS and uses appropriate syntax for ISO 8601 timestampsget_next_hour_time()- Auto-detects OS and uses appropriate syntax for date arithmeticChanges
lib/date_utils.sh- Cross-platform date utility libraryralph_loop.sh- Updated 2 date operations (status timestamps)lib/circuit_breaker.sh- Updated 4 date operations (state tracking)lib/response_analyzer.sh- Updated 1 date operation (analysis timestamps)Platform Support
date -Iseconds,date -d)date -u +format,date -v)Test Plan
Linux Testing (Completed)
macOS Testing (Required)
get_iso_timestamp()returns valid ISO 8601 formatget_next_hour_time()returns valid time format (HH:MM:SS)ralph_loop.shand verify status.json timestampsIntegration Testing
Manual Verification Commands
Breaking Changes
None - This is a backward-compatible enhancement that maintains all existing functionality.
Notes
unamefor OS detectionlib/date_utils.shwith no external dependenciesSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.