Merge PR #126: fix(monitor): forward all CLI parameters to inner ralph loop
Cherry-pick of #126 rebased onto current main to pass CI. Original work by @zerone0x. Fixes #120. Co-Authored-By: zerone0x <hi@trine.dev> Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
commit
33739e0fb2
2 changed files with 131 additions and 2 deletions
|
|
@ -188,20 +188,47 @@ setup_tmux_session() {
|
|||
fi
|
||||
|
||||
# Start ralph loop in the left pane (exclude tmux flag to avoid recursion)
|
||||
# Forward all CLI parameters that were set by the user
|
||||
local ralph_cmd
|
||||
if command -v ralph &> /dev/null; then
|
||||
ralph_cmd="ralph"
|
||||
else
|
||||
ralph_cmd="'$ralph_home/ralph_loop.sh'"
|
||||
fi
|
||||
|
||||
|
||||
# Forward --calls if non-default
|
||||
if [[ "$MAX_CALLS_PER_HOUR" != "100" ]]; then
|
||||
ralph_cmd="$ralph_cmd --calls $MAX_CALLS_PER_HOUR"
|
||||
fi
|
||||
# Forward --prompt if non-default
|
||||
if [[ "$PROMPT_FILE" != "$RALPH_DIR/PROMPT.md" ]]; then
|
||||
ralph_cmd="$ralph_cmd --prompt '$PROMPT_FILE'"
|
||||
fi
|
||||
|
||||
# Forward --output-format if non-default (default is json)
|
||||
if [[ "$CLAUDE_OUTPUT_FORMAT" != "json" ]]; then
|
||||
ralph_cmd="$ralph_cmd --output-format $CLAUDE_OUTPUT_FORMAT"
|
||||
fi
|
||||
# Forward --verbose if enabled
|
||||
if [[ "$VERBOSE_PROGRESS" == "true" ]]; then
|
||||
ralph_cmd="$ralph_cmd --verbose"
|
||||
fi
|
||||
# Forward --timeout if non-default (default is 15)
|
||||
if [[ "$CLAUDE_TIMEOUT_MINUTES" != "15" ]]; then
|
||||
ralph_cmd="$ralph_cmd --timeout $CLAUDE_TIMEOUT_MINUTES"
|
||||
fi
|
||||
# Forward --allowed-tools if non-default
|
||||
if [[ "$CLAUDE_ALLOWED_TOOLS" != "Write,Bash(git *),Read" ]]; then
|
||||
ralph_cmd="$ralph_cmd --allowed-tools '$CLAUDE_ALLOWED_TOOLS'"
|
||||
fi
|
||||
# Forward --no-continue if session continuity disabled
|
||||
if [[ "$CLAUDE_USE_CONTINUE" == "false" ]]; then
|
||||
ralph_cmd="$ralph_cmd --no-continue"
|
||||
fi
|
||||
# Forward --session-expiry if non-default (default is 24)
|
||||
if [[ "$CLAUDE_SESSION_EXPIRY_HOURS" != "24" ]]; then
|
||||
ralph_cmd="$ralph_cmd --session-expiry $CLAUDE_SESSION_EXPIRY_HOURS"
|
||||
fi
|
||||
|
||||
tmux send-keys -t "$session_name:0.0" "$ralph_cmd" Enter
|
||||
|
||||
# Focus on left pane (main ralph loop)
|
||||
|
|
|
|||
|
|
@ -362,3 +362,105 @@ EOF
|
|||
|
||||
assert_success
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# MONITOR PARAMETER FORWARDING TESTS (Issue #120)
|
||||
# Tests that --monitor correctly forwards all CLI parameters to the inner loop
|
||||
# =============================================================================
|
||||
|
||||
# Helper function to extract the ralph_cmd that would be built in setup_tmux_session
|
||||
# This sources ralph_loop.sh and simulates the parameter forwarding logic
|
||||
build_ralph_cmd_for_test() {
|
||||
local ralph_cmd="ralph"
|
||||
local MAX_CALLS_PER_HOUR="${1:-100}"
|
||||
local PROMPT_FILE="${2:-.ralph/PROMPT.md}"
|
||||
local CLAUDE_OUTPUT_FORMAT="${3:-json}"
|
||||
local VERBOSE_PROGRESS="${4:-false}"
|
||||
local CLAUDE_TIMEOUT_MINUTES="${5:-15}"
|
||||
local CLAUDE_ALLOWED_TOOLS="${6:-Write,Bash(git *),Read}"
|
||||
local CLAUDE_USE_CONTINUE="${7:-true}"
|
||||
local CLAUDE_SESSION_EXPIRY_HOURS="${8:-24}"
|
||||
local RALPH_DIR=".ralph"
|
||||
|
||||
# Forward --calls if non-default
|
||||
if [[ "$MAX_CALLS_PER_HOUR" != "100" ]]; then
|
||||
ralph_cmd="$ralph_cmd --calls $MAX_CALLS_PER_HOUR"
|
||||
fi
|
||||
# Forward --prompt if non-default
|
||||
if [[ "$PROMPT_FILE" != "$RALPH_DIR/PROMPT.md" ]]; then
|
||||
ralph_cmd="$ralph_cmd --prompt '$PROMPT_FILE'"
|
||||
fi
|
||||
# Forward --output-format if non-default (default is json)
|
||||
if [[ "$CLAUDE_OUTPUT_FORMAT" != "json" ]]; then
|
||||
ralph_cmd="$ralph_cmd --output-format $CLAUDE_OUTPUT_FORMAT"
|
||||
fi
|
||||
# Forward --verbose if enabled
|
||||
if [[ "$VERBOSE_PROGRESS" == "true" ]]; then
|
||||
ralph_cmd="$ralph_cmd --verbose"
|
||||
fi
|
||||
# Forward --timeout if non-default (default is 15)
|
||||
if [[ "$CLAUDE_TIMEOUT_MINUTES" != "15" ]]; then
|
||||
ralph_cmd="$ralph_cmd --timeout $CLAUDE_TIMEOUT_MINUTES"
|
||||
fi
|
||||
# Forward --allowed-tools if non-default
|
||||
if [[ "$CLAUDE_ALLOWED_TOOLS" != "Write,Bash(git *),Read" ]]; then
|
||||
ralph_cmd="$ralph_cmd --allowed-tools '$CLAUDE_ALLOWED_TOOLS'"
|
||||
fi
|
||||
# Forward --no-continue if session continuity disabled
|
||||
if [[ "$CLAUDE_USE_CONTINUE" == "false" ]]; then
|
||||
ralph_cmd="$ralph_cmd --no-continue"
|
||||
fi
|
||||
# Forward --session-expiry if non-default (default is 24)
|
||||
if [[ "$CLAUDE_SESSION_EXPIRY_HOURS" != "24" ]]; then
|
||||
ralph_cmd="$ralph_cmd --session-expiry $CLAUDE_SESSION_EXPIRY_HOURS"
|
||||
fi
|
||||
|
||||
echo "$ralph_cmd"
|
||||
}
|
||||
|
||||
@test "monitor forwards --output-format text parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "text")
|
||||
[[ "$result" == *"--output-format text"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards --verbose parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "true")
|
||||
[[ "$result" == *"--verbose"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards --timeout parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "false" "30")
|
||||
[[ "$result" == *"--timeout 30"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards --allowed-tools parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "false" "15" "Read,Write")
|
||||
[[ "$result" == *"--allowed-tools 'Read,Write'"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards --no-continue parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "false" "15" "Write,Bash(git *),Read" "false")
|
||||
[[ "$result" == *"--no-continue"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards --session-expiry parameter" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "false" "15" "Write,Bash(git *),Read" "true" "48")
|
||||
[[ "$result" == *"--session-expiry 48"* ]]
|
||||
}
|
||||
|
||||
@test "monitor forwards multiple parameters together" {
|
||||
local result=$(build_ralph_cmd_for_test 50 ".ralph/PROMPT.md" "text" "true" "30" "Read,Write" "false" "12")
|
||||
[[ "$result" == *"--calls 50"* ]]
|
||||
[[ "$result" == *"--output-format text"* ]]
|
||||
[[ "$result" == *"--verbose"* ]]
|
||||
[[ "$result" == *"--timeout 30"* ]]
|
||||
[[ "$result" == *"--allowed-tools 'Read,Write'"* ]]
|
||||
[[ "$result" == *"--no-continue"* ]]
|
||||
[[ "$result" == *"--session-expiry 12"* ]]
|
||||
}
|
||||
|
||||
@test "monitor does not forward default parameters" {
|
||||
local result=$(build_ralph_cmd_for_test 100 ".ralph/PROMPT.md" "json" "false" "15" "Write,Bash(git *),Read" "true" "24")
|
||||
# Should only be "ralph" with no extra flags
|
||||
[[ "$result" == "ralph" ]]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue