-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add autonomous grok-swarm-agent for iterative file modifications #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
65c6b6b
feat: Add autonomous grok-swarm-agent for iterative file modifications
35550a9
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 35ca81b
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] fd60d8e
Initial plan
Copilot ca49d23
fix: apply CodeRabbit auto-fixes
coderabbitai[bot] 3f6a3d0
feat: create src/shared/patterns.py with centralized get_filename_pat…
Copilot 4d460a4
Merge pull request #19 from KHAEntertainment/copilot/sub-pr-16
KHAEntertainment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| #!/bin/bash | ||
| # grok-swarm-agent command for Claude Code | ||
| # Invokes the grok_agent.py Python script with Claude Code context | ||
|
|
||
| set -e | ||
|
|
||
| # Find the plugin root (3 levels up from commands/) | ||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||
| PLUGIN_ROOT="$(cd "$SCRIPT_DIR/../../.." && pwd)" | ||
| AGENT_SCRIPT="$PLUGIN_ROOT/src/agent/grok_agent.py" | ||
|
|
||
| # Default: preview mode | ||
| APPLY_FLAG="" | ||
| MAX_ITERATIONS="5" | ||
| VERIFY_CMD="" | ||
| TARGET="." | ||
|
|
||
| # Parse arguments | ||
| TASK="" | ||
| while [[ $# -gt 0 ]]; do | ||
| case $1 in | ||
| --apply) | ||
| APPLY_FLAG="--apply" | ||
| shift | ||
| ;; | ||
| --target) | ||
| TARGET="$2" | ||
| shift 2 | ||
| ;; | ||
| --max-iterations) | ||
| MAX_ITERATIONS="$2" | ||
| shift 2 | ||
| ;; | ||
| --verify-cmd) | ||
| VERIFY_CMD="$2" | ||
| shift 2 | ||
| ;; | ||
| -*) | ||
| echo "Unknown option: $1" >&2 | ||
| echo "Usage: grok-swarm-agent [task description] [--apply] [--target DIR] [--max-iterations N] [--verify-cmd CMD]" >&2 | ||
| exit 1 | ||
| ;; | ||
| *) | ||
| # First non-flag is the task | ||
| if [[ -z "$TASK" ]]; then | ||
| TASK="$1" | ||
| fi | ||
| shift | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| if [[ -z "$TASK" ]]; then | ||
| echo "Usage: grok-swarm-agent [task description] [--apply] [--target DIR] [--max-iterations N] [--verify-cmd CMD]" | ||
| echo "" | ||
| echo "Example:" | ||
| echo " grok-swarm-agent refactor the auth module" | ||
| echo " grok-swarm-agent add tests --apply --verify-cmd pytest" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Build argument array | ||
| ARGS=( | ||
| "$AGENT_SCRIPT" | ||
| "--platform" "claude" | ||
| "--target" "$TARGET" | ||
| "--max-iterations" "$MAX_ITERATIONS" | ||
| ) | ||
|
|
||
| if [[ -n "$APPLY_FLAG" ]]; then | ||
| ARGS+=("$APPLY_FLAG") | ||
| fi | ||
|
|
||
| if [[ -n "$VERIFY_CMD" ]]; then | ||
| ARGS+=("--verify-cmd" "$VERIFY_CMD") | ||
| fi | ||
|
|
||
| ARGS+=("$TASK") | ||
|
|
||
| # Execute | ||
| python3 "${ARGS[@]}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| --- | ||
| name: grok-swarm-agent | ||
| description: Spawn an autonomous Grok agent to accomplish tasks. Use when asked to "use grok agent to refactor X", "let grok agent handle this", "grok agent mode", "autonomous grok". Triggers: "grok agent", "agent mode", "autonomous grok", "grok-swarm-agent" | ||
| author: OpenClaw | ||
| version: 1.0.0 | ||
| --- | ||
|
|
||
| # Grok Swarm Agent | ||
|
|
||
| Spawn an autonomous agent powered by Grok 4.20 Multi-Agent Beta that iteratively refactors, analyzes, or modifies your codebase. | ||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| use grok agent to refactor src/auth/ | ||
| grok agent mode: improve error handling in lib/ | ||
| let grok swarm agent add tests to the backend | ||
| ``` | ||
|
|
||
| ## How It Works | ||
|
|
||
| 1. **Discover**: Agent finds relevant files in target directory | ||
| 2. **Plan**: Agent creates modification plan using Grok 4.20 | ||
| 3. **Apply**: Agent writes changes using file tools | ||
| 4. **Verify**: Agent validates changes (syntax check, tests) | ||
| 5. **Iterate**: Agent refines until satisfied or max iterations reached | ||
|
|
||
| ## Options | ||
|
|
||
| | Option | Description | | ||
| |--------|-------------| | ||
| | `--apply` | Actually write files (default is preview mode) | | ||
| | `--max-iterations N` | Max agent iterations (default: 5) | | ||
| | `--verify-cmd CMD` | Command to verify changes work | | ||
|
|
||
| ## Examples | ||
|
|
||
| ``` | ||
| # Preview mode - shows what would change | ||
| grok agent refactor the auth module | ||
|
|
||
| # Actually apply changes | ||
| grok agent refactor the auth module --apply | ||
|
|
||
| # With verification | ||
| grok agent add tests --apply --verify-cmd "pytest tests/" | ||
|
|
||
| # Analyze with agent | ||
| grok agent analyze security vulnerabilities --target ./src | ||
| ``` | ||
|
|
||
| ## Requirements | ||
|
|
||
| - Grok Swarm plugin installed and configured | ||
| - OpenRouter API key set up (run `/grok-swarm:setup` if needed) | ||
|
|
||
| ## Output | ||
|
|
||
| The agent reports: | ||
| - Status (success, max iterations, or errors) | ||
| - Number of iterations used | ||
| - List of files changed | ||
| - Verification results if applicable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """ | ||
| grok-swarm-agent - Autonomous agent wrapper for Grok 4.20. | ||
|
|
||
| This module provides an iterative agent loop that: | ||
| 1. Receives natural language tasks | ||
| 2. Discovers relevant files | ||
| 3. Calls Grok 4.20 via grok_bridge | ||
| 4. Parses code blocks and applies changes | ||
| 5. Verifies changes with tests | ||
| 6. Iterates until done or max iterations reached | ||
|
|
||
| Cross-platform: works with both Claude Code and OpenClaw. | ||
| """ | ||
|
|
||
| from .grok_agent import main, run_agent_loop, AgentState, Platform, AgentStatus | ||
|
|
||
| __all__ = ["main", "run_agent_loop", "AgentState", "Platform", "AgentStatus"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.