-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add --ci mode and prompt passing for non-interactive shuvcode execution #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implements issue #19: Add --ci flag for non-interactive shuvcode execution with automatic permission approval. Changes: - Add PromptPreset enum and PROMPT_PRESETS dict (RALPH_LOOP, STANDARD_OOTL, MINIMAL) - Add prompt settings to WorktreeSettings (agent_prompt, agent_prompt_preset, no_prompt, ci_mode) - Add CLI flags: --agent-prompt, --agent-preset, --no-prompt, --ci - Implement _resolve_shuvcode_prompt() with priority order (CLI > env var > WT-TASK.md) - Modify _open_shuvcode() to support CI mode with OPENCODE_PERMISSION env var - Add comprehensive tests: 9 prompt passing tests, 11 validation tests - Update README with usage examples and CI/CD integration CI Mode Behavior: - Uses "shuvcode run" command instead of interactive TUI - Sets OPENCODE_PERMISSION='{"*":"allow"}' to auto-approve all operations - Perfect for CI/CD pipelines and automated workflows Testing: - 9/9 prompt passing tests pass - 11/11 validation tests pass - 87/89 total tests pass (2 pre-existing failures unrelated to changes) Closes #19 Related: Closed #20 (yolo flag - functionality covered by --ci)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
5 issues found across 7 files
Prompt for AI agents (all issues)
Check if these issues are valid — if so, understand the root cause of each and fix them.
<file name="README.md">
<violation number="1" location="README.md:163">
P2: Documentation inaccuracy: `--no-prompt` is listed as priority item 5, but it's actually a bypass flag that disables prompt passing entirely, not a fallback. According to the code, item 5 should be "None (no prompt passed)" when no source is configured. Consider: `5. None (if no prompt source is configured)`
Then add a separate note: "Use `--no-prompt` to explicitly disable prompt passing."</violation>
</file>
<file name="config.py">
<violation number="1" location="config.py:154">
P2: Error message is misleading when only 2 of 3 mutually exclusive flags are used. The message implies all three are provided together, but the validation triggers for any 2+ flags. Consider a clearer message like "Only one of --agent-prompt, --agent-preset, or --no-prompt can be specified".</violation>
</file>
<file name="worktree_creator.py">
<violation number="1" location="worktree_creator.py:548">
P3: Dead code: The `no_prompt` check here will never be True because `_resolve_shuvcode_prompt` is only called when `no_prompt` is False (checked in `_open_shuvcode` before calling). This block should be removed.</violation>
<violation number="2" location="worktree_creator.py:588">
P1: CI mode doesn't pass `worktree_path` to shuvcode. Unlike other modes that pass the path as an argument, CI mode runs `shuvcode run <prompt>` without any directory context. Consider passing the worktree path or setting `cwd=worktree_path` in the subprocess call.</violation>
<violation number="3" location="worktree_creator.py:600">
P2: Logging the full command may expose large or sensitive prompt content. In CI mode, `cmd` includes the entire prompt which could be the full WT-TASK.md content. Consider logging only the command structure or truncating the prompt.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| 2. `GHWT_AGENT_INIT_PROMPT` environment variable | ||
| 3. `--agent-preset` CLI flag or `GHWT_AGENT_INIT_PRESET` environment variable | ||
| 4. WT-TASK.md file content (default) | ||
| 5. No prompt (`--no-prompt` flag) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Documentation inaccuracy: --no-prompt is listed as priority item 5, but it's actually a bypass flag that disables prompt passing entirely, not a fallback. According to the code, item 5 should be "None (no prompt passed)" when no source is configured. Consider: 5. None (if no prompt source is configured)
Then add a separate note: "Use --no-prompt to explicitly disable prompt passing."
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At README.md, line 163:
<comment>Documentation inaccuracy: `--no-prompt` is listed as priority item 5, but it's actually a bypass flag that disables prompt passing entirely, not a fallback. According to the code, item 5 should be "None (no prompt passed)" when no source is configured. Consider: `5. None (if no prompt source is configured)`
Then add a separate note: "Use `--no-prompt` to explicitly disable prompt passing."</comment>
<file context>
@@ -97,6 +97,71 @@ export WORKTREE_ROOT=/path/to/worktrees
+2. `GHWT_AGENT_INIT_PROMPT` environment variable
+3. `--agent-preset` CLI flag or `GHWT_AGENT_INIT_PRESET` environment variable
+4. WT-TASK.md file content (default)
+5. No prompt (`--no-prompt` flag)
+
### Output
</file context>
| 5. No prompt (`--no-prompt` flag) | |
| 5. None (no prompt if nothing configured) | |
| **Note:** Use `--no-prompt` to explicitly disable prompt passing entirely. |
| active_flags = [f for f in prompt_flags if f] | ||
| if len(active_flags) > 1: | ||
| raise ValueError( | ||
| "Cannot use --agent-prompt, --agent-preset, and --no-prompt together" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Error message is misleading when only 2 of 3 mutually exclusive flags are used. The message implies all three are provided together, but the validation triggers for any 2+ flags. Consider a clearer message like "Only one of --agent-prompt, --agent-preset, or --no-prompt can be specified".
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At config.py, line 154:
<comment>Error message is misleading when only 2 of 3 mutually exclusive flags are used. The message implies all three are provided together, but the validation triggers for any 2+ flags. Consider a clearer message like "Only one of --agent-prompt, --agent-preset, or --no-prompt can be specified".</comment>
<file context>
@@ -56,10 +111,50 @@ class WorktreeSettings(BaseSettings):
+ active_flags = [f for f in prompt_flags if f]
+ if len(active_flags) > 1:
+ raise ValueError(
+ "Cannot use --agent-prompt, --agent-preset, and --no-prompt together"
+ )
+ if self.ci_mode and self.no_prompt:
</file context>
| "Cannot use --agent-prompt, --agent-preset, and --no-prompt together" | |
| "Only one of --agent-prompt, --agent-preset, or --no-prompt can be specified" |
| cmd = ["shuvcode", str(worktree_path), "--prompt", prompt] | ||
| env = None # Use parent process environment | ||
|
|
||
| self.logger.debug("Executing shuvcode command", command=" ".join(cmd)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Logging the full command may expose large or sensitive prompt content. In CI mode, cmd includes the entire prompt which could be the full WT-TASK.md content. Consider logging only the command structure or truncating the prompt.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At worktree_creator.py, line 600:
<comment>Logging the full command may expose large or sensitive prompt content. In CI mode, `cmd` includes the entire prompt which could be the full WT-TASK.md content. Consider logging only the command structure or truncating the prompt.</comment>
<file context>
@@ -477,13 +569,44 @@ def _open_shuvcode(self, worktree_path: Path) -> None:
+ cmd = ["shuvcode", str(worktree_path), "--prompt", prompt]
+ env = None # Use parent process environment
+
+ self.logger.debug("Executing shuvcode command", command=" ".join(cmd))
- with contextlib.suppress(subprocess.CalledProcessError, FileNotFoundError, subprocess.TimeoutExpired):
</file context>
| self.logger.debug("Executing shuvcode command", command=" ".join(cmd)) | |
| self.logger.debug( | |
| "Executing shuvcode command", | |
| command=cmd[0], | |
| subcommand=cmd[1] if len(cmd) > 1 else None, | |
| prompt_length=len(cmd[2]) if len(cmd) > 2 and cmd[1] == "run" else None, | |
| ) |
| self.logger.info( | ||
| "Opening shuvcode in CI mode", prompt_length=len(prompt) | ||
| ) | ||
| cmd = ["shuvcode", "run", prompt] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P1: CI mode doesn't pass worktree_path to shuvcode. Unlike other modes that pass the path as an argument, CI mode runs shuvcode run <prompt> without any directory context. Consider passing the worktree path or setting cwd=worktree_path in the subprocess call.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At worktree_creator.py, line 588:
<comment>CI mode doesn't pass `worktree_path` to shuvcode. Unlike other modes that pass the path as an argument, CI mode runs `shuvcode run <prompt>` without any directory context. Consider passing the worktree path or setting `cwd=worktree_path` in the subprocess call.</comment>
<file context>
@@ -477,13 +569,44 @@ def _open_shuvcode(self, worktree_path: Path) -> None:
+ self.logger.info(
+ "Opening shuvcode in CI mode", prompt_length=len(prompt)
+ )
+ cmd = ["shuvcode", "run", prompt]
+ # Set OPENCODE_PERMISSION to auto-allow all operations in CI
+ env = os.environ.copy()
</file context>
| return content | ||
|
|
||
| # Priority 4: No prompt (--no-prompt or file missing) | ||
| if self.settings.no_prompt: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: Dead code: The no_prompt check here will never be True because _resolve_shuvcode_prompt is only called when no_prompt is False (checked in _open_shuvcode before calling). This block should be removed.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At worktree_creator.py, line 548:
<comment>Dead code: The `no_prompt` check here will never be True because `_resolve_shuvcode_prompt` is only called when `no_prompt` is False (checked in `_open_shuvcode` before calling). This block should be removed.</comment>
<file context>
@@ -458,13 +496,67 @@ def _write_task_file(
+ return content
+
+ # Priority 4: No prompt (--no-prompt or file missing)
+ if self.settings.no_prompt:
+ self.logger.debug("No prompt (no-prompt flag set)")
+
</file context>
Summary
Implements issue #19: Add --ci flag for non-interactive shuvcode execution with automatic permission handling.
Features Added
Prompt Passing System
PromptPresetenum: RALPH_LOOP, STANDARD_OOTL, MINIMALPROMPT_PRESETSdict with detailed instructions for each presetCLI Flags
--agent-prompt: Custom prompt override--agent-preset ralph-loop|standard-ootl|minimal: Preset selection--no-prompt: Disable prompt passing (old behavior)--ci: Non-interactive mode with auto-permissionsConfiguration
WorktreeSettings--ciand--no-promptcannot be used togetherCore Logic
_resolve_shuvcode_prompt(): Implements priority order_open_shuvcode(): Supports 3 modes:shuvcode run "<prompt>"+OPENCODE_PERMISSION='{"*":"allow"}'shuvcode <path> --prompt "<prompt>"shuvcode <path>(old behavior)Testing
Documentation
OPENCODE_PERMISSIONsettingCI Mode Behavior
When
--ciflag is used:Key benefits:
shuvcode run)OPENCODE_PERMISSIONenvironment variableUsage Examples
Test Results
Files Modified
config.py: Added enums, presets, validatorsmain.py: Added CLI flags and validationworktree_creator.py: Added prompt resolution and CI modetests/unit/test_prompt_passing.py: 9 new teststests/unit/test_config.py: 11 validation testsREADME.md: Documentation and examplesIssue #20 Closure
Issue #20 (YOLO flag) has been closed as redundant. The
--ciflag implemented in this PR provides the requested autonomous execution functionality:--ciuses non-interactiveshuvcode runcommandOPENCODE_PERMISSION='{"*":"allow"}'auto-approves all operations--ci --agent-promptSeparate
--yoloflag would duplicate functionality without adding value.Acceptance Criteria
--agent-promptflag overrides WT-TASK.md content--no-promptflag disables prompt passing (current behavior)GHWT_AGENT_INIT_PROMPTenvironment variable is respectedGHWT_AGENT_INIT_PRESETenvironment variable selects predefined preset--promptflagOPENCODE_PERMISSIONenvironment variable for non-interactive executionCloses #19
Related: Closed #20