redcode-cli 2.4.5 → 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 +1 -1
- package/package.json +2 -1
- package/scripts/install.js +103 -88
package/README.md
CHANGED
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -8,7 +8,7 @@ const crypto = require("node:crypto")
|
|
|
8
8
|
const { spawnSync } = require("node:child_process")
|
|
9
9
|
|
|
10
10
|
const PKG = require("../package.json")
|
|
11
|
-
const VERSION = PKG.version
|
|
11
|
+
const VERSION = PKG.redcodeRelease || PKG.version
|
|
12
12
|
const REPO = "red-code-cli/redcodecli"
|
|
13
13
|
const BASE = `https://github.com/${REPO}/releases/download/v${VERSION}`
|
|
14
14
|
const root = path.join(__dirname, "..")
|
|
@@ -16,7 +16,6 @@ const vendor = path.join(root, "vendor")
|
|
|
16
16
|
const bin = path.join(vendor, "redcode")
|
|
17
17
|
const FORCE = process.argv.includes("--force")
|
|
18
18
|
|
|
19
|
-
// Open controlling TTY so animation stays visible even when npm buffers postinstall stdout.
|
|
20
19
|
function createDisplay() {
|
|
21
20
|
let ttyFd = null
|
|
22
21
|
let interactive = Boolean(process.stdout.isTTY)
|
|
@@ -28,6 +27,18 @@ function createDisplay() {
|
|
|
28
27
|
ttyFd = null
|
|
29
28
|
}
|
|
30
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
|
+
|
|
31
42
|
const write = (str) => {
|
|
32
43
|
if (ttyFd !== null) {
|
|
33
44
|
try {
|
|
@@ -45,7 +56,7 @@ function createDisplay() {
|
|
|
45
56
|
ttyFd = null
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
|
-
return { write, close, interactive }
|
|
59
|
+
return { write, close, interactive, cols }
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
const ui = createDisplay()
|
|
@@ -53,7 +64,6 @@ const C = ui.interactive
|
|
|
53
64
|
? {
|
|
54
65
|
reset: "\x1b[0m",
|
|
55
66
|
bold: "\x1b[1m",
|
|
56
|
-
dim: "\x1b[2m",
|
|
57
67
|
red1: "\x1b[38;5;196m",
|
|
58
68
|
red2: "\x1b[38;5;203m",
|
|
59
69
|
red3: "\x1b[38;5;160m",
|
|
@@ -61,7 +71,6 @@ const C = ui.interactive
|
|
|
61
71
|
white: "\x1b[97m",
|
|
62
72
|
green: "\x1b[38;5;46m",
|
|
63
73
|
amber: "\x1b[38;5;214m",
|
|
64
|
-
cyan: "\x1b[38;5;51m",
|
|
65
74
|
hideCursor: "\x1b[?25l",
|
|
66
75
|
showCursor: "\x1b[?25h",
|
|
67
76
|
clearLine: "\r\x1b[2K",
|
|
@@ -69,7 +78,6 @@ const C = ui.interactive
|
|
|
69
78
|
: {
|
|
70
79
|
reset: "",
|
|
71
80
|
bold: "",
|
|
72
|
-
dim: "",
|
|
73
81
|
red1: "",
|
|
74
82
|
red2: "",
|
|
75
83
|
red3: "",
|
|
@@ -77,7 +85,6 @@ const C = ui.interactive
|
|
|
77
85
|
white: "",
|
|
78
86
|
green: "",
|
|
79
87
|
amber: "",
|
|
80
|
-
cyan: "",
|
|
81
88
|
hideCursor: "",
|
|
82
89
|
showCursor: "",
|
|
83
90
|
clearLine: "",
|
|
@@ -97,48 +104,76 @@ function sleep(ms) {
|
|
|
97
104
|
return new Promise((r) => setTimeout(r, ms))
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
async function
|
|
107
|
+
async function renderBannerOnce() {
|
|
101
108
|
ui.write("\n")
|
|
102
109
|
if (ui.interactive) ui.write(C.hideCursor)
|
|
103
110
|
for (let i = 0; i < LOGO.length; i++) {
|
|
104
|
-
|
|
105
|
-
ui.
|
|
106
|
-
if (ui.interactive) await sleep(35)
|
|
111
|
+
ui.write(` ${C.bold}${GRADIENT[i]}${LOGO[i]}${C.reset}\n`)
|
|
112
|
+
if (ui.interactive) await sleep(20)
|
|
107
113
|
}
|
|
108
|
-
|
|
109
|
-
ui.write(` ${C.
|
|
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`)
|
|
110
117
|
}
|
|
111
118
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
let
|
|
119
|
+
// Single-line in-place status controller: everything animates on ONE line (no terminal scroll).
|
|
120
|
+
function createSingleLineStatus() {
|
|
121
|
+
let spinIdx = 0
|
|
115
122
|
let timer = null
|
|
116
|
-
|
|
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
|
+
}
|
|
117
135
|
const draw = () => {
|
|
118
|
-
const frame = SPINNER[
|
|
119
|
-
ui.write(`${C.clearLine} ${C.red1}${frame}${C.reset} ${C.white}${
|
|
136
|
+
const frame = SPINNER[spinIdx++ % SPINNER.length]
|
|
137
|
+
ui.write(`${C.clearLine} ${C.red1}${frame}${C.reset} ${C.white}${currentLabel}${C.reset}`)
|
|
120
138
|
}
|
|
121
139
|
draw()
|
|
122
|
-
timer = setInterval(draw,
|
|
123
|
-
}
|
|
124
|
-
|
|
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
|
+
)
|
|
125
163
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
136
|
-
fail(msg) {
|
|
137
|
-
if (timer) clearInterval(timer)
|
|
138
|
-
if (ui.interactive) ui.write(`${C.clearLine} ${C.amber}!${C.reset} ${C.amber}${msg}${C.reset}\n`)
|
|
139
|
-
else ui.write(` [warn] ${msg}\n`)
|
|
140
|
-
},
|
|
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
|
+
}
|
|
141
174
|
}
|
|
175
|
+
|
|
176
|
+
return { startSpinner, stopSpinner, drawProgress, finish }
|
|
142
177
|
}
|
|
143
178
|
|
|
144
179
|
function detectLibc() {
|
|
@@ -155,7 +190,7 @@ function httpGet(url, redirects = 8) {
|
|
|
155
190
|
return new Promise((resolve, reject) => {
|
|
156
191
|
const req = https.get(
|
|
157
192
|
url,
|
|
158
|
-
{ headers: { "user-agent": `redcode-cli/${
|
|
193
|
+
{ headers: { "user-agent": `redcode-cli/${PKG.version}` }, timeout: 30_000 },
|
|
159
194
|
(res) => {
|
|
160
195
|
if ([301, 302, 303, 307, 308].includes(res.statusCode) && res.headers.location && redirects > 0) {
|
|
161
196
|
res.resume()
|
|
@@ -185,53 +220,36 @@ async function fetchText(url) {
|
|
|
185
220
|
}
|
|
186
221
|
|
|
187
222
|
function formatMB(bytes) {
|
|
188
|
-
return (bytes / (1024 * 1024)).toFixed(
|
|
223
|
+
return (bytes / (1024 * 1024)).toFixed(0)
|
|
189
224
|
}
|
|
190
225
|
|
|
191
|
-
async function downloadWithProgress(url, dest) {
|
|
226
|
+
async function downloadWithProgress(url, dest, status) {
|
|
192
227
|
const res = await httpGet(url)
|
|
193
228
|
const total = Number.parseInt(res.headers["content-length"] || "0", 10)
|
|
229
|
+
const totalMB = total > 0 ? formatMB(total) : ""
|
|
194
230
|
const out = fs.createWriteStream(dest)
|
|
195
231
|
let loaded = 0
|
|
196
|
-
let spinIdx = 0
|
|
197
232
|
let lastDraw = 0
|
|
198
233
|
const startedAt = Date.now()
|
|
199
|
-
const barWidth = 22
|
|
200
|
-
|
|
201
|
-
const renderBar = (force = false) => {
|
|
202
|
-
const now = Date.now()
|
|
203
|
-
if (!force && now - lastDraw < 90) return
|
|
204
|
-
lastDraw = now
|
|
205
|
-
const elapsedSec = Math.max((now - startedAt) / 1000, 0.1)
|
|
206
|
-
const mbPerSec = (loaded / (1024 * 1024) / elapsedSec).toFixed(1)
|
|
207
|
-
const frame = SPINNER[spinIdx++ % SPINNER.length]
|
|
208
|
-
if (total > 0) {
|
|
209
|
-
const pct = Math.min(100, Math.round((loaded / total) * 100))
|
|
210
|
-
const filled = Math.round((pct / 100) * barWidth)
|
|
211
|
-
const bar = `${C.red1}${"█".repeat(filled)}${C.slate}${"░".repeat(barWidth - filled)}${C.reset}`
|
|
212
|
-
ui.write(
|
|
213
|
-
`${C.clearLine} ${C.red1}${frame}${C.reset} Downloading [${bar}] ${C.bold}${C.white}${pct}%${C.reset} ${C.slate}${formatMB(loaded)}/${formatMB(total)} MB (${mbPerSec} MB/s)${C.reset}`,
|
|
214
|
-
)
|
|
215
|
-
} else {
|
|
216
|
-
ui.write(
|
|
217
|
-
`${C.clearLine} ${C.red1}${frame}${C.reset} Downloading ${C.white}${formatMB(loaded)} MB${C.reset} ${C.slate}(${mbPerSec} MB/s)${C.reset}`,
|
|
218
|
-
)
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
234
|
|
|
222
235
|
return await new Promise((resolve, reject) => {
|
|
223
236
|
res.on("data", (chunk) => {
|
|
224
237
|
loaded += chunk.length
|
|
225
|
-
if (ui.interactive)
|
|
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)
|
|
226
246
|
})
|
|
227
247
|
res.pipe(out)
|
|
228
248
|
out.on("finish", () => {
|
|
229
249
|
if (ui.interactive) {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
)
|
|
233
|
-
} else {
|
|
234
|
-
ui.write(` [ok] Downloaded ${formatMB(loaded)} MB\n`)
|
|
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)
|
|
235
253
|
}
|
|
236
254
|
resolve()
|
|
237
255
|
})
|
|
@@ -242,26 +260,29 @@ async function downloadWithProgress(url, dest) {
|
|
|
242
260
|
|
|
243
261
|
async function main() {
|
|
244
262
|
if (process.platform !== "linux" || process.arch !== "arm64") {
|
|
245
|
-
ui.write(`\n ${C.amber}! redcode-cli
|
|
246
|
-
ui.
|
|
263
|
+
ui.write(`\n ${C.amber}! redcode-cli ships Linux ARM64 binaries (${process.platform}/${process.arch}).${C.reset}\n\n`)
|
|
264
|
+
ui.close()
|
|
247
265
|
return
|
|
248
266
|
}
|
|
249
267
|
|
|
250
268
|
if (!FORCE && fs.existsSync(bin)) {
|
|
251
269
|
const probe = spawnSync(bin, ["--version"], { encoding: "utf8" })
|
|
252
270
|
if ((probe.stdout || "").includes(VERSION)) {
|
|
253
|
-
ui.write(`\n ${C.green}✓${C.reset} ${C.bold}${C.white}RedCode
|
|
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()
|
|
254
273
|
return
|
|
255
274
|
}
|
|
256
275
|
}
|
|
257
276
|
|
|
258
277
|
fs.mkdirSync(vendor, { recursive: true })
|
|
259
|
-
await
|
|
278
|
+
await renderBannerOnce()
|
|
279
|
+
const status = createSingleLineStatus()
|
|
260
280
|
|
|
261
281
|
const libc = detectLibc()
|
|
262
282
|
const asset = libc === "musl" ? "redcode-linux-arm64-musl.tar.gz" : "redcode-linux-arm64.tar.gz"
|
|
263
283
|
const archive = path.join(vendor, `${asset}.tmp`)
|
|
264
284
|
const cleanup = () => {
|
|
285
|
+
status.stopSpinner()
|
|
265
286
|
if (fs.existsSync(archive)) {
|
|
266
287
|
try {
|
|
267
288
|
fs.unlinkSync(archive)
|
|
@@ -277,17 +298,16 @@ async function main() {
|
|
|
277
298
|
})
|
|
278
299
|
|
|
279
300
|
try {
|
|
280
|
-
|
|
301
|
+
status.startSpinner(`Checking v${VERSION} (${libc})...`)
|
|
281
302
|
const sums = await fetchText(`${BASE}/SHA256SUMS`)
|
|
282
303
|
const sumLine = sums.split(/\r?\n/).find((l) => l.trim().endsWith(asset))
|
|
283
304
|
if (!sumLine) throw new Error(`SHA256SUMS missing entry for ${asset}`)
|
|
284
305
|
const expectedSha = sumLine.trim().split(/\s+/)[0]
|
|
285
|
-
s1.succeed(`Target matched: ${asset} (${libc})`)
|
|
286
306
|
|
|
287
|
-
if (!ui.interactive) ui.write(` * Downloading ${
|
|
288
|
-
await downloadWithProgress(`${BASE}/${asset}`, archive)
|
|
307
|
+
if (!ui.interactive) ui.write(` * Downloading ${asset}...\n`)
|
|
308
|
+
await downloadWithProgress(`${BASE}/${asset}`, archive, status)
|
|
289
309
|
|
|
290
|
-
|
|
310
|
+
status.startSpinner("Verifying SHA-256...")
|
|
291
311
|
const actualSha = await new Promise((resolve, reject) => {
|
|
292
312
|
const hash = crypto.createHash("sha256")
|
|
293
313
|
const stream = fs.createReadStream(archive)
|
|
@@ -296,24 +316,20 @@ async function main() {
|
|
|
296
316
|
stream.on("error", reject)
|
|
297
317
|
})
|
|
298
318
|
if (actualSha !== expectedSha) {
|
|
299
|
-
throw new Error(
|
|
319
|
+
throw new Error("SHA-256 checksum mismatch")
|
|
300
320
|
}
|
|
301
|
-
s2.succeed(`SHA-256 verified (${expectedSha.slice(0, 12)}...)`)
|
|
302
321
|
|
|
303
|
-
|
|
322
|
+
status.startSpinner("Extracting redcode...")
|
|
304
323
|
const untar = spawnSync("tar", ["-xzf", archive, "-C", vendor, "redcode"], { encoding: "utf8" })
|
|
305
324
|
if (untar.status !== 0) {
|
|
306
|
-
throw new Error(`tar
|
|
325
|
+
throw new Error(`tar failed: ${untar.stderr || "unknown error"}`)
|
|
307
326
|
}
|
|
308
327
|
fs.chmodSync(bin, 0o755)
|
|
309
328
|
try {
|
|
310
329
|
fs.unlinkSync(archive)
|
|
311
330
|
} catch {}
|
|
312
|
-
s3.succeed(`RedCode CLI v${VERSION} installed`)
|
|
313
331
|
|
|
314
|
-
|
|
315
|
-
ui.write(` ${C.green}★${C.reset} ${C.bold}${C.white}Ready!${C.reset} Run ${C.red2}redcode${C.reset} (TUI) or ${C.red2}redcode serve${C.reset} (Web UI :4444)\n`)
|
|
316
|
-
ui.write(` ${C.slate} Commands: /swarm /issue /critic /perf /architect /security${C.reset}\n\n`)
|
|
332
|
+
status.finish(true, `RedCode v${VERSION} ready! Run: redcode`)
|
|
317
333
|
} finally {
|
|
318
334
|
cleanup()
|
|
319
335
|
}
|
|
@@ -321,8 +337,7 @@ async function main() {
|
|
|
321
337
|
|
|
322
338
|
main().catch((err) => {
|
|
323
339
|
if (ui.interactive) ui.write(C.showCursor)
|
|
324
|
-
ui.write(
|
|
325
|
-
ui.write(` ${C.slate} Run 'redcode' later to auto-download with animation, or set REDCODE_BIN.${C.reset}\n\n`)
|
|
340
|
+
ui.write(`${C.clearLine} ${C.amber}! Install deferred. Run 'redcode' to retry.${C.reset}\n\n`)
|
|
326
341
|
ui.close()
|
|
327
342
|
process.exit(0)
|
|
328
343
|
})
|