@charmland/crush 0.1.1
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/LICENSE +134 -0
- package/README.md +341 -0
- package/install.js +6 -0
- package/lib.js +215 -0
- package/package.json +107 -0
- package/run-crush.js +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# Functional Source License, Version 1.1, MIT Future License
|
|
2
|
+
|
|
3
|
+
## Abbreviation
|
|
4
|
+
|
|
5
|
+
FSL-1.1-MIT
|
|
6
|
+
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2025 Charmbracelet, Inc
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the MIT license that is effective on the second anniversary of the date we make
|
|
91
|
+
the Software available. On or after that date, you may use the Software under
|
|
92
|
+
the MIT license, in which case the following will apply:
|
|
93
|
+
|
|
94
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
95
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
96
|
+
the Software without restriction, including without limitation the rights to
|
|
97
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
98
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
99
|
+
so, subject to the following conditions:
|
|
100
|
+
|
|
101
|
+
The above copyright notice and this permission notice shall be included in all
|
|
102
|
+
copies or substantial portions of the Software.
|
|
103
|
+
|
|
104
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
105
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
106
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
107
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
108
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
109
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
110
|
+
SOFTWARE.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
MIT License
|
|
115
|
+
|
|
116
|
+
Copyright (c) 2025-03-21 - 2025-05-30 Kujtim Hoxha
|
|
117
|
+
|
|
118
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
119
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
120
|
+
in the Software without restriction, including without limitation the rights
|
|
121
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
122
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
123
|
+
furnished to do so, subject to the following conditions:
|
|
124
|
+
|
|
125
|
+
The above copyright notice and this permission notice shall be included in all
|
|
126
|
+
copies or substantial portions of the Software.
|
|
127
|
+
|
|
128
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
129
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
130
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
131
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
132
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
133
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
134
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
# Crush
|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://stuff.charm.sh/crush/charm-crush.png"><img width="450" alt="Charm Crush Logo" src="https://github.com/user-attachments/assets/adc1a6f4-b284-4603-836c-59038caa2e8b" /></a><br />
|
|
5
|
+
<a href="https://github.com/charmbracelet/crush/releases"><img src="https://img.shields.io/github/release/charmbracelet/crush" alt="Latest Release"></a>
|
|
6
|
+
<a href="https://github.com/charmbracelet/crush/actions"><img src="https://github.com/charmbracelet/crush/workflows/build/badge.svg" alt="Build Status"></a>
|
|
7
|
+
</p>
|
|
8
|
+
|
|
9
|
+
<p align="center">Your new coding bestie, now available in your favourite terminal.<br />Your tools, your code, and your workflows, wired into your LLM of choice.</p>
|
|
10
|
+
|
|
11
|
+
<p align="center"><img width="800" alt="Crush Demo" src="https://github.com/user-attachments/assets/58280caf-851b-470a-b6f7-d5c4ea8a1968" /></p>
|
|
12
|
+
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- **Multi-Model:** choose from a wide range of LLMs or add your own via OpenAI- or Anthropic-compatible APIs
|
|
16
|
+
- **Flexible:** switch LLMs mid-session while preserving context
|
|
17
|
+
- **Session-Based:** maintain multiple work sessions and contexts per project
|
|
18
|
+
- **LSP-Enhanced:** Crush uses LSPs for additional context, just like you do
|
|
19
|
+
- **Extensible:** add capabilities via MCPs (`http`, `stdio`, and `sse`)
|
|
20
|
+
- **Works Everywhere:** first-class support in every terminal on macOS, Linux, Windows (PowerShell and WSL), and FreeBSD
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
Use a package manager:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# macOS or Linux
|
|
28
|
+
brew install charmbracelet/tap/crush
|
|
29
|
+
|
|
30
|
+
# NPM
|
|
31
|
+
npm install -g @charmland/crush
|
|
32
|
+
|
|
33
|
+
# Arch Linux (btw)
|
|
34
|
+
yay -S crush-bin
|
|
35
|
+
|
|
36
|
+
# Windows (with Winget)
|
|
37
|
+
winget install charmbracelet.crush
|
|
38
|
+
|
|
39
|
+
# Nix
|
|
40
|
+
nix-shell -p nur.repos.charmbracelet.crush
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
<details>
|
|
44
|
+
<summary><strong>Debian/Ubuntu</strong></summary>
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
sudo mkdir -p /etc/apt/keyrings
|
|
48
|
+
curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg
|
|
49
|
+
echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list
|
|
50
|
+
sudo apt update && sudo apt install crush
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
</details>
|
|
54
|
+
|
|
55
|
+
<details>
|
|
56
|
+
<summary><strong>Fedora/RHEL</strong></summary>
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
echo '[charm]
|
|
60
|
+
name=Charm
|
|
61
|
+
baseurl=https://repo.charm.sh/yum/
|
|
62
|
+
enabled=1
|
|
63
|
+
gpgcheck=1
|
|
64
|
+
gpgkey=https://repo.charm.sh/yum/gpg.key' | sudo tee /etc/yum.repos.d/charm.repo
|
|
65
|
+
sudo yum install crush
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
</details>
|
|
69
|
+
|
|
70
|
+
Or, download it:
|
|
71
|
+
|
|
72
|
+
- [Packages][releases] are available in Debian and RPM formats
|
|
73
|
+
- [Binaries][releases] are available for Linux, macOS, Windows, FreeBSD, OpenBSD, and NetBSD
|
|
74
|
+
|
|
75
|
+
[releases]: https://github.com/charmbracelet/crush/releases
|
|
76
|
+
|
|
77
|
+
Or just install it with go:
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
go install github.com/charmbracelet/crush@latest
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
> [!WARNING]
|
|
84
|
+
> Productivity may increase when using Crush and you may find yourself nerd
|
|
85
|
+
> sniped when first using the application. If the symptoms persist, join the
|
|
86
|
+
> [Discord][discord] and nerd snipe the rest of us.
|
|
87
|
+
|
|
88
|
+
## Getting Started
|
|
89
|
+
|
|
90
|
+
The quickest way to get started is to grab an API key for your preferred
|
|
91
|
+
provider such as Anthropic, OpenAI, Groq, or OpenRouter and just start
|
|
92
|
+
Crush. You'll be prompted to enter your API key.
|
|
93
|
+
|
|
94
|
+
That said, you can also set environment variables for preferred providers.
|
|
95
|
+
|
|
96
|
+
<details>
|
|
97
|
+
<summary><strong>Supported Environment Variables</strong></summary>
|
|
98
|
+
|
|
99
|
+
| Environment Variable | Provider |
|
|
100
|
+
| -------------------------- | -------------------------------------------------- |
|
|
101
|
+
| `ANTHROPIC_API_KEY` | Anthropic |
|
|
102
|
+
| `OPENAI_API_KEY` | OpenAI |
|
|
103
|
+
| `GEMINI_API_KEY` | Google Gemini |
|
|
104
|
+
| `VERTEXAI_PROJECT` | Google Cloud VertexAI (Gemini) |
|
|
105
|
+
| `VERTEXAI_LOCATION` | Google Cloud VertexAI (Gemini) |
|
|
106
|
+
| `GROQ_API_KEY` | Groq |
|
|
107
|
+
| `AWS_ACCESS_KEY_ID` | AWS Bedrock (Claude) |
|
|
108
|
+
| `AWS_SECRET_ACCESS_KEY` | AWS Bedrock (Claude) |
|
|
109
|
+
| `AWS_REGION` | AWS Bedrock (Claude) |
|
|
110
|
+
| `AZURE_OPENAI_ENDPOINT` | Azure OpenAI models |
|
|
111
|
+
| `AZURE_OPENAI_API_KEY` | Azure OpenAI models (optional when using Entra ID) |
|
|
112
|
+
| `AZURE_OPENAI_API_VERSION` | Azure OpenAI models |
|
|
113
|
+
|
|
114
|
+
</details>
|
|
115
|
+
|
|
116
|
+
## Configuration
|
|
117
|
+
|
|
118
|
+
Crush runs great with no configuration. That said, if you do need or want to
|
|
119
|
+
customize Crush, configuration can be added either local to the project itself,
|
|
120
|
+
or globally, with the following priority:
|
|
121
|
+
|
|
122
|
+
1. `./.crush.json`
|
|
123
|
+
2. `./crush.json`
|
|
124
|
+
3. `$HOME/.config/crush/crush.json`
|
|
125
|
+
|
|
126
|
+
Configuration itself is stored as a JSON object:
|
|
127
|
+
|
|
128
|
+
```json
|
|
129
|
+
{
|
|
130
|
+
"this-setting": { }
|
|
131
|
+
"that-setting": { }
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### LSPs
|
|
136
|
+
|
|
137
|
+
Crush can use LSPs for additional context to help inform its decisions, just
|
|
138
|
+
like you would. LSPs can be added manually like so:
|
|
139
|
+
|
|
140
|
+
```json
|
|
141
|
+
{
|
|
142
|
+
"$schema": "https://charm.land/crush.json",
|
|
143
|
+
"lsp": {
|
|
144
|
+
"go": {
|
|
145
|
+
"command": "gopls"
|
|
146
|
+
},
|
|
147
|
+
"typescript": {
|
|
148
|
+
"command": "typescript-language-server",
|
|
149
|
+
"args": ["--stdio"]
|
|
150
|
+
},
|
|
151
|
+
"nix": {
|
|
152
|
+
"command": "nil"
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### MCPs
|
|
159
|
+
|
|
160
|
+
Crush also supports Model Context Protocol (MCP) servers through three
|
|
161
|
+
transport types: `stdio` for command-line servers, `http` for HTTP endpoints,
|
|
162
|
+
and `sse` for Server-Sent Events. Environment variable expansion is supported
|
|
163
|
+
using `$(echo $VAR)` syntax.
|
|
164
|
+
|
|
165
|
+
```json
|
|
166
|
+
{
|
|
167
|
+
"$schema": "https://charm.land/crush.json",
|
|
168
|
+
"mcp": {
|
|
169
|
+
"filesystem": {
|
|
170
|
+
"type": "stdio",
|
|
171
|
+
"command": "node",
|
|
172
|
+
"args": ["/path/to/mcp-server.js"],
|
|
173
|
+
"env": {
|
|
174
|
+
"NODE_ENV": "production"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"github": {
|
|
178
|
+
"type": "http",
|
|
179
|
+
"url": "https://example.com/mcp/",
|
|
180
|
+
"headers": {
|
|
181
|
+
"Authorization": "$(echo Bearer $EXAMPLE_MCP_TOKEN)"
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"streaming-service": {
|
|
185
|
+
"type": "sse",
|
|
186
|
+
"url": "https://example.com/mcp/sse",
|
|
187
|
+
"headers": {
|
|
188
|
+
"API-Key": "$(echo $API_KEY)"
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### Whitelisting Tools
|
|
196
|
+
|
|
197
|
+
By default, Crush will ask you for permission before running tool calls. If
|
|
198
|
+
you'd like, you can whitelist tools to be executed without prompting you for
|
|
199
|
+
permissions. Use this with care.
|
|
200
|
+
|
|
201
|
+
```json
|
|
202
|
+
{
|
|
203
|
+
"$schema": "https://charm.land/crush.json",
|
|
204
|
+
"permissions": {
|
|
205
|
+
"allowed_tools": [
|
|
206
|
+
"view",
|
|
207
|
+
"ls",
|
|
208
|
+
"grep",
|
|
209
|
+
"edit",
|
|
210
|
+
"mcp_context7_get-library-doc"
|
|
211
|
+
]
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
You can also skip all permission prompts entirely by running Crush with the
|
|
217
|
+
`--yolo` flag. Be very, very careful with this feature.
|
|
218
|
+
|
|
219
|
+
### Custom Providers
|
|
220
|
+
|
|
221
|
+
Crush supports custom provider configurations for both OpenAI-compatible and
|
|
222
|
+
Anthropic-compatible APIs.
|
|
223
|
+
|
|
224
|
+
#### OpenAI-Compatible APIs
|
|
225
|
+
|
|
226
|
+
Here’s an example configuration for Deepseek, which uses an OpenAI-compatible
|
|
227
|
+
API. Don't forget to set `DEEPSEEK_API_KEY` in your environment.
|
|
228
|
+
|
|
229
|
+
```json
|
|
230
|
+
{
|
|
231
|
+
"$schema": "https://charm.land/crush.json",
|
|
232
|
+
"providers": {
|
|
233
|
+
"deepseek": {
|
|
234
|
+
"type": "openai",
|
|
235
|
+
"base_url": "https://api.deepseek.com/v1",
|
|
236
|
+
"api_key": "$DEEPSEEK_API_KEY",
|
|
237
|
+
"models": [
|
|
238
|
+
{
|
|
239
|
+
"id": "deepseek-chat",
|
|
240
|
+
"name": "Deepseek V3",
|
|
241
|
+
"cost_per_1m_in": 0.27,
|
|
242
|
+
"cost_per_1m_out": 1.1,
|
|
243
|
+
"cost_per_1m_in_cached": 0.07,
|
|
244
|
+
"cost_per_1m_out_cached": 1.1,
|
|
245
|
+
"context_window": 64000,
|
|
246
|
+
"default_max_tokens": 5000
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
```
|
|
253
|
+
|
|
254
|
+
#### Anthropic-Compatible APIs
|
|
255
|
+
|
|
256
|
+
Custom Anthropic-compatible providers follow this format:
|
|
257
|
+
|
|
258
|
+
```json
|
|
259
|
+
{
|
|
260
|
+
"$schema": "https://charm.land/crush.json",
|
|
261
|
+
"providers": {
|
|
262
|
+
"custom-anthropic": {
|
|
263
|
+
"type": "anthropic",
|
|
264
|
+
"base_url": "https://api.anthropic.com/v1",
|
|
265
|
+
"api_key": "$ANTHROPIC_API_KEY",
|
|
266
|
+
"extra_headers": {
|
|
267
|
+
"anthropic-version": "2023-06-01"
|
|
268
|
+
},
|
|
269
|
+
"models": [
|
|
270
|
+
{
|
|
271
|
+
"id": "claude-sonnet-4-20250514",
|
|
272
|
+
"name": "Claude Sonnet 4",
|
|
273
|
+
"cost_per_1m_in": 3,
|
|
274
|
+
"cost_per_1m_out": 15,
|
|
275
|
+
"cost_per_1m_in_cached": 3.75,
|
|
276
|
+
"cost_per_1m_out_cached": 0.3,
|
|
277
|
+
"context_window": 200000,
|
|
278
|
+
"default_max_tokens": 50000,
|
|
279
|
+
"can_reason": true,
|
|
280
|
+
"supports_attachments": true
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
## Logging
|
|
289
|
+
|
|
290
|
+
Sometimes you need to look at logs. Luckily, Crush logs all sorts of
|
|
291
|
+
stuff. Logs are stored in `./.crush/logs/crush.log` relative to the project.
|
|
292
|
+
|
|
293
|
+
The CLI also contains some helper commands to make perusing recent logs easier:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
# Print the last 1000 lines
|
|
297
|
+
crush logs
|
|
298
|
+
|
|
299
|
+
# Print the last 500 lines
|
|
300
|
+
crush logs --tail 500
|
|
301
|
+
|
|
302
|
+
# Follow logs in real time
|
|
303
|
+
crush logs --follow
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
Want more logging? Run `crush` with the `--debug` flag, or enable it in the
|
|
307
|
+
config:
|
|
308
|
+
|
|
309
|
+
```json
|
|
310
|
+
{
|
|
311
|
+
"$schema": "https://charm.land/crush.json",
|
|
312
|
+
"options": {
|
|
313
|
+
"debug": true,
|
|
314
|
+
"debug_lsp": true
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
## Whatcha think?
|
|
320
|
+
|
|
321
|
+
We’d love to hear your thoughts on this project. Need help? We gotchu. You can find us on:
|
|
322
|
+
|
|
323
|
+
- [Twitter](https://twitter.com/charmcli)
|
|
324
|
+
- [Discord][discord]
|
|
325
|
+
- [Slack](https://charm.land/slack)
|
|
326
|
+
- [The Fediverse](https://mastodon.social/@charmcli)
|
|
327
|
+
|
|
328
|
+
[discord]: https://charm.land/discord
|
|
329
|
+
|
|
330
|
+
## License
|
|
331
|
+
|
|
332
|
+
[FSL-1.1-MIT](https://github.com/charmbracelet/crush/raw/main/LICENSE)
|
|
333
|
+
|
|
334
|
+
---
|
|
335
|
+
|
|
336
|
+
Part of [Charm](https://charm.land).
|
|
337
|
+
|
|
338
|
+
<a href="https://charm.land/"><img alt="The Charm logo" width="400" src="https://stuff.charm.sh/charm-banner-next.jpg" /></a>
|
|
339
|
+
|
|
340
|
+
<!--prettier-ignore-->
|
|
341
|
+
Charm热爱开源 • Charm loves open source
|
package/install.js
ADDED
package/lib.js
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
// This file was generated by GoReleaser. DO NOT EDIT.
|
|
2
|
+
const { archives } = require("./package.json");
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const crypto = require("crypto");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
const JSZip = require("jszip");
|
|
7
|
+
const tar = require("tar");
|
|
8
|
+
const axios = require("axios");
|
|
9
|
+
const { spawnSync } = require("child_process");
|
|
10
|
+
|
|
11
|
+
const getArchive = () => {
|
|
12
|
+
let target = `${process.platform}-${process.arch}`;
|
|
13
|
+
const archive = archives[target];
|
|
14
|
+
if (!archive) {
|
|
15
|
+
throw new Error(`No archive available for ${target}`);
|
|
16
|
+
}
|
|
17
|
+
return archive;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const binDir = path.join(__dirname, "bin");
|
|
21
|
+
|
|
22
|
+
async function extractTar(tarPath, binaries, dir, wrappedIn) {
|
|
23
|
+
try {
|
|
24
|
+
const filesToExtract = wrappedIn
|
|
25
|
+
? binaries.map((bin) =>
|
|
26
|
+
path.join(wrappedIn, bin).replace(/\\/g, "/"),
|
|
27
|
+
)
|
|
28
|
+
: binaries;
|
|
29
|
+
|
|
30
|
+
await tar.x({
|
|
31
|
+
file: tarPath,
|
|
32
|
+
cwd: dir,
|
|
33
|
+
filter: (path) => filesToExtract.includes(path),
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// If wrapped, move files from wrapped directory to bin directory
|
|
37
|
+
if (wrappedIn) {
|
|
38
|
+
const wrappedDir = path.join(dir, wrappedIn);
|
|
39
|
+
for (const binary of binaries) {
|
|
40
|
+
const srcPath = path.join(wrappedDir, binary);
|
|
41
|
+
const destPath = path.join(dir, binary);
|
|
42
|
+
if (fs.existsSync(srcPath)) {
|
|
43
|
+
fs.renameSync(srcPath, destPath);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Clean up empty wrapped directory
|
|
47
|
+
try {
|
|
48
|
+
fs.rmSync(wrappedDir, { recursive: true, force: true });
|
|
49
|
+
} catch (err) {
|
|
50
|
+
// Ignore cleanup errors
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
console.log(`Successfully extracted ${binaries} to "${dir}"`);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
throw new Error(`Extraction failed: ${err.message}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async function extractZip(zipPath, binaries, dir, wrappedIn) {
|
|
61
|
+
try {
|
|
62
|
+
const zipData = fs.readFileSync(zipPath);
|
|
63
|
+
const zip = await JSZip.loadAsync(zipData);
|
|
64
|
+
|
|
65
|
+
for (const binary of binaries) {
|
|
66
|
+
const binaryPath = wrappedIn
|
|
67
|
+
? path.join(wrappedIn, binary).replace(/\\/g, "/")
|
|
68
|
+
: binary;
|
|
69
|
+
|
|
70
|
+
if (!zip.files[binaryPath]) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Error: ${binaryPath} does not exist in ${zipPath}`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const content = await zip.files[binaryPath].async("nodebuffer");
|
|
77
|
+
if (!fs.existsSync(dir)) {
|
|
78
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
79
|
+
}
|
|
80
|
+
const file = path.join(dir, binary);
|
|
81
|
+
fs.writeFileSync(file, content);
|
|
82
|
+
fs.chmodSync(file, "755");
|
|
83
|
+
console.log(`Successfully extracted "${binary}" to "${dir}"`);
|
|
84
|
+
}
|
|
85
|
+
} catch (err) {
|
|
86
|
+
throw new Error(`Extraction failed: ${err.message}`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const run = async (bin) => {
|
|
91
|
+
await install();
|
|
92
|
+
if (process.platform === "win32") {
|
|
93
|
+
bin += ".exe";
|
|
94
|
+
}
|
|
95
|
+
const [, , ...args] = process.argv;
|
|
96
|
+
let result = spawnSync(path.join(binDir, bin), args, {
|
|
97
|
+
cwd: process.cwd(),
|
|
98
|
+
stdio: "inherit",
|
|
99
|
+
});
|
|
100
|
+
if (result.error) {
|
|
101
|
+
console.error(result.error);
|
|
102
|
+
}
|
|
103
|
+
return result.status;
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const install = async () => {
|
|
107
|
+
try {
|
|
108
|
+
let archive = getArchive();
|
|
109
|
+
if (await exists(archive)) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
let tmp = fs.mkdtempSync("archive-");
|
|
113
|
+
let archivePath = path.join(tmp, archive.name);
|
|
114
|
+
await download(archive.url, archivePath);
|
|
115
|
+
verify(archivePath, archive.checksum);
|
|
116
|
+
|
|
117
|
+
if (!fs.existsSync(binDir)) {
|
|
118
|
+
fs.mkdirSync(binDir);
|
|
119
|
+
}
|
|
120
|
+
switch (archive.format) {
|
|
121
|
+
case "binary":
|
|
122
|
+
const bin = path.join(binDir, archive.bins[0]);
|
|
123
|
+
fs.copyFileSync(archivePath, bin);
|
|
124
|
+
fs.chmodSync(bin, 0o755);
|
|
125
|
+
return;
|
|
126
|
+
case "zip":
|
|
127
|
+
return extractZip(
|
|
128
|
+
archivePath,
|
|
129
|
+
archive.bins,
|
|
130
|
+
binDir,
|
|
131
|
+
archive.wrappedIn,
|
|
132
|
+
);
|
|
133
|
+
case "tar":
|
|
134
|
+
case "tar.gz":
|
|
135
|
+
case "tgz":
|
|
136
|
+
return extractTar(
|
|
137
|
+
archivePath,
|
|
138
|
+
archive.bins,
|
|
139
|
+
binDir,
|
|
140
|
+
archive.wrappedIn,
|
|
141
|
+
);
|
|
142
|
+
case "tar.zst":
|
|
143
|
+
case "tzst":
|
|
144
|
+
case "tar.xz":
|
|
145
|
+
case "txz":
|
|
146
|
+
default:
|
|
147
|
+
throw new Error(`unsupported format: ${archive.format}`);
|
|
148
|
+
}
|
|
149
|
+
} catch (err) {
|
|
150
|
+
throw new Error(`Installation failed: ${err.message}`);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const verify = (filename, checksum) => {
|
|
155
|
+
if (checksum.algorithm == "" || checksum.digest == "") {
|
|
156
|
+
console.warn("Warning: No checksum provided for verification");
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
let digest = crypto
|
|
160
|
+
.createHash(checksum.algorithm)
|
|
161
|
+
.update(fs.readFileSync(filename))
|
|
162
|
+
.digest("hex");
|
|
163
|
+
if (digest != checksum.digest) {
|
|
164
|
+
throw new Error(
|
|
165
|
+
`${filename}: ${checksum.algorithm} does not match, expected ${checksum.digest}, got ${digest}`,
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const download = async (url, filename) => {
|
|
171
|
+
try {
|
|
172
|
+
console.log(`Downloading ${url} to ${filename}...`);
|
|
173
|
+
const dir = path.dirname(filename);
|
|
174
|
+
if (!fs.existsSync(dir)) {
|
|
175
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const response = await axios({
|
|
179
|
+
method: "GET",
|
|
180
|
+
url: url,
|
|
181
|
+
responseType: "stream",
|
|
182
|
+
timeout: 300000, // 5min
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const writer = fs.createWriteStream(filename);
|
|
186
|
+
response.data.pipe(writer);
|
|
187
|
+
|
|
188
|
+
return new Promise((resolve, reject) => {
|
|
189
|
+
writer.on("finish", () => {
|
|
190
|
+
console.log(`Download complete: ${filename}`);
|
|
191
|
+
resolve(dir);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
writer.on("error", (err) => {
|
|
195
|
+
console.error(`Error writing file: ${err.message}`);
|
|
196
|
+
reject(err);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
} catch (err) {
|
|
200
|
+
throw new Error(`Download failed: ${err.message}`);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
function exists(archive) {
|
|
205
|
+
if (!fs.existsSync(binDir)) {
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
return archive.bins.every((bin) => fs.existsSync(path.join(binDir, bin)));
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = {
|
|
212
|
+
install,
|
|
213
|
+
run,
|
|
214
|
+
getArchive,
|
|
215
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@charmland/crush",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A powerful terminal-based AI assistant for developers, providing intelligent coding assistance directly in your terminal.",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"postinstall": "node install.js",
|
|
7
|
+
"run": "node run-crush.js"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/charmbracelet/crush.git"
|
|
12
|
+
},
|
|
13
|
+
"author": "kujtimiihoxha \u003ckujtim@charm.sh\u003e",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/charmbracelet/crush/issues"
|
|
17
|
+
},
|
|
18
|
+
"homepage": "https://charm.sh/crush",
|
|
19
|
+
"bin": {
|
|
20
|
+
"crush": "run-crush.js"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"axios": "^1.8.2",
|
|
24
|
+
"jszip": "^3.10.1",
|
|
25
|
+
"tar": "^7.4.3"
|
|
26
|
+
},
|
|
27
|
+
"archives": {
|
|
28
|
+
"darwin-arm64": {
|
|
29
|
+
"name": "crush_0.1.1_Darwin_arm64.tar.gz",
|
|
30
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Darwin_arm64.tar.gz",
|
|
31
|
+
"bins": [
|
|
32
|
+
"crush"
|
|
33
|
+
],
|
|
34
|
+
"format": "tar.gz",
|
|
35
|
+
"checksum": {
|
|
36
|
+
"algorithm": "sha256",
|
|
37
|
+
"digest": "5aff7e423554e5a87a2332b0b5419396574bc370a0a475692ee0adcc202e4c4f"
|
|
38
|
+
},
|
|
39
|
+
"wrappedIn": "crush_0.1.1_Darwin_arm64"
|
|
40
|
+
},
|
|
41
|
+
"darwin-x64": {
|
|
42
|
+
"name": "crush_0.1.1_Darwin_x86_64.tar.gz",
|
|
43
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Darwin_x86_64.tar.gz",
|
|
44
|
+
"bins": [
|
|
45
|
+
"crush"
|
|
46
|
+
],
|
|
47
|
+
"format": "tar.gz",
|
|
48
|
+
"checksum": {
|
|
49
|
+
"algorithm": "sha256",
|
|
50
|
+
"digest": "6628644c4b15daf2d5a9c9253cb1b285cd13b50d46f535a7c9e5412aed94cbae"
|
|
51
|
+
},
|
|
52
|
+
"wrappedIn": "crush_0.1.1_Darwin_x86_64"
|
|
53
|
+
},
|
|
54
|
+
"linux-arm64": {
|
|
55
|
+
"name": "crush_0.1.1_Linux_arm64.tar.gz",
|
|
56
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Linux_arm64.tar.gz",
|
|
57
|
+
"bins": [
|
|
58
|
+
"crush"
|
|
59
|
+
],
|
|
60
|
+
"format": "tar.gz",
|
|
61
|
+
"checksum": {
|
|
62
|
+
"algorithm": "sha256",
|
|
63
|
+
"digest": "2f215930030b273ff7ea83a538057a476d8c8e442ef31a3b32d3b70d535e526f"
|
|
64
|
+
},
|
|
65
|
+
"wrappedIn": "crush_0.1.1_Linux_arm64"
|
|
66
|
+
},
|
|
67
|
+
"linux-x64": {
|
|
68
|
+
"name": "crush_0.1.1_Linux_x86_64.tar.gz",
|
|
69
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Linux_x86_64.tar.gz",
|
|
70
|
+
"bins": [
|
|
71
|
+
"crush"
|
|
72
|
+
],
|
|
73
|
+
"format": "tar.gz",
|
|
74
|
+
"checksum": {
|
|
75
|
+
"algorithm": "sha256",
|
|
76
|
+
"digest": "f9969ddad399855bead1348e3cfda615e550db213d1899fd78add904a501c06f"
|
|
77
|
+
},
|
|
78
|
+
"wrappedIn": "crush_0.1.1_Linux_x86_64"
|
|
79
|
+
},
|
|
80
|
+
"win32-arm64": {
|
|
81
|
+
"name": "crush_0.1.1_Windows_arm64.zip",
|
|
82
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Windows_arm64.zip",
|
|
83
|
+
"bins": [
|
|
84
|
+
"crush.exe"
|
|
85
|
+
],
|
|
86
|
+
"format": "zip",
|
|
87
|
+
"checksum": {
|
|
88
|
+
"algorithm": "sha256",
|
|
89
|
+
"digest": "66bb4d699691acedd1203d29b9618391201a719e3b68bf3d791793002a2fceb3"
|
|
90
|
+
},
|
|
91
|
+
"wrappedIn": "crush_0.1.1_Windows_arm64"
|
|
92
|
+
},
|
|
93
|
+
"win32-x64": {
|
|
94
|
+
"name": "crush_0.1.1_Windows_x86_64.zip",
|
|
95
|
+
"url": "https://github.com/charmbracelet/crush/releases/download/v0.1.1/crush_0.1.1_Windows_x86_64.zip",
|
|
96
|
+
"bins": [
|
|
97
|
+
"crush.exe"
|
|
98
|
+
],
|
|
99
|
+
"format": "zip",
|
|
100
|
+
"checksum": {
|
|
101
|
+
"algorithm": "sha256",
|
|
102
|
+
"digest": "a2195194bdd0deb6cb6ce626da03b4431a9997590e10b9c6fbaced9b5f19622b"
|
|
103
|
+
},
|
|
104
|
+
"wrappedIn": "crush_0.1.1_Windows_x86_64"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|