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
package/SECURITY.md ADDED
@@ -0,0 +1,463 @@
1
+ # Security Guide
2
+
3
+ This document outlines the security features and best practices for Grok CLI, with a focus on shell command execution safety.
4
+
5
+ ## Overview
6
+
7
+ Grok CLI implements a comprehensive permission system for shell commands executed through the `!` prefix in interactive mode. This system is inspired by Gemini CLI's security model and provides multiple layers of protection against accidental or malicious command execution.
8
+
9
+ ## Shell Command Permission System
10
+
11
+ ### How It Works
12
+
13
+ When you execute a shell command using `!` in interactive mode, the following security checks are performed:
14
+
15
+ 1. **Blocklist Check** - Commands are checked against a blocklist of dangerous operations
16
+ 2. **Allowlist Check** - Previously approved commands are automatically allowed
17
+ 3. **User Prompt** - New commands require explicit user approval
18
+ 4. **Persistent Policy** - Approved commands can be saved permanently
19
+
20
+ ### Approval Modes
21
+
22
+ #### Default Mode (Recommended)
23
+
24
+ ```bash
25
+ GROK_SHELL_APPROVAL_MODE=default
26
+ ```
27
+
28
+ In default mode, every new command requires explicit user approval:
29
+
30
+ ```
31
+ ⚠️ Shell command requires permission: git status
32
+
33
+ a) Allow once
34
+ s) Allow always (this session)
35
+ p) Allow always (save permanently)
36
+ d) Deny
37
+
38
+ Choose [a/s/p/d]:
39
+ ```
40
+
41
+ **Options:**
42
+ - **a (Allow once)** - Execute this command once without saving permission
43
+ - **s (Session)** - Allow this command for the current session only
44
+ - **p (Permanent)** - Save permission permanently to `~/.grok/shell_policy.json`
45
+ - **d (Deny)** - Reject the command
46
+
47
+ #### YOLO Mode (⚠️ DANGEROUS!)
48
+
49
+ ```bash
50
+ GROK_SHELL_APPROVAL_MODE=yolo
51
+ ```
52
+
53
+ **NOT RECOMMENDED** - All non-blocked commands execute without prompts. Use only in trusted, isolated environments.
54
+
55
+ ### Blocklist
56
+
57
+ The following commands are automatically blocked for safety:
58
+
59
+ #### Destructive File Operations
60
+ - `rm` - Remove files/directories
61
+ - `del` - Delete files (Windows)
62
+ - `rmdir` / `rd` - Remove directories
63
+ - `format` - Format drives
64
+ - `fdisk` - Disk partitioning
65
+ - `mkfs` - Make filesystem
66
+ - `dd` - Disk operations (can overwrite data)
67
+
68
+ #### System Operations
69
+ - `shutdown` - Shut down the system
70
+ - `reboot` - Reboot the system
71
+ - `halt` - Halt the system
72
+ - `poweroff` - Power off the system
73
+ - `init` - Change system runlevel
74
+
75
+ #### Package Management
76
+ - `apt-get` - APT package manager
77
+ - `yum` - YUM package manager
78
+ - `dnf` - DNF package manager
79
+ - `pacman` - Pacman package manager
80
+
81
+ #### Dangerous Patterns
82
+ - `rm -rf /` - Recursive root deletion
83
+ - `del /s /q` - Recursive Windows deletion
84
+ - `:(){ :|:& };:` - Fork bomb
85
+
86
+ **Note:** These commands are blocked even in YOLO mode.
87
+
88
+ ### Allowlist Management
89
+
90
+ #### Session Allowlist
91
+
92
+ Temporary permissions that last only for the current session:
93
+ - Stored in memory
94
+ - Cleared when you exit Grok CLI
95
+ - Useful for frequently used commands during development
96
+
97
+ #### Persistent Allowlist
98
+
99
+ Permanent permissions saved to disk:
100
+ - Stored in `~/.grok/shell_policy.json`
101
+ - Persists across sessions
102
+ - Automatically loaded on startup
103
+
104
+ **View your persistent allowlist:**
105
+ ```bash
106
+ cat ~/.grok/shell_policy.json
107
+ ```
108
+
109
+ **Example policy file:**
110
+ ```json
111
+ {
112
+ "allowed_commands": [
113
+ "git",
114
+ "ls",
115
+ "cat",
116
+ "cargo"
117
+ ]
118
+ }
119
+ ```
120
+
121
+ #### Managing Allowlist
122
+
123
+ **Clear session allowlist:**
124
+ Exit and restart Grok CLI
125
+
126
+ **Clear persistent allowlist:**
127
+ Delete or edit `~/.grok/shell_policy.json`:
128
+ ```bash
129
+ rm ~/.grok/shell_policy.json
130
+ ```
131
+
132
+ ### Command Parsing
133
+
134
+ The permission system extracts the root command from complex shell expressions:
135
+
136
+ ```bash
137
+ !git status | grep modified # Root command: "git"
138
+ !ls -la && cat file.txt # Root command: "ls"
139
+ !echo "test" > output.txt # Root command: "echo"
140
+ ```
141
+
142
+ Once approved, all variations of that root command are allowed:
143
+ ```bash
144
+ !git status # Approved
145
+ !git commit # Also allowed (same root: "git")
146
+ !git push # Also allowed (same root: "git")
147
+ ```
148
+
149
+ ## Best Practices
150
+
151
+ ### 1. Use Default Mode
152
+
153
+ Always use `default` approval mode unless you have a specific reason not to:
154
+
155
+ ```bash
156
+ # In .env
157
+ GROK_SHELL_APPROVAL_MODE=default
158
+ ```
159
+
160
+ ### 2. Review Commands Carefully
161
+
162
+ Before approving a command:
163
+ - Read the full command carefully
164
+ - Verify the command does what you expect
165
+ - Check for typos or unexpected arguments
166
+ - Be cautious with commands that modify files or system state
167
+
168
+ ### 3. Use Session Allowlist for Development
169
+
170
+ During active development:
171
+ - Use "s" (session) for temporary convenience
172
+ - Avoids permanent allowlist bloat
173
+ - Resets when you start a new session
174
+
175
+ ### 4. Be Selective with Permanent Allowlist
176
+
177
+ Only add to permanent allowlist:
178
+ - Commands you use frequently
179
+ - Commands you fully trust
180
+ - Commands with predictable, safe behavior
181
+
182
+ **Good candidates:**
183
+ ```bash
184
+ !git status
185
+ !ls -la
186
+ !cat somefile.txt
187
+ !cargo check
188
+ ```
189
+
190
+ **Poor candidates:**
191
+ ```bash
192
+ !rm -rf build/ # Destructive
193
+ !sudo systemctl # Requires elevated privileges
194
+ !curl | bash # Arbitrary code execution
195
+ ```
196
+
197
+ ### 5. Regular Allowlist Audits
198
+
199
+ Periodically review your persistent allowlist:
200
+
201
+ ```bash
202
+ cat ~/.grok/shell_policy.json
203
+ ```
204
+
205
+ Remove commands you no longer use:
206
+ ```bash
207
+ # Edit the file manually or delete and rebuild
208
+ rm ~/.grok/shell_policy.json
209
+ ```
210
+
211
+ ### 6. Project-Specific Policies
212
+
213
+ For projects with specific security requirements:
214
+
215
+ **Option 1:** Use session allowlist only
216
+ ```
217
+ Don't use "p" (permanent), only use "s" (session)
218
+ ```
219
+
220
+ **Option 2:** Document approved commands
221
+ Create `.grok/APPROVED_COMMANDS.md` in your project:
222
+ ```markdown
223
+ # Approved Shell Commands
224
+
225
+ This project has approved these commands:
226
+ - git (version control)
227
+ - cargo (build system)
228
+ - npm test (testing)
229
+ ```
230
+
231
+ ## Threat Model
232
+
233
+ ### What This Protects Against
234
+
235
+ ✅ **Accidental dangerous commands**
236
+ - Typos in destructive commands
237
+ - Copy-paste errors
238
+ - Muscle memory mistakes
239
+
240
+ ✅ **Novice user errors**
241
+ - Running unfamiliar commands
242
+ - Not understanding command implications
243
+ - Learning without risk
244
+
245
+ ✅ **AI suggestion mistakes**
246
+ - AI recommending unsafe commands
247
+ - Misunderstanding context
248
+ - Edge case failures
249
+
250
+ ### What This Does NOT Protect Against
251
+
252
+ ❌ **Malicious intent**
253
+ - A determined attacker can bypass these controls
254
+ - User can still approve dangerous commands
255
+ - Not a substitute for proper system security
256
+
257
+ ❌ **Complex command exploitation**
258
+ - Sophisticated command injection
259
+ - Shell escape sequences
260
+ - Command obfuscation
261
+
262
+ ❌ **Social engineering**
263
+ - Users can be tricked into approving bad commands
264
+ - No protection against user approval
265
+
266
+ ❌ **System-level vulnerabilities**
267
+ - OS-level security issues
268
+ - Kernel vulnerabilities
269
+ - Hardware exploits
270
+
271
+ ## Configuration Examples
272
+
273
+ ### Development Environment
274
+
275
+ ```bash
276
+ # .grok/.env (project root)
277
+ GROK_SHELL_APPROVAL_MODE=default
278
+ ```
279
+
280
+ **Workflow:**
281
+ - Review each command
282
+ - Use session allowlist (s) for current work
283
+ - Don't save permanently during experimentation
284
+
285
+ ### Production/CI Environment
286
+
287
+ ```bash
288
+ # .env
289
+ GROK_SHELL_APPROVAL_MODE=yolo
290
+ ```
291
+
292
+ **⚠️ Only if:**
293
+ - Running in isolated container
294
+ - Commands are pre-vetted
295
+ - No interactive input possible
296
+ - Failures are acceptable/recoverable
297
+
298
+ **Better approach for CI:**
299
+ Use explicit commands instead of Grok CLI interactive mode.
300
+
301
+ ### Trusted Development Machine
302
+
303
+ ```bash
304
+ # ~/.grok/.env (system-wide)
305
+ GROK_SHELL_APPROVAL_MODE=default
306
+
307
+ # Plus persistent allowlist at ~/.grok/shell_policy.json
308
+ {
309
+ "allowed_commands": [
310
+ "git",
311
+ "ls",
312
+ "cat",
313
+ "grep",
314
+ "find",
315
+ "cargo",
316
+ "npm",
317
+ "yarn"
318
+ ]
319
+ }
320
+ ```
321
+
322
+ **Rationale:**
323
+ - Frequent commands pre-approved
324
+ - Unusual commands still prompt
325
+ - Balance of convenience and safety
326
+
327
+ ## Troubleshooting
328
+
329
+ ### Command Always Blocked
330
+
331
+ **Problem:** A safe command is being blocked
332
+
333
+ **Solutions:**
334
+
335
+ 1. Check if it's actually on the blocklist
336
+ 2. Use a different command variant
337
+ 3. If absolutely needed, modify the source code (not recommended)
338
+
339
+ **Example:**
340
+ ```bash
341
+ # Instead of using blocked "rm"
342
+ !mv file.txt ~/.trash/ # Move to trash instead
343
+ !rm file.txt # Blocked
344
+
345
+ # Or use safe alternatives
346
+ !trash file.txt # If trash-cli is installed
347
+ ```
348
+
349
+ ### Permission Prompt Not Appearing
350
+
351
+ **Problem:** Commands execute without prompting
352
+
353
+ **Check:**
354
+ 1. Verify approval mode: `echo $GROK_SHELL_APPROVAL_MODE`
355
+ 2. Check if command is already in allowlist
356
+ 3. Ensure you're in interactive mode
357
+
358
+ ### Reset All Permissions
359
+
360
+ **To start fresh:**
361
+
362
+ ```bash
363
+ # Remove persistent allowlist
364
+ rm ~/.grok/shell_policy.json
365
+
366
+ # Restart Grok CLI (clears session allowlist)
367
+ exit
368
+ grok
369
+ ```
370
+
371
+ ### Allowlist Not Persisting
372
+
373
+ **Problem:** Approved commands don't save
374
+
375
+ **Check:**
376
+ 1. Ensure you used "p" (permanent), not "s" (session)
377
+ 2. Verify write permissions: `ls -la ~/.grok/`
378
+ 3. Check for filesystem errors
379
+ 4. Try creating the file manually:
380
+ ```bash
381
+ mkdir -p ~/.grok
382
+ echo '{"allowed_commands":[]}' > ~/.grok/shell_policy.json
383
+ ```
384
+
385
+ ## Reporting Security Issues
386
+
387
+ If you discover a security vulnerability in Grok CLI:
388
+
389
+ 1. **DO NOT** open a public GitHub issue
390
+ 2. Email security concerns to: john.microtech@gmail.com
391
+ 3. Include:
392
+ - Description of the vulnerability
393
+ - Steps to reproduce
394
+ - Potential impact
395
+ - Suggested fix (if any)
396
+
397
+ We take security seriously and will respond promptly.
398
+
399
+ ## Additional Security Measures
400
+
401
+ ### Beyond Shell Commands
402
+
403
+ 1. **API Key Protection**
404
+ - Never commit `.env` files
405
+ - Use `.env.example` for templates
406
+ - Set restrictive file permissions: `chmod 600 .env`
407
+
408
+ 2. **Network Security**
409
+ - All API calls use HTTPS
410
+ - Built-in retry logic for network failures
411
+ - Timeout protection against hanging requests
412
+
413
+ 3. **Data Privacy**
414
+ - Conversations are not logged by default
415
+ - Telemetry is opt-in only
416
+ - API keys are redacted from logs
417
+
418
+ 4. **Dependency Security**
419
+ - Regular `cargo audit` runs
420
+ - Minimal dependency footprint
421
+ - Vetted crates only
422
+
423
+ ### System Permissions
424
+
425
+ Grok CLI runs with your user permissions. To limit risk:
426
+
427
+ ```bash
428
+ # Create a restricted user for testing (Linux)
429
+ sudo useradd -m -s /bin/bash groktest
430
+ sudo su - groktest
431
+
432
+ # Run Grok CLI as limited user
433
+ grok
434
+ ```
435
+
436
+ ## Security Checklist
437
+
438
+ Before using Grok CLI in production:
439
+
440
+ - [ ] Review and understand approval modes
441
+ - [ ] Configure `GROK_SHELL_APPROVAL_MODE` appropriately
442
+ - [ ] Audit persistent allowlist regularly
443
+ - [ ] Protect `.env` files (`.gitignore`, file permissions)
444
+ - [ ] Use session allowlist for temporary needs
445
+ - [ ] Document approved commands for your project
446
+ - [ ] Train team members on security features
447
+ - [ ] Set up monitoring for unexpected command execution
448
+ - [ ] Test in isolated environment first
449
+ - [ ] Have rollback plan for accidents
450
+
451
+ ## References
452
+
453
+ - [Grok CLI Configuration Guide](CONFIGURATION.md)
454
+ - [Interactive Mode Guide](docs/INTERACTIVE.md)
455
+ - [Quick Start Guide](QUICKSTART.md)
456
+
457
+ ## License
458
+
459
+ This software is provided as-is with no warranty. Use at your own risk.
460
+
461
+ ---
462
+
463
+ **Remember:** The best security is informed, careful usage. No system can protect against user approval of dangerous commands. Always think before you approve!