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,449 @@
1
+ # Automated File Operations Guide
2
+
3
+ ## Overview
4
+
5
+ Grok CLI now features **automatic tool execution** that allows Grok AI to create, modify, and manage files directly during conversations. This powerful feature eliminates the need for manual copy-pasting and enables true conversational project creation.
6
+
7
+ ## What Changed?
8
+
9
+ ### Before (v0.1.1 and earlier)
10
+ When you asked Grok to create a project, it would output text descriptions:
11
+ ```
12
+ Creating project structure:
13
+ - Create directory: src/
14
+ - Create file: src/main.rs with content...
15
+ - Create file: Cargo.toml with content...
16
+ ```
17
+
18
+ **Problem**: You had to manually create each file and copy the content.
19
+
20
+ ### After (v0.1.2+)
21
+ Grok automatically executes file operations:
22
+ ```
23
+ You: Create a new Rust project structure
24
+
25
+ Grok is executing operations...
26
+ ✓ Successfully wrote to Cargo.toml
27
+ ✓ Successfully wrote to src/main.rs
28
+ ✓ Successfully wrote to .gitignore
29
+ All operations completed!
30
+ ```
31
+
32
+ **Result**: Files are created automatically in your current directory!
33
+
34
+ ## Available Tools
35
+
36
+ ### 1. write_file
37
+ Creates a new file or overwrites an existing one with specified content.
38
+
39
+ **Usage Example**:
40
+ ```
41
+ You: Write a hello world program to main.rs
42
+ You: Create a README.md with project documentation
43
+ You: Make a .env.example file with the required environment variables
44
+ ```
45
+
46
+ **What happens**:
47
+ - **Automatically creates parent directories** (e.g., `.grok/` for `.grok/context.md`)
48
+ - Overwrites existing files (use with caution!)
49
+ - Shows confirmation with file path
50
+ - Works with deeply nested paths like `src/utils/helpers/file.rs`
51
+
52
+ ### 2. read_file
53
+ Reads the content of an existing file.
54
+
55
+ **Usage Example**:
56
+ ```
57
+ You: What's in the main.rs file?
58
+ You: Show me the contents of config.toml
59
+ You: Read the README
60
+ ```
61
+
62
+ **What happens**:
63
+ - Reads and displays file contents
64
+ - Shows file size in bytes
65
+ - Returns error if file doesn't exist
66
+
67
+ ### 3. replace
68
+ Finds and replaces text within a file.
69
+
70
+ **Usage Example**:
71
+ ```
72
+ You: Replace "localhost" with "0.0.0.0" in config.toml
73
+ You: Change the version from 0.1.0 to 0.2.0 in Cargo.toml
74
+ You: Update the author name in all source files
75
+ ```
76
+
77
+ **What happens**:
78
+ - Performs find/replace operation
79
+ - Shows number of replacements made
80
+ - Validates expected replacement count if specified
81
+
82
+ ### 4. list_directory
83
+ Lists all files and directories in a specified path.
84
+
85
+ **Usage Example**:
86
+ ```
87
+ You: What files are in the src directory?
88
+ You: List all files in the current folder
89
+ You: Show me what's in the docs/ directory
90
+ ```
91
+
92
+ **What happens**:
93
+ - Lists all entries with directories marked with `/`
94
+ - Sorted alphabetically
95
+ - Shows error if directory doesn't exist
96
+ - Works with nested directories like `src/utils/`
97
+
98
+ ### 5. glob_search
99
+ Finds files matching a glob pattern.
100
+
101
+ **Usage Example**:
102
+ ```
103
+ You: Find all Rust files in the project
104
+ You: List all markdown files
105
+ You: Show me all .toml configuration files
106
+ ```
107
+
108
+ **What happens**:
109
+ - Searches recursively from current directory
110
+ - Returns full paths of matching files
111
+ - Respects security restrictions
112
+
113
+ ### 6. save_memory
114
+ Saves important facts to long-term memory.
115
+
116
+ **Usage Example**:
117
+ ```
118
+ You: Remember that this project uses PostgreSQL
119
+ You: Save the fact that we're following clean architecture
120
+ You: Note that deployment happens via GitHub Actions
121
+ ```
122
+
123
+ **What happens**:
124
+ - Appends fact to `~/.grok/memory.md`
125
+ - Persists across sessions
126
+ - Available for future context
127
+
128
+ ### 7. run_shell_command
129
+ Executes shell commands in the current directory.
130
+
131
+ **Usage Example**:
132
+ ```
133
+ You: Run cargo init to initialize a new Rust project
134
+ You: Execute git init to start version control
135
+ You: Run cargo build to compile the project
136
+ You: Run cargo new my_project --lib and then cd into it and run git init
137
+ ```
138
+
139
+ **What happens**:
140
+ - Executes the command via PowerShell (Windows) or sh (Linux/Mac)
141
+ - **Automatic syntax conversion on Windows**: `&&` is converted to `;` for PowerShell compatibility
142
+ - Shows command output
143
+ - Returns exit status
144
+ - Subject to security validation
145
+
146
+ **PowerShell Note**:
147
+ On Windows, bash-style command chaining (`command1 && command2`) is automatically converted to PowerShell syntax (`command1; command2`). This means you can use natural bash syntax and it will work correctly on Windows.
148
+
149
+ **Examples**:
150
+ ```
151
+ # This works on all platforms:
152
+ You: Run cargo new project && cd project && git init
153
+
154
+ # Automatically converted to on Windows:
155
+ cargo new project; cd project; git init
156
+ ```
157
+
158
+ ## Security & Permissions
159
+
160
+ ### Trusted Directories
161
+ Tool execution is **restricted to safe directories**:
162
+ - ✅ Current working directory
163
+ - ✅ Subdirectories of current directory
164
+ - ❌ Parent directories
165
+ - ❌ System directories
166
+ - ❌ User home directory (except `.grok/`)
167
+
168
+ ### How Security Works
169
+ ```rust
170
+ // Current directory is automatically trusted
171
+ let mut security = SecurityPolicy::new();
172
+ security.add_trusted_directory(&env::current_dir()?);
173
+
174
+ // All tool operations are validated
175
+ tools::write_file(path, content, &security)?;
176
+ ```
177
+
178
+ ### Best Practices
179
+ 1. **Start in your project directory** before running grok CLI
180
+ 2. **Review operations** - Grok shows what it's doing
181
+ 3. **Use version control** - Commit before major changes
182
+ 4. **Check file contents** - Use `read_file` to verify results
183
+
184
+ ## Practical Examples
185
+
186
+ ### Example 1: Create a New Rust CLI Project
187
+
188
+ ```bash
189
+ cd ~/projects
190
+ mkdir my-cli && cd my-cli
191
+ grok
192
+
193
+ You: Create a new Rust CLI project structure with:
194
+ - Cargo.toml for a binary called my-cli
195
+ - src/main.rs with argument parsing using clap
196
+ - README.md with basic documentation
197
+ - .gitignore for Rust projects
198
+ - .grok/context.md with project rules
199
+ ```
200
+
201
+ **Result**:
202
+ ```
203
+ Grok is executing operations...
204
+ ✓ Successfully wrote to Cargo.toml
205
+ ✓ Successfully wrote to src/main.rs
206
+ ✓ Successfully wrote to README.md
207
+ ✓ Successfully wrote to .gitignore
208
+ ✓ Successfully wrote to .grok/context.md
209
+ All operations completed!
210
+ ```
211
+
212
+ **Note**: The `.grok/` directory is automatically created!
213
+
214
+ ### Example 2: Create a Web API Project
215
+
216
+ ```bash
217
+ mkdir api-server && cd api-server
218
+ grok
219
+
220
+ You: Set up a Rust web API project using Axum with:
221
+ - Cargo.toml with axum, tokio, and serde dependencies
222
+ - src/main.rs with a basic server setup
223
+ - src/routes/ directory structure for API endpoints
224
+ - .env.example with configuration variables
225
+ - README with API documentation
226
+ ```
227
+
228
+ ### Example 3: Modify Existing Project
229
+
230
+ ```bash
231
+ cd existing-project
232
+ grok
233
+
234
+ You: Update all files to use version 2.0.0 instead of 1.0.0
235
+ You: Add error handling to src/main.rs
236
+ You: Create a new module src/utils/logger.rs
237
+ ```
238
+
239
+ ### Example 4: Generate Documentation
240
+
241
+ ```bash
242
+ grok
243
+
244
+ You: Create comprehensive documentation:
245
+ - docs/ARCHITECTURE.md explaining the project structure
246
+ - docs/API.md with endpoint documentation
247
+ - docs/SETUP.md with installation instructions
248
+ - Update README.md with links to all docs
249
+ ```
250
+
251
+ ## Enabling/Disabling Tool Execution
252
+
253
+ ### Interactive Mode (Default: Enabled)
254
+ Tool execution is **always enabled** in interactive mode:
255
+ ```bash
256
+ grok interactive
257
+ # or just
258
+ grok
259
+ ```
260
+
261
+ ### Single Query Mode
262
+ Tool execution is **enabled** for single queries:
263
+ ```bash
264
+ grok query "Create a hello world program"
265
+ ```
266
+
267
+ ### Chat Mode
268
+ Tool execution is **enabled** in chat mode:
269
+ ```bash
270
+ grok chat "Set up a new project" --interactive
271
+ ```
272
+
273
+ ## Troubleshooting
274
+
275
+ ### Issue: Files Not Being Created
276
+
277
+ **Problem**: Grok describes what to do but doesn't create files.
278
+
279
+ **Solution**:
280
+ 1. Make sure you're using **v0.1.2 or later**:
281
+ ```bash
282
+ grok --version
283
+ ```
284
+ 2. Check that you're in interactive mode or using the query command
285
+ 3. Verify your API key is set correctly
286
+
287
+ ### Issue: Permission Denied
288
+
289
+ **Problem**: "Access denied: Path is not in a trusted directory"
290
+
291
+ **Solution**:
292
+ 1. Make sure you're in your project directory
293
+ 2. Don't try to access parent directories with `../`
294
+ 3. System directories are not accessible
295
+
296
+ ### Issue: Directory Not Found (FIXED)
297
+
298
+ **Problem**: "Failed to resolve path '.grok/context.md': The system cannot find the file specified"
299
+
300
+ **Solution**: This is now automatically fixed! Parent directories are created automatically.
301
+
302
+ If you see this error, rebuild:
303
+ ```bash
304
+ cargo build --release
305
+ ```
306
+
307
+ ### Issue: File Already Exists
308
+
309
+ **Problem**: Concerned about overwriting files
310
+
311
+ **Solution**:
312
+ 1. Use version control (git) to track changes
313
+ 2. Ask Grok to "read the file first" before modifying
314
+ 3. Use the `replace` tool for targeted edits instead of full rewrites
315
+
316
+ ### Issue: Tool Not Executed
317
+
318
+ **Problem**: Grok responds with text instead of executing tools
319
+
320
+ **Solution**:
321
+ 1. Be more explicit: "Create the file..." instead of "You could create..."
322
+ 2. Use imperative language: "Write to main.rs" not "Maybe write to main.rs"
323
+ 3. Update to latest version - tool calling was added in v0.1.2
324
+
325
+ ## Tips for Best Results
326
+
327
+ ### 1. Be Specific and Direct
328
+ ❌ "It would be nice to have a config file"
329
+ ✅ "Create a config.toml file with database settings"
330
+
331
+ ### 2. Provide Context
332
+ ❌ "Make a web server"
333
+ ✅ "Create a Rust web server using Axum on port 3000 with health check endpoint"
334
+
335
+ ### 3. Break Down Complex Tasks
336
+ ❌ "Build a complete authentication system"
337
+ ✅ "First, create the user model in src/models/user.rs"
338
+ ✅ "Next, add authentication middleware in src/middleware/auth.rs"
339
+
340
+ ### 4. Verify Results
341
+ After file operations:
342
+ ```
343
+ You: List all files we just created
344
+ You: Show me the contents of main.rs
345
+ ```
346
+
347
+ ### 5. Use Natural Language
348
+ The system understands natural requests:
349
+ - "Make a new file called..."
350
+ - "Write the following code to..."
351
+ - "Update the configuration in..."
352
+ - "Create a directory structure for..."
353
+
354
+ ## Technical Details
355
+
356
+ ### How It Works
357
+
358
+ 1. **Tool Definitions**: The CLI sends tool schemas to Grok AI
359
+ 2. **AI Decision**: Grok decides if tools are needed for your request
360
+ 3. **Tool Calls**: Response includes structured function calls
361
+ 4. **Execution**: CLI executes each tool call sequentially
362
+ 5. **Feedback**: Results are displayed to you
363
+
364
+ ### Response Format
365
+ ```json
366
+ {
367
+ "role": "assistant",
368
+ "content": "I'll create those files for you.",
369
+ "tool_calls": [
370
+ {
371
+ "id": "call_123",
372
+ "type": "function",
373
+ "function": {
374
+ "name": "write_file",
375
+ "arguments": "{\"path\":\"main.rs\",\"content\":\"fn main() {}\"}"
376
+ }
377
+ }
378
+ ]
379
+ }
380
+ ```
381
+
382
+ ### Execution Flow
383
+ ```
384
+ User Request
385
+
386
+ Grok API (with tool definitions)
387
+
388
+ Response with tool_calls
389
+
390
+ CLI executes each tool
391
+
392
+ Display results to user
393
+ ```
394
+
395
+ ## Integration with Other Features
396
+
397
+ ### Works with Session Persistence
398
+ ```bash
399
+ grok
400
+
401
+ You: Create a new project structure
402
+ # ... files created ...
403
+
404
+ You: /save my-project-setup
405
+
406
+ # Later...
407
+ You: /load my-project-setup
408
+ # Continue where you left off
409
+ ```
410
+
411
+ ### Works with Context Discovery
412
+ Grok understands your project context when creating files:
413
+ ```bash
414
+ # In a project with .zed/rules
415
+ grok
416
+
417
+ You: Create a new module following our project conventions
418
+ # Grok uses context from .zed/rules to match your style
419
+ ```
420
+
421
+ ### Works with Chat Logging
422
+ All tool executions are logged:
423
+ ```bash
424
+ grok history view <session-id>
425
+ # See exactly what files were created and when
426
+ ```
427
+
428
+ ## Future Enhancements
429
+
430
+ Planned features for future versions:
431
+ - [ ] Undo/redo for file operations
432
+ - [ ] Dry-run mode to preview changes
433
+ - [ ] Batch operation confirmation prompts
434
+ - [ ] Git integration for automatic commits
435
+ - [ ] File templates and scaffolding
436
+ - [ ] Multi-file refactoring operations
437
+
438
+ ## Feedback
439
+
440
+ This is a new feature! If you encounter issues or have suggestions:
441
+ - Open an issue: https://github.com/microtech/grok-cli/issues
442
+ - Contribute: See CONTRIBUTING.md
443
+ - Discuss: Start a discussion in GitHub Discussions
444
+
445
+ ---
446
+
447
+ **Last Updated**: Version 0.1.2
448
+ **Feature Status**: ✅ Stable
449
+ **Platform Support**: Windows 11, macOS, Linux