@quillaudits/cli 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/README.md +60 -0
- package/dist/qs.js +668 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# QuillAudits CLI
|
|
2
|
+
|
|
3
|
+
Submit Solidity projects for audit from the command line.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @quillaudits/cli
|
|
9
|
+
# or
|
|
10
|
+
npx @quillaudits/cli <command>
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js 18+.
|
|
14
|
+
|
|
15
|
+
## Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# 1. Get an API key from the QuillAudits web UI
|
|
19
|
+
# Settings → API Keys → Create API Key
|
|
20
|
+
|
|
21
|
+
# 2. Configure the CLI
|
|
22
|
+
qs init
|
|
23
|
+
|
|
24
|
+
# 3. Submit an audit
|
|
25
|
+
qs audit https://github.com/org/contract --ref main --watch
|
|
26
|
+
|
|
27
|
+
# 4. View results
|
|
28
|
+
qs findings <job-id>
|
|
29
|
+
qs report <job-id>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Commands
|
|
33
|
+
|
|
34
|
+
| Command | Description |
|
|
35
|
+
|---|---|
|
|
36
|
+
| `qs init` | Configure API key + URL |
|
|
37
|
+
| `qs audit <git-url>` | Submit a git repo for audit |
|
|
38
|
+
| `qs audit --zip <path>` | Submit a zip/sol file for audit |
|
|
39
|
+
| `qs status <job-id>` | Check audit status |
|
|
40
|
+
| `qs watch <job-id>` | Live progress stream |
|
|
41
|
+
| `qs findings <job-id>` | List findings |
|
|
42
|
+
| `qs report <job-id>` | Download report |
|
|
43
|
+
| `qs projects` | List projects |
|
|
44
|
+
| `qs versions <project-id>` | List versions |
|
|
45
|
+
| `qs credits` | Show credit balance |
|
|
46
|
+
| `qs cancel <job-id>` | Cancel a running audit |
|
|
47
|
+
| `qs logout` | Clear stored credentials |
|
|
48
|
+
|
|
49
|
+
## Environment Variables
|
|
50
|
+
|
|
51
|
+
For CI/CD, set these instead of running `qs init`:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export QUILLSHIELD_API_URL=https://api.quillaudits.ai
|
|
55
|
+
export QUILLSHIELD_API_KEY=qs_live_xxxxxxxxxxxx
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Full Documentation
|
|
59
|
+
|
|
60
|
+
See [docs/CLI.md](https://github.com/quillai-network/quillshield-saas/blob/main/docs/CLI.md) for the complete user guide.
|
package/dist/qs.js
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
// src/index.ts
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { readFileSync, existsSync } from "node:fs";
|
|
8
|
+
import { basename, resolve } from "node:path";
|
|
9
|
+
|
|
10
|
+
// src/config.ts
|
|
11
|
+
import { homedir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { mkdir, readFile, writeFile, unlink } from "node:fs/promises";
|
|
14
|
+
var CONFIG_DIR = join(homedir(), ".quillshield");
|
|
15
|
+
var CONFIG_FILE = join(CONFIG_DIR, "config.json");
|
|
16
|
+
var DEFAULT_API_URL = "http://localhost:3001";
|
|
17
|
+
async function loadConfig() {
|
|
18
|
+
const envKey = process.env.QUILLSHIELD_API_KEY;
|
|
19
|
+
const envUrl = process.env.QUILLSHIELD_API_URL;
|
|
20
|
+
if (envKey && envUrl) {
|
|
21
|
+
return {
|
|
22
|
+
api_url: envUrl,
|
|
23
|
+
api_key: envKey,
|
|
24
|
+
org_id: process.env.QUILLSHIELD_ORG_ID
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const raw = await readFile(CONFIG_FILE, "utf8");
|
|
29
|
+
const cfg = JSON.parse(raw);
|
|
30
|
+
if (envKey)
|
|
31
|
+
cfg.api_key = envKey;
|
|
32
|
+
if (envUrl)
|
|
33
|
+
cfg.api_url = envUrl;
|
|
34
|
+
if (!cfg.api_key || !cfg.api_url)
|
|
35
|
+
return null;
|
|
36
|
+
return cfg;
|
|
37
|
+
} catch {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function saveConfig(cfg) {
|
|
42
|
+
await mkdir(CONFIG_DIR, { recursive: true });
|
|
43
|
+
await writeFile(CONFIG_FILE, JSON.stringify(cfg, null, 2) + `
|
|
44
|
+
`, "utf8");
|
|
45
|
+
try {
|
|
46
|
+
const { chmod } = await import("node:fs/promises");
|
|
47
|
+
await chmod(CONFIG_FILE, 384);
|
|
48
|
+
} catch {}
|
|
49
|
+
}
|
|
50
|
+
async function clearConfig() {
|
|
51
|
+
try {
|
|
52
|
+
await unlink(CONFIG_FILE);
|
|
53
|
+
} catch {}
|
|
54
|
+
}
|
|
55
|
+
async function requireConfig() {
|
|
56
|
+
const cfg = await loadConfig();
|
|
57
|
+
if (!cfg) {
|
|
58
|
+
console.error("Not configured. Run: qs init");
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
61
|
+
return cfg;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// src/api.ts
|
|
65
|
+
class QuillShieldApi {
|
|
66
|
+
cfg;
|
|
67
|
+
constructor(cfg) {
|
|
68
|
+
this.cfg = cfg;
|
|
69
|
+
}
|
|
70
|
+
headers(extra) {
|
|
71
|
+
const h = {
|
|
72
|
+
Authorization: `Bearer ${this.cfg.api_key}`,
|
|
73
|
+
...extra
|
|
74
|
+
};
|
|
75
|
+
if (this.cfg.org_id)
|
|
76
|
+
h["X-Org-Id"] = this.cfg.org_id;
|
|
77
|
+
return h;
|
|
78
|
+
}
|
|
79
|
+
async request(method, path, opts = {}) {
|
|
80
|
+
const url = `${this.cfg.api_url}${path}`;
|
|
81
|
+
const isJson = opts.body !== undefined && !(opts.body instanceof FormData);
|
|
82
|
+
const res = await fetch(url, {
|
|
83
|
+
method,
|
|
84
|
+
headers: this.headers({
|
|
85
|
+
...isJson ? { "Content-Type": "application/json" } : {},
|
|
86
|
+
...opts.headers
|
|
87
|
+
}),
|
|
88
|
+
body: opts.body instanceof FormData ? opts.body : isJson ? JSON.stringify(opts.body) : undefined
|
|
89
|
+
});
|
|
90
|
+
if (res.status === 204)
|
|
91
|
+
return null;
|
|
92
|
+
const text = await res.text();
|
|
93
|
+
if (!res.ok) {
|
|
94
|
+
let parsed;
|
|
95
|
+
try {
|
|
96
|
+
parsed = JSON.parse(text);
|
|
97
|
+
} catch {
|
|
98
|
+
throw new Error(`API error ${res.status}: ${text.slice(0, 200)}`);
|
|
99
|
+
}
|
|
100
|
+
const msg = parsed.error?.message ?? `API error ${res.status}`;
|
|
101
|
+
const err = new Error(msg);
|
|
102
|
+
err.code = parsed.error?.code;
|
|
103
|
+
err.details = parsed.error?.details;
|
|
104
|
+
throw err;
|
|
105
|
+
}
|
|
106
|
+
if (!text)
|
|
107
|
+
return null;
|
|
108
|
+
return JSON.parse(text);
|
|
109
|
+
}
|
|
110
|
+
async verifyKey() {
|
|
111
|
+
const projects = await this.request("GET", "/v1/projects");
|
|
112
|
+
return { orgs: [] };
|
|
113
|
+
}
|
|
114
|
+
async listProjects() {
|
|
115
|
+
return this.request("GET", "/v1/projects");
|
|
116
|
+
}
|
|
117
|
+
async getProject(id) {
|
|
118
|
+
return this.request("GET", `/v1/projects/${id}`);
|
|
119
|
+
}
|
|
120
|
+
async listVersions(projectId) {
|
|
121
|
+
return this.request("GET", `/v1/projects/${projectId}/versions`);
|
|
122
|
+
}
|
|
123
|
+
async submitGitAudit(args) {
|
|
124
|
+
return this.request("POST", "/v1/audit/submit", { body: args });
|
|
125
|
+
}
|
|
126
|
+
async submitZipAudit(args) {
|
|
127
|
+
const form = new FormData;
|
|
128
|
+
const blob = new Blob([new Uint8Array(args.file)], { type: "application/zip" });
|
|
129
|
+
form.append("file", blob, args.filename);
|
|
130
|
+
if (args.project_name)
|
|
131
|
+
form.append("project_name", args.project_name);
|
|
132
|
+
if (args.scope_files?.length) {
|
|
133
|
+
form.append("scope_files", args.scope_files.join(`
|
|
134
|
+
`));
|
|
135
|
+
}
|
|
136
|
+
return this.request("POST", "/v1/audit/submit", { body: form });
|
|
137
|
+
}
|
|
138
|
+
async getAudit(jobId) {
|
|
139
|
+
return this.request("GET", `/v1/audits/${jobId}`);
|
|
140
|
+
}
|
|
141
|
+
async listAudits() {
|
|
142
|
+
return this.request("GET", "/v1/audits");
|
|
143
|
+
}
|
|
144
|
+
async cancelAudit(jobId) {
|
|
145
|
+
await this.request("POST", `/v1/audits/${jobId}/cancel`);
|
|
146
|
+
}
|
|
147
|
+
async getFindings(jobId) {
|
|
148
|
+
return this.request("GET", `/v1/audits/${jobId}/findings`);
|
|
149
|
+
}
|
|
150
|
+
async getReportUrl(jobId, format = "pdf") {
|
|
151
|
+
const res = await this.request("GET", `/v1/audits/${jobId}/report?format=${format}`);
|
|
152
|
+
return res.url ?? res;
|
|
153
|
+
}
|
|
154
|
+
async getCredits() {
|
|
155
|
+
return this.request("GET", "/v1/credits/balance");
|
|
156
|
+
}
|
|
157
|
+
streamEvents(jobId) {
|
|
158
|
+
const url = `${this.cfg.api_url}/v1/audits/${jobId}/events`;
|
|
159
|
+
const urlWithAuth = `${url}?api_key=${encodeURIComponent(this.cfg.api_key)}`;
|
|
160
|
+
return new EventSource(urlWithAuth);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// src/index.ts
|
|
165
|
+
var BOLD = "\x1B[1m";
|
|
166
|
+
var DIM = "\x1B[2m";
|
|
167
|
+
var GREEN = "\x1B[32m";
|
|
168
|
+
var RED = "\x1B[31m";
|
|
169
|
+
var YELLOW = "\x1B[33m";
|
|
170
|
+
var CYAN = "\x1B[36m";
|
|
171
|
+
var BRAND = "\x1B[38;2;16;61;211m";
|
|
172
|
+
var SKY = "\x1B[38;2;40;198;255m";
|
|
173
|
+
var RESET = "\x1B[0m";
|
|
174
|
+
function info(msg) {
|
|
175
|
+
console.log(`${BRAND}●${RESET} ${msg}`);
|
|
176
|
+
}
|
|
177
|
+
function success(msg) {
|
|
178
|
+
console.log(`${GREEN}✓${RESET} ${msg}`);
|
|
179
|
+
}
|
|
180
|
+
function warn(msg) {
|
|
181
|
+
console.log(`${YELLOW}⚠${RESET} ${msg}`);
|
|
182
|
+
}
|
|
183
|
+
function fail(msg) {
|
|
184
|
+
console.error(`${RED}✗${RESET} ${msg}`);
|
|
185
|
+
}
|
|
186
|
+
function printHelp() {
|
|
187
|
+
console.log(`${BOLD}QuillAudits CLI${RESET} — submit Solidity projects for audit
|
|
188
|
+
|
|
189
|
+
${BOLD}USAGE${RESET}
|
|
190
|
+
qs <command> [options]
|
|
191
|
+
|
|
192
|
+
${BOLD}COMMANDS${RESET}
|
|
193
|
+
${BOLD}init${RESET} Configure API key + URL
|
|
194
|
+
${BOLD}audit${RESET} <git-url> [options] Submit a git repo for audit
|
|
195
|
+
--ref <ref> Branch/tag/commit (default: repo default)
|
|
196
|
+
--name <name> Override project name
|
|
197
|
+
--scope <file1,file2,...> Comma-separated .sol files to audit
|
|
198
|
+
(default: all .sol files)
|
|
199
|
+
--watch Watch progress after submission
|
|
200
|
+
|
|
201
|
+
${BOLD}audit${RESET} --zip <path> [options] Submit a zip/sol file for audit
|
|
202
|
+
--name <name> Override project name
|
|
203
|
+
--scope <file1,file2,...> Comma-separated files to audit
|
|
204
|
+
--watch Watch progress after submission
|
|
205
|
+
|
|
206
|
+
${BOLD}status${RESET} <job-id> Check audit status
|
|
207
|
+
${BOLD}watch${RESET} <job-id> Live progress stream (SSE)
|
|
208
|
+
${BOLD}findings${RESET} <job-id> List findings
|
|
209
|
+
${BOLD}report${RESET} <job-id> [options] Download report
|
|
210
|
+
--format <pdf|json> Report format (default: pdf)
|
|
211
|
+
|
|
212
|
+
${BOLD}projects${RESET} List projects
|
|
213
|
+
${BOLD}versions${RESET} <project-id> List versions for a project
|
|
214
|
+
${BOLD}credits${RESET} Show credit balance
|
|
215
|
+
${BOLD}cancel${RESET} <job-id> Cancel a running audit
|
|
216
|
+
${BOLD}logout${RESET} Clear stored credentials
|
|
217
|
+
|
|
218
|
+
${BOLD}EXAMPLES${RESET}
|
|
219
|
+
qs init
|
|
220
|
+
qs audit https://github.com/org/contract --ref main --watch
|
|
221
|
+
qs audit --zip ./my-contract.zip --name "My Contract"
|
|
222
|
+
qs status 01KXK...
|
|
223
|
+
qs watch 01KXK...
|
|
224
|
+
qs findings 01KXK...
|
|
225
|
+
qs report 01KXK... --format pdf
|
|
226
|
+
`);
|
|
227
|
+
}
|
|
228
|
+
async function cmdInit() {
|
|
229
|
+
console.log(`${BOLD}QuillAudits CLI Setup${RESET}
|
|
230
|
+
`);
|
|
231
|
+
process.stdout.write(`API URL [${DEFAULT_API_URL}]: `);
|
|
232
|
+
const apiUrl = await readLine();
|
|
233
|
+
const finalUrl = apiUrl.trim() || DEFAULT_API_URL;
|
|
234
|
+
process.stdout.write("API Key (qs_live_...): ");
|
|
235
|
+
const apiKey = await readLine();
|
|
236
|
+
if (!apiKey.trim()) {
|
|
237
|
+
fail("API key is required. Get one from Settings → API Keys in the web UI.");
|
|
238
|
+
process.exit(1);
|
|
239
|
+
}
|
|
240
|
+
if (!apiKey.trim().startsWith("qs_live_")) {
|
|
241
|
+
warn("API key should start with 'qs_live_'. Are you sure you entered it correctly?");
|
|
242
|
+
}
|
|
243
|
+
process.stdout.write("Org ID (optional, press Enter to skip): ");
|
|
244
|
+
const orgId = await readLine();
|
|
245
|
+
await saveConfig({
|
|
246
|
+
api_url: finalUrl.replace(/\/$/, ""),
|
|
247
|
+
api_key: apiKey.trim(),
|
|
248
|
+
org_id: orgId.trim() || undefined
|
|
249
|
+
});
|
|
250
|
+
success(`Saved to ~/.quillshield/config.json`);
|
|
251
|
+
console.log(` API URL: ${finalUrl}`);
|
|
252
|
+
console.log(` API Key: ${apiKey.trim().slice(0, 12)}...`);
|
|
253
|
+
if (orgId.trim())
|
|
254
|
+
console.log(` Org ID: ${orgId.trim()}`);
|
|
255
|
+
console.log(`
|
|
256
|
+
Verifying connection...`);
|
|
257
|
+
try {
|
|
258
|
+
const savedCfg = await loadConfig();
|
|
259
|
+
if (!savedCfg) {
|
|
260
|
+
fail("Config save failed");
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
const api = new QuillShieldApi(savedCfg);
|
|
264
|
+
const projects = await api.listProjects();
|
|
265
|
+
success(`Connected! Found ${projects.length} existing project(s).`);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
fail(`Connection failed: ${err.message}`);
|
|
268
|
+
console.log("You can re-run `qs init` to fix the configuration.");
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
async function cmdAudit(args) {
|
|
272
|
+
const cfg = await requireConfig();
|
|
273
|
+
const api = new QuillShieldApi(cfg);
|
|
274
|
+
const { values, positionals } = parseArgs({
|
|
275
|
+
args,
|
|
276
|
+
options: {
|
|
277
|
+
zip: { type: "string" },
|
|
278
|
+
ref: { type: "string" },
|
|
279
|
+
name: { type: "string" },
|
|
280
|
+
scope: { type: "string" },
|
|
281
|
+
watch: { type: "boolean", default: false }
|
|
282
|
+
},
|
|
283
|
+
allowPositionals: true
|
|
284
|
+
});
|
|
285
|
+
const scopeFiles = values.scope ? values.scope.split(",").map((s) => s.trim()).filter(Boolean) : undefined;
|
|
286
|
+
let res;
|
|
287
|
+
if (values.zip) {
|
|
288
|
+
const zipPath = resolve(values.zip);
|
|
289
|
+
if (!existsSync(zipPath)) {
|
|
290
|
+
fail(`File not found: ${zipPath}`);
|
|
291
|
+
process.exit(1);
|
|
292
|
+
}
|
|
293
|
+
const buf = readFileSync(zipPath);
|
|
294
|
+
const filename = basename(zipPath);
|
|
295
|
+
info(`Uploading ${filename} (${(buf.length / 1024).toFixed(0)} KB)...`);
|
|
296
|
+
res = await api.submitZipAudit({
|
|
297
|
+
file: buf,
|
|
298
|
+
filename,
|
|
299
|
+
project_name: values.name,
|
|
300
|
+
scope_files: scopeFiles
|
|
301
|
+
});
|
|
302
|
+
} else if (positionals[0]) {
|
|
303
|
+
const repoUrl = positionals[0];
|
|
304
|
+
info(`Submitting ${repoUrl}${values.ref ? ` @ ${values.ref}` : ""}...`);
|
|
305
|
+
res = await api.submitGitAudit({
|
|
306
|
+
repo_url: repoUrl,
|
|
307
|
+
git_ref: values.ref,
|
|
308
|
+
project_name: values.name,
|
|
309
|
+
scope_files: scopeFiles
|
|
310
|
+
});
|
|
311
|
+
} else {
|
|
312
|
+
fail("Provide a git URL or --zip <path>");
|
|
313
|
+
process.exit(1);
|
|
314
|
+
}
|
|
315
|
+
if (!res) {
|
|
316
|
+
fail("Submission failed — no response received.");
|
|
317
|
+
process.exit(1);
|
|
318
|
+
}
|
|
319
|
+
console.log();
|
|
320
|
+
success("Audit submitted!");
|
|
321
|
+
console.log();
|
|
322
|
+
console.log(` ${BOLD}Project${RESET} ${res.project.name} (${res.project.id})`);
|
|
323
|
+
console.log(` ${BOLD}Version${RESET} ${res.version.id}`);
|
|
324
|
+
console.log(` ${BOLD}SLOC${RESET} ${res.version.sloc}`);
|
|
325
|
+
console.log(` ${BOLD}Scope${RESET} ${res.scope.file_count} .sol file(s)`);
|
|
326
|
+
if (res.scope.files.length > 0) {
|
|
327
|
+
for (const f of res.scope.files) {
|
|
328
|
+
console.log(` ${DIM}${f}${RESET}`);
|
|
329
|
+
}
|
|
330
|
+
if (res.scope.total_files > res.scope.files.length) {
|
|
331
|
+
console.log(` ${DIM}... and ${res.scope.total_files - res.scope.files.length} more${RESET}`);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
console.log(` ${BOLD}Credits${RESET} ${res.credits.quoted} quoted (balance: ${res.credits.balance_after})`);
|
|
335
|
+
console.log(` ${BOLD}Job ID${RESET} ${SKY}${res.audit.id}${RESET}`);
|
|
336
|
+
console.log(` ${BOLD}Status${RESET} ${res.audit.status}`);
|
|
337
|
+
console.log();
|
|
338
|
+
console.log(` Track progress: ${DIM}qs watch ${res.audit.id}${RESET}`);
|
|
339
|
+
console.log(` Get findings: ${DIM}qs findings ${res.audit.id}${RESET}`);
|
|
340
|
+
if (values.watch) {
|
|
341
|
+
console.log();
|
|
342
|
+
await cmdWatch([res.audit.id]);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async function cmdStatus(args) {
|
|
346
|
+
const cfg = await requireConfig();
|
|
347
|
+
const api = new QuillShieldApi(cfg);
|
|
348
|
+
const jobId = args[0];
|
|
349
|
+
if (!jobId) {
|
|
350
|
+
fail("Usage: qs status <job-id>");
|
|
351
|
+
process.exit(1);
|
|
352
|
+
}
|
|
353
|
+
const job = await api.getAudit(jobId);
|
|
354
|
+
console.log(` ${BOLD}Job ID${RESET} ${job.id}`);
|
|
355
|
+
console.log(` ${BOLD}Status${RESET} ${colorStatus(job.status)}`);
|
|
356
|
+
console.log(` ${BOLD}Project${RESET} ${job.project_id}`);
|
|
357
|
+
console.log(` ${BOLD}Version${RESET} ${job.project_version_id}`);
|
|
358
|
+
console.log(` ${BOLD}Depth${RESET} ${job.depth}`);
|
|
359
|
+
console.log(` ${BOLD}Trigger${RESET} ${job.trigger}`);
|
|
360
|
+
console.log(` ${BOLD}Credits${RESET} ${job.credits_quoted} quoted / ${job.credits_charged} charged`);
|
|
361
|
+
if (job.progress) {
|
|
362
|
+
console.log(` ${BOLD}Phase${RESET} ${job.progress.phase} (${job.progress.pct}%)`);
|
|
363
|
+
}
|
|
364
|
+
if (job.error) {
|
|
365
|
+
console.log(` ${BOLD}Error${RESET} ${RED}${job.error}${RESET}`);
|
|
366
|
+
}
|
|
367
|
+
console.log(` ${BOLD}Created${RESET} ${job.created_at}`);
|
|
368
|
+
if (job.started_at)
|
|
369
|
+
console.log(` ${BOLD}Started${RESET} ${job.started_at}`);
|
|
370
|
+
if (job.finished_at)
|
|
371
|
+
console.log(` ${BOLD}Finished${RESET} ${job.finished_at}`);
|
|
372
|
+
}
|
|
373
|
+
async function cmdWatch(args) {
|
|
374
|
+
const cfg = await requireConfig();
|
|
375
|
+
const api = new QuillShieldApi(cfg);
|
|
376
|
+
const jobId = args[0];
|
|
377
|
+
if (!jobId) {
|
|
378
|
+
fail("Usage: qs watch <job-id>");
|
|
379
|
+
process.exit(1);
|
|
380
|
+
}
|
|
381
|
+
const job = await api.getAudit(jobId);
|
|
382
|
+
console.log(`Watching job ${SKY}${jobId}${RESET} — status: ${colorStatus(job.status)}`);
|
|
383
|
+
if (job.progress) {
|
|
384
|
+
console.log(` Phase: ${job.progress.phase} (${job.progress.pct}%)`);
|
|
385
|
+
}
|
|
386
|
+
if (["completed", "failed", "cancelled"].includes(job.status)) {
|
|
387
|
+
console.log(`
|
|
388
|
+
Job already ${colorStatus(job.status)}.`);
|
|
389
|
+
if (job.status === "completed") {
|
|
390
|
+
console.log(`Run ${DIM}qs findings ${jobId}${RESET} to see results.`);
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
info("Connecting to live stream...");
|
|
395
|
+
const es = api.streamEvents(jobId);
|
|
396
|
+
const done = new Promise((resolve2) => {
|
|
397
|
+
es.addEventListener("status", (e) => {
|
|
398
|
+
const data = JSON.parse(e.data);
|
|
399
|
+
console.log(` [status] ${colorStatus(data.status)}`);
|
|
400
|
+
if (["completed", "failed", "cancelled"].includes(data.status)) {
|
|
401
|
+
es.close();
|
|
402
|
+
resolve2();
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
es.addEventListener("phase", (e) => {
|
|
406
|
+
const data = JSON.parse(e.data);
|
|
407
|
+
console.log(` [phase] ${data.phase} (${data.pct}%)`);
|
|
408
|
+
});
|
|
409
|
+
es.addEventListener("log", (e) => {
|
|
410
|
+
const data = JSON.parse(e.data);
|
|
411
|
+
const prefix = data.level === "error" ? RED : data.level === "warn" ? YELLOW : DIM;
|
|
412
|
+
console.log(` [log] ${prefix}${data.message}${RESET}`);
|
|
413
|
+
});
|
|
414
|
+
es.addEventListener("finding", (e) => {
|
|
415
|
+
const data = JSON.parse(e.data);
|
|
416
|
+
const sev = data.severity ?? "info";
|
|
417
|
+
const sevColor = sev === "critical" ? RED : sev === "high" ? YELLOW : CYAN;
|
|
418
|
+
console.log(` [finding] ${sevColor}[${sev.toUpperCase()}]${RESET} ${data.title}`);
|
|
419
|
+
});
|
|
420
|
+
es.addEventListener("done", (e) => {
|
|
421
|
+
const data = JSON.parse(e.data);
|
|
422
|
+
console.log(`
|
|
423
|
+
${BOLD}Job ${data.status}.${RESET}`);
|
|
424
|
+
if (data.error)
|
|
425
|
+
console.log(` ${RED}Error: ${data.error}${RESET}`);
|
|
426
|
+
es.close();
|
|
427
|
+
resolve2();
|
|
428
|
+
});
|
|
429
|
+
es.onerror = () => {
|
|
430
|
+
es.close();
|
|
431
|
+
console.log(`${DIM}(stream disconnected, falling back to polling)${RESET}`);
|
|
432
|
+
pollUntilDone(api, jobId, resolve2);
|
|
433
|
+
};
|
|
434
|
+
});
|
|
435
|
+
await done;
|
|
436
|
+
console.log(`
|
|
437
|
+
Run ${DIM}qs findings ${jobId}${RESET} to see full results.`);
|
|
438
|
+
}
|
|
439
|
+
async function pollUntilDone(api, jobId, resolve2) {
|
|
440
|
+
const poll = async () => {
|
|
441
|
+
try {
|
|
442
|
+
const job = await api.getAudit(jobId);
|
|
443
|
+
if (["completed", "failed", "cancelled"].includes(job.status)) {
|
|
444
|
+
console.log(`
|
|
445
|
+
${BOLD}Job ${job.status}.${RESET}`);
|
|
446
|
+
if (job.error)
|
|
447
|
+
console.log(` ${RED}Error: ${job.error}${RESET}`);
|
|
448
|
+
resolve2();
|
|
449
|
+
return;
|
|
450
|
+
}
|
|
451
|
+
if (job.progress) {
|
|
452
|
+
console.log(` [poll] ${job.progress.phase} (${job.progress.pct}%)`);
|
|
453
|
+
}
|
|
454
|
+
setTimeout(poll, 5000);
|
|
455
|
+
} catch (err) {
|
|
456
|
+
fail(`Polling failed: ${err.message}`);
|
|
457
|
+
resolve2();
|
|
458
|
+
}
|
|
459
|
+
};
|
|
460
|
+
setTimeout(poll, 5000);
|
|
461
|
+
}
|
|
462
|
+
async function cmdFindings(args) {
|
|
463
|
+
const cfg = await requireConfig();
|
|
464
|
+
const api = new QuillShieldApi(cfg);
|
|
465
|
+
const jobId = args[0];
|
|
466
|
+
if (!jobId) {
|
|
467
|
+
fail("Usage: qs findings <job-id>");
|
|
468
|
+
process.exit(1);
|
|
469
|
+
}
|
|
470
|
+
const findings = await api.getFindings(jobId);
|
|
471
|
+
if (findings.length === 0) {
|
|
472
|
+
console.log("No findings yet. The audit may still be running.");
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
console.log(`${BOLD}Findings (${findings.length})${RESET}
|
|
476
|
+
`);
|
|
477
|
+
for (const f of findings) {
|
|
478
|
+
const sev = (f.severity ?? "info").toUpperCase();
|
|
479
|
+
const sevColor = sev === "CRITICAL" ? RED : sev === "HIGH" ? YELLOW : sev === "MEDIUM" ? CYAN : DIM;
|
|
480
|
+
const status = f.status ? ` ${DIM}[${f.status}]${RESET}` : "";
|
|
481
|
+
console.log(` ${sevColor}[${sev}]${RESET} ${BOLD}${f.title}${RESET}${status}`);
|
|
482
|
+
if (f.file) {
|
|
483
|
+
const loc = f.line ? `${f.file}:${f.line}` : f.file;
|
|
484
|
+
console.log(` ${DIM}${loc}${RESET}`);
|
|
485
|
+
}
|
|
486
|
+
if (f.description) {
|
|
487
|
+
const desc = f.description.length > 120 ? f.description.slice(0, 117) + "..." : f.description;
|
|
488
|
+
console.log(` ${desc}`);
|
|
489
|
+
}
|
|
490
|
+
console.log();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
async function cmdReport(args) {
|
|
494
|
+
const cfg = await requireConfig();
|
|
495
|
+
const api = new QuillShieldApi(cfg);
|
|
496
|
+
const { values, positionals } = parseArgs({
|
|
497
|
+
args,
|
|
498
|
+
options: { format: { type: "string", default: "pdf" } },
|
|
499
|
+
allowPositionals: true
|
|
500
|
+
});
|
|
501
|
+
const jobId = positionals[0];
|
|
502
|
+
if (!jobId) {
|
|
503
|
+
fail("Usage: qs report <job-id> [--format pdf|json]");
|
|
504
|
+
process.exit(1);
|
|
505
|
+
}
|
|
506
|
+
info(`Fetching ${values.format} report for job ${jobId}...`);
|
|
507
|
+
const url = await api.getReportUrl(jobId, values.format);
|
|
508
|
+
console.log(` Report URL: ${url}`);
|
|
509
|
+
console.log(` ${DIM}(Open in a browser or download with curl)${RESET}`);
|
|
510
|
+
}
|
|
511
|
+
async function cmdProjects() {
|
|
512
|
+
const cfg = await requireConfig();
|
|
513
|
+
const api = new QuillShieldApi(cfg);
|
|
514
|
+
const projects = await api.listProjects();
|
|
515
|
+
if (projects.length === 0) {
|
|
516
|
+
console.log("No projects yet. Run `qs audit <git-url>` to create one.");
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
console.log(`${BOLD}Projects (${projects.length})${RESET}
|
|
520
|
+
`);
|
|
521
|
+
for (const p of projects) {
|
|
522
|
+
console.log(` ${SKY}${p.id}${RESET} ${p.name}`);
|
|
523
|
+
console.log(` ${DIM}${p.source_type} · ${p.repo_url ?? "upload"} · ${p.created_at}${RESET}`);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
async function cmdVersions(args) {
|
|
527
|
+
const cfg = await requireConfig();
|
|
528
|
+
const api = new QuillShieldApi(cfg);
|
|
529
|
+
const projectId = args[0];
|
|
530
|
+
if (!projectId) {
|
|
531
|
+
fail("Usage: qs versions <project-id>");
|
|
532
|
+
process.exit(1);
|
|
533
|
+
}
|
|
534
|
+
const versions = await api.listVersions(projectId);
|
|
535
|
+
if (versions.length === 0) {
|
|
536
|
+
console.log("No versions yet.");
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
console.log(`${BOLD}Versions (${versions.length})${RESET}
|
|
540
|
+
`);
|
|
541
|
+
for (const v of versions) {
|
|
542
|
+
console.log(` ${SKY}${v.id}${RESET} SLOC: ${v.sloc ?? "?"} deps: ${v.dependency_count ?? 0}`);
|
|
543
|
+
if (v.commit_sha)
|
|
544
|
+
console.log(` ${DIM}commit: ${v.commit_sha.slice(0, 7)}${RESET}`);
|
|
545
|
+
console.log(` ${DIM}${v.created_at}${RESET}`);
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
async function cmdCredits() {
|
|
549
|
+
const cfg = await requireConfig();
|
|
550
|
+
const api = new QuillShieldApi(cfg);
|
|
551
|
+
const { balance } = await api.getCredits();
|
|
552
|
+
console.log(` ${BOLD}Credit balance${RESET} ${GREEN}${balance}${RESET}`);
|
|
553
|
+
}
|
|
554
|
+
async function cmdCancel(args) {
|
|
555
|
+
const cfg = await requireConfig();
|
|
556
|
+
const api = new QuillShieldApi(cfg);
|
|
557
|
+
const jobId = args[0];
|
|
558
|
+
if (!jobId) {
|
|
559
|
+
fail("Usage: qs cancel <job-id>");
|
|
560
|
+
process.exit(1);
|
|
561
|
+
}
|
|
562
|
+
await api.cancelAudit(jobId);
|
|
563
|
+
success(`Cancelled audit ${jobId}`);
|
|
564
|
+
}
|
|
565
|
+
async function cmdLogout() {
|
|
566
|
+
await clearConfig();
|
|
567
|
+
success("Logged out. Config removed from ~/.quillshield/config.json");
|
|
568
|
+
}
|
|
569
|
+
var stdinBuffer = [];
|
|
570
|
+
var stdinEnded = false;
|
|
571
|
+
async function readLine() {
|
|
572
|
+
if (stdinBuffer.length > 0) {
|
|
573
|
+
return stdinBuffer.shift();
|
|
574
|
+
}
|
|
575
|
+
return new Promise((resolve2) => {
|
|
576
|
+
process.stdin.resume();
|
|
577
|
+
process.stdin.setEncoding("utf8");
|
|
578
|
+
const onData = (chunk) => {
|
|
579
|
+
const lines = chunk.split(`
|
|
580
|
+
`);
|
|
581
|
+
const first = lines.shift();
|
|
582
|
+
for (const line of lines) {
|
|
583
|
+
stdinBuffer.push(line);
|
|
584
|
+
}
|
|
585
|
+
process.stdin.pause();
|
|
586
|
+
process.stdin.removeListener("data", onData);
|
|
587
|
+
resolve2(first.trim());
|
|
588
|
+
};
|
|
589
|
+
const onEnd = () => {
|
|
590
|
+
stdinEnded = true;
|
|
591
|
+
process.stdin.removeListener("end", onEnd);
|
|
592
|
+
process.stdin.removeListener("data", onData);
|
|
593
|
+
resolve2("");
|
|
594
|
+
};
|
|
595
|
+
process.stdin.on("data", onData);
|
|
596
|
+
process.stdin.on("end", onEnd);
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
function colorStatus(status) {
|
|
600
|
+
const colors = {
|
|
601
|
+
queued: SKY,
|
|
602
|
+
building: YELLOW,
|
|
603
|
+
running: YELLOW,
|
|
604
|
+
completed: GREEN,
|
|
605
|
+
failed: RED,
|
|
606
|
+
cancelled: DIM
|
|
607
|
+
};
|
|
608
|
+
const c = colors[status] ?? RESET;
|
|
609
|
+
return `${c}${status}${RESET}`;
|
|
610
|
+
}
|
|
611
|
+
async function main() {
|
|
612
|
+
const args = process.argv.slice(2);
|
|
613
|
+
const command = args[0];
|
|
614
|
+
const rest = args.slice(1);
|
|
615
|
+
if (!command || command === "-h" || command === "--help" || command === "help") {
|
|
616
|
+
printHelp();
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
try {
|
|
620
|
+
switch (command) {
|
|
621
|
+
case "init":
|
|
622
|
+
await cmdInit();
|
|
623
|
+
break;
|
|
624
|
+
case "audit":
|
|
625
|
+
await cmdAudit(rest);
|
|
626
|
+
break;
|
|
627
|
+
case "status":
|
|
628
|
+
await cmdStatus(rest);
|
|
629
|
+
break;
|
|
630
|
+
case "watch":
|
|
631
|
+
await cmdWatch(rest);
|
|
632
|
+
break;
|
|
633
|
+
case "findings":
|
|
634
|
+
await cmdFindings(rest);
|
|
635
|
+
break;
|
|
636
|
+
case "report":
|
|
637
|
+
await cmdReport(rest);
|
|
638
|
+
break;
|
|
639
|
+
case "projects":
|
|
640
|
+
await cmdProjects();
|
|
641
|
+
break;
|
|
642
|
+
case "versions":
|
|
643
|
+
await cmdVersions(rest);
|
|
644
|
+
break;
|
|
645
|
+
case "credits":
|
|
646
|
+
await cmdCredits();
|
|
647
|
+
break;
|
|
648
|
+
case "cancel":
|
|
649
|
+
await cmdCancel(rest);
|
|
650
|
+
break;
|
|
651
|
+
case "logout":
|
|
652
|
+
await cmdLogout();
|
|
653
|
+
break;
|
|
654
|
+
default:
|
|
655
|
+
fail(`Unknown command: ${command}`);
|
|
656
|
+
console.log("Run `qs help` for usage.");
|
|
657
|
+
process.exit(1);
|
|
658
|
+
}
|
|
659
|
+
} catch (err) {
|
|
660
|
+
const e = err;
|
|
661
|
+
fail(e.message);
|
|
662
|
+
if (e.message.includes("Not configured")) {
|
|
663
|
+
console.log("Run `qs init` to set up your API key.");
|
|
664
|
+
}
|
|
665
|
+
process.exit(1);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
main();
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@quillaudits/cli",
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "QuillAudits CLI — submit Solidity projects for audit from the command line",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/quillai-network/quillshield-saas",
|
|
10
|
+
"directory": "packages/cli"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://www.quillaudits.com",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"quillaudits",
|
|
15
|
+
"quillshield",
|
|
16
|
+
"solidity",
|
|
17
|
+
"smart-contract",
|
|
18
|
+
"audit",
|
|
19
|
+
"security",
|
|
20
|
+
"cli"
|
|
21
|
+
],
|
|
22
|
+
"bin": {
|
|
23
|
+
"qs": "./dist/qs.js"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist",
|
|
27
|
+
"README.md"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"dev": "bun run src/index.ts",
|
|
31
|
+
"build": "bun build src/index.ts --outfile dist/qs.js --target node",
|
|
32
|
+
"typecheck": "tsc --noEmit",
|
|
33
|
+
"prepublishOnly": "bun run build",
|
|
34
|
+
"prepack": "bun run build"
|
|
35
|
+
},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=18"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/node": "^26.1.1",
|
|
41
|
+
"typescript": "^5.6.3"
|
|
42
|
+
}
|
|
43
|
+
}
|