redcode-cli 0.0.0-stage → 2.4.6
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 +31 -2
- package/bin/redcode.js +56 -0
- package/package.json +45 -4
- package/scripts/install.js +343 -0
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
#
|
|
1
|
+
# redcode-cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Official npm installer & launcher for **RedCode CLI `v2.4.5`** (`redcode-cli@2.4.6`, Linux ARM64 — `glibc` & `musl`).
|
|
4
|
+
|
|
5
|
+
## Install Globally
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm i -g redcode-cli --foreground-scripts
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or run anytime without global flags:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i -g redcode-cli
|
|
15
|
+
redcode
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Quick Start
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
redcode # Launch interactive RedCode TUI
|
|
22
|
+
redcode serve # Launch RedCode Web UI on http://127.0.0.1:4444
|
|
23
|
+
redcode run "hello" # One-shot autonomous run
|
|
24
|
+
redcode --version # Verify version
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Built-in Frontier Capabilities (`v2.4.5`)
|
|
28
|
+
- **Intelligence Tools**: `repo_map` (PageRank symbol map), `lsp`, `ast_search`, `codebase_search`, `dep_graph`, `refactor`, `repo_pack`, `git_intel`, `secret_scan`, `db_intel`, `test_mutate`, `perf_bench`, persistent cross-session `memory`
|
|
29
|
+
- **Specialist Subagents**: `explore`, `architect`, `reviewer`, `debugger`, `tester`, `critic`, `swarm`
|
|
30
|
+
- **Slash Commands**: `/swarm`, `/issue`, `/critic`, `/perf`, `/architect`, `/debug`, `/test`, `/security`, `/review`, `/init`
|
|
31
|
+
|
|
32
|
+
Downloads are fetched directly from [red-code-cli/redcodecli](https://github.com/red-code-cli/redcodecli/releases) and verified against `SHA256SUMS`.
|
package/bin/redcode.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict"
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs")
|
|
5
|
+
const os = require("node:os")
|
|
6
|
+
const path = require("node:path")
|
|
7
|
+
const { spawnSync } = require("node:child_process")
|
|
8
|
+
|
|
9
|
+
const root = path.join(__dirname, "..")
|
|
10
|
+
const vendorBin = path.join(root, "vendor", "redcode")
|
|
11
|
+
const installScript = path.join(root, "scripts", "install.js")
|
|
12
|
+
|
|
13
|
+
function run(binary, args) {
|
|
14
|
+
const result = spawnSync(binary, args, { stdio: "inherit" })
|
|
15
|
+
if (result.error) {
|
|
16
|
+
if (result.error.code === "EACCES") {
|
|
17
|
+
// Fallback for noexec mounts (e.g., certain Android / shared filesystems)
|
|
18
|
+
const fallbackDir = path.join(os.homedir(), ".redcode-run")
|
|
19
|
+
const fallbackBin = path.join(fallbackDir, "redcode")
|
|
20
|
+
fs.mkdirSync(fallbackDir, { recursive: true })
|
|
21
|
+
fs.copyFileSync(binary, fallbackBin)
|
|
22
|
+
fs.chmodSync(fallbackBin, 0o755)
|
|
23
|
+
const retry = spawnSync(fallbackBin, args, { stdio: "inherit" })
|
|
24
|
+
if (retry.error) {
|
|
25
|
+
console.error(retry.error.message)
|
|
26
|
+
process.exit(1)
|
|
27
|
+
}
|
|
28
|
+
process.exit(retry.status ?? 1)
|
|
29
|
+
}
|
|
30
|
+
console.error(result.error.message)
|
|
31
|
+
process.exit(1)
|
|
32
|
+
}
|
|
33
|
+
process.exit(result.status ?? 1)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const args = process.argv.slice(2)
|
|
37
|
+
if (args[0] === "--reinstall-binary") {
|
|
38
|
+
const res = spawnSync(process.execPath, [installScript, "--force"], { stdio: "inherit" })
|
|
39
|
+
process.exit(res.status ?? 1)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let binary = process.env.REDCODE_BIN
|
|
43
|
+
if (!binary) {
|
|
44
|
+
if (!fs.existsSync(vendorBin)) {
|
|
45
|
+
spawnSync(process.execPath, [installScript], { stdio: "inherit" })
|
|
46
|
+
}
|
|
47
|
+
binary = vendorBin
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (!fs.existsSync(binary)) {
|
|
51
|
+
console.error("\x1b[38;5;196mRedCode CLI binary is not installed.\x1b[0m")
|
|
52
|
+
console.error("Run: \x1b[1mredcode --reinstall-binary\x1b[0m or \x1b[1mnpm rebuild redcode-cli --foreground-scripts\x1b[0m")
|
|
53
|
+
process.exit(1)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
run(binary, args)
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "redcode-cli",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "2.4.6",
|
|
4
|
+
"redcodeRelease": "2.4.5",
|
|
5
|
+
"description": "RedCode CLI v2.4.5 — Autonomous AI coding agent, Swarm/Judge workflows & Web UI for Linux ARM64",
|
|
6
|
+
"bin": {
|
|
7
|
+
"redcode": "bin/redcode.js",
|
|
8
|
+
"redcode-cli": "bin/redcode.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"scripts",
|
|
13
|
+
"README.md"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"postinstall": "node scripts/install.js"
|
|
17
|
+
},
|
|
18
|
+
"os": [
|
|
19
|
+
"linux"
|
|
20
|
+
],
|
|
21
|
+
"cpu": [
|
|
22
|
+
"arm64"
|
|
23
|
+
],
|
|
24
|
+
"engines": {
|
|
25
|
+
"node": ">=18"
|
|
26
|
+
},
|
|
27
|
+
"preferGlobal": true,
|
|
28
|
+
"license": "MIT",
|
|
29
|
+
"homepage": "https://github.com/red-code-cli/redcodecli#readme",
|
|
30
|
+
"repository": {
|
|
31
|
+
"type": "git",
|
|
32
|
+
"url": "git+https://github.com/red-code-cli/redcodecli.git"
|
|
33
|
+
},
|
|
34
|
+
"bugs": {
|
|
35
|
+
"url": "https://github.com/red-code-cli/redcodecli/issues"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"redcode",
|
|
39
|
+
"redcode-cli",
|
|
40
|
+
"ai",
|
|
41
|
+
"coding-agent",
|
|
42
|
+
"cli",
|
|
43
|
+
"swarm",
|
|
44
|
+
"lsp",
|
|
45
|
+
"arm64"
|
|
46
|
+
]
|
|
47
|
+
}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict"
|
|
3
|
+
|
|
4
|
+
const fs = require("node:fs")
|
|
5
|
+
const path = require("node:path")
|
|
6
|
+
const https = require("node:https")
|
|
7
|
+
const crypto = require("node:crypto")
|
|
8
|
+
const { spawnSync } = require("node:child_process")
|
|
9
|
+
|
|
10
|
+
const PKG = require("../package.json")
|
|
11
|
+
const VERSION = PKG.redcodeRelease || PKG.version
|
|
12
|
+
const REPO = "red-code-cli/redcodecli"
|
|
13
|
+
const BASE = `https://github.com/${REPO}/releases/download/v${VERSION}`
|
|
14
|
+
const root = path.join(__dirname, "..")
|
|
15
|
+
const vendor = path.join(root, "vendor")
|
|
16
|
+
const bin = path.join(vendor, "redcode")
|
|
17
|
+
const FORCE = process.argv.includes("--force")
|
|
18
|
+
|
|
19
|
+
function createDisplay() {
|
|
20
|
+
let ttyFd = null
|
|
21
|
+
let interactive = Boolean(process.stdout.isTTY)
|
|
22
|
+
if (!process.env.CI) {
|
|
23
|
+
try {
|
|
24
|
+
ttyFd = fs.openSync("/dev/tty", "w")
|
|
25
|
+
interactive = true
|
|
26
|
+
} catch {
|
|
27
|
+
ttyFd = null
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
let cols = process.stdout.columns || process.stderr.columns || 0
|
|
31
|
+
if (!cols && ttyFd !== null) {
|
|
32
|
+
try {
|
|
33
|
+
const ttyIn = fs.openSync("/dev/tty", "r")
|
|
34
|
+
const out = spawnSync("stty", ["size"], { stdio: [ttyIn, "pipe", "ignore"], encoding: "utf8" })
|
|
35
|
+
fs.closeSync(ttyIn)
|
|
36
|
+
const parsedCols = Number.parseInt((out.stdout || "").trim().split(/\s+/)[1] || "0", 10)
|
|
37
|
+
if (parsedCols > 0) cols = parsedCols
|
|
38
|
+
} catch {}
|
|
39
|
+
}
|
|
40
|
+
if (!cols) cols = 44
|
|
41
|
+
|
|
42
|
+
const write = (str) => {
|
|
43
|
+
if (ttyFd !== null) {
|
|
44
|
+
try {
|
|
45
|
+
fs.writeSync(ttyFd, str)
|
|
46
|
+
return
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
process.stdout.write(str)
|
|
50
|
+
}
|
|
51
|
+
const close = () => {
|
|
52
|
+
if (ttyFd !== null) {
|
|
53
|
+
try {
|
|
54
|
+
fs.closeSync(ttyFd)
|
|
55
|
+
} catch {}
|
|
56
|
+
ttyFd = null
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { write, close, interactive, cols }
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const ui = createDisplay()
|
|
63
|
+
const C = ui.interactive
|
|
64
|
+
? {
|
|
65
|
+
reset: "\x1b[0m",
|
|
66
|
+
bold: "\x1b[1m",
|
|
67
|
+
red1: "\x1b[38;5;196m",
|
|
68
|
+
red2: "\x1b[38;5;203m",
|
|
69
|
+
red3: "\x1b[38;5;160m",
|
|
70
|
+
slate: "\x1b[38;5;246m",
|
|
71
|
+
white: "\x1b[97m",
|
|
72
|
+
green: "\x1b[38;5;46m",
|
|
73
|
+
amber: "\x1b[38;5;214m",
|
|
74
|
+
hideCursor: "\x1b[?25l",
|
|
75
|
+
showCursor: "\x1b[?25h",
|
|
76
|
+
clearLine: "\r\x1b[2K",
|
|
77
|
+
}
|
|
78
|
+
: {
|
|
79
|
+
reset: "",
|
|
80
|
+
bold: "",
|
|
81
|
+
red1: "",
|
|
82
|
+
red2: "",
|
|
83
|
+
red3: "",
|
|
84
|
+
slate: "",
|
|
85
|
+
white: "",
|
|
86
|
+
green: "",
|
|
87
|
+
amber: "",
|
|
88
|
+
hideCursor: "",
|
|
89
|
+
showCursor: "",
|
|
90
|
+
clearLine: "",
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const SPINNER = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
|
|
94
|
+
const LOGO = [
|
|
95
|
+
" ____ _ ____ _ ",
|
|
96
|
+
"| _ \\ ___ __| |/ ___|___ __| | ___ ",
|
|
97
|
+
"| |_) / _ \\/ _` | | / _ \\ / _` |/ _ \\",
|
|
98
|
+
"| _ < __/ (_| | |__| (_) | (_| | __/",
|
|
99
|
+
"|_| \\_\\___|\\__,_|\\____\\___/ \\__,_|\\___|",
|
|
100
|
+
]
|
|
101
|
+
const GRADIENT = [C.red1, C.red1, C.red2, C.red2, C.red3]
|
|
102
|
+
|
|
103
|
+
function sleep(ms) {
|
|
104
|
+
return new Promise((r) => setTimeout(r, ms))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async function renderBannerOnce() {
|
|
108
|
+
ui.write("\n")
|
|
109
|
+
if (ui.interactive) ui.write(C.hideCursor)
|
|
110
|
+
for (let i = 0; i < LOGO.length; i++) {
|
|
111
|
+
ui.write(` ${C.bold}${GRADIENT[i]}${LOGO[i]}${C.reset}\n`)
|
|
112
|
+
if (ui.interactive) await sleep(20)
|
|
113
|
+
}
|
|
114
|
+
const ruleLen = Math.min(39, Math.max(20, ui.cols - 4))
|
|
115
|
+
ui.write(` ${C.slate}RedCode CLI v${VERSION} • linux-arm64${C.reset}\n`)
|
|
116
|
+
ui.write(` ${C.red3}${"━".repeat(ruleLen)}${C.reset}\n`)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Single-line in-place status controller: everything animates on ONE line (no terminal scroll).
|
|
120
|
+
function createSingleLineStatus() {
|
|
121
|
+
let spinIdx = 0
|
|
122
|
+
let timer = null
|
|
123
|
+
let currentLabel = ""
|
|
124
|
+
const maxVisible = Math.max(28, ui.cols - 2)
|
|
125
|
+
|
|
126
|
+
const clipPlain = (text, limit) => (text.length > limit ? `${text.slice(0, limit - 1)}…` : text)
|
|
127
|
+
|
|
128
|
+
const startSpinner = (label) => {
|
|
129
|
+
stopSpinner()
|
|
130
|
+
currentLabel = clipPlain(label, maxVisible - 4)
|
|
131
|
+
if (!ui.interactive) {
|
|
132
|
+
ui.write(` * ${label}\n`)
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
const draw = () => {
|
|
136
|
+
const frame = SPINNER[spinIdx++ % SPINNER.length]
|
|
137
|
+
ui.write(`${C.clearLine} ${C.red1}${frame}${C.reset} ${C.white}${currentLabel}${C.reset}`)
|
|
138
|
+
}
|
|
139
|
+
draw()
|
|
140
|
+
timer = setInterval(draw, 90)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const stopSpinner = () => {
|
|
144
|
+
if (timer) {
|
|
145
|
+
clearInterval(timer)
|
|
146
|
+
timer = null
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const drawProgress = (pct, loadedMB, totalMB, mbPerSec) => {
|
|
151
|
+
stopSpinner()
|
|
152
|
+
if (!ui.interactive) return
|
|
153
|
+
const frame = SPINNER[spinIdx++ % SPINNER.length]
|
|
154
|
+
const compact = ui.cols < 44
|
|
155
|
+
const barWidth = compact ? 10 : 14
|
|
156
|
+
const filled = Math.round((pct / 100) * barWidth)
|
|
157
|
+
const bar = `${C.red1}${"█".repeat(filled)}${C.slate}${"░".repeat(barWidth - filled)}${C.reset}`
|
|
158
|
+
const stats = totalMB ? `${loadedMB}/${totalMB}M` : `${loadedMB}M`
|
|
159
|
+
const speed = compact ? "" : ` ${mbPerSec}M/s`
|
|
160
|
+
ui.write(
|
|
161
|
+
`${C.clearLine} ${C.red1}${frame}${C.reset} [${bar}] ${C.bold}${C.white}${pct}%${C.reset} ${C.slate}${stats}${speed}${C.reset}`,
|
|
162
|
+
)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const finish = (ok, msg) => {
|
|
166
|
+
stopSpinner()
|
|
167
|
+
const clean = clipPlain(msg, maxVisible - 4)
|
|
168
|
+
if (ui.interactive) {
|
|
169
|
+
const icon = ok ? `${C.green}✓${C.reset}` : `${C.amber}!${C.reset}`
|
|
170
|
+
ui.write(`${C.clearLine} ${icon} ${C.white}${clean}${C.reset}\n\n`)
|
|
171
|
+
} else {
|
|
172
|
+
ui.write(` ${ok ? "[ok]" : "[warn]"} ${msg}\n`)
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return { startSpinner, stopSpinner, drawProgress, finish }
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function detectLibc() {
|
|
180
|
+
try {
|
|
181
|
+
if (fs.existsSync("/lib/ld-musl-aarch64.so.1")) return "musl"
|
|
182
|
+
const probe = spawnSync("ldd", ["--version"], { encoding: "utf8" })
|
|
183
|
+
const out = `${probe.stdout || ""}${probe.stderr || ""}`.toLowerCase()
|
|
184
|
+
if (out.includes("musl")) return "musl"
|
|
185
|
+
} catch {}
|
|
186
|
+
return "glibc"
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function httpGet(url, redirects = 8) {
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
const req = https.get(
|
|
192
|
+
url,
|
|
193
|
+
{ headers: { "user-agent": `redcode-cli/${PKG.version}` }, timeout: 30_000 },
|
|
194
|
+
(res) => {
|
|
195
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) {
|
|
196
|
+
res.resume()
|
|
197
|
+
const nextUrl = new URL(res.headers.location, url).toString()
|
|
198
|
+
return resolve(httpGet(nextUrl, redirects - 1))
|
|
199
|
+
}
|
|
200
|
+
if (res.statusCode !== 200) {
|
|
201
|
+
res.resume()
|
|
202
|
+
return reject(new Error(`HTTP ${res.statusCode} for ${url}`))
|
|
203
|
+
}
|
|
204
|
+
resolve(res)
|
|
205
|
+
},
|
|
206
|
+
)
|
|
207
|
+
req.on("timeout", () => req.destroy(new Error(`Request timeout for ${url}`)))
|
|
208
|
+
req.on("error", reject)
|
|
209
|
+
})
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
async function fetchText(url) {
|
|
213
|
+
const res = await httpGet(url)
|
|
214
|
+
return await new Promise((resolve, reject) => {
|
|
215
|
+
const chunks = []
|
|
216
|
+
res.on("data", (d) => chunks.push(d))
|
|
217
|
+
res.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")))
|
|
218
|
+
res.on("error", reject)
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function formatMB(bytes) {
|
|
223
|
+
return (bytes / (1024 * 1024)).toFixed(0)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
async function downloadWithProgress(url, dest, status) {
|
|
227
|
+
const res = await httpGet(url)
|
|
228
|
+
const total = Number.parseInt(res.headers["content-length"] || "0", 10)
|
|
229
|
+
const totalMB = total > 0 ? formatMB(total) : ""
|
|
230
|
+
const out = fs.createWriteStream(dest)
|
|
231
|
+
let loaded = 0
|
|
232
|
+
let lastDraw = 0
|
|
233
|
+
const startedAt = Date.now()
|
|
234
|
+
|
|
235
|
+
return await new Promise((resolve, reject) => {
|
|
236
|
+
res.on("data", (chunk) => {
|
|
237
|
+
loaded += chunk.length
|
|
238
|
+
if (!ui.interactive) return
|
|
239
|
+
const now = Date.now()
|
|
240
|
+
if (now - lastDraw < 110) return
|
|
241
|
+
lastDraw = now
|
|
242
|
+
const elapsedSec = Math.max((now - startedAt) / 1000, 0.1)
|
|
243
|
+
const mbPerSec = (loaded / (1024 * 1024) / elapsedSec).toFixed(1)
|
|
244
|
+
const pct = total > 0 ? Math.min(100, Math.round((loaded / total) * 100)) : 0
|
|
245
|
+
status.drawProgress(pct, formatMB(loaded), totalMB, mbPerSec)
|
|
246
|
+
})
|
|
247
|
+
res.pipe(out)
|
|
248
|
+
out.on("finish", () => {
|
|
249
|
+
if (ui.interactive) {
|
|
250
|
+
const elapsedSec = Math.max((Date.now() - startedAt) / 1000, 0.1)
|
|
251
|
+
const mbPerSec = (loaded / (1024 * 1024) / elapsedSec).toFixed(1)
|
|
252
|
+
status.drawProgress(100, formatMB(loaded), totalMB || formatMB(loaded), mbPerSec)
|
|
253
|
+
}
|
|
254
|
+
resolve()
|
|
255
|
+
})
|
|
256
|
+
out.on("error", reject)
|
|
257
|
+
res.on("error", reject)
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
async function main() {
|
|
262
|
+
if (process.platform !== "linux" || process.arch !== "arm64") {
|
|
263
|
+
ui.write(`\n ${C.amber}! redcode-cli ships Linux ARM64 binaries (${process.platform}/${process.arch}).${C.reset}\n\n`)
|
|
264
|
+
ui.close()
|
|
265
|
+
return
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
if (!FORCE && fs.existsSync(bin)) {
|
|
269
|
+
const probe = spawnSync(bin, ["--version"], { encoding: "utf8" })
|
|
270
|
+
if ((probe.stdout || "").includes(VERSION)) {
|
|
271
|
+
ui.write(`\n ${C.green}✓${C.reset} ${C.bold}${C.white}RedCode v${VERSION}${C.reset} ${C.slate}ready (${bin})${C.reset}\n\n`)
|
|
272
|
+
ui.close()
|
|
273
|
+
return
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
fs.mkdirSync(vendor, { recursive: true })
|
|
278
|
+
await renderBannerOnce()
|
|
279
|
+
const status = createSingleLineStatus()
|
|
280
|
+
|
|
281
|
+
const libc = detectLibc()
|
|
282
|
+
const asset = libc === "musl" ? "redcode-linux-arm64-musl.tar.gz" : "redcode-linux-arm64.tar.gz"
|
|
283
|
+
const archive = path.join(vendor, `${asset}.tmp`)
|
|
284
|
+
const cleanup = () => {
|
|
285
|
+
status.stopSpinner()
|
|
286
|
+
if (fs.existsSync(archive)) {
|
|
287
|
+
try {
|
|
288
|
+
fs.unlinkSync(archive)
|
|
289
|
+
} catch {}
|
|
290
|
+
}
|
|
291
|
+
if (ui.interactive) ui.write(C.showCursor)
|
|
292
|
+
ui.close()
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
process.on("SIGINT", () => {
|
|
296
|
+
cleanup()
|
|
297
|
+
process.exit(130)
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
try {
|
|
301
|
+
status.startSpinner(`Checking v${VERSION} (${libc})...`)
|
|
302
|
+
const sums = await fetchText(`${BASE}/SHA256SUMS`)
|
|
303
|
+
const sumLine = sums.split(/\r?\n/).find((l) => l.trim().endsWith(asset))
|
|
304
|
+
if (!sumLine) throw new Error(`SHA256SUMS missing entry for ${asset}`)
|
|
305
|
+
const expectedSha = sumLine.trim().split(/\s+/)[0]
|
|
306
|
+
|
|
307
|
+
if (!ui.interactive) ui.write(` * Downloading ${asset}...\n`)
|
|
308
|
+
await downloadWithProgress(`${BASE}/${asset}`, archive, status)
|
|
309
|
+
|
|
310
|
+
status.startSpinner("Verifying SHA-256...")
|
|
311
|
+
const actualSha = await new Promise((resolve, reject) => {
|
|
312
|
+
const hash = crypto.createHash("sha256")
|
|
313
|
+
const stream = fs.createReadStream(archive)
|
|
314
|
+
stream.on("data", (d) => hash.update(d))
|
|
315
|
+
stream.on("end", () => resolve(hash.digest("hex")))
|
|
316
|
+
stream.on("error", reject)
|
|
317
|
+
})
|
|
318
|
+
if (actualSha !== expectedSha) {
|
|
319
|
+
throw new Error("SHA-256 checksum mismatch")
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
status.startSpinner("Extracting redcode...")
|
|
323
|
+
const untar = spawnSync("tar", ["-xzf", archive, "-C", vendor, "redcode"], { encoding: "utf8" })
|
|
324
|
+
if (untar.status !== 0) {
|
|
325
|
+
throw new Error(`tar failed: ${untar.stderr || "unknown error"}`)
|
|
326
|
+
}
|
|
327
|
+
fs.chmodSync(bin, 0o755)
|
|
328
|
+
try {
|
|
329
|
+
fs.unlinkSync(archive)
|
|
330
|
+
} catch {}
|
|
331
|
+
|
|
332
|
+
status.finish(true, `RedCode v${VERSION} ready! Run: redcode`)
|
|
333
|
+
} finally {
|
|
334
|
+
cleanup()
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
main().catch((err) => {
|
|
339
|
+
if (ui.interactive) ui.write(C.showCursor)
|
|
340
|
+
ui.write(`${C.clearLine} ${C.amber}! Install deferred. Run 'redcode' to retry.${C.reset}\n\n`)
|
|
341
|
+
ui.close()
|
|
342
|
+
process.exit(0)
|
|
343
|
+
})
|