grok-cli-acp 0.1.2

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.
Files changed (100) hide show
  1. package/.env.example +42 -0
  2. package/.github/workflows/ci.yml +30 -0
  3. package/.github/workflows/rust.yml +22 -0
  4. package/.grok/.env.example +85 -0
  5. package/.grok/COMPLETE_FIX_SUMMARY.md +466 -0
  6. package/.grok/ENV_CONFIG_GUIDE.md +173 -0
  7. package/.grok/QUICK_REFERENCE.md +180 -0
  8. package/.grok/README.md +104 -0
  9. package/.grok/TESTING_GUIDE.md +393 -0
  10. package/CHANGELOG.md +465 -0
  11. package/CODE_REVIEW_SUMMARY.md +414 -0
  12. package/COMPLETE_FIX_SUMMARY.md +415 -0
  13. package/CONFIGURATION.md +489 -0
  14. package/CONTEXT_FILES_GUIDE.md +419 -0
  15. package/CONTRIBUTING.md +55 -0
  16. package/CURSOR_POSITION_FIX.md +206 -0
  17. package/Cargo.toml +88 -0
  18. package/ERROR_HANDLING_REPORT.md +361 -0
  19. package/FINAL_FIX_SUMMARY.md +462 -0
  20. package/FIXES.md +37 -0
  21. package/FIXES_SUMMARY.md +87 -0
  22. package/GROK_API_MIGRATION_SUMMARY.md +111 -0
  23. package/LICENSE +22 -0
  24. package/MIGRATION_TO_GROK_API.md +223 -0
  25. package/README.md +504 -0
  26. package/REVIEW_COMPLETE.md +416 -0
  27. package/REVIEW_QUICK_REFERENCE.md +173 -0
  28. package/SECURITY.md +463 -0
  29. package/SECURITY_AUDIT.md +661 -0
  30. package/SETUP.md +287 -0
  31. package/TESTING_TOOLS.md +88 -0
  32. package/TESTING_TOOL_EXECUTION.md +239 -0
  33. package/TOOL_EXECUTION_FIX.md +491 -0
  34. package/VERIFICATION_CHECKLIST.md +419 -0
  35. package/docs/API.md +74 -0
  36. package/docs/CHAT_LOGGING.md +39 -0
  37. package/docs/CURSOR_FIX_DEMO.md +306 -0
  38. package/docs/ERROR_HANDLING_GUIDE.md +547 -0
  39. package/docs/FILE_OPERATIONS.md +449 -0
  40. package/docs/INTERACTIVE.md +401 -0
  41. package/docs/PROJECT_CREATION_GUIDE.md +570 -0
  42. package/docs/QUICKSTART.md +378 -0
  43. package/docs/QUICK_REFERENCE.md +691 -0
  44. package/docs/RELEASE_NOTES_0.1.2.md +240 -0
  45. package/docs/TOOLS.md +459 -0
  46. package/docs/TOOLS_QUICK_REFERENCE.md +210 -0
  47. package/docs/ZED_INTEGRATION.md +371 -0
  48. package/docs/extensions.md +464 -0
  49. package/docs/settings.md +293 -0
  50. package/examples/extensions/logging-hook/README.md +91 -0
  51. package/examples/extensions/logging-hook/extension.json +22 -0
  52. package/package.json +30 -0
  53. package/scripts/test_acp.py +252 -0
  54. package/scripts/test_acp.sh +143 -0
  55. package/scripts/test_acp_simple.sh +72 -0
  56. package/src/acp/mod.rs +741 -0
  57. package/src/acp/protocol.rs +323 -0
  58. package/src/acp/security.rs +298 -0
  59. package/src/acp/tools.rs +697 -0
  60. package/src/bin/banner_demo.rs +216 -0
  61. package/src/bin/docgen.rs +18 -0
  62. package/src/bin/installer.rs +217 -0
  63. package/src/cli/app.rs +310 -0
  64. package/src/cli/commands/acp.rs +721 -0
  65. package/src/cli/commands/chat.rs +485 -0
  66. package/src/cli/commands/code.rs +513 -0
  67. package/src/cli/commands/config.rs +394 -0
  68. package/src/cli/commands/health.rs +442 -0
  69. package/src/cli/commands/history.rs +421 -0
  70. package/src/cli/commands/mod.rs +14 -0
  71. package/src/cli/commands/settings.rs +1384 -0
  72. package/src/cli/mod.rs +166 -0
  73. package/src/config/mod.rs +2212 -0
  74. package/src/display/ascii_art.rs +139 -0
  75. package/src/display/banner.rs +289 -0
  76. package/src/display/components/input.rs +323 -0
  77. package/src/display/components/mod.rs +2 -0
  78. package/src/display/components/settings_list.rs +306 -0
  79. package/src/display/interactive.rs +1255 -0
  80. package/src/display/mod.rs +62 -0
  81. package/src/display/terminal.rs +42 -0
  82. package/src/display/tips.rs +316 -0
  83. package/src/grok_client_ext.rs +177 -0
  84. package/src/hooks/loader.rs +407 -0
  85. package/src/hooks/mod.rs +158 -0
  86. package/src/lib.rs +174 -0
  87. package/src/main.rs +65 -0
  88. package/src/mcp/client.rs +195 -0
  89. package/src/mcp/config.rs +20 -0
  90. package/src/mcp/mod.rs +6 -0
  91. package/src/mcp/protocol.rs +67 -0
  92. package/src/utils/auth.rs +41 -0
  93. package/src/utils/chat_logger.rs +568 -0
  94. package/src/utils/context.rs +390 -0
  95. package/src/utils/mod.rs +16 -0
  96. package/src/utils/network.rs +320 -0
  97. package/src/utils/rate_limiter.rs +166 -0
  98. package/src/utils/session.rs +73 -0
  99. package/src/utils/shell_permissions.rs +389 -0
  100. package/src/utils/telemetry.rs +41 -0
