@khaentertainment/grok-swarm 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KHA Entertainment
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # Grok Swarm Tool
2
+
3
+ **Dual-Platform: OpenClaw + Claude Code**
4
+
5
+ Give any AI coding agent access to Grok 4.20's 4-agent swarm with ~2M token context.
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## The Story
12
+
13
+ You've been building with AI coding agents for a while now. They're great — they can write features, refactor modules, analyze codebases. But there's always been this ceiling. The models they run on are designed for single-turn conversations.
14
+
15
+ **Enter Grok 4.20 Multi-Agent Beta.**
16
+
17
+ It's different. Instead of one model responding, it's *four agents coordinating* in real-time. An orchestrator, specialists, critics — all working together to break down your request and reason through it from multiple angles. It can hold ~2M tokens of context — that's entire codebases in a single request.
18
+
19
+ **The Problem:**
20
+
21
+ Grok 4.20 is groundbreaking, but it doesn't play nicely with current coding tools. Claude Code doesn't have a Grok integration. OpenClaw's tooling system doesn't support multi-agent swarms. If you wanted to use Grok, you'd have to hack together custom scripts or modify your platform's core components. Not ideal.
22
+
23
+ **The Solution:**
24
+
25
+ This plugin bridges that gap. It makes Grok 4.20 available as a tool that any agent in Claude Code or OpenClaw can call. No core modifications, no hacking — just install and go.
26
+
27
+ Now when your agent needs deep codebase analysis, large-scale refactoring, or complex reasoning, it can delegate to Grok's swarm and get back the kind of coordinated, multi-perspective thinking that single models can't deliver.
28
+
29
+ ---
30
+
31
+ ## Features
32
+
33
+ - **4-Agent Swarm** — Grok 4.20 coordinates multiple agents for deeper analysis
34
+ - **Massive Context** — ~2M token window, handles entire codebases
35
+ - **5 Modes** — Analyze, Refactor, Code, Reason, Orchestrate
36
+ - **Tool Passthrough** — Pass OpenAI-format tool schemas for function calling
37
+ - **File Writing** — Write annotated code blocks directly to disk
38
+ - **Dual Platform** — Works with both Claude Code and OpenClaw
39
+
40
+ ---
41
+
42
+ ## File Writing
43
+
44
+ When `write_files=true`, Grok parses code blocks for filename annotations and writes them directly to disk, returning only a compact summary instead of the full response.
45
+
46
+ ### Supported Patterns
47
+
48
+ **Fenced code blocks with path in the language tag:**
49
+
50
+ ```typescript:src/auth/login.ts
51
+ export function login() { ... }
52
+ ```
53
+
54
+ **Fenced code blocks with `// FILE:` marker:**
55
+
56
+ ```typescript
57
+ // FILE: src/auth/login.ts
58
+ export function login() { ... }
59
+ ```
60
+
61
+ ### Example
62
+
63
+ ```javascript
64
+ const result = await tools.grok_swarm({
65
+ prompt: "Write a FastAPI auth module with JWT",
66
+ mode: "code",
67
+ write_files: true,
68
+ output_dir: "./src"
69
+ });
70
+ // Returns: "Wrote 3 files to ./src
71
+ // src/auth.py (1,234 bytes)
72
+ // src/jwt_utils.py (567 bytes)
73
+ // src/middleware.py (890 bytes)"
74
+ ```
75
+
76
+ ### Why This Matters
77
+
78
+ Grok can generate ~350K token responses. Without file writing, that floods your orchestrator's context window. With file writing, you get a brief summary and the files on disk.
79
+
80
+ ---
81
+
82
+ ## Requirements
83
+
84
+ - OpenClaw v2026.3.0+ (for OpenClaw integration)
85
+ - Python 3.8+
86
+ - Node.js 18+
87
+ - OpenRouter API key with Grok 4.20 access
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ Choose the method that fits your platform:
94
+
95
+ ### Option 1: NPM (Recommended — CLI Tool)
96
+
97
+ ```bash
98
+ npm install -g @openclaw/grok-swarm
99
+
100
+ # Set up API key
101
+ ./scripts/setup.sh
102
+ ```
103
+
104
+ ### Option 2: Claude Code Marketplace
105
+
106
+ ```bash
107
+ # Add the marketplace
108
+ /plugin marketplace add https://github.com/KHAEntertainment/grok-multiagent-plugin
109
+
110
+ # Install the plugin
111
+ /plugin install grok-swarm@khaentertainment
112
+
113
+ # Set up API key
114
+ ./scripts/setup.sh
115
+ ```
116
+
117
+ ### Option 3: ClawHub (OpenClaw)
118
+
119
+ ```bash
120
+ clawhub install grok-swarm
121
+ ```
122
+
123
+ ### Option 4: Git Clone
124
+
125
+ ```bash
126
+ git clone https://github.com/KHAEntertainment/grok-multiagent-plugin.git
127
+ cd grok-multiagent-plugin
128
+
129
+ # Auto-detect and install
130
+ ./install.sh
131
+
132
+ # Or install for specific platform
133
+ ./install.sh claude # Claude Code only
134
+ ./install.sh openclaw # OpenClaw only
135
+ ./install.sh both # Both platforms
136
+ ```
137
+
138
+ For detailed instructions for each method, see [INSTALL.md](INSTALL.md).
139
+
140
+ ---
141
+
142
+ ## Quick Start
143
+
144
+ ### For Claude Code
145
+
146
+ ```
147
+ /grok-swarm:analyze Review the security of my auth module
148
+ /grok-swarm:refactor Convert these callbacks to async/await
149
+ /grok-swarm:code Write a FastAPI endpoint for user registration
150
+ /grok-swarm:reason Compare microservices vs monolith for this project
151
+ ```
152
+
153
+ ### For OpenClaw
154
+
155
+ ```bash
156
+ # After ClawHub or git install, add to openclaw.json:
157
+ openclaw gateway restart
158
+ ```
159
+
160
+ Then use in your agent:
161
+
162
+ ```javascript
163
+ const result = await tools.grok_swarm({
164
+ prompt: "Analyze the architecture of this codebase",
165
+ mode: "analyze",
166
+ files: ["src/", "tests/"],
167
+ timeout: 180
168
+ });
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Usage
174
+
175
+ ### Claude Code
176
+
177
+ ```
178
+ /grok-swarm:analyze Review the security of my auth module
179
+ /grok-swarm:refactor Convert this to async/await
180
+ /grok-swarm:code Write a FastAPI user registration endpoint
181
+ /grok-swarm:reason Compare these two architectural approaches
182
+ ```
183
+
184
+ ### OpenClaw
185
+
186
+ ```javascript
187
+ const result = await tools.grok_swarm({
188
+ prompt: "Analyze the architecture of this codebase",
189
+ mode: "analyze",
190
+ files: ["src/", "tests/"],
191
+ timeout: 180
192
+ });
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Modes
198
+
199
+ | Mode | Description | Use Case |
200
+ |------|-------------|----------|
201
+ | `analyze` | Deep code review, security audit, architecture assessment | Security reviews, PR reviews, tech debt assessment |
202
+ | `refactor` | Improve code quality while preserving behavior | Modernization, migration, cleanup of legacy code |
203
+ | `code` | Generate clean, production-ready code | Building features, writing tests, boilerplate |
204
+ | `reason` | Collaborative multi-perspective reasoning | Research synthesis, decision making, trade-off analysis |
205
+ | `orchestrate` | Custom agent handoff with your system prompt | When you need full control over swarm's behavior |
206
+
207
+ ---
208
+
209
+ ## Parameters
210
+
211
+ | Parameter | Type | Required | Default | Description |
212
+ |-----------|------|----------|---------|-------------|
213
+ | `prompt` | string | Yes | — | Task instruction |
214
+ | `mode` | string | No | `reason` | Task mode |
215
+ | `files` | string[] | No | — | Files for context |
216
+ | `system` | string | No | — | Custom system prompt |
217
+ | `timeout` | number | No | 120 | Timeout in seconds |
218
+ | `write_files` | boolean | No | false | Write annotated code blocks to disk |
219
+ | `output_dir` | string | No | ./grok-output/ | Directory for file writes |
220
+
221
+ ---
222
+
223
+ ## OpenRouter API Key
224
+
225
+ Grok Swarm resolves your API key in this order (highest to lowest priority):
226
+
227
+ 1. **Environment variables** — `OPENROUTER_API_KEY` or `XAI_API_KEY`
228
+ 2. **Local config file** — `~/.config/grok-swarm/config.json` with `{"api_key": "..."}`
229
+ 3. **OpenClaw auth profiles** — `~/.openclaw/agents/coder/agent/auth-profiles.json`
230
+
231
+ ```bash
232
+ # If you set an env var, it takes precedence over config files:
233
+ export OPENROUTER_API_KEY="sk-or-v1-xxx" # This overrides ~/.config/grok-swarm/config.json!
234
+
235
+ # To use the local config file instead, unset the env var:
236
+ unset OPENROUTER_API_KEY
237
+ ```
238
+
239
+ **Get a key at:** https://openrouter.ai/keys
240
+
241
+ ---
242
+
243
+ ## Morph LLM Integration
244
+
245
+ For **partial file edits** (not full replacement), use the `--use-morph` flag:
246
+
247
+ ```bash
248
+ grok-swarm refactor --prompt "Convert this function to async" --use-morph --apply
249
+ ```
250
+
251
+ This requires Morph LLM MCP installed:
252
+
253
+ ```bash
254
+ claude mcp add morphllm
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Architecture
260
+
261
+ ```
262
+ OpenClaw Agent / Claude Code
263
+
264
+
265
+ grok_swarm tool / skill
266
+
267
+
268
+ index.js (Node wrapper)
269
+
270
+
271
+ grok_bridge.py (Python/OpenAI SDK)
272
+
273
+
274
+ OpenRouter API
275
+
276
+
277
+ xAI Grok 4.20 Multi-Agent Beta
278
+
279
+
280
+ Response
281
+ ```
282
+
283
+ ---
284
+
285
+ ## License
286
+
287
+ MIT — see [LICENSE](LICENSE)
288
+
289
+ ---
290
+
291
+ ## Support
292
+
293
+ - [Issues](https://github.com/KHAEntertainment/grok-multiagent-plugin/issues)
294
+ - [Discord](https://discord.com/invite/clawd)
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KHA Entertainment
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # Grok Swarm Tool
2
+
3
+ **Dual-Platform: OpenClaw + Claude Code**
4
+
5
+ Give any AI coding agent access to Grok 4.20's 4-agent swarm with ~2M token context.
6
+
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
8
+
9
+ ---
10
+
11
+ ## The Story
12
+
13
+ You've been building with AI coding agents for a while now. They're great — they can write features, refactor modules, analyze codebases. But there's always been this ceiling. The models they run on are designed for single-turn conversations.
14
+
15
+ **Enter Grok 4.20 Multi-Agent Beta.**
16
+
17
+ It's different. Instead of one model responding, it's *four agents coordinating* in real-time. An orchestrator, specialists, critics — all working together to break down your request and reason through it from multiple angles. It can hold ~2M tokens of context — that's entire codebases in a single request.
18
+
19
+ **The Problem:**
20
+
21
+ Grok 4.20 is groundbreaking, but it doesn't play nicely with current coding tools. Claude Code doesn't have a Grok integration. OpenClaw's tooling system doesn't support multi-agent swarms. If you wanted to use Grok, you'd have to hack together custom scripts or modify your platform's core components. Not ideal.
22
+
23
+ **The Solution:**
24
+
25
+ This plugin bridges that gap. It makes Grok 4.20 available as a tool that any agent in Claude Code or OpenClaw can call. No core modifications, no hacking — just install and go.
26
+
27
+ Now when your agent needs deep codebase analysis, large-scale refactoring, or complex reasoning, it can delegate to Grok's swarm and get back the kind of coordinated, multi-perspective thinking that single models can't deliver.
28
+
29
+ ---
30
+
31
+ ## Features
32
+
33
+ - **4-Agent Swarm** — Grok 4.20 coordinates multiple agents for deeper analysis
34
+ - **Massive Context** — ~2M token window, handles entire codebases
35
+ - **5 Modes** — Analyze, Refactor, Code, Reason, Orchestrate
36
+ - **Tool Passthrough** — Pass OpenAI-format tool schemas for function calling
37
+ - **File Writing** — Write annotated code blocks directly to disk
38
+ - **Dual Platform** — Works with both Claude Code and OpenClaw
39
+
40
+ ---
41
+
42
+ ## File Writing
43
+
44
+ When `write_files=true`, Grok parses code blocks for filename annotations and writes them directly to disk, returning only a compact summary instead of the full response.
45
+
46
+ ### Supported Patterns
47
+
48
+ **Fenced code blocks with path in the language tag:**
49
+
50
+ ```typescript:src/auth/login.ts
51
+ export function login() { ... }
52
+ ```
53
+
54
+ **Fenced code blocks with `// FILE:` marker:**
55
+
56
+ ```typescript
57
+ // FILE: src/auth/login.ts
58
+ export function login() { ... }
59
+ ```
60
+
61
+ ### Example
62
+
63
+ ```javascript
64
+ const result = await tools.grok_swarm({
65
+ prompt: "Write a FastAPI auth module with JWT",
66
+ mode: "code",
67
+ write_files: true,
68
+ output_dir: "./src"
69
+ });
70
+ // Returns: "Wrote 3 files to ./src
71
+ // src/auth.py (1,234 bytes)
72
+ // src/jwt_utils.py (567 bytes)
73
+ // src/middleware.py (890 bytes)"
74
+ ```
75
+
76
+ ### Why This Matters
77
+
78
+ Grok can generate ~350K token responses. Without file writing, that floods your orchestrator's context window. With file writing, you get a brief summary and the files on disk.
79
+
80
+ ---
81
+
82
+ ## Requirements
83
+
84
+ - OpenClaw v2026.3.0+ (for OpenClaw integration)
85
+ - Python 3.8+
86
+ - Node.js 18+
87
+ - OpenRouter API key with Grok 4.20 access
88
+
89
+ ---
90
+
91
+ ## Installation
92
+
93
+ Choose the method that fits your platform:
94
+
95
+ ### Option 1: NPM (Recommended — CLI Tool)
96
+
97
+ ```bash
98
+ npm install -g @openclaw/grok-swarm
99
+
100
+ # Set up API key
101
+ ./scripts/setup.sh
102
+ ```
103
+
104
+ ### Option 2: Claude Code Marketplace
105
+
106
+ ```bash
107
+ # Add the marketplace
108
+ /plugin marketplace add https://github.com/KHAEntertainment/grok-multiagent-plugin
109
+
110
+ # Install the plugin
111
+ /plugin install grok-swarm@khaentertainment
112
+
113
+ # Set up API key
114
+ ./scripts/setup.sh
115
+ ```
116
+
117
+ ### Option 3: ClawHub (OpenClaw)
118
+
119
+ ```bash
120
+ clawhub install grok-swarm
121
+ ```
122
+
123
+ ### Option 4: Git Clone
124
+
125
+ ```bash
126
+ git clone https://github.com/KHAEntertainment/grok-multiagent-plugin.git
127
+ cd grok-multiagent-plugin
128
+
129
+ # Auto-detect and install
130
+ ./install.sh
131
+
132
+ # Or install for specific platform
133
+ ./install.sh claude # Claude Code only
134
+ ./install.sh openclaw # OpenClaw only
135
+ ./install.sh both # Both platforms
136
+ ```
137
+
138
+ For detailed instructions for each method, see [INSTALL.md](INSTALL.md).
139
+
140
+ ---
141
+
142
+ ## Quick Start
143
+
144
+ ### For Claude Code
145
+
146
+ ```
147
+ /grok-swarm:analyze Review the security of my auth module
148
+ /grok-swarm:refactor Convert these callbacks to async/await
149
+ /grok-swarm:code Write a FastAPI endpoint for user registration
150
+ /grok-swarm:reason Compare microservices vs monolith for this project
151
+ ```
152
+
153
+ ### For OpenClaw
154
+
155
+ ```bash
156
+ # After ClawHub or git install, add to openclaw.json:
157
+ openclaw gateway restart
158
+ ```
159
+
160
+ Then use in your agent:
161
+
162
+ ```javascript
163
+ const result = await tools.grok_swarm({
164
+ prompt: "Analyze the architecture of this codebase",
165
+ mode: "analyze",
166
+ files: ["src/", "tests/"],
167
+ timeout: 180
168
+ });
169
+ ```
170
+
171
+ ---
172
+
173
+ ## Usage
174
+
175
+ ### Claude Code
176
+
177
+ ```
178
+ /grok-swarm:analyze Review the security of my auth module
179
+ /grok-swarm:refactor Convert this to async/await
180
+ /grok-swarm:code Write a FastAPI user registration endpoint
181
+ /grok-swarm:reason Compare these two architectural approaches
182
+ ```
183
+
184
+ ### OpenClaw
185
+
186
+ ```javascript
187
+ const result = await tools.grok_swarm({
188
+ prompt: "Analyze the architecture of this codebase",
189
+ mode: "analyze",
190
+ files: ["src/", "tests/"],
191
+ timeout: 180
192
+ });
193
+ ```
194
+
195
+ ---
196
+
197
+ ## Modes
198
+
199
+ | Mode | Description | Use Case |
200
+ |------|-------------|----------|
201
+ | `analyze` | Deep code review, security audit, architecture assessment | Security reviews, PR reviews, tech debt assessment |
202
+ | `refactor` | Improve code quality while preserving behavior | Modernization, migration, cleanup of legacy code |
203
+ | `code` | Generate clean, production-ready code | Building features, writing tests, boilerplate |
204
+ | `reason` | Collaborative multi-perspective reasoning | Research synthesis, decision making, trade-off analysis |
205
+ | `orchestrate` | Custom agent handoff with your system prompt | When you need full control over swarm's behavior |
206
+
207
+ ---
208
+
209
+ ## Parameters
210
+
211
+ | Parameter | Type | Required | Default | Description |
212
+ |-----------|------|----------|---------|-------------|
213
+ | `prompt` | string | Yes | — | Task instruction |
214
+ | `mode` | string | No | `reason` | Task mode |
215
+ | `files` | string[] | No | — | Files for context |
216
+ | `system` | string | No | — | Custom system prompt |
217
+ | `timeout` | number | No | 120 | Timeout in seconds |
218
+ | `write_files` | boolean | No | false | Write annotated code blocks to disk |
219
+ | `output_dir` | string | No | ./grok-output/ | Directory for file writes |
220
+
221
+ ---
222
+
223
+ ## OpenRouter API Key
224
+
225
+ Grok Swarm resolves your API key in this order (highest to lowest priority):
226
+
227
+ 1. **Environment variables** — `OPENROUTER_API_KEY` or `XAI_API_KEY`
228
+ 2. **Local config file** — `~/.config/grok-swarm/config.json` with `{"api_key": "..."}`
229
+ 3. **OpenClaw auth profiles** — `~/.openclaw/agents/coder/agent/auth-profiles.json`
230
+
231
+ ```bash
232
+ # If you set an env var, it takes precedence over config files:
233
+ export OPENROUTER_API_KEY="sk-or-v1-xxx" # This overrides ~/.config/grok-swarm/config.json!
234
+
235
+ # To use the local config file instead, unset the env var:
236
+ unset OPENROUTER_API_KEY
237
+ ```
238
+
239
+ **Get a key at:** https://openrouter.ai/keys
240
+
241
+ ---
242
+
243
+ ## Morph LLM Integration
244
+
245
+ For **partial file edits** (not full replacement), use the `--use-morph` flag:
246
+
247
+ ```bash
248
+ grok-swarm refactor --prompt "Convert this function to async" --use-morph --apply
249
+ ```
250
+
251
+ This requires Morph LLM MCP installed:
252
+
253
+ ```bash
254
+ claude mcp add morphllm
255
+ ```
256
+
257
+ ---
258
+
259
+ ## Architecture
260
+
261
+ ```
262
+ OpenClaw Agent / Claude Code
263
+
264
+
265
+ grok_swarm tool / skill
266
+
267
+
268
+ index.js (Node wrapper)
269
+
270
+
271
+ grok_bridge.py (Python/OpenAI SDK)
272
+
273
+
274
+ OpenRouter API
275
+
276
+
277
+ xAI Grok 4.20 Multi-Agent Beta
278
+
279
+
280
+ Response
281
+ ```
282
+
283
+ ---
284
+
285
+ ## License
286
+
287
+ MIT — see [LICENSE](LICENSE)
288
+
289
+ ---
290
+
291
+ ## Support
292
+
293
+ - [Issues](https://github.com/KHAEntertainment/grok-multiagent-plugin/issues)
294
+ - [Discord](https://discord.com/invite/clawd)
package/dist/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0