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,240 @@
1
+ # Grok CLI v0.1.2 Release Notes
2
+
3
+ **Release Date**: 2026-01-13
4
+ **Author**: john mcconnell (john.microtech@gmail.com)
5
+ **Repository**: https://github.com/microtech/grok-cli
6
+
7
+ ## 🎉 What's New
8
+
9
+ ### 📜 Chat Session Logging (Major Feature)
10
+
11
+ The headline feature of v0.1.2 is **comprehensive chat session logging**! Every conversation with Grok is now automatically saved and searchable.
12
+
13
+ #### Key Features:
14
+ - ✅ **Automatic Logging**: All ACP (Zed) conversations saved automatically
15
+ - ✅ **Dual Format Output**: JSON (machine-readable) + TXT (human-readable)
16
+ - ✅ **Full History Management**: List, view, search, and clear past sessions
17
+ - ✅ **Session Tracking**: Each chat gets a unique ID with timestamps
18
+ - ✅ **Smart Search**: Find conversations by content with highlighting
19
+ - ✅ **Auto-Rotation**: Configurable log size limits with automatic cleanup
20
+
21
+ #### New Commands
22
+
23
+ ```bash
24
+ grok history list # Browse all your chat sessions
25
+ grok history view <session-id> # View complete conversation
26
+ grok history search "query" # Search through all chats
27
+ grok history clear --confirm # Clear chat history
28
+ ```
29
+
30
+ #### Configuration
31
+
32
+ ```bash
33
+ # Environment variables for chat logging
34
+ GROK_CHAT_LOGGING_ENABLED=true
35
+ GROK_CHAT_LOG_DIR=~/.grok/logs/chat_sessions
36
+ GROK_CHAT_LOG_MAX_SIZE_MB=10
37
+ GROK_CHAT_LOG_ROTATION_COUNT=5
38
+ GROK_CHAT_LOG_INCLUDE_SYSTEM=true
39
+ ```
40
+
41
+ ### Key Features
42
+
43
+ - **Automatic Logging**: All ACP/Zed conversations saved automatically
44
+ - **Dual Format**: JSON (machine-readable) + TXT (human-readable)
45
+ - **Full-Text Search**: Search through all your conversations
46
+ - **Beautiful Output**: Color-coded, formatted terminal display
47
+ - **Privacy First**: 100% local storage, no cloud uploads
48
+ - **Network Resilient**: Handles Starlink drops gracefully
49
+
50
+ ### Example Usage
51
+
52
+ ```bash
53
+ # List all your chat sessions
54
+ grok history list
55
+
56
+ # View a specific conversation
57
+ grok history view <session-id>
58
+
59
+ # Search through all your chats
60
+ grok history search "authentication"
61
+
62
+ # Clear old logs
63
+ grok history clear --confirm
64
+ ```
65
+
66
+ ## 🎯 Quick Start
67
+
68
+ ### Using Chat Logging
69
+
70
+ Chat logging is **enabled by default** and works automatically when you use Grok through Zed editor (ACP mode).
71
+
72
+ 1. **Use Grok in Zed** or run `grok acp stdio`
73
+ 2. **Have conversations** - they're automatically saved!
74
+ 3. **Review history**:
75
+ ```bash
76
+ grok history list
77
+ grok history view <session-id>
78
+ grok history search "your query"
79
+ ```
80
+
81
+ ### Configuration (Optional)
82
+
83
+ Add to your `.env` file:
84
+ ```bash
85
+ # Enable/disable logging (default: true)
86
+ GROK_CHAT_LOGGING_ENABLED=true
87
+
88
+ # Custom log directory
89
+ GROK_CHAT_LOG_DIR=~/.grok/logs/chat_sessions
90
+
91
+ # Rotation settings
92
+ GROK_CHAT_LOG_MAX_SIZE_MB=10
93
+ GROK_CHAT_LOG_ROTATION_COUNT=5
94
+ ```
95
+
96
+ ## 📦 What's Included
97
+
98
+ ### Chat Logging System
99
+ - **564 lines** of robust logging code
100
+ - **421 lines** of history management commands
101
+ - **415+ lines** of comprehensive documentation
102
+ - **Zero new dependencies** - uses existing crates
103
+
104
+ ### Commands Added
105
+ - `grok history list` - Browse all saved sessions
106
+ - `grok history view <session-id>` - View full conversation
107
+ - `grok history search "query"` - Search through chats
108
+ - `grok history clear --confirm` - Delete all logs
109
+
110
+ ### Configuration Added
111
+ - `GROK_CHAT_LOGGING_ENABLED` - Enable/disable logging
112
+ - `GROK_CHAT_LOG_DIR` - Custom log directory
113
+ - `GROK_CHAT_LOG_MAX_SIZE_MB` - Max file size
114
+ - `GROK_CHAT_LOG_ROTATION_COUNT` - Number of files to keep
115
+ - `GROK_CHAT_LOG_INCLUDE_SYSTEM` - Include system messages
116
+
117
+ ### Files Modified
118
+ - `Cargo.toml` - Version bump to 0.1.2
119
+ - `src/main.rs` - Added chat logger initialization
120
+ - `src/utils/mod.rs` - Added chat_logger module
121
+ - `src/cli/commands/mod.rs` - Added history module
122
+ - `src/cli/commands/acp.rs` - Integrated logging into ACP
123
+ - `src/cli/app.rs` - Added History command
124
+ - `src/lib.rs` - Added HistoryAction enum
125
+
126
+ ### New Files
127
+ - `src/utils/chat_logger.rs` (564 lines) - Core logging implementation
128
+ - `src/cli/commands/history.rs` (421 lines) - History commands
129
+ - `docs/CHAT_LOGGING.md` (415 lines) - Complete documentation
130
+ - `docs/CHAT_LOGGING_IMPLEMENTATION.md` (451 lines) - Technical details
131
+ - `docs/CHAT_LOGGING_SUMMARY.md` (292 lines) - Quick reference
132
+
133
+ ## 🎉 Highlights
134
+
135
+ ### 🆕 Chat Session Logging
136
+ Every conversation you have with Grok through Zed editor (ACP mode) is now automatically saved! Review, search, and analyze your chat history anytime.
137
+
138
+ ### 🔍 Powerful Search
139
+ Find that helpful explanation from last week with full-text search across all your conversations.
140
+
141
+ ### 📊 Beautiful Output
142
+ Color-coded, well-formatted terminal output makes browsing history a pleasure.
143
+
144
+ ### 🔒 Privacy First
145
+ All logs stored locally on your machine. Nothing sent to the cloud. You have complete control.
146
+
147
+ ## 🆕 New Commands
148
+
149
+ ```bash
150
+ # View all your chat sessions
151
+ grok history list
152
+
153
+ # Read a full conversation
154
+ grok history view <session-id>
155
+
156
+ # Search through all your chats
157
+ grok history search "authentication"
158
+
159
+ # Clear all history
160
+ grok history clear --confirm
161
+ ```
162
+
163
+ ## 📁 Where Logs Are Saved
164
+
165
+ **Default Locations:**
166
+ - **Windows**: `C:\Users\<username>\.grok\logs\chat_sessions\`
167
+ - **Linux/macOS**: `~/.grok/logs/chat_sessions/`
168
+
169
+ Each session creates two files:
170
+ - `<session-id>.json` - Machine-readable with full metadata
171
+ - `<session-id>.txt` - Beautiful human-readable transcript
172
+
173
+ ## 🎨 Example Usage
174
+
175
+ ### View Your Chat History
176
+ ```bash
177
+ # List all sessions
178
+ grok history list
179
+
180
+ # Output:
181
+ # ================================================================================
182
+ # CHAT SESSIONS (3 total)
183
+ # ================================================================================
184
+ #
185
+ # 1. 550e8400-e29b-41d4-a716-446655440000 Completed
186
+ # Started: 2026-01-13 10:30:00 UTC | 12 messages
187
+ # Duration: 930 seconds
188
+ # Preview: How do I implement authentication in Rust?
189
+ ```
190
+
191
+ ### View a Conversation
192
+ ```bash
193
+ grok history view 550e8400-e29b-41d4-a716-446655440000
194
+ ```
195
+
196
+ Shows the complete conversation with beautiful formatting:
197
+ ```
198
+ ================================================================================
199
+ GROK CLI CHAT SESSION LOG
200
+ ================================================================================
201
+ Session ID: 550e8400-e29b-41d4-a716-446655440000
202
+ Start Time: 2026-01-13 10:30:00 UTC
203
+ End Time: 2026-01-13 10:45:30 UTC
204
+ Duration: 930 seconds
205
+ Messages: 12
206
+ ================================================================================
207
+
208
+ [1] USER (10:30:05)
209
+ --------------------------------------------------------------------------------
210
+ How do I implement authentication in Rust?
211
+
212
+ [2] ASSISTANT (10:30:15)
213
+ --------------------------------------------------------------------------------
214
+ Here's a comprehensive guide to implementing authentication in Rust...
215
+ ```
216
+
217
+ Perfect! **Version 0.1.2 is now released!** 🎉
218
+
219
+ ## Summary of Version Update
220
+
221
+ ✅ **Updated files:**
222
+ - `Cargo.toml` - Version bumped from 0.1.1 → 0.1.2
223
+ - `CHANGELOG.md` - Updated release date to 2026-01-13
224
+ - Created `RELEASE_NOTES_0.1.2.md` - Comprehensive release notes
225
+
226
+ ✅ **Version verified:**
227
+ ```
228
+ grok-cli 0.1.2
229
+ ```
230
+
231
+ ### 🎉 Version 0.1.2 is now officially released!
232
+
233
+ **Key Features:**
234
+ - ✅ Chat session logging with automatic saving
235
+ - ✅ History management commands (list, view, search, clear)
236
+ - ✅ Dual format output (JSON + TXT)
237
+ - ✅ Network-resilient for Starlink users
238
+ - ✅ Comprehensive documentation
239
+
240
+ **Ready for distribution!** 🚀
package/docs/TOOLS.md ADDED
@@ -0,0 +1,459 @@
1
+ # Grok CLI Tools Documentation
2
+
3
+ ## Overview
4
+
5
+ Grok CLI provides a comprehensive set of tools that enable the AI to interact with your local development environment. These tools are automatically available when using the ACP (Agent Client Protocol) server mode or when Grok needs to perform file operations during interactive sessions.
6
+
7
+ ## Accessing Tools
8
+
9
+ ### In Interactive Mode
10
+ Use the `/tools` command to list all available tools:
11
+ ```
12
+ /tools
13
+ ```
14
+
15
+ ### In ACP Server Mode
16
+ Tools are automatically available when running:
17
+ ```bash
18
+ grok acp stdio
19
+ ```
20
+
21
+ ## Available Tools
22
+
23
+ ### File Operations
24
+
25
+ #### `read_file`
26
+ **Description:** Read the content of a file
27
+
28
+ **Signature:** `read_file(path: string)`
29
+
30
+ **Parameters:**
31
+ - `path` (string, required): The path to the file to read
32
+
33
+ **Example Usage:**
34
+ ```
35
+ Grok will use: read_file("src/main.rs")
36
+ ```
37
+
38
+ **Returns:** The file content as a string
39
+
40
+ **Security:** Respects security policy and trusted directories
41
+
42
+ ---
43
+
44
+ #### `write_file`
45
+ **Description:** Write content to a file
46
+
47
+ **Signature:** `write_file(path: string, content: string)`
48
+
49
+ **Parameters:**
50
+ - `path` (string, required): The path to the file to write
51
+ - `content` (string, required): The content to write to the file
52
+
53
+ **Example Usage:**
54
+ ```
55
+ Grok will use: write_file("src/utils/helper.rs", "pub fn example() { }")
56
+ ```
57
+
58
+ **Returns:** Success message or error
59
+
60
+ **Security:** Respects security policy and trusted directories
61
+
62
+ ---
63
+
64
+ #### `replace`
65
+ **Description:** Replace text in a file with surgical precision
66
+
67
+ **Signature:** `replace(path: string, old_string: string, new_string: string, expected_replacements?: integer)`
68
+
69
+ **Parameters:**
70
+ - `path` (string, required): The path to the file to modify
71
+ - `old_string` (string, required): The exact string to be replaced
72
+ - `new_string` (string, required): The new string to replace with
73
+ - `expected_replacements` (integer, optional): Expected number of replacements for validation
74
+
75
+ **Example Usage:**
76
+ ```
77
+ Grok will use: replace("src/config.rs", "default_port = 8080", "default_port = 3000")
78
+ ```
79
+
80
+ **Returns:** Success message with replacement count or error
81
+
82
+ **Security:** Respects security policy and trusted directories
83
+
84
+ **Notes:**
85
+ - Exact string matching - whitespace matters!
86
+ - Use `expected_replacements` to catch unexpected multiple replacements
87
+ - Safer than regex-based replacements for most use cases
88
+
89
+ ---
90
+
91
+ ### File Search & Discovery
92
+
93
+ #### `list_directory`
94
+ **Description:** List files and directories in a specified path
95
+
96
+ **Signature:** `list_directory(path: string)`
97
+
98
+ **Parameters:**
99
+ - `path` (string, required): The directory path to list
100
+
101
+ **Example Usage:**
102
+ ```
103
+ Grok will use: list_directory("src/")
104
+ ```
105
+
106
+ **Returns:** JSON array of files and directories with metadata
107
+
108
+ **Security:** Respects security policy and trusted directories
109
+
110
+ ---
111
+
112
+ #### `glob_search`
113
+ **Description:** Find files matching a glob pattern
114
+
115
+ **Signature:** `glob_search(pattern: string)`
116
+
117
+ **Parameters:**
118
+ - `pattern` (string, required): The glob pattern to match (e.g., `**/*.rs`, `src/**/*.toml`)
119
+
120
+ **Example Usage:**
121
+ ```
122
+ Grok will use: glob_search("**/*.rs")
123
+ ```
124
+
125
+ **Returns:** List of matching file paths
126
+
127
+ **Security:** Respects security policy and trusted directories
128
+
129
+ **Pattern Examples:**
130
+ - `**/*.rs` - All Rust files recursively
131
+ - `src/**/*.toml` - All TOML files under src/
132
+ - `*.json` - JSON files in current directory
133
+ - `test_*.rs` - Test files starting with "test_"
134
+
135
+ ---
136
+
137
+ #### `search_file_content`
138
+ **Description:** Search for text patterns in files using regular expressions
139
+
140
+ **Signature:** `search_file_content(path: string, pattern: string)`
141
+
142
+ **Parameters:**
143
+ - `path` (string, required): The file or directory to search in
144
+ - `pattern` (string, required): The regex pattern to search for
145
+
146
+ **Example Usage:**
147
+ ```
148
+ Grok will use: search_file_content("src/", "fn main")
149
+ ```
150
+
151
+ **Returns:** List of matches with file paths, line numbers, and matched text
152
+
153
+ **Security:** Respects security policy and trusted directories
154
+
155
+ **Pattern Examples:**
156
+ - `fn main` - Find main functions
157
+ - `TODO|FIXME` - Find TODO or FIXME comments
158
+ - `struct \w+` - Find struct definitions
159
+ - `pub async fn` - Find public async functions
160
+
161
+ ---
162
+
163
+ ### Execution & Web
164
+
165
+ #### `run_shell_command`
166
+ **Description:** Execute a shell command in the system
167
+
168
+ **Signature:** `run_shell_command(command: string)`
169
+
170
+ **Parameters:**
171
+ - `command` (string, required): The shell command to execute
172
+
173
+ **Example Usage:**
174
+ ```
175
+ Grok will use: run_shell_command("cargo test")
176
+ ```
177
+
178
+ **Returns:** Command output (stdout and stderr combined)
179
+
180
+ **Security:**
181
+ - Respects security policy
182
+ - Use with caution - can execute arbitrary commands
183
+ - Best for build tools, tests, and development commands
184
+
185
+ **Common Use Cases:**
186
+ - `cargo build` - Build Rust projects
187
+ - `cargo test` - Run tests
188
+ - `git status` - Check git status
189
+ - `npm install` - Install Node packages
190
+ - `rustfmt src/**/*.rs` - Format code
191
+
192
+ ---
193
+
194
+ #### `web_search`
195
+ **Description:** Search the web using Google Custom Search API
196
+
197
+ **Signature:** `web_search(query: string)`
198
+
199
+ **Parameters:**
200
+ - `query` (string, required): The search query
201
+
202
+ **Example Usage:**
203
+ ```
204
+ Grok will use: web_search("Rust async programming best practices")
205
+ ```
206
+
207
+ **Returns:** Search results with titles, URLs, and snippets
208
+
209
+ **Requirements:**
210
+ - Requires Google Custom Search API key
211
+ - Configure in `.env` file
212
+
213
+ **Configuration:**
214
+ ```env
215
+ GOOGLE_API_KEY=your_api_key_here
216
+ GOOGLE_CSE_ID=your_search_engine_id_here
217
+ ```
218
+
219
+ ---
220
+
221
+ #### `web_fetch`
222
+ **Description:** Fetch content from a URL
223
+
224
+ **Signature:** `web_fetch(url: string)`
225
+
226
+ **Parameters:**
227
+ - `url` (string, required): The URL to fetch
228
+
229
+ **Example Usage:**
230
+ ```
231
+ Grok will use: web_fetch("https://docs.rs/tokio")
232
+ ```
233
+
234
+ **Returns:** The content of the fetched page
235
+
236
+ **Notes:**
237
+ - Respects network timeouts
238
+ - Handles SSL/TLS connections
239
+ - Includes retry logic for Starlink/satellite connections
240
+
241
+ ---
242
+
243
+ ### Memory
244
+
245
+ #### `save_memory`
246
+ **Description:** Save a fact to long-term memory for future sessions
247
+
248
+ **Signature:** `save_memory(fact: string)`
249
+
250
+ **Parameters:**
251
+ - `fact` (string, required): The fact to remember
252
+
253
+ **Example Usage:**
254
+ ```
255
+ Grok will use: save_memory("User prefers tabs over spaces for indentation")
256
+ ```
257
+
258
+ **Returns:** Confirmation message
259
+
260
+ **Use Cases:**
261
+ - User preferences
262
+ - Project-specific conventions
263
+ - Important context for future sessions
264
+
265
+ ---
266
+
267
+ ## Tool Execution Flow
268
+
269
+ When Grok needs to use a tool, the following happens:
270
+
271
+ 1. **Request Analysis** - Grok analyzes your request and determines which tools are needed
272
+ 2. **Tool Call** - Grok makes a function call with the appropriate parameters
273
+ 3. **Security Check** - The security manager validates the operation
274
+ 4. **Execution** - The tool is executed with the provided parameters
275
+ 5. **Result Integration** - The result is integrated into Grok's response
276
+ 6. **Iteration** - If needed, Grok may call additional tools (up to 10 iterations)
277
+
278
+ ## Security Model
279
+
280
+ ### Trusted Directories
281
+ - By default, the current working directory is trusted
282
+ - Additional directories can be added via configuration
283
+ - File operations are restricted to trusted directories
284
+
285
+ ### Security Policy
286
+ The security manager enforces:
287
+ - Path validation (no directory traversal attacks)
288
+ - File operation restrictions
289
+ - Command execution policies
290
+ - Rate limiting on network operations
291
+
292
+ ### Configuration
293
+ Configure security settings in your config file:
294
+
295
+ ```json
296
+ {
297
+ "acp": {
298
+ "enabled": true,
299
+ "dev_mode": false,
300
+ "trusted_directories": [
301
+ "/path/to/your/project"
302
+ ]
303
+ }
304
+ }
305
+ ```
306
+
307
+ ## Best Practices
308
+
309
+ ### For File Operations
310
+ 1. **Read before write** - Always read a file before modifying it
311
+ 2. **Use `replace` for precision** - Prefer `replace` over full file rewrites
312
+ 3. **Validate paths** - Ensure paths are correct before operations
313
+ 4. **Check results** - Always verify tool results before proceeding
314
+
315
+ ### For Search Operations
316
+ 1. **Start broad, then narrow** - Use `glob_search` to find files, then `search_file_content` to find specific content
317
+ 2. **Test patterns** - Test regex patterns before using in production
318
+ 3. **Use appropriate tools** - `glob_search` for file names, `search_file_content` for file content
319
+
320
+ ### For Shell Commands
321
+ 1. **Be specific** - Use exact commands, avoid complex shell scripts
322
+ 2. **Check dependencies** - Ensure required tools are installed
323
+ 3. **Handle errors** - Expect and handle command failures
324
+ 4. **Use timeouts** - Long-running commands may timeout
325
+
326
+ ### For Web Operations
327
+ 1. **Configure API keys** - Set up `.env` file for web search
328
+ 2. **Handle failures** - Network operations can fail, especially on Starlink
329
+ 3. **Cache results** - Avoid repeated fetches of the same data
330
+ 4. **Respect rate limits** - Don't abuse web APIs
331
+
332
+ ## Troubleshooting
333
+
334
+ ### "Permission denied" errors
335
+ - Check that the file/directory is in a trusted directory
336
+ - Verify file permissions on your system
337
+ - Add the directory to `trusted_directories` in config
338
+
339
+ ### "File not found" errors
340
+ - Verify the path is correct (use `list_directory` to check)
341
+ - Ensure you're using the correct path separator for your OS
342
+ - Check that the file exists using `glob_search`
343
+
344
+ ### "Tool execution timeout"
345
+ - Increase timeout in configuration
346
+ - For long-running commands, consider background execution
347
+ - Check network connectivity for web operations
348
+
349
+ ### "Max tool loop iterations reached"
350
+ - The tool execution loop has a limit of 10 iterations
351
+ - This prevents infinite loops
352
+ - Break complex tasks into smaller steps
353
+
354
+ ## Examples
355
+
356
+ ### Example 1: Refactor a function
357
+ ```
358
+ You: "Can you refactor the parse_config function in src/config.rs to use serde?"
359
+
360
+ Grok will:
361
+ 1. Use read_file("src/config.rs") to read the current implementation
362
+ 2. Analyze the code
363
+ 3. Use replace(...) to update the function
364
+ 4. Use run_shell_command("cargo check") to verify it compiles
365
+ ```
366
+
367
+ ### Example 2: Find and fix TODOs
368
+ ```
369
+ You: "Find all TODO comments in the project and show me what needs to be done"
370
+
371
+ Grok will:
372
+ 1. Use glob_search("**/*.rs") to find all Rust files
373
+ 2. Use search_file_content(".", "TODO|FIXME") to find all TODOs
374
+ 3. Analyze and summarize the results
375
+ ```
376
+
377
+ ### Example 3: Add a new feature
378
+ ```
379
+ You: "Add a new logger module to the project"
380
+
381
+ Grok will:
382
+ 1. Use list_directory("src/") to understand the project structure
383
+ 2. Use write_file("src/logger.rs") to create the new module
384
+ 3. Use read_file("src/lib.rs") to read the lib file
385
+ 4. Use replace(...) to add the module declaration
386
+ 5. Use run_shell_command("cargo test") to verify everything works
387
+ ```
388
+
389
+ ## Integration with Zed Editor
390
+
391
+ When using Grok with Zed via ACP:
392
+
393
+ 1. **Start the ACP server:**
394
+ ```bash
395
+ grok acp stdio
396
+ ```
397
+
398
+ 2. **In Zed, tools are automatically available** - No manual invocation needed
399
+
400
+ 3. **Grok will use tools contextually** - Based on your requests
401
+
402
+ 4. **Security is enforced** - Only trusted directories are accessible
403
+
404
+ ## Configuration Reference
405
+
406
+ ### Environment Variables
407
+ ```env
408
+ # Required for API access
409
+ GROK_API_KEY=your_grok_api_key_here
410
+
411
+ # Optional for web search
412
+ GOOGLE_API_KEY=your_google_api_key_here
413
+ GOOGLE_CSE_ID=your_search_engine_id_here
414
+ ```
415
+
416
+ ### Config File (`~/.config/grok-cli/config.json`)
417
+ ```json
418
+ {
419
+ "api_key": "your_api_key",
420
+ "default_model": "grok-3",
421
+ "timeout_secs": 30,
422
+ "max_retries": 3,
423
+ "acp": {
424
+ "enabled": true,
425
+ "dev_mode": false,
426
+ "default_port": null,
427
+ "trusted_directories": [
428
+ "/home/user/projects"
429
+ ]
430
+ }
431
+ }
432
+ ```
433
+
434
+ ## Tool Development
435
+
436
+ Want to add your own tools? See the implementation in:
437
+ - `src/acp/tools.rs` - Tool implementations
438
+ - `src/acp/mod.rs` - Tool registration and execution
439
+
440
+ Each tool needs:
441
+ 1. **Implementation function** - The actual tool logic
442
+ 2. **Tool definition** - JSON schema for parameters
443
+ 3. **Registration** - Add to `get_tool_definitions()`
444
+ 4. **Handler** - Add to the match statement in `handle_chat_completion()`
445
+
446
+ ## Notes
447
+
448
+ - Tools are automatically invoked by Grok when needed
449
+ - Tool execution is logged for debugging
450
+ - All file operations are relative to the current working directory
451
+ - Network operations include retry logic for unreliable connections (Starlink support)
452
+ - Tool results are integrated into the conversation context
453
+
454
+ ## Support
455
+
456
+ For issues or questions about tools:
457
+ 1. Check the [GitHub Issues](https://github.com/microtech/grok-cli/issues)
458
+ 2. Review the [security documentation](SECURITY.md)
459
+ 3. Check tool logs in verbose mode: `grok -v acp stdio`