@@ -0,0 +1,210 @@
1
+ # Tools Quick Reference Card
2
+
3
+ ## 🛠️ Available Tools Overview
4
+
5
+ ### 📁 File Operations
6
+ ```
7
+ read_file(path) - Read file content
8
+ write_file(path, content) - Write to file
9
+ replace(path, old, new) - Replace text in file
10
+ ```
11
+
12
+ ### 🔍 Search & Discovery
13
+ ```
14
+ list_directory(path) - List directory contents
15
+ glob_search(pattern) - Find files by pattern
16
+ search_file_content(path, pattern) - Search text in files (regex)
17
+ ```
18
+
19
+ ### ⚡ Execution & Web
20
+ ```
21
+ run_shell_command(command) - Execute shell command
22
+ web_search(query) - Search the web
23
+ web_fetch(url) - Fetch URL content
24
+ ```
25
+
26
+ ### 💾 Memory
27
+ ```
28
+ save_memory(fact) - Save to long-term memory
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 📝 Quick Examples
34
+
35
+ ### Read a file
36
+ ```
37
+ "Can you read src/main.rs?"
38
+ → Grok uses: read_file("src/main.rs")
39
+ ```
40
+
41
+ ### Find all Rust files
42
+ ```
43
+ "Show me all Rust files"
44
+ → Grok uses: glob_search("**/*.rs")
45
+ ```
46
+
47
+ ### Search for TODOs
48
+ ```
49
+ "Find all TODO comments"
50
+ → Grok uses: search_file_content(".", "TODO|FIXME")
51
+ ```
52
+
53
+ ### Replace text
54
+ ```
55
+ "Change port 8080 to 3000 in config.rs"
56
+ → Grok uses: replace("src/config.rs", "port = 8080", "port = 3000")
57
+ ```
58
+
59
+ ### Run tests
60
+ ```
61
+ "Run the test suite"
62
+ → Grok uses: run_shell_command("cargo test")
63
+ ```
64
+
65
+ ---
66
+
67
+ ## 🎯 Common Patterns
68
+
69
+ ### Refactoring
70
+ ```
71
+ 1. read_file() - Get current code
72
+ 2. replace() - Make changes
73
+ 3. run_shell_command("cargo check") - Verify
74
+ ```
75
+
76
+ ### Project Analysis
77
+ ```
78
+ 1. list_directory() - See structure
79
+ 2. glob_search() - Find specific files
80
+ 3. search_file_content() - Find patterns
81
+ ```
82
+
83
+ ### Code Review
84
+ ```
85
+ 1. glob_search("**/*.rs") - Find files
86
+ 2. read_file() - Read each file
87
+ 3. search_file_content() - Find issues
88
+ ```
89
+
90
+ ---
91
+
92
+ ## 🔒 Security Notes
93
+
94
+ ✅ **Trusted directories only** - Operations restricted to safe paths
95
+ ✅ **No directory traversal** - Path validation enforced
96
+ ✅ **Command restrictions** - Shell commands monitored
97
+ ✅ **Rate limiting** - Network operations throttled
98
+
99
+ ---
100
+
101
+ ## 💡 Pro Tips
102
+
103
+ ### File Operations
104
+ - Always read before writing
105
+ - Use `replace` for precision edits
106
+ - Verify paths with `list_directory` first
107
+
108
+ ### Search Operations
109
+ - Use glob for file names
110
+ - Use content search for text
111
+ - Test regex patterns carefully
112
+
113
+ ### Shell Commands
114
+ - Keep commands simple
115
+ - Handle errors gracefully
116
+ - Use timeouts for long operations
117
+
118
+ ### Best Practices
119
+ - Start with narrow scope
120
+ - Verify before executing
121
+ - Check results after operations
122
+ - Use appropriate tool for task
123
+
124
+ ---
125
+
126
+ ## 🚀 Getting Started
127
+
128
+ ### Interactive Mode
129
+ ```bash
130
+ grok interactive
131
+ ```
132
+ Then type: `/tools` to see all tools
133
+
134
+ ### ACP Server (for Zed)
135
+ ```bash
136
+ grok acp stdio
137
+ ```
138
+ Tools auto-available in editor
139
+
140
+ ### Quick Query
141
+ ```bash
142
+ grok query "Find all main functions"
143
+ ```
144
+
145
+ ---
146
+
147
+ ## 📊 Glob Pattern Examples
148
+
149
+ ```
150
+ **/*.rs - All Rust files (recursive)
151
+ src/**/*.toml - All TOML in src/ tree
152
+ *.json - JSON in current dir
153
+ test_*.rs - Test files with prefix
154
+ **/Cargo.toml - All Cargo.toml files
155
+ ```
156
+
157
+ ---
158
+
159
+ ## 🔎 Regex Pattern Examples
160
+
161
+ ```
162
+ fn main - Find main functions
163
+ TODO|FIXME - Find TODO/FIXME comments
164
+ struct \w+ - Find struct definitions
165
+ pub async fn - Find public async functions
166
+ #\[derive.*\] - Find derive attributes
167
+ ```
168
+
169
+ ---
170
+
171
+ ## ⚙️ Configuration
172
+
173
+ ### Set API Key
174
+ ```bash
175
+ export GROK_API_KEY=your_key_here
176
+ ```
177
+
178
+ ### Trust Directory
179
+ In `~/.config/grok-cli/config.json`:
180
+ ```json
181
+ {
182
+ "acp": {
183
+ "trusted_directories": ["/path/to/project"]
184
+ }
185
+ }
186
+ ```
187
+
188
+ ---
189
+
190
+ ## 🆘 Troubleshooting
191
+
192
+ | Error | Solution |
193
+ |-------|----------|
194
+ | Permission denied | Add to trusted_directories |
195
+ | File not found | Check path with list_directory |
196
+ | Tool timeout | Increase timeout in config |
197
+ | Max iterations | Break into smaller tasks |
198
+
199
+ ---
200
+
201
+ ## 📚 More Info
202
+
203
+ - Full docs: `docs/TOOLS.md`
204
+ - Examples: `docs/TOOLS.md#examples`
205
+ - Security: `docs/TOOLS.md#security-model`
206
+ - Config: `docs/TOOLS.md#configuration-reference`
207
+
208
+ ---
209
+
210
+ **Need Help?** Type `/help` in interactive mode or visit the GitHub repo!
@@ -0,0 +1,371 @@
1
+ # Zed Editor Integration Guide for Grok CLI
2
+
3
+ This guide will help you integrate Grok CLI with the Zed editor using the Agent Client Protocol (ACP).
4
+
5
+ ## Prerequisites
6
+
7
+ - Zed editor installed (latest version recommended)
8
+ - Grok CLI built and installed
9
+ - X/Grok API key configured
10
+
11
+ ## Quick Start
12
+
13
+ ### 1. Build Grok CLI
14
+
15
+ ```bash
16
+ cd grok-cli
17
+ cargo build --release
18
+ ```
19
+
20
+ The binary will be located at `target/release/grok.exe` (Windows) or `target/release/grok` (Linux/Mac).
21
+
22
+ ### 2. Set Your API Key
23
+
24
+ Create a `.env` file in `~/.grok/.env` (system-wide):
25
+
26
+ ```bash
27
+ # Windows
28
+ mkdir %USERPROFILE%\.grok
29
+ echo GROK_API_KEY=xai-your-key-here > %USERPROFILE%\.grok\.env
30
+
31
+ # Linux/Mac
32
+ mkdir -p ~/.grok
33
+ echo "GROK_API_KEY=xai-your-key-here" > ~/.grok/.env
34
+ ```
35
+
36
+ Or for a specific project, create `.grok/.env` in your project directory:
37
+
38
+ ```bash
39
+ mkdir .grok
40
+ echo "GROK_API_KEY=xai-your-key-here" > .grok/.env
41
+ echo "GROK_MODEL=grok-code-fast-1" >> .grok/.env
42
+ ```
43
+
44
+ ### 3. Verify Configuration
45
+
46
+ ```bash
47
+ grok config show
48
+ grok health --all
49
+ ```
50
+
51
+ ## Zed Editor Configuration
52
+
53
+ ### Method 1: STDIO Mode (Recommended)
54
+
55
+ Zed can launch Grok CLI as a subprocess and communicate via stdin/stdout.
56
+
57
+ #### Add to Zed Settings
58
+
59
+ Open Zed settings (`Ctrl+,` or `Cmd+,`) and add:
60
+
61
+ ```json
62
+ {
63
+ "language_models": {
64
+ "grok": {
65
+ "version": "1",
66
+ "provider": "agent",
67
+ "default_model": "grok-2-latest",
68
+ "agent": {
69
+ "command": "grok",
70
+ "args": ["acp", "stdio"],
71
+ "env": {
72
+ "GROK_API_KEY": "your-api-key-here"
73
+ }
74
+ }
75
+ }
76
+ }
77
+ }
78
+ ```
79
+
80
+ **Note**: Replace `"grok"` in the command with the full path to your Grok CLI binary if it's not in your PATH:
81
+ - Windows: `"H:\\GitHub\\grok-cli\\target\\release\\grok.exe"`
82
+ - Linux/Mac: `"/path/to/grok-cli/target/release/grok"`
83
+
84
+ ### Method 2: Server Mode
85
+
86
+ Run Grok CLI as a persistent server that Zed connects to.
87
+
88
+ #### Start the ACP Server
89
+
90
+ ```bash
91
+ grok acp server --port 3000
92
+ ```
93
+
94
+ Or let it auto-assign a port:
95
+ ```bash
96
+ grok acp server
97
+ ```
98
+
99
+ #### Add to Zed Settings
100
+
101
+ ```json
102
+ {
103
+ "language_models": {
104
+ "grok": {
105
+ "version": "1",
106
+ "provider": "agent",
107
+ "default_model": "grok-2-latest",
108
+ "agent": {
109
+ "endpoint": "http://127.0.0.1:3000"
110
+ }
111
+ }
112
+ }
113
+ }
114
+ ```
115
+
116
+ ## Configuration Options
117
+
118
+ ### Environment Variables
119
+
120
+ Configuration is managed via `.env` files. Create either:
121
+ - System-wide: `~/.grok/.env`
122
+ - Project-specific: `.grok/.env` (higher priority)
123
+
124
+ ```env
125
+ # API Configuration
126
+ GROK_API_KEY=xai-your-key-here
127
+ GROK_MODEL=grok-code-fast-1
128
+
129
+ # Network settings (for Starlink)
130
+ GROK_STARLINK_OPTIMIZATIONS=true
131
+ GROK_TIMEOUT=60
132
+ GROK_MAX_RETRIES=5
133
+
134
+ # ACP Configuration
135
+ GROK_ACP_ENABLED=true
136
+ GROK_ACP_DEFAULT_PORT=3000
137
+ GROK_ACP_DEV_MODE=false
138
+ ```
139
+
140
+ See `.grok/ENV_CONFIG_GUIDE.md` in the repository for all available options.
141
+
142
+ ## Testing the Integration
143
+
144
+ ### Test ACP Capabilities
145
+
146
+ ```bash
147
+ grok acp capabilities
148
+ ```
149
+
150
+ This shows all available tools and models that Zed can use.
151
+
152
+ ### Test ACP Server Connection
153
+
154
+ If running in server mode:
155
+
156
+ ```bash
157
+ grok acp test --address 127.0.0.1:3000
158
+ ```
159
+
160
+ ### Test STDIO Mode
161
+
162
+ ```bash
163
+ echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocol_version":"1.0","client_info":{"name":"test","version":"1.0"}}}' | grok acp stdio
164
+ ```
165
+
166
+ ## Available Features
167
+
168
+ ### Chat Completion
169
+ Ask questions and get AI responses directly in Zed.
170
+
171
+ ### Code Explanation
172
+ Select code and ask Grok to explain what it does.
173
+
174
+ ### Code Review
175
+ Get detailed code reviews with security and performance suggestions.
176
+
177
+ ### Code Generation
178
+ Describe what you want in natural language and generate code.
179
+
180
+ ### File Operations
181
+ Read, write, and search files in your project.
182
+
183
+ ## Troubleshooting
184
+
185
+ ### Issue: "failed to deserialize response"
186
+
187
+ This was caused by incorrect Clap argument definitions. The issue has been fixed in the latest version. Make sure you:
188
+
189
+ 1. Rebuild the project: `cargo build --release`
190
+ 2. Verify your `.env` configuration is correct
191
+
192
+ ### Issue: ACP Server Not Starting
193
+
194
+ Check if the port is already in use:
195
+
196
+ **Windows:**
197
+ ```bash
198
+ netstat -ano | findstr :3000
199
+ ```
200
+
201
+ **Linux/Mac:**
202
+ ```bash
203
+ lsof -i :3000
204
+ ```
205
+
206
+ Try a different port:
207
+ ```bash
208
+ grok acp server --port 3001
209
+ ```
210
+
211
+ ### Issue: API Key Not Found
212
+
213
+ Verify your API key is set:
214
+ ```bash
215
+ grok config show
216
+ ```
217
+
218
+ If not set, create or edit `~/.grok/.env`:
219
+ ```bash
220
+ # Windows
221
+ echo GROK_API_KEY=xai-your-key-here > %USERPROFILE%\.grok\.env
222
+
223
+ # Linux/Mac
224
+ echo "GROK_API_KEY=xai-your-key-here" > ~/.grok/.env
225
+ ```
226
+
227
+ ### Issue: Network Connectivity
228
+
229
+ Test network connectivity:
230
+ ```bash
231
+ grok test-network --timeout 10
232
+ grok health --api
233
+ ```
234
+
235
+ Enable Starlink optimizations if using satellite internet by adding to `.env`:
236
+ ```env
237
+ GROK_STARLINK_OPTIMIZATIONS=true
238
+ ```
239
+
240
+ ### Issue: Zed Can't Find Grok Binary
241
+
242
+ Use the full path to the binary in Zed settings:
243
+
244
+ **Windows:**
245
+ ```json
246
+ "command": "H:\\GitHub\\grok-cli\\target\\release\\grok.exe"
247
+ ```
248
+
249
+ **Linux/Mac:**
250
+ ```json
251
+ "command": "/home/user/grok-cli/target/release/grok"
252
+ ```
253
+
254
+ ### Debug Logging
255
+
256
+ Enable verbose logging to troubleshoot issues:
257
+
258
+ ```bash
259
+ RUST_LOG=debug grok acp stdio
260
+ ```
261
+
262
+ Or for server mode:
263
+ ```bash
264
+ RUST_LOG=debug grok acp server --port 3000
265
+ ```
266
+
267
+ ## Advanced Configuration
268
+
269
+ ### Custom Model Selection
270
+
271
+ In Zed settings, specify which Grok model to use:
272
+
273
+ ```json
274
+ {
275
+ "language_models": {
276
+ "grok": {
277
+ "default_model": "grok-2-latest"
278
+ }
279
+ }
280
+ }
281
+ ```
282
+
283
+ Available models:
284
+ - `grok-2-latest` - Latest Grok 2 model (recommended)
285
+ - `grok-2` - Stable Grok 2 model
286
+ - `grok-1` - Original Grok model
287
+
288
+ ### Multiple Configurations
289
+
290
+ You can configure multiple Grok instances:
291
+
292
+ ```json
293
+ {
294
+ "language_models": {
295
+ "grok-fast": {
296
+ "provider": "agent",
297
+ "agent": {
298
+ "command": "grok",
299
+ "args": ["acp", "stdio", "--model", "grok-2-latest"]
300
+ }
301
+ },
302
+ "grok-creative": {
303
+ "provider": "agent",
304
+ "agent": {
305
+ "command": "grok",
306
+ "args": ["acp", "stdio", "--model", "grok-1"]
307
+ }
308
+ }
309
+ }
310
+ }
311
+ ```
312
+
313
+ ### Custom Timeout and Retries
314
+
315
+ Adjust network settings for your connection in `.env`:
316
+
317
+ ```env
318
+ GROK_TIMEOUT=45
319
+ GROK_MAX_RETRIES=5
320
+ GROK_BASE_RETRY_DELAY=3000
321
+ ```
322
+
323
+ ## Performance Tips
324
+
325
+ 1. **Use STDIO Mode**: Faster startup than server mode
326
+ 2. **Enable Starlink Optimizations**: If using satellite internet
327
+ 3. **Adjust Timeouts**: Increase for slow connections in `.env`
328
+ 4. **Use Release Build**: Much faster than debug builds
329
+ 5. **Use `.env` Files**: Project `.env` overrides system `.env`
330
+
331
+ ## Security Considerations
332
+
333
+ 1. **API Key Storage**: Never commit `.env` files with API keys to version control (they're in `.gitignore`)
334
+ 2. **Use System `.env`**: Store API keys in `~/.grok/.env` (not in project)
335
+ 3. **Restrict Network Access**: Bind to localhost only (127.0.0.1)
336
+ 4. **Enable Security Features**: Use the built-in policy engine for shell commands
337
+
338
+ ## Getting Help
339
+
340
+ If you encounter issues:
341
+
342
+ - Check the logs: `RUST_LOG=debug grok acp stdio`
343
+ 2. Verify configuration: `grok config show`
344
+ 3. Test connectivity: `grok health --all`
345
+ 4. Review this guide's troubleshooting section
346
+ 5. Open an issue: https://github.com/microtech/grok-cli/issues
347
+
348
+ ## Example Workflow
349
+
350
+ 1. Open a project in Zed
351
+ 2. Press `Ctrl+Shift+P` (or `Cmd+Shift+P` on Mac)
352
+ 3. Type "assistant" and select "Toggle Assistant"
353
+ 4. The Grok AI assistant panel opens
354
+ 5. Ask questions about your code or request changes
355
+ 6. Grok analyzes your project context and responds
356
+ 7. Accept suggested code changes with one click
357
+
358
+ ## Next Steps
359
+
360
+ - Explore all available commands: `grok --help`
361
+ - Check ACP capabilities: `grok acp capabilities`
362
+ - View configuration: `grok config show`
363
+ - Configure settings: Edit `.grok/.env` or `~/.grok/.env`
364
+ - Read the main README: `README.md`
365
+
366
+ ---
367
+
368
+ **Made with ❤️ for the Zed and Rust community**
369
+
370
+ Repository: https://github.com/microtech/grok-cli
371
+ Author: John McConnell (john.microtech@gmail.com)