@kevinguo1007/ruask 0.0.0-stage → 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/.gitignore +2 -0
- package/LICENSE +21 -0
- package/README.md +180 -2
- package/binary-install.js +348 -0
- package/binary.js +124 -0
- package/install.js +4 -0
- package/npm-shrinkwrap.json +52 -0
- package/package.json +93 -3
- package/run-ruask.js +4 -0
package/.gitignore
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kevin Guo
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,181 @@
|
|
|
1
|
-
|
|
1
|
+
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
<a href="https://ruask.vercel.app">
|
|
4
|
+
<picture>
|
|
5
|
+
<source media="(prefers-color-scheme: dark)" srcset="site/public/brand/ruask-wordmark-dark.svg">
|
|
6
|
+
<img src="site/public/brand/ruask-wordmark-light.svg" alt="ruask" height="72">
|
|
7
|
+
</picture>
|
|
8
|
+
</a>
|
|
9
|
+
|
|
10
|
+
<h3>Ask your terminal how to use a command.</h3>
|
|
11
|
+
|
|
12
|
+
<p>Instant tldr pages for quick lookups. Streamed, reference-backed LLM answers for everything else.</p>
|
|
13
|
+
|
|
14
|
+
<p>
|
|
15
|
+
<a href="https://ruask.vercel.app"><img src="https://img.shields.io/website?url=https%3A%2F%2Fruask.vercel.app&label=website&up_message=ruask.vercel.app&down_message=offline&up_color=brightgreen&logo=vercel" alt="Website"></a>
|
|
16
|
+
<a href="https://github.com/KevinGuo1007/ruask/stargazers"><img src="https://img.shields.io/github/stars/KevinGuo1007/ruask?style=flat&logo=github&color=blue" alt="GitHub stars"></a>
|
|
17
|
+
<a href="#license"><img src="https://img.shields.io/badge/license-MIT-blue" alt="License: MIT"></a>
|
|
18
|
+
<a href="https://doc.rust-lang.org/edition-guide/rust-2024/index.html"><img src="https://img.shields.io/badge/rust-2024%20edition-orange?logo=rust" alt="Rust 2024 edition"></a>
|
|
19
|
+
<img src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey?logo=linux&logoColor=white" alt="Platform: macOS | Linux">
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
<p>
|
|
23
|
+
<b>English</b> · <a href="README.zh-CN.md">简体中文</a>
|
|
24
|
+
|
|
|
25
|
+
<a href="#quick-start">Quick start</a> ·
|
|
26
|
+
<a href="#usage">Usage</a> ·
|
|
27
|
+
<a href="#configuration">Configuration</a> ·
|
|
28
|
+
<a href="docs/reference.md">Reference</a>
|
|
29
|
+
</p>
|
|
30
|
+
|
|
31
|
+
<img src="site/public/assets/ruask-demo.en.gif" alt="ruask demo: a tldr page, a natural-language question and a piped error" width="760">
|
|
32
|
+
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
<br>
|
|
36
|
+
|
|
37
|
+
## Why ruask
|
|
38
|
+
|
|
39
|
+
| | |
|
|
40
|
+
| --- | --- |
|
|
41
|
+
| ⚡ **Milliseconds for quick lookups** | `ruask tar` or `ruask git commit` renders the local tldr page directly: no network, no model, no API key. |
|
|
42
|
+
| 📚 **Answers grounded in docs** | Questions like `ruask git commit -q "how do I edit the last commit message"` send the matching tldr pages to the model as reference, so it invents fewer flags. |
|
|
43
|
+
| 🔍 **Explains command output** | `cat error.log \| ruask cargo build -q "why did it fail"` reads the output, the command and your question together. |
|
|
44
|
+
| 🖥️ **Made for the terminal** | Streams as it arrives, colors by meaning, numbers examples, never wraps a command. Redirected output stays plain text. |
|
|
45
|
+
| 🛡️ **Safe by default** | Shows commands, never runs them. Flags destructive ones (`rm -r`, `git reset --hard`, `git push --force` …). No history, no project `.env` loading. |
|
|
46
|
+
| 🔌 **Bring your own model** | OpenAI-compatible Chat Completions or native Anthropic Messages, configured once per user. |
|
|
47
|
+
|
|
48
|
+
## Quick start
|
|
49
|
+
|
|
50
|
+
Runs on macOS and Linux (x86_64 / arm64). Install with whichever you prefer:
|
|
51
|
+
|
|
52
|
+
| Package manager | Command |
|
|
53
|
+
| --- | --- |
|
|
54
|
+
| Homebrew | `brew install KevinGuo1007/tap/ruask` |
|
|
55
|
+
| Install script | `curl --proto '=https' --tlsv1.2 -LsSf https://github.com/KevinGuo1007/ruask/releases/latest/download/ruask-installer.sh \| sh` |
|
|
56
|
+
| Cargo | `cargo install ruask --locked` (builds from source; needs a Rust toolchain with 2024 edition support) or `cargo binstall ruask` |
|
|
57
|
+
| npm | `npm install -g @kevinguo1007/ruask` |
|
|
58
|
+
|
|
59
|
+
Prebuilt binaries are also on [GitHub Releases](https://github.com/KevinGuo1007/ruask/releases), each archive with a `.sha256` checksum. The install script puts `ruask` in `$XDG_BIN_HOME` or `~/.local/bin`.
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
ruask --update-pages # optional, recommended: download and verify the official tldr pages
|
|
63
|
+
ruask tar # local page, no configuration needed
|
|
64
|
+
|
|
65
|
+
ruask --init-config # create a 0600 config template and print its path
|
|
66
|
+
# fill in your model's base_url, api_key and model, then:
|
|
67
|
+
ruask "find files larger than 100 MB"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
<details>
|
|
71
|
+
<summary>Build from a clone instead</summary>
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
git clone https://github.com/KevinGuo1007/ruask
|
|
75
|
+
cd ruask
|
|
76
|
+
cargo install --path . # or: cargo build --release && ./target/release/ruask
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Make sure Cargo's bin directory (usually `~/.cargo/bin`) is on your `PATH`.
|
|
80
|
+
|
|
81
|
+
</details>
|
|
82
|
+
|
|
83
|
+
## How it works
|
|
84
|
+
|
|
85
|
+
```mermaid
|
|
86
|
+
flowchart LR
|
|
87
|
+
Q["ruask args / stdin"] --> R{"command only?<br/>no -q, no stdin"}
|
|
88
|
+
R -- "yes, page installed" --> T["render local tldr page<br/><i>milliseconds, offline</i>"]
|
|
89
|
+
R -- "no" --> P["attach matching tldr pages<br/>as reference"]
|
|
90
|
+
P --> M["stream from your model"]
|
|
91
|
+
M --> O["render line by line<br/>colors · numbering · warnings"]
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Pages are installed by `ruask --update-pages` into `$RUASK_TLDR_DIR`, or `$XDG_DATA_HOME/ruask/tldr`, or `~/.local/share/ruask/tldr`. Only English and Simplified Chinese pages are kept. Without pages, every query goes to the model as before.
|
|
95
|
+
|
|
96
|
+
## Usage
|
|
97
|
+
|
|
98
|
+
| Command | What happens |
|
|
99
|
+
| --- | --- |
|
|
100
|
+
| `ruask cargo` | Look up a command |
|
|
101
|
+
| `ruask git commit` | Look up a subcommand (positional args are joined) |
|
|
102
|
+
| `ruask "find the process listening on port 8080"` | Natural-language task |
|
|
103
|
+
| `ruask git commit -q "how do I undo a commit"` | Command plus a focused question |
|
|
104
|
+
| `ruask --question "how do I watch a log file"` | A question on its own |
|
|
105
|
+
| `cat error.log \| ruask cargo build -q "why did it fail"` | Explain piped output (up to 64 KiB) |
|
|
106
|
+
| `ruask tar -xzvf` | Unknown options after the command word belong to the target command |
|
|
107
|
+
| `ruask -- git log -p` | Use `--` (or quotes) when a target option clashes with ruask's own |
|
|
108
|
+
| `ruask -L zh -p linux "check disk usage"` | Pick answer language (`en` / `zh`) and target platform (`linux` / `macos`) |
|
|
109
|
+
| `ruask git status > usage.txt` | stdout carries only the answer, as plain text |
|
|
110
|
+
| `ruask --version` | Version and local tldr page status |
|
|
111
|
+
|
|
112
|
+
Run `ruask -h` for short help or `ruask --help` for the full one.
|
|
113
|
+
|
|
114
|
+
## Configuration
|
|
115
|
+
|
|
116
|
+
`ruask --init-config` creates `$XDG_CONFIG_HOME/ruask/config.toml` (default `~/.config/ruask/config.toml`) with `0600` permissions and keeps an existing file.
|
|
117
|
+
|
|
118
|
+
```toml
|
|
119
|
+
api_type = "openai" # or "anthropic"
|
|
120
|
+
# language = "en" # en / zh; defaults to your locale, then English
|
|
121
|
+
|
|
122
|
+
[openai]
|
|
123
|
+
base_url = "https://your-provider.example/v1" # /chat/completions is appended
|
|
124
|
+
model = "your-model"
|
|
125
|
+
api_key = "YOUR_API_KEY"
|
|
126
|
+
# thinking = "disabled" # only for services that support thinking.type; usually much faster
|
|
127
|
+
|
|
128
|
+
[anthropic]
|
|
129
|
+
base_url = "https://your-anthropic-provider.example/v1" # /messages is appended
|
|
130
|
+
model = "your-model"
|
|
131
|
+
api_key = "YOUR_API_KEY"
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Environment variables override the file field by field for the selected protocol and never borrow from the other one:
|
|
135
|
+
|
|
136
|
+
| Protocol | Variables |
|
|
137
|
+
| --- | --- |
|
|
138
|
+
| selection | `RUASK_API_TYPE` (`openai` / `anthropic`) |
|
|
139
|
+
| `openai` | `OPENAI_BASE_URL`, `OPENAI_API_KEY`, `OPENAI_MODEL`, `OPENAI_THINKING` |
|
|
140
|
+
| `anthropic` | `ANTHROPIC_BASE_URL`, `ANTHROPIC_API_KEY`, `ANTHROPIC_MODEL`, `ANTHROPIC_WORKSPACE_ID` |
|
|
141
|
+
|
|
142
|
+
ruask never reads `.env` files from your project and never edits shell startup files. Full details, including streaming fallback rules and the Anthropic headers, are in the [reference](docs/reference.md).
|
|
143
|
+
|
|
144
|
+
## Output and exit codes
|
|
145
|
+
|
|
146
|
+
- **stdout** carries only the answer; **stderr** carries notices, the waiting spinner and the source line (model · elapsed time · tldr pages used).
|
|
147
|
+
- Color follows `--color auto|always|never` and `NO_COLOR`. Placeholders such as `{{file}}` show as underlined italics in a terminal and stay literal when redirected.
|
|
148
|
+
- A stream that breaks after output has started keeps what was shown and exits with `5`. Nothing is retried or replayed.
|
|
149
|
+
|
|
150
|
+
| Code | Meaning |
|
|
151
|
+
| :-: | --- |
|
|
152
|
+
| `0` | success |
|
|
153
|
+
| `1` | other error |
|
|
154
|
+
| `2` | usage or input error |
|
|
155
|
+
| `3` | configuration error |
|
|
156
|
+
| `4` | connection or service error |
|
|
157
|
+
| `5` | incomplete answer |
|
|
158
|
+
|
|
159
|
+
## Documentation
|
|
160
|
+
|
|
161
|
+
- [Behavior reference](docs/reference.md): protocols, streaming, configuration, input and output rules (Chinese)
|
|
162
|
+
- [Development guide](docs/development.md) · [Testing](docs/testing.md) · [Performance notes](docs/performance.md)
|
|
163
|
+
- [Website](https://ruask.vercel.app), with a 20-second launch video
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
cargo test
|
|
169
|
+
cargo fmt --check
|
|
170
|
+
cargo clippy --all-targets -- -D warnings
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Tests need no real API key. They start local HTTP stand-ins on random ports and, on macOS/Linux, a pseudo-terminal for color tests. The website lives in [`site/`](site/README.md) (Vite + React) and deploys to Vercel from `main`.
|
|
174
|
+
|
|
175
|
+
Not yet on crates.io, Homebrew or as prebuilt binaries. Windows is out of scope for now.
|
|
176
|
+
|
|
177
|
+
## License
|
|
178
|
+
|
|
179
|
+
ruask is released under the [MIT License](LICENSE).
|
|
180
|
+
|
|
181
|
+
Local page content comes from [tldr-pages](https://github.com/tldr-pages/tldr) under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) and is not bundled with ruask.
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
const {
|
|
2
|
+
createWriteStream,
|
|
3
|
+
existsSync,
|
|
4
|
+
mkdirSync,
|
|
5
|
+
mkdtemp,
|
|
6
|
+
rmSync,
|
|
7
|
+
} = require("fs");
|
|
8
|
+
const { join, sep } = require("path");
|
|
9
|
+
const { spawnSync } = require("child_process");
|
|
10
|
+
const { tmpdir } = require("os");
|
|
11
|
+
|
|
12
|
+
const https = require("node:https");
|
|
13
|
+
const http = require("node:http");
|
|
14
|
+
|
|
15
|
+
const tmpDir = tmpdir();
|
|
16
|
+
|
|
17
|
+
const error = (msg) => {
|
|
18
|
+
console.error(msg);
|
|
19
|
+
process.exit(1);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
function getProxyForUrl(urlString) {
|
|
23
|
+
const url = new URL(urlString);
|
|
24
|
+
const isHttps = url.protocol === "https:";
|
|
25
|
+
|
|
26
|
+
const noProxy = process.env.NO_PROXY || process.env.no_proxy || "";
|
|
27
|
+
if (noProxy === "*") return null;
|
|
28
|
+
if (noProxy) {
|
|
29
|
+
const hostname = url.hostname.toLowerCase();
|
|
30
|
+
const noProxyList = noProxy.split(",").map((s) => s.trim().toLowerCase());
|
|
31
|
+
for (const entry of noProxyList) {
|
|
32
|
+
if (hostname === entry || hostname.endsWith("." + entry)) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const proxyEnv = isHttps
|
|
39
|
+
? process.env.HTTPS_PROXY || process.env.https_proxy
|
|
40
|
+
: process.env.HTTP_PROXY || process.env.http_proxy;
|
|
41
|
+
|
|
42
|
+
if (!proxyEnv) return null;
|
|
43
|
+
|
|
44
|
+
const proxyUrl = new URL(proxyEnv);
|
|
45
|
+
|
|
46
|
+
let auth = null;
|
|
47
|
+
if (proxyUrl.username || proxyUrl.password) {
|
|
48
|
+
auth = `${proxyUrl.username}:${proxyUrl.password}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return {
|
|
52
|
+
hostname: proxyUrl.hostname,
|
|
53
|
+
port: proxyUrl.port || (proxyUrl.protocol === "https:" ? 443 : 80),
|
|
54
|
+
auth: auth,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function connectThroughProxy(proxy, target) {
|
|
59
|
+
return new Promise((resolve, reject) => {
|
|
60
|
+
const headers = {};
|
|
61
|
+
if (proxy.auth) {
|
|
62
|
+
headers["Proxy-Authorization"] =
|
|
63
|
+
"Basic " + Buffer.from(proxy.auth).toString("base64");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const connectReq = http.request({
|
|
67
|
+
hostname: proxy.hostname,
|
|
68
|
+
port: proxy.port,
|
|
69
|
+
method: "CONNECT",
|
|
70
|
+
path: `${target.hostname}:${target.port || 443}`,
|
|
71
|
+
headers,
|
|
72
|
+
});
|
|
73
|
+
connectReq.on("connect", (res, socket) => {
|
|
74
|
+
if (res.statusCode === 200) {
|
|
75
|
+
resolve(socket);
|
|
76
|
+
} else {
|
|
77
|
+
reject(new Error(`Proxy CONNECT failed with status ${res.statusCode}`));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
connectReq.on("error", reject);
|
|
81
|
+
connectReq.end();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function download(urlString, maxRedirects) {
|
|
86
|
+
if (maxRedirects === undefined) maxRedirects = 5;
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
if (maxRedirects < 0) {
|
|
89
|
+
return reject(new Error("Too many redirects"));
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const parsed = new URL(urlString);
|
|
93
|
+
const isHttps = parsed.protocol === "https:";
|
|
94
|
+
const mod = isHttps ? https : http;
|
|
95
|
+
const proxy = getProxyForUrl(urlString);
|
|
96
|
+
|
|
97
|
+
const doRequest = (extraOptions) => {
|
|
98
|
+
const options = Object.assign(
|
|
99
|
+
{
|
|
100
|
+
hostname: parsed.hostname,
|
|
101
|
+
port: parsed.port || (isHttps ? 443 : 80),
|
|
102
|
+
path: parsed.pathname + parsed.search,
|
|
103
|
+
method: "GET",
|
|
104
|
+
headers: { "User-Agent": "cargo-dist-npm-installer" },
|
|
105
|
+
},
|
|
106
|
+
extraOptions || {},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
if (proxy && !isHttps) {
|
|
110
|
+
// HTTP through HTTP proxy: request the full URL via the proxy
|
|
111
|
+
options.hostname = proxy.hostname;
|
|
112
|
+
options.port = proxy.port;
|
|
113
|
+
options.path = urlString;
|
|
114
|
+
if (proxy.auth) {
|
|
115
|
+
options.headers["Proxy-Authorization"] =
|
|
116
|
+
"Basic " + Buffer.from(proxy.auth).toString("base64");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const req = mod.request(options, (res) => {
|
|
121
|
+
if (
|
|
122
|
+
res.statusCode >= 300 &&
|
|
123
|
+
res.statusCode < 400 &&
|
|
124
|
+
res.headers.location
|
|
125
|
+
) {
|
|
126
|
+
res.resume();
|
|
127
|
+
const nextUrl = new URL(res.headers.location, urlString).toString();
|
|
128
|
+
return download(nextUrl, maxRedirects - 1).then(resolve, reject);
|
|
129
|
+
}
|
|
130
|
+
if (res.statusCode < 200 || res.statusCode >= 300) {
|
|
131
|
+
res.resume();
|
|
132
|
+
return reject(new Error(`HTTP ${res.statusCode} from ${urlString}`));
|
|
133
|
+
}
|
|
134
|
+
resolve(res);
|
|
135
|
+
});
|
|
136
|
+
req.on("error", reject);
|
|
137
|
+
req.end();
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (proxy && isHttps) {
|
|
141
|
+
connectThroughProxy(proxy, parsed).then(
|
|
142
|
+
(socket) => doRequest({ socket, agent: false }),
|
|
143
|
+
reject,
|
|
144
|
+
);
|
|
145
|
+
} else {
|
|
146
|
+
doRequest();
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
class Package {
|
|
152
|
+
constructor(platform, name, url, filename, zipExt, binaries) {
|
|
153
|
+
let errors = [];
|
|
154
|
+
if (typeof url !== "string") {
|
|
155
|
+
errors.push("url must be a string");
|
|
156
|
+
} else {
|
|
157
|
+
try {
|
|
158
|
+
new URL(url);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
errors.push(e);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (name && typeof name !== "string") {
|
|
164
|
+
errors.push("package name must be a string");
|
|
165
|
+
}
|
|
166
|
+
if (!name) {
|
|
167
|
+
errors.push("You must specify the name of your package");
|
|
168
|
+
}
|
|
169
|
+
if (binaries && typeof binaries !== "object") {
|
|
170
|
+
errors.push("binaries must be a string => string map");
|
|
171
|
+
}
|
|
172
|
+
if (!binaries) {
|
|
173
|
+
errors.push("You must specify the binaries in the package");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (errors.length > 0) {
|
|
177
|
+
let errorMsg =
|
|
178
|
+
"One or more of the parameters you passed to the Binary constructor are invalid:\n";
|
|
179
|
+
errors.forEach((error) => {
|
|
180
|
+
errorMsg += error;
|
|
181
|
+
});
|
|
182
|
+
errorMsg +=
|
|
183
|
+
'\n\nCorrect usage: new Package("my-binary", "https://example.com/binary/download.tar.gz", {"my-binary": "my-binary"})';
|
|
184
|
+
error(errorMsg);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.platform = platform;
|
|
188
|
+
this.url = url;
|
|
189
|
+
this.name = name;
|
|
190
|
+
this.filename = filename;
|
|
191
|
+
this.zipExt = zipExt;
|
|
192
|
+
this.installDirectory = join(__dirname, "node_modules", ".bin_real");
|
|
193
|
+
this.binaries = binaries;
|
|
194
|
+
|
|
195
|
+
if (!existsSync(this.installDirectory)) {
|
|
196
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
exists() {
|
|
201
|
+
for (const binaryName in this.binaries) {
|
|
202
|
+
const binRelPath = this.binaries[binaryName];
|
|
203
|
+
const binPath = join(this.installDirectory, binRelPath);
|
|
204
|
+
if (!existsSync(binPath)) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
install(suppressLogs = false) {
|
|
212
|
+
if (this.exists()) {
|
|
213
|
+
if (!suppressLogs) {
|
|
214
|
+
console.error(
|
|
215
|
+
`${this.name} is already installed, skipping installation.`,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
return Promise.resolve();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
try {
|
|
222
|
+
rmSync(this.installDirectory, { recursive: true, force: true });
|
|
223
|
+
} catch {
|
|
224
|
+
// ignore - directory may not exist
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
mkdirSync(this.installDirectory, { recursive: true });
|
|
228
|
+
|
|
229
|
+
if (!suppressLogs) {
|
|
230
|
+
console.error(`Downloading release from ${this.url}`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return download(this.url)
|
|
234
|
+
.then((res) => {
|
|
235
|
+
return new Promise((resolve, reject) => {
|
|
236
|
+
mkdtemp(`${tmpDir}${sep}`, (err, directory) => {
|
|
237
|
+
if (err) return reject(err);
|
|
238
|
+
let tempFile = join(directory, this.filename);
|
|
239
|
+
const sink = res.pipe(createWriteStream(tempFile));
|
|
240
|
+
sink.on("error", (err) => reject(err));
|
|
241
|
+
sink.on("close", () => {
|
|
242
|
+
if (/\.tar\.*/.test(this.zipExt)) {
|
|
243
|
+
const result = spawnSync("tar", [
|
|
244
|
+
"xf",
|
|
245
|
+
tempFile,
|
|
246
|
+
// The tarballs are stored with a leading directory
|
|
247
|
+
// component; we strip one component in the
|
|
248
|
+
// shell installers too.
|
|
249
|
+
"--strip-components",
|
|
250
|
+
"1",
|
|
251
|
+
"-C",
|
|
252
|
+
this.installDirectory,
|
|
253
|
+
]);
|
|
254
|
+
if (result.status == 0) {
|
|
255
|
+
resolve();
|
|
256
|
+
} else if (result.error) {
|
|
257
|
+
reject(result.error);
|
|
258
|
+
} else {
|
|
259
|
+
reject(
|
|
260
|
+
new Error(
|
|
261
|
+
`An error occurred untarring the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
|
|
262
|
+
),
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
} else if (this.zipExt == ".zip") {
|
|
266
|
+
let result;
|
|
267
|
+
if (this.platform.artifactName.includes("windows")) {
|
|
268
|
+
// Windows does not have "unzip" by default on many installations, instead
|
|
269
|
+
// we use Expand-Archive from powershell
|
|
270
|
+
result = spawnSync("powershell.exe", [
|
|
271
|
+
"-NoProfile",
|
|
272
|
+
"-NonInteractive",
|
|
273
|
+
"-Command",
|
|
274
|
+
`& {
|
|
275
|
+
param([string]$LiteralPath, [string]$DestinationPath)
|
|
276
|
+
Expand-Archive -LiteralPath $LiteralPath -DestinationPath $DestinationPath -Force
|
|
277
|
+
}`,
|
|
278
|
+
tempFile,
|
|
279
|
+
this.installDirectory,
|
|
280
|
+
]);
|
|
281
|
+
} else {
|
|
282
|
+
result = spawnSync("unzip", [
|
|
283
|
+
"-q",
|
|
284
|
+
tempFile,
|
|
285
|
+
"-d",
|
|
286
|
+
this.installDirectory,
|
|
287
|
+
]);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (result.status == 0) {
|
|
291
|
+
resolve();
|
|
292
|
+
} else if (result.error) {
|
|
293
|
+
reject(result.error);
|
|
294
|
+
} else {
|
|
295
|
+
reject(
|
|
296
|
+
new Error(
|
|
297
|
+
`An error occurred unzipping the artifact: stdout: ${result.stdout}; stderr: ${result.stderr}`,
|
|
298
|
+
),
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
} else {
|
|
302
|
+
reject(
|
|
303
|
+
new Error(`Unrecognized file extension: ${this.zipExt}`),
|
|
304
|
+
);
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
})
|
|
310
|
+
.then(() => {
|
|
311
|
+
if (!suppressLogs) {
|
|
312
|
+
console.error(`${this.name} has been installed!`);
|
|
313
|
+
}
|
|
314
|
+
})
|
|
315
|
+
.catch((e) => {
|
|
316
|
+
error(`Error fetching release: ${e.message}`);
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
run(binaryName) {
|
|
321
|
+
const promise = !this.exists() ? this.install(true) : Promise.resolve();
|
|
322
|
+
|
|
323
|
+
promise
|
|
324
|
+
.then(() => {
|
|
325
|
+
const [, , ...args] = process.argv;
|
|
326
|
+
|
|
327
|
+
const options = { cwd: process.cwd(), stdio: "inherit" };
|
|
328
|
+
|
|
329
|
+
const binRelPath = this.binaries[binaryName];
|
|
330
|
+
if (!binRelPath) {
|
|
331
|
+
error(`${binaryName} is not a known binary in ${this.name}`);
|
|
332
|
+
}
|
|
333
|
+
const binPath = join(this.installDirectory, binRelPath);
|
|
334
|
+
const result = spawnSync(binPath, args, options);
|
|
335
|
+
|
|
336
|
+
if (result.error) {
|
|
337
|
+
error(result.error);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
process.exit(result.status);
|
|
341
|
+
})
|
|
342
|
+
.catch((e) => {
|
|
343
|
+
error(e.message);
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
module.exports.Package = Package;
|
package/binary.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
const { Package } = require("./binary-install");
|
|
2
|
+
const os = require("os");
|
|
3
|
+
const libc = require("detect-libc");
|
|
4
|
+
|
|
5
|
+
const error = (msg) => {
|
|
6
|
+
console.error(msg);
|
|
7
|
+
process.exit(1);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
name,
|
|
12
|
+
artifactDownloadUrls,
|
|
13
|
+
supportedPlatforms,
|
|
14
|
+
glibcMinimum,
|
|
15
|
+
} = require("./package.json");
|
|
16
|
+
|
|
17
|
+
// FIXME: implement NPM installer handling of fallback download URLs
|
|
18
|
+
const artifactDownloadUrl = artifactDownloadUrls[0];
|
|
19
|
+
const builderGlibcMajorVersion = glibcMinimum.major;
|
|
20
|
+
const builderGlibcMinorVersion = glibcMinimum.series;
|
|
21
|
+
|
|
22
|
+
const getPlatform = () => {
|
|
23
|
+
const rawOsType = os.type();
|
|
24
|
+
const rawArchitecture = os.arch();
|
|
25
|
+
|
|
26
|
+
// We want to use rust-style target triples as the canonical key
|
|
27
|
+
// for a platform, so translate the "os" library's concepts into rust ones
|
|
28
|
+
let osType = "";
|
|
29
|
+
switch (rawOsType) {
|
|
30
|
+
case "Windows_NT":
|
|
31
|
+
osType = "pc-windows-msvc";
|
|
32
|
+
break;
|
|
33
|
+
case "Darwin":
|
|
34
|
+
osType = "apple-darwin";
|
|
35
|
+
break;
|
|
36
|
+
case "Linux":
|
|
37
|
+
osType = "unknown-linux-gnu";
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let arch = "";
|
|
42
|
+
switch (rawArchitecture) {
|
|
43
|
+
case "x64":
|
|
44
|
+
arch = "x86_64";
|
|
45
|
+
break;
|
|
46
|
+
case "arm64":
|
|
47
|
+
arch = "aarch64";
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (rawOsType === "Linux") {
|
|
52
|
+
if (libc.familySync() == "musl") {
|
|
53
|
+
osType = "unknown-linux-musl-dynamic";
|
|
54
|
+
} else if (libc.isNonGlibcLinuxSync()) {
|
|
55
|
+
console.warn(
|
|
56
|
+
"Your libc is neither glibc nor musl; trying static musl binary instead",
|
|
57
|
+
);
|
|
58
|
+
osType = "unknown-linux-musl-static";
|
|
59
|
+
} else {
|
|
60
|
+
let libcVersion = libc.versionSync();
|
|
61
|
+
let splitLibcVersion = libcVersion.split(".");
|
|
62
|
+
let libcMajorVersion = splitLibcVersion[0];
|
|
63
|
+
let libcMinorVersion = splitLibcVersion[1];
|
|
64
|
+
if (
|
|
65
|
+
libcMajorVersion != builderGlibcMajorVersion ||
|
|
66
|
+
libcMinorVersion < builderGlibcMinorVersion
|
|
67
|
+
) {
|
|
68
|
+
// We can't run the glibc binaries, but we can run the static musl ones
|
|
69
|
+
// if they exist
|
|
70
|
+
console.warn(
|
|
71
|
+
"Your glibc isn't compatible; trying static musl binary instead",
|
|
72
|
+
);
|
|
73
|
+
osType = "unknown-linux-musl-static";
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Assume the above succeeded and build a target triple to look things up with.
|
|
79
|
+
// If any of it failed, this lookup will fail and we'll handle it like normal.
|
|
80
|
+
let targetTriple = `${arch}-${osType}`;
|
|
81
|
+
let platform = supportedPlatforms[targetTriple];
|
|
82
|
+
|
|
83
|
+
if (!platform) {
|
|
84
|
+
error(
|
|
85
|
+
`Platform with type "${rawOsType}" and architecture "${rawArchitecture}" is not supported by ${name}.\nYour system must be one of the following:\n\n${Object.keys(
|
|
86
|
+
supportedPlatforms,
|
|
87
|
+
).join(",")}`,
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return platform;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const getPackage = () => {
|
|
95
|
+
const platform = getPlatform();
|
|
96
|
+
const url = `${artifactDownloadUrl}/${platform.artifactName}`;
|
|
97
|
+
let filename = platform.artifactName;
|
|
98
|
+
let ext = platform.zipExt;
|
|
99
|
+
let binary = new Package(platform, name, url, filename, ext, platform.bins);
|
|
100
|
+
|
|
101
|
+
return binary;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const install = (suppressLogs) => {
|
|
105
|
+
if (!artifactDownloadUrl || artifactDownloadUrl.length === 0) {
|
|
106
|
+
console.warn("in demo mode, not installing binaries");
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const pkg = getPackage();
|
|
110
|
+
|
|
111
|
+
return pkg.install(suppressLogs);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const run = (binaryName) => {
|
|
115
|
+
const pkg = getPackage();
|
|
116
|
+
|
|
117
|
+
pkg.run(binaryName);
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
install,
|
|
122
|
+
run,
|
|
123
|
+
getPackage,
|
|
124
|
+
};
|
package/install.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 3,
|
|
3
|
+
"name": "@kevinguo1007/ruask",
|
|
4
|
+
"packages": {
|
|
5
|
+
"": {
|
|
6
|
+
"bin": {
|
|
7
|
+
"ruask": "run-ruask.js"
|
|
8
|
+
},
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"detect-libc": "^2.1.2"
|
|
11
|
+
},
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"prettier": "^3.9.10"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=14.18",
|
|
17
|
+
"npm": ">=6"
|
|
18
|
+
},
|
|
19
|
+
"hasInstallScript": true,
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"name": "@kevinguo1007/ruask",
|
|
22
|
+
"version": "0.1.1"
|
|
23
|
+
},
|
|
24
|
+
"node_modules/detect-libc": {
|
|
25
|
+
"engines": {
|
|
26
|
+
"node": ">=8"
|
|
27
|
+
},
|
|
28
|
+
"integrity": "sha512-Btj2BOOO83o3WyH59e8MgXsxEQVcarkUOpEYrubB0urwnN10yQ364rsiByU11nZlqWYZm05i/of7io4mzihBtQ==",
|
|
29
|
+
"license": "Apache-2.0",
|
|
30
|
+
"resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.1.2.tgz",
|
|
31
|
+
"version": "2.1.2"
|
|
32
|
+
},
|
|
33
|
+
"node_modules/prettier": {
|
|
34
|
+
"bin": {
|
|
35
|
+
"prettier": "bin/prettier.cjs"
|
|
36
|
+
},
|
|
37
|
+
"dev": true,
|
|
38
|
+
"engines": {
|
|
39
|
+
"node": ">=14"
|
|
40
|
+
},
|
|
41
|
+
"funding": {
|
|
42
|
+
"url": "https://github.com/prettier/prettier?sponsor=1"
|
|
43
|
+
},
|
|
44
|
+
"integrity": "sha512-skGHTH1Yb9QvaTC4hWnRTzEYtCpApF0UMBPz+t/0ZPzP8ihefo/btKd+QA7pUE0fEwA1SbS/NmhyEcstdXOIdA==",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.9.10.tgz",
|
|
47
|
+
"version": "3.9.10"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"requires": true,
|
|
51
|
+
"version": "0.1.1"
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,96 @@
|
|
|
1
1
|
{
|
|
2
|
+
"artifactDownloadUrls": [
|
|
3
|
+
"https://github.com/KevinGuo1007/ruask/releases/download/v0.1.1"
|
|
4
|
+
],
|
|
5
|
+
"bin": {
|
|
6
|
+
"ruask": "run-ruask.js"
|
|
7
|
+
},
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"detect-libc": "^2.1.2"
|
|
10
|
+
},
|
|
11
|
+
"description": "A command-line assistant for command lookup and command output explanation",
|
|
12
|
+
"devDependencies": {
|
|
13
|
+
"prettier": "^3.9.10"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=14.18",
|
|
17
|
+
"npm": ">=6"
|
|
18
|
+
},
|
|
19
|
+
"glibcMinimum": {
|
|
20
|
+
"major": 2,
|
|
21
|
+
"series": 35
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://ruask.vercel.app",
|
|
24
|
+
"license": "MIT",
|
|
2
25
|
"name": "@kevinguo1007/ruask",
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
26
|
+
"preferUnplugged": true,
|
|
27
|
+
"repository": "https://github.com/KevinGuo1007/ruask",
|
|
28
|
+
"scripts": {
|
|
29
|
+
"fmt": "prettier --write **/*.js",
|
|
30
|
+
"fmt:check": "prettier --check **/*.js",
|
|
31
|
+
"postinstall": "node ./install.js"
|
|
32
|
+
},
|
|
33
|
+
"supportedPlatforms": {
|
|
34
|
+
"aarch64-apple-darwin": {
|
|
35
|
+
"artifactName": "ruask-aarch64-apple-darwin.tar.xz",
|
|
36
|
+
"bins": {
|
|
37
|
+
"ruask": "ruask"
|
|
38
|
+
},
|
|
39
|
+
"zipExt": ".tar.xz"
|
|
40
|
+
},
|
|
41
|
+
"aarch64-unknown-linux-gnu": {
|
|
42
|
+
"artifactName": "ruask-aarch64-unknown-linux-gnu.tar.xz",
|
|
43
|
+
"bins": {
|
|
44
|
+
"ruask": "ruask"
|
|
45
|
+
},
|
|
46
|
+
"zipExt": ".tar.xz"
|
|
47
|
+
},
|
|
48
|
+
"aarch64-unknown-linux-musl-dynamic": {
|
|
49
|
+
"artifactName": "ruask-aarch64-unknown-linux-musl.tar.xz",
|
|
50
|
+
"bins": {
|
|
51
|
+
"ruask": "ruask"
|
|
52
|
+
},
|
|
53
|
+
"zipExt": ".tar.xz"
|
|
54
|
+
},
|
|
55
|
+
"aarch64-unknown-linux-musl-static": {
|
|
56
|
+
"artifactName": "ruask-aarch64-unknown-linux-musl.tar.xz",
|
|
57
|
+
"bins": {
|
|
58
|
+
"ruask": "ruask"
|
|
59
|
+
},
|
|
60
|
+
"zipExt": ".tar.xz"
|
|
61
|
+
},
|
|
62
|
+
"x86_64-apple-darwin": {
|
|
63
|
+
"artifactName": "ruask-x86_64-apple-darwin.tar.xz",
|
|
64
|
+
"bins": {
|
|
65
|
+
"ruask": "ruask"
|
|
66
|
+
},
|
|
67
|
+
"zipExt": ".tar.xz"
|
|
68
|
+
},
|
|
69
|
+
"x86_64-unknown-linux-gnu": {
|
|
70
|
+
"artifactName": "ruask-x86_64-unknown-linux-gnu.tar.xz",
|
|
71
|
+
"bins": {
|
|
72
|
+
"ruask": "ruask"
|
|
73
|
+
},
|
|
74
|
+
"zipExt": ".tar.xz"
|
|
75
|
+
},
|
|
76
|
+
"x86_64-unknown-linux-musl-dynamic": {
|
|
77
|
+
"artifactName": "ruask-x86_64-unknown-linux-musl.tar.xz",
|
|
78
|
+
"bins": {
|
|
79
|
+
"ruask": "ruask"
|
|
80
|
+
},
|
|
81
|
+
"zipExt": ".tar.xz"
|
|
82
|
+
},
|
|
83
|
+
"x86_64-unknown-linux-musl-static": {
|
|
84
|
+
"artifactName": "ruask-x86_64-unknown-linux-musl.tar.xz",
|
|
85
|
+
"bins": {
|
|
86
|
+
"ruask": "ruask"
|
|
87
|
+
},
|
|
88
|
+
"zipExt": ".tar.xz"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"version": "0.1.1",
|
|
92
|
+
"volta": {
|
|
93
|
+
"node": "18.14.1",
|
|
94
|
+
"npm": "9.5.0"
|
|
95
|
+
}
|
|
6
96
|
}
|
package/run-ruask.js
ADDED