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.
- package/.env.example +42 -0
- package/.github/workflows/ci.yml +30 -0
- package/.github/workflows/rust.yml +22 -0
- package/.grok/.env.example +85 -0
- package/.grok/COMPLETE_FIX_SUMMARY.md +466 -0
- package/.grok/ENV_CONFIG_GUIDE.md +173 -0
- package/.grok/QUICK_REFERENCE.md +180 -0
- package/.grok/README.md +104 -0
- package/.grok/TESTING_GUIDE.md +393 -0
- package/CHANGELOG.md +465 -0
- package/CODE_REVIEW_SUMMARY.md +414 -0
- package/COMPLETE_FIX_SUMMARY.md +415 -0
- package/CONFIGURATION.md +489 -0
- package/CONTEXT_FILES_GUIDE.md +419 -0
- package/CONTRIBUTING.md +55 -0
- package/CURSOR_POSITION_FIX.md +206 -0
- package/Cargo.toml +88 -0
- package/ERROR_HANDLING_REPORT.md +361 -0
- package/FINAL_FIX_SUMMARY.md +462 -0
- package/FIXES.md +37 -0
- package/FIXES_SUMMARY.md +87 -0
- package/GROK_API_MIGRATION_SUMMARY.md +111 -0
- package/LICENSE +22 -0
- package/MIGRATION_TO_GROK_API.md +223 -0
- package/README.md +504 -0
- package/REVIEW_COMPLETE.md +416 -0
- package/REVIEW_QUICK_REFERENCE.md +173 -0
- package/SECURITY.md +463 -0
- package/SECURITY_AUDIT.md +661 -0
- package/SETUP.md +287 -0
- package/TESTING_TOOLS.md +88 -0
- package/TESTING_TOOL_EXECUTION.md +239 -0
- package/TOOL_EXECUTION_FIX.md +491 -0
- package/VERIFICATION_CHECKLIST.md +419 -0
- package/docs/API.md +74 -0
- package/docs/CHAT_LOGGING.md +39 -0
- package/docs/CURSOR_FIX_DEMO.md +306 -0
- package/docs/ERROR_HANDLING_GUIDE.md +547 -0
- package/docs/FILE_OPERATIONS.md +449 -0
- package/docs/INTERACTIVE.md +401 -0
- package/docs/PROJECT_CREATION_GUIDE.md +570 -0
- package/docs/QUICKSTART.md +378 -0
- package/docs/QUICK_REFERENCE.md +691 -0
- package/docs/RELEASE_NOTES_0.1.2.md +240 -0
- package/docs/TOOLS.md +459 -0
- package/docs/TOOLS_QUICK_REFERENCE.md +210 -0
- package/docs/ZED_INTEGRATION.md +371 -0
- package/docs/extensions.md +464 -0
- package/docs/settings.md +293 -0
- package/examples/extensions/logging-hook/README.md +91 -0
- package/examples/extensions/logging-hook/extension.json +22 -0
- package/package.json +30 -0
- package/scripts/test_acp.py +252 -0
- package/scripts/test_acp.sh +143 -0
- package/scripts/test_acp_simple.sh +72 -0
- package/src/acp/mod.rs +741 -0
- package/src/acp/protocol.rs +323 -0
- package/src/acp/security.rs +298 -0
- package/src/acp/tools.rs +697 -0
- package/src/bin/banner_demo.rs +216 -0
- package/src/bin/docgen.rs +18 -0
- package/src/bin/installer.rs +217 -0
- package/src/cli/app.rs +310 -0
- package/src/cli/commands/acp.rs +721 -0
- package/src/cli/commands/chat.rs +485 -0
- package/src/cli/commands/code.rs +513 -0
- package/src/cli/commands/config.rs +394 -0
- package/src/cli/commands/health.rs +442 -0
- package/src/cli/commands/history.rs +421 -0
- package/src/cli/commands/mod.rs +14 -0
- package/src/cli/commands/settings.rs +1384 -0
- package/src/cli/mod.rs +166 -0
- package/src/config/mod.rs +2212 -0
- package/src/display/ascii_art.rs +139 -0
- package/src/display/banner.rs +289 -0
- package/src/display/components/input.rs +323 -0
- package/src/display/components/mod.rs +2 -0
- package/src/display/components/settings_list.rs +306 -0
- package/src/display/interactive.rs +1255 -0
- package/src/display/mod.rs +62 -0
- package/src/display/terminal.rs +42 -0
- package/src/display/tips.rs +316 -0
- package/src/grok_client_ext.rs +177 -0
- package/src/hooks/loader.rs +407 -0
- package/src/hooks/mod.rs +158 -0
- package/src/lib.rs +174 -0
- package/src/main.rs +65 -0
- package/src/mcp/client.rs +195 -0
- package/src/mcp/config.rs +20 -0
- package/src/mcp/mod.rs +6 -0
- package/src/mcp/protocol.rs +67 -0
- package/src/utils/auth.rs +41 -0
- package/src/utils/chat_logger.rs +568 -0
- package/src/utils/context.rs +390 -0
- package/src/utils/mod.rs +16 -0
- package/src/utils/network.rs +320 -0
- package/src/utils/rate_limiter.rs +166 -0
- package/src/utils/session.rs +73 -0
- package/src/utils/shell_permissions.rs +389 -0
- package/src/utils/telemetry.rs +41 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026- Microtech
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
Permission is granted to any person obtaining a copy of this software
|
|
7
|
+
and associated documentation files (the “Software”) to use, modify,
|
|
8
|
+
and redistribute the Software for non-commercial purposes only.
|
|
9
|
+
|
|
10
|
+
Any redistribution or modification must include clear attribution to
|
|
11
|
+
the original author, including this copyright notice.
|
|
12
|
+
|
|
13
|
+
Commercial use of the Software is strictly prohibited. “Commercial use”
|
|
14
|
+
includes selling the Software, using it in a product or service that is
|
|
15
|
+
sold, or using it in any context intended for commercial advantage or
|
|
16
|
+
monetary compensation.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
21
|
+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES, OR
|
|
22
|
+
OTHER LIABILITY ARISING FROM THE SOFTWARE OR THE USE OF THE SOFTWARE.
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
# Migration to grok_api Crate
|
|
2
|
+
|
|
3
|
+
**Date:** 2026-01-13
|
|
4
|
+
**Version:** 0.1.2 → 0.1.3 (unreleased)
|
|
5
|
+
**Author:** AI Assistant with user approval
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This document describes the migration from the local API implementation to the published `grok_api` crate from crates.io.
|
|
10
|
+
|
|
11
|
+
## Summary
|
|
12
|
+
|
|
13
|
+
Successfully migrated from a local `src/api` module to using the external `grok_api = "0.1.0"` crate. This migration maintains 100% API compatibility with existing code through a compatibility wrapper layer.
|
|
14
|
+
|
|
15
|
+
## Changes Made
|
|
16
|
+
|
|
17
|
+
### 1. Dependencies
|
|
18
|
+
|
|
19
|
+
**File:** `Cargo.toml`
|
|
20
|
+
|
|
21
|
+
Added the `grok_api` dependency:
|
|
22
|
+
|
|
23
|
+
```toml
|
|
24
|
+
[dependencies]
|
|
25
|
+
# Grok API client library
|
|
26
|
+
grok_api = "0.1.0"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### 2. Removed Local Implementation
|
|
30
|
+
|
|
31
|
+
**Deleted:** `src/api/` directory
|
|
32
|
+
- `src/api/mod.rs` - Base API types and client
|
|
33
|
+
- `src/api/grok.rs` - GrokClient implementation
|
|
34
|
+
|
|
35
|
+
### 3. Created Compatibility Layer
|
|
36
|
+
|
|
37
|
+
**File:** `src/grok_client_ext.rs` (new)
|
|
38
|
+
|
|
39
|
+
Created a wrapper module that provides:
|
|
40
|
+
- `GrokClient` struct wrapping `grok_api::GrokClient`
|
|
41
|
+
- Compatibility methods matching the old API:
|
|
42
|
+
- `with_settings(api_key, timeout_secs, max_retries)` → uses builder pattern internally
|
|
43
|
+
- `with_rate_limits(config)` → stores config (for future use)
|
|
44
|
+
- `chat_completion(...)` → converts to `chat_with_history` call
|
|
45
|
+
- `chat_completion_with_history(...)` → converts JSON messages to ChatMessage format
|
|
46
|
+
- `test_connection()` → delegates to inner client
|
|
47
|
+
- `list_models()` → delegates to inner client
|
|
48
|
+
|
|
49
|
+
### 4. Updated Library Exports
|
|
50
|
+
|
|
51
|
+
**File:** `src/lib.rs`
|
|
52
|
+
|
|
53
|
+
Changes:
|
|
54
|
+
- Removed `pub mod api;` declaration
|
|
55
|
+
- Added `pub mod grok_client_ext;` declaration
|
|
56
|
+
- Re-exported types from `grok_api`:
|
|
57
|
+
- `ChatResponse`, `Message`, `ToolCall`, `FunctionCall`, `Choice`, `Usage`
|
|
58
|
+
- `Error as GrokApiError`
|
|
59
|
+
- Re-exported wrapped `GrokClient` from `grok_client_ext`
|
|
60
|
+
|
|
61
|
+
### 5. Updated Imports
|
|
62
|
+
|
|
63
|
+
Updated imports in the following files to use the re-exported types:
|
|
64
|
+
|
|
65
|
+
- `src/acp/mod.rs` - Changed `use crate::api::grok::GrokClient;` to `use crate::GrokClient;`
|
|
66
|
+
- `src/cli/commands/chat.rs` - Simplified imports to use `crate::{ToolCall, GrokClient}`
|
|
67
|
+
- `src/cli/commands/code.rs` - Changed to `use crate::GrokClient;`
|
|
68
|
+
- `src/cli/commands/health.rs` - Changed to `use crate::GrokClient;`
|
|
69
|
+
- `src/display/interactive.rs` - Changed to `use crate::GrokClient;` and updated ToolCall reference
|
|
70
|
+
|
|
71
|
+
## Type Compatibility
|
|
72
|
+
|
|
73
|
+
The `grok_api` crate types are largely compatible with the old local implementation:
|
|
74
|
+
|
|
75
|
+
| Old Type | New Type | Notes |
|
|
76
|
+
|----------|----------|-------|
|
|
77
|
+
| `GrokResponse` | `ChatResponse` | Different name, same structure |
|
|
78
|
+
| `Message` | `Message` | Identical structure |
|
|
79
|
+
| `ToolCall` | `ToolCall` | Field `r#type` → `call_type` |
|
|
80
|
+
| `FunctionCall` | `FunctionCall` | Identical structure |
|
|
81
|
+
| `Choice` | `Choice` | Identical structure |
|
|
82
|
+
| `Usage` | `Usage` | Identical structure |
|
|
83
|
+
| `GrokApiError` | `Error` | Re-exported as `GrokApiError` |
|
|
84
|
+
|
|
85
|
+
## API Differences Handled
|
|
86
|
+
|
|
87
|
+
### Builder Pattern vs Direct Construction
|
|
88
|
+
|
|
89
|
+
**Old API:**
|
|
90
|
+
```rust
|
|
91
|
+
let client = GrokClient::with_settings(api_key, timeout_secs, max_retries)?;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**New API (wrapped):**
|
|
95
|
+
```rust
|
|
96
|
+
// Uses builder pattern internally
|
|
97
|
+
let inner = grok_api::GrokClient::builder()
|
|
98
|
+
.api_key(api_key)
|
|
99
|
+
.timeout_secs(timeout_secs)
|
|
100
|
+
.max_retries(max_retries)
|
|
101
|
+
.build()?;
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Message Format Conversion
|
|
105
|
+
|
|
106
|
+
**Old API:** Used `serde_json::Value` for messages
|
|
107
|
+
|
|
108
|
+
**New API:** Uses `ChatMessage` enum
|
|
109
|
+
|
|
110
|
+
The wrapper converts between formats:
|
|
111
|
+
```rust
|
|
112
|
+
let chat_messages: Vec<ChatMessage> = messages
|
|
113
|
+
.iter()
|
|
114
|
+
.filter_map(|msg| {
|
|
115
|
+
let role = msg.get("role")?.as_str()?;
|
|
116
|
+
let content = msg.get("content")?.as_str()?;
|
|
117
|
+
Some(match role {
|
|
118
|
+
"system" => ChatMessage::system(content),
|
|
119
|
+
"user" => ChatMessage::user(content),
|
|
120
|
+
"assistant" => ChatMessage::assistant(content),
|
|
121
|
+
_ => return None,
|
|
122
|
+
})
|
|
123
|
+
})
|
|
124
|
+
.collect();
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
### Tools Parameter
|
|
128
|
+
|
|
129
|
+
**Old API:** `Option<Vec<Value>>`
|
|
130
|
+
|
|
131
|
+
**New API:** Direct `Vec<Value>` with builder method
|
|
132
|
+
|
|
133
|
+
The wrapper converts:
|
|
134
|
+
```rust
|
|
135
|
+
if let Some(tool_defs) = tools {
|
|
136
|
+
request = request.tools(tool_defs);
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Benefits
|
|
141
|
+
|
|
142
|
+
1. **Maintenance**: API implementation maintained separately, reducing code duplication
|
|
143
|
+
2. **Versioning**: Can update API independently via semantic versioning
|
|
144
|
+
3. **Reusability**: Other projects can use the same `grok_api` crate
|
|
145
|
+
4. **Testing**: API tests maintained in the `grok_api` crate
|
|
146
|
+
5. **Documentation**: API docs available on docs.rs
|
|
147
|
+
6. **Community**: Published on crates.io for wider ecosystem use
|
|
148
|
+
|
|
149
|
+
## Testing
|
|
150
|
+
|
|
151
|
+
All existing tests pass without modification:
|
|
152
|
+
- ✅ 78 unit tests passing
|
|
153
|
+
- ✅ No changes required to test code
|
|
154
|
+
- ✅ Full backward compatibility maintained
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
cargo test --lib
|
|
158
|
+
# test result: ok. 78 passed; 0 failed; 0 ignored
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Migration Statistics
|
|
162
|
+
|
|
163
|
+
- **Files Modified:** 7
|
|
164
|
+
- **Files Deleted:** 2 (api/mod.rs, api/grok.rs)
|
|
165
|
+
- **Files Added:** 1 (grok_client_ext.rs)
|
|
166
|
+
- **Lines of Compatibility Code:** ~203 lines
|
|
167
|
+
- **Breaking Changes:** 0 (fully backward compatible)
|
|
168
|
+
- **Test Failures:** 0
|
|
169
|
+
|
|
170
|
+
## Build Results
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
Finished `dev` profile [unoptimized + debuginfo] target(s) in 40.37s
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**Warnings:** Only unused import warnings (pre-existing, unrelated to migration)
|
|
177
|
+
|
|
178
|
+
## Future Considerations
|
|
179
|
+
|
|
180
|
+
### Potential Improvements
|
|
181
|
+
|
|
182
|
+
1. **Direct Migration**: Eventually migrate to use `grok_api` API directly without wrapper
|
|
183
|
+
2. **Rate Limiting**: Implement actual rate limiting in the wrapper (currently a no-op)
|
|
184
|
+
3. **Streaming Support**: If `grok_api` adds streaming, add wrapper support
|
|
185
|
+
4. **Error Mapping**: Create more detailed error type mappings if needed
|
|
186
|
+
|
|
187
|
+
### Deprecation Path
|
|
188
|
+
|
|
189
|
+
If we want to eventually remove the compatibility layer:
|
|
190
|
+
|
|
191
|
+
1. Mark wrapper methods as `#[deprecated]` with migration guidance
|
|
192
|
+
2. Update calling code to use `grok_api` directly
|
|
193
|
+
3. Remove `grok_client_ext.rs` module
|
|
194
|
+
4. Update documentation and examples
|
|
195
|
+
|
|
196
|
+
## Rollback Plan
|
|
197
|
+
|
|
198
|
+
If issues arise, rollback is straightforward:
|
|
199
|
+
|
|
200
|
+
1. Remove `grok_api = "0.1.0"` from `Cargo.toml`
|
|
201
|
+
2. Restore `src/api/` directory from git history
|
|
202
|
+
3. Revert changes to `src/lib.rs`
|
|
203
|
+
4. Revert import changes in affected files
|
|
204
|
+
5. Delete `src/grok_client_ext.rs`
|
|
205
|
+
|
|
206
|
+
## Conclusion
|
|
207
|
+
|
|
208
|
+
The migration to the `grok_api` crate was successful with:
|
|
209
|
+
- ✅ Zero breaking changes
|
|
210
|
+
- ✅ All tests passing
|
|
211
|
+
- ✅ Clean compatibility layer
|
|
212
|
+
- ✅ Improved maintainability
|
|
213
|
+
- ✅ Follows Rust ecosystem best practices
|
|
214
|
+
|
|
215
|
+
This was indeed a "minor change" as expected, requiring only a thin compatibility wrapper to bridge the two APIs.
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
**Next Steps:**
|
|
220
|
+
1. Monitor for any edge cases in production use
|
|
221
|
+
2. Consider updating to future `grok_api` versions as they're released
|
|
222
|
+
3. Potentially contribute improvements back to the `grok_api` crate
|
|
223
|
+
4. Update documentation to reference the external crate
|