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,173 @@
1
+ # .env Configuration Guide for grok-cli
2
+
3
+ This file documents the recommended `.env` configuration for the grok-cli project.
4
+
5
+ ## Location
6
+
7
+ Create this file at: `grok-cli/.grok/.env`
8
+
9
+ ## Recommended Configuration
10
+
11
+ ```env
12
+ # =============================================================================
13
+ # GROK-CLI PROJECT CONFIGURATION
14
+ # =============================================================================
15
+
16
+ # -----------------------------------------------------------------------------
17
+ # API Configuration
18
+ # -----------------------------------------------------------------------------
19
+ # Your Grok API key (REQUIRED - get from https://console.x.ai/)
20
+ # GROK_API_KEY=xai-your-key-here
21
+
22
+ # Default model to use for this project
23
+ GROK_MODEL=grok-code-fast-1
24
+
25
+ # Temperature setting (0.0 = deterministic, 1.0 = creative)
26
+ GROK_TEMPERATURE=0.7
27
+
28
+ # Maximum tokens in response
29
+ GROK_MAX_TOKENS=4096
30
+
31
+ # -----------------------------------------------------------------------------
32
+ # Network Configuration (Starlink Optimized)
33
+ # -----------------------------------------------------------------------------
34
+ # Enable Starlink-specific optimizations
35
+ GROK_STARLINK_OPTIMIZATIONS=true
36
+
37
+ # Request timeout in seconds
38
+ GROK_TIMEOUT=60
39
+
40
+ # Maximum retry attempts for failed requests
41
+ GROK_MAX_RETRIES=5
42
+
43
+ # Base retry delay in milliseconds
44
+ GROK_BASE_RETRY_DELAY=1000
45
+
46
+ # Maximum retry delay in milliseconds
47
+ GROK_MAX_RETRY_DELAY=30000
48
+
49
+ # Connection timeout in seconds
50
+ GROK_CONNECT_TIMEOUT=30
51
+
52
+ # Read timeout in seconds
53
+ GROK_READ_TIMEOUT=60
54
+
55
+ # Enable network health monitoring
56
+ GROK_HEALTH_MONITORING=true
57
+
58
+ # -----------------------------------------------------------------------------
59
+ # UI Configuration
60
+ # -----------------------------------------------------------------------------
61
+ # Enable colored output
62
+ GROK_COLORS=true
63
+
64
+ # Enable Unicode characters in output
65
+ GROK_UNICODE=true
66
+
67
+ # Enable progress bars
68
+ GROK_PROGRESS_BARS=true
69
+
70
+ # Enable animations
71
+ GROK_ANIMATIONS=true
72
+
73
+ # Show tips in interactive mode
74
+ GROK_SHOW_TIPS=true
75
+
76
+ # -----------------------------------------------------------------------------
77
+ # Security Configuration
78
+ # -----------------------------------------------------------------------------
79
+ # Shell command approval mode: strict, default, or permissive
80
+ GROK_SHELL_APPROVAL_MODE=default
81
+
82
+ # Enable sandbox for shell commands
83
+ GROK_SHELL_SANDBOX=true
84
+
85
+ # -----------------------------------------------------------------------------
86
+ # Logging Configuration
87
+ # -----------------------------------------------------------------------------
88
+ # Log level: trace, debug, info, warn, error
89
+ GROK_LOG_LEVEL=info
90
+
91
+ # Enable session logging
92
+ GROK_SESSION_LOGGING=true
93
+
94
+ # Log format: json or text
95
+ GROK_LOG_FORMAT=json
96
+
97
+ # Enable performance metrics
98
+ GROK_PERFORMANCE_METRICS=true
99
+
100
+ # -----------------------------------------------------------------------------
101
+ # Context Configuration
102
+ # -----------------------------------------------------------------------------
103
+ # Maximum file size to include in context (in bytes)
104
+ GROK_MAX_FILE_SIZE=1048576
105
+
106
+ # Maximum total context size (in bytes)
107
+ GROK_MAX_CONTEXT_SIZE=10485760
108
+
109
+ # Enable smart context filtering
110
+ GROK_SMART_CONTEXT_FILTERING=true
111
+
112
+ # Respect .grokignore files
113
+ GROK_RESPECT_GROKIGNORE=true
114
+
115
+ # -----------------------------------------------------------------------------
116
+ # Development Settings
117
+ # -----------------------------------------------------------------------------
118
+ # Enable preview features
119
+ GROK_PREVIEW_FEATURES=true
120
+
121
+ # Enable experimental features
122
+ GROK_EXPERIMENTAL_FEATURES=false
123
+
124
+ # Enable debug mode
125
+ GROK_DEBUG=false
126
+
127
+ # Enable verbose output
128
+ GROK_VERBOSE=false
129
+ ```
130
+
131
+ ## Notes
132
+
133
+ 1. **API Key**: You must set `GROK_API_KEY` or `X_API_KEY`. For security, consider storing this in your system-wide `~/.grok/.env` instead of the project-level file.
134
+
135
+ 2. **Model Selection**: The `GROK_MODEL=grok-code-fast-1` setting is optimized for coding tasks. Other options:
136
+ - `grok-3` - Most capable, slower
137
+ - `grok-code-fast-1` - Fast, optimized for code
138
+ - `grok-2` - Balanced performance
139
+
140
+ 3. **Starlink Settings**: The network configuration is tuned for Starlink satellite internet with higher timeouts and retry logic to handle connection drops.
141
+
142
+ 4. **Priority Order**: Settings are loaded in this order (later overrides earlier):
143
+ - Built-in defaults
144
+ - System config (`~/.grok/.env`)
145
+ - Project config (`.grok/.env`) ← This file
146
+ - Environment variables
147
+ - CLI arguments (highest priority)
148
+
149
+ ## Quick Start
150
+
151
+ To use this configuration:
152
+
153
+ 1. Copy the recommended settings above
154
+ 2. Create `.grok/.env` in your project root
155
+ 3. Paste the settings
156
+ 4. Uncomment and set `GROK_API_KEY` (or set it system-wide)
157
+ 5. Adjust other settings as needed
158
+
159
+ ## Verification
160
+
161
+ After creating your `.env` file, verify it's being loaded:
162
+
163
+ ```bash
164
+ grok config show
165
+ ```
166
+
167
+ You should see:
168
+ - Configuration: Project (.grok/.env)
169
+ - Model: grok-code-fast-1
170
+
171
+ ## Security Note
172
+
173
+ **Never commit `.env` files to git!** They're already in `.gitignore`, but be careful when sharing code.
@@ -0,0 +1,180 @@
1
+ # Quick Reference: File Access Fixes
2
+
3
+ ## Problem & Solution
4
+
5
+ **Problem:** grok-cli couldn't access files using relative paths like `./file.txt` or `src/main.rs`
6
+
7
+ **Solution:** Added path resolution to convert relative paths to absolute before checking security
8
+
9
+ ## What Changed
10
+
11
+ ### Before ❌
12
+ ```bash
13
+ cd /home/user/project
14
+ grok query "read src/main.rs"
15
+ # Error: Access denied: Path is not in a trusted directory
16
+ ```
17
+
18
+ ### After ✅
19
+ ```bash
20
+ cd /home/user/project
21
+ grok query "read src/main.rs"
22
+ # ✅ Works! Resolves to /home/user/project/src/main.rs
23
+ ```
24
+
25
+ ## Now Supported
26
+
27
+ | Path Type | Example | Status |
28
+ |-----------|---------|--------|
29
+ | Relative | `src/main.rs` | ✅ Works |
30
+ | Current Dir | `./README.md` | ✅ Works |
31
+ | Parent Dir | `../config.toml` | ✅ Works |
32
+ | Absolute | `/home/user/project/file.txt` | ✅ Works |
33
+ | Symlinks | `link.txt` → `/other/file.txt` | ✅ Resolves & checks |
34
+ | Outside Workspace | `/etc/passwd` | ❌ Correctly denied |
35
+
36
+ ## Technical Details
37
+
38
+ ### Files Modified
39
+ - `src/acp/security.rs` - Added `resolve_path()` method
40
+ - `src/acp/tools.rs` - Updated all file tools
41
+ - `src/acp/mod.rs` - Enhanced initialization
42
+
43
+ ### Key Changes
44
+ 1. **Working directory tracking** - SecurityPolicy stores current working directory
45
+ 2. **Path resolution** - Converts relative → absolute before security checks
46
+ 3. **Symlink following** - Uses `canonicalize()` to resolve symlinks
47
+ 4. **Parent directory support** - Handles `..` components correctly
48
+
49
+ ### Tests Added
50
+ - 9 new security tests covering all path scenarios
51
+ - All existing tests still pass
52
+ - Test coverage for relative paths, symlinks, parent dirs, etc.
53
+
54
+ ## Common Use Cases
55
+
56
+ ### Reading Files in Current Directory
57
+ ```bash
58
+ grok query "read README.md"
59
+ grok query "read ./Cargo.toml"
60
+ ```
61
+
62
+ ### Reading Files in Subdirectories
63
+ ```bash
64
+ grok query "read src/main.rs"
65
+ grok query "read docs/guide.md"
66
+ ```
67
+
68
+ ### Accessing Parent Directory
69
+ ```bash
70
+ cd src
71
+ grok query "read ../README.md"
72
+ ```
73
+
74
+ ### Multiple Operations
75
+ ```bash
76
+ grok query "read src/lib.rs and src/main.rs"
77
+ ```
78
+
79
+ ## Security
80
+
81
+ ### Still Protected ✅
82
+ - Paths outside trusted directories are blocked
83
+ - No security regressions
84
+ - Deny-by-default policy maintained
85
+ - Symlinks are resolved and checked
86
+
87
+ ### Trust Model
88
+ 1. Current directory is trusted by default
89
+ 2. Paths must resolve within trusted directories
90
+ 3. Symlinks are followed and destination is checked
91
+ 4. Relative paths work within trusted scope
92
+
93
+ ## Configuration
94
+
95
+ ### Model Selection
96
+ Create `.grok/.env` in your project:
97
+ ```env
98
+ GROK_MODEL=grok-code-fast-1
99
+ ```
100
+
101
+ Or system-wide at `~/.grok/.env`
102
+
103
+ ### API Key (Required)
104
+ ```env
105
+ GROK_API_KEY=xai-your-key-here
106
+ ```
107
+
108
+ Store in system-wide `~/.grok/.env` for security
109
+
110
+ ## Verification
111
+
112
+ Test that it works:
113
+ ```bash
114
+ # Navigate to your project
115
+ cd /path/to/your/project
116
+
117
+ # Test relative path
118
+ grok query "list files in current directory"
119
+
120
+ # Test file reading
121
+ grok query "read README.md"
122
+
123
+ # Test subdirectory
124
+ grok query "read src/main.rs"
125
+ ```
126
+
127
+ ## ACP Protocol
128
+
129
+ The fix applies to:
130
+ - ✅ Direct CLI usage
131
+ - ✅ ACP protocol (Zed editor integration)
132
+ - ✅ Interactive chat mode
133
+ - ✅ All file operation tools
134
+
135
+ ## Documentation
136
+
137
+ For detailed information:
138
+ - `.grok/FILE_ACCESS_ANALYSIS.md` - Technical deep dive
139
+ - `.grok/FILE_ACCESS_FIX_SUMMARY.md` - Complete summary
140
+ - `.grok/ENV_CONFIG_GUIDE.md` - Configuration guide
141
+
142
+ ## Troubleshooting
143
+
144
+ ### Still getting access denied?
145
+ 1. Check you're in the project directory
146
+ 2. Verify path is correct: `ls -la <path>`
147
+ 3. Check if file exists
148
+ 4. Try absolute path to confirm it's a path resolution issue
149
+
150
+ ### Path not found?
151
+ 1. Verify working directory: `pwd`
152
+ 2. Check file exists: `ls <file>`
153
+ 3. Use tab completion to verify path
154
+ 4. Try `./<file>` prefix
155
+
156
+ ### Outside workspace?
157
+ This is correct behavior - files outside your project are intentionally blocked for security.
158
+
159
+ ## Quick Test
160
+
161
+ ```bash
162
+ # Create test file
163
+ echo "Hello from grok-cli" > test.txt
164
+
165
+ # Test reading it
166
+ grok query "read test.txt"
167
+
168
+ # Should show: "Hello from grok-cli"
169
+ ```
170
+
171
+ ## Summary
172
+
173
+ ✅ Relative paths now work correctly
174
+ ✅ Symlinks are resolved properly
175
+ ✅ Parent directory access works
176
+ ✅ Security is maintained
177
+ ✅ All tests pass
178
+ ✅ Ready for production use
179
+
180
+ The fix aligns grok-cli with gemini-cli's path handling approach while maintaining security.
@@ -0,0 +1,104 @@
1
+ # .grok Directory Documentation
2
+
3
+ This directory contains documentation for the grok-cli project's recent fixes and configuration.
4
+
5
+ ## 📚 Documentation Files
6
+
7
+ ### Quick Start
8
+ - **[QUICK_REFERENCE.md](QUICK_REFERENCE.md)** - Quick reference card for file access fixes and common commands
9
+
10
+ ### Testing & Verification
11
+ - **[TESTING_GUIDE.md](TESTING_GUIDE.md)** - Step-by-step testing guide for verifying file access and Zed integration fixes
12
+
13
+ ### Configuration
14
+ - **[ENV_CONFIG_GUIDE.md](ENV_CONFIG_GUIDE.md)** - Complete guide for `.env` configuration options
15
+
16
+ ### Technical Summary
17
+ - **[COMPLETE_FIX_SUMMARY.md](COMPLETE_FIX_SUMMARY.md)** - Comprehensive summary of all fixes (file access & Zed integration)
18
+
19
+ ## 🎯 What Was Fixed
20
+
21
+ ### File Access with Relative Paths
22
+ ✅ CLI can now access files using relative paths (`src/main.rs`, `./README.md`, `../file.txt`)
23
+ ✅ Symlinks are properly resolved
24
+ ✅ Parent directory access works
25
+ ✅ Security is maintained
26
+
27
+ ### Zed Editor Integration
28
+ ✅ Workspace context is extracted from ACP session initialization
29
+ ✅ grok-cli properly trusts the workspace directory
30
+ ✅ File operations work within the project context
31
+
32
+ ## 🚀 Getting Started
33
+
34
+ 1. **Configure your model:**
35
+ ```bash
36
+ echo GROK_MODEL=grok-code-fast-1 > .env
37
+ ```
38
+
39
+ 2. **Test file access:**
40
+ ```bash
41
+ grok query "read README.md"
42
+ ```
43
+
44
+ 3. **Configure Zed:**
45
+ See [ENV_CONFIG_GUIDE.md](ENV_CONFIG_GUIDE.md) and `docs/ZED_INTEGRATION.md`
46
+
47
+ 4. **Run tests:**
48
+ Follow [TESTING_GUIDE.md](TESTING_GUIDE.md)
49
+
50
+ ## 📖 Which Doc Should I Read?
51
+
52
+ - **Just want to get started?** → [QUICK_REFERENCE.md](QUICK_REFERENCE.md)
53
+ - **Setting up configuration?** → [ENV_CONFIG_GUIDE.md](ENV_CONFIG_GUIDE.md)
54
+ - **Testing the fixes?** → [TESTING_GUIDE.md](TESTING_GUIDE.md)
55
+ - **Want full technical details?** → [COMPLETE_FIX_SUMMARY.md](COMPLETE_FIX_SUMMARY.md)
56
+
57
+ ## 📝 Configuration Priority
58
+
59
+ Settings are loaded in this order (later overrides earlier):
60
+ 1. Built-in defaults
61
+ 2. System config (`~/.grok/.env`)
62
+ 3. Project config (`.grok/.env`) ← This directory
63
+ 4. Environment variables
64
+ 5. CLI arguments (highest priority)
65
+
66
+ ## ✅ Verification
67
+
68
+ ```bash
69
+ # Check configuration
70
+ grok config show
71
+
72
+ # Should show:
73
+ # Model: grok-code-fast-1
74
+ # Configuration: Project (.grok/.env) or Hierarchical
75
+ ```
76
+
77
+ ## 🔒 Security Note
78
+
79
+ Never commit `.env` files with API keys to git! They're in `.gitignore` by default.
80
+
81
+ Store API keys in:
82
+ - System-wide: `~/.grok/.env`
83
+ - Project: `.grok/.env` (gitignored)
84
+ - Environment: `export GROK_API_KEY=xai-...`
85
+
86
+ ## 📦 What's in .grok/.env?
87
+
88
+ Example minimal configuration:
89
+ ```env
90
+ # Model selection
91
+ GROK_MODEL=grok-code-fast-1
92
+
93
+ # API key (optional - better in ~/.grok/.env)
94
+ # GROK_API_KEY=xai-your-key-here
95
+ ```
96
+
97
+ See [ENV_CONFIG_GUIDE.md](ENV_CONFIG_GUIDE.md) for all available options.
98
+
99
+ ---
100
+
101
+ **Last Updated:** 2025
102
+ **Status:** Ready for Production
103
+ **Author:** John McConnell (john.microtech@gmail.com)
104
+ **Repository:** https://github.com/microtech/grok-cli