Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions platforms/claude/commands/grok-swarm-agent.sh
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
;;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
*)
# 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[@]}"
63 changes: 63 additions & 0 deletions platforms/claude/skills/grok-swarm-agent/SKILL.md
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
6 changes: 5 additions & 1 deletion skills/grok-refactor/openclaw.plugin.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "grok-swarm",
"name": "Grok Multi-Agent Swarm",
"description": "Bridge to xAI Grok 4.20 Multi-Agent Beta (4-agent swarm) for codebase analysis, refactoring, reasoning, and code generation.",
"description": "Bridge to xAI Grok 4.20 Multi-Agent Beta (4-agent swarm) for codebase analysis, refactoring, reasoning, and code generation. Also supports autonomous agent mode for iterative multi-file modifications.",
"version": "1.0.0",
"configSchema": {
"type": "object",
Expand All @@ -19,6 +19,10 @@
"type": "string",
"description": "Path to grok_bridge.py script"
},
"agentScript": {
"type": "string",
"description": "Path to grok_agent.py script (for autonomous agent mode)"
},
"defaultOutputDir": {
"type": "string",
"description": "Default output directory for file writes (default: ./grok-output/)"
Expand Down
17 changes: 17 additions & 0 deletions src/agent/__init__.py
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"]
Loading