@delta-infra/cli 1.1.19 → 1.1.23

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.
Files changed (77) hide show
  1. package/README.md +511 -520
  2. package/checksums.txt +5 -5
  3. package/package.json +1 -1
  4. package/scripts/install-wizard.js +689 -688
  5. package/scripts/install.js +442 -442
  6. package/scripts/run.js +65 -65
  7. package/skills/delta-protein/AGENTS.md +72 -72
  8. package/skills/delta-protein/SKILL.md +388 -388
  9. package/skills/delta-protein/agents/openai.yaml +3 -3
  10. package/skills/delta-protein/references/bfitter.md +63 -63
  11. package/skills/delta-protein/references/catapro_predict.md +62 -62
  12. package/skills/delta-protein/references/catpred_predict.md +64 -64
  13. package/skills/delta-protein/references/caver_tunnel_analyze.md +62 -62
  14. package/skills/delta-protein/references/consensus_mutation.md +60 -60
  15. package/skills/delta-protein/references/consurf_predict.md +66 -66
  16. package/skills/delta-protein/references/crop_sequence.md +68 -68
  17. package/skills/delta-protein/references/dock.md +81 -81
  18. package/skills/delta-protein/references/dock_score.md +69 -69
  19. package/skills/delta-protein/references/easifa_predict_active_site.md +69 -69
  20. package/skills/delta-protein/references/ephod_predict_mutation.md +65 -65
  21. package/skills/delta-protein/references/ephod_predict_protein.md +60 -60
  22. package/skills/delta-protein/references/esmfold2_predict.md +66 -66
  23. package/skills/delta-protein/references/evcouplings_mutation.md +63 -63
  24. package/skills/delta-protein/references/fasta_to_sequence.md +58 -58
  25. package/skills/delta-protein/references/foldseek.md +60 -60
  26. package/skills/delta-protein/references/generate_msa.md +60 -60
  27. package/skills/delta-protein/references/interpro_analyze.md +62 -62
  28. package/skills/delta-protein/references/mpnn_design_sequence.md +70 -70
  29. package/skills/delta-protein/references/multievolve.md +72 -72
  30. package/skills/delta-protein/references/pisa_query.md +69 -69
  31. package/skills/delta-protein/references/plip_analyze.md +64 -64
  32. package/skills/delta-protein/references/pocket_prediction.md +62 -62
  33. package/skills/delta-protein/references/protein_design.md +64 -64
  34. package/skills/delta-protein/references/protein_evolution.md +76 -76
  35. package/skills/delta-protein/references/protein_sol_predict_mutation.md +65 -65
  36. package/skills/delta-protein/references/protein_sol_predict_protein.md +60 -60
  37. package/skills/delta-protein/references/protenix.md +65 -65
  38. package/skills/delta-protein/references/protrek_search.md +89 -89
  39. package/skills/delta-protein/references/pubchem_search.md +67 -67
  40. package/skills/delta-protein/references/pubmed_search.md +78 -78
  41. package/skills/delta-protein/references/reap_design_primer.md +68 -68
  42. package/skills/delta-protein/references/rfd3_design.md +64 -64
  43. package/skills/delta-protein/references/structure_to_sequence.md +60 -60
  44. package/skills/delta-protein/references/summarize_result.md +67 -67
  45. package/skills/delta-protein/references/surface_charge.md +83 -83
  46. package/skills/delta-protein/references/uniprot_batch_query.md +62 -62
  47. package/skills/delta-protein/references/uniprot_query.md +63 -63
  48. package/skills/delta-protein/references/zero_shot_mutant_candidates.md +75 -75
  49. package/skills/delta-protein/scripts/gen_references.py +166 -166
  50. package/skills/delta-protein/scripts/output_metadata.json +274 -274
  51. package/skills/delta-sandbox/SKILL.md +388 -388
  52. package/skills/delta-sandbox/agents/openai.yaml +4 -4
  53. package/skills/delta-sandbox/references/commands.md +71 -58
  54. package/skills/delta-sandbox/references/lifecycle.md +101 -100
  55. package/skills/delta-sandbox/references/recipes.md +138 -138
  56. package/skills/delta-science/AGENTS.md +47 -47
  57. package/skills/delta-science/SKILL.md +227 -227
  58. package/skills/delta-science/agents/openai.yaml +4 -4
  59. package/skills/delta-science/references/antbo.md +105 -105
  60. package/skills/delta-science/references/delta-bo.md +92 -92
  61. package/skills/delta-science/references/gsasii.md +118 -118
  62. package/skills/delta-science/references/lammps.md +68 -68
  63. package/skills/delta-science/references/ldm-bo.md +132 -132
  64. package/skills/delta-science/references/materials-design.md +130 -130
  65. package/skills/delta-science/references/pubchem.md +128 -128
  66. package/skills/delta-science/references/pymatgen.md +69 -69
  67. package/skills/delta-science/references/qe.md +134 -134
  68. package/skills/delta-science/references/rdkit.md +141 -141
  69. package/skills/delta-science/references/strbo.md +95 -95
  70. package/skills/delta-science/references/synbo.md +201 -201
  71. package/skills/delta-science/references/xrd.md +154 -170
  72. package/skills/delta-science/scripts/catalog.py +92 -92
  73. package/skills/delta-science/scripts/generated_catalog.py +69 -69
  74. package/skills/delta-science/scripts/invoke.py +346 -346
  75. package/skills/delta-shared/SKILL.md +115 -113
  76. package/skills/delta-shared/agents/openai.yaml +4 -4
  77. package/skills/manifest.json +20 -20
@@ -1,442 +1,442 @@
1
- // Copyright (c) 2026 Delta Agent Cloud Authors
2
- // SPDX-License-Identifier: MIT
3
-
4
- const fs = require("fs");
5
- const path = require("path");
6
- const { execFileSync } = require("child_process");
7
- const os = require("os");
8
- const crypto = require("crypto");
9
-
10
- const PKG = "@delta-infra/cli";
11
-
12
- // Resolve the version to download:
13
- // env var > npm registry > local package.json (fallback)
14
- function resolveVersion() {
15
- if (process.env.DELTA_CLI_VERSION) return process.env.DELTA_CLI_VERSION.replace(/^v/, "");
16
- try {
17
- const out = require("child_process").execFileSync("npm", ["view", PKG, "version"], {
18
- stdio: ["ignore", "pipe", "pipe"],
19
- timeout: 15000,
20
- encoding: "utf8",
21
- });
22
- const ver = out.trim();
23
- if (/^\d+\.\d+\.\d+/.test(ver)) return ver;
24
- } catch {}
25
- return require("../package.json").version.replace(/-.*$/, "");
26
- }
27
-
28
- const VERSION = resolveVersion();
29
- const NAME = "delta-cli";
30
- const REPO = "yzailab/delta-infra-cli";
31
- const DEFAULT_ALLOWED_HOSTS = new Set([
32
- "github.com",
33
- "gh-proxy.com",
34
- "ghproxy.net",
35
- "gh.ddlc.top",
36
- "objects.githubusercontent.com",
37
- "release-assets.githubusercontent.com",
38
- "github-releases.githubusercontent.com",
39
- "raw.githubusercontent.com",
40
- "registry.npmmirror.com",
41
- ]);
42
- const DEFAULT_ALLOWED_HOST_PREFIXES = [
43
- "github-production-release-asset-",
44
- ];
45
-
46
- const PLATFORM_MAP = {
47
- darwin: "darwin",
48
- linux: "linux",
49
- win32: "windows",
50
- };
51
-
52
- const ARCH_MAP = {
53
- x64: "amd64",
54
- arm64: "arm64",
55
- };
56
-
57
- const platform = PLATFORM_MAP[process.platform];
58
- const arch = ARCH_MAP[process.arch];
59
-
60
- const isWindows = process.platform === "win32";
61
- const ext = isWindows ? ".zip" : ".tar.gz";
62
- const archiveName = `${NAME}-${platform}-${arch}${ext}`;
63
- const GITHUB_URL = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
64
-
65
- const binDir = path.join(__dirname, "..", "bin");
66
- const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
67
-
68
- // ── Mirror URL resolution ──────────────────────────────────────────────────
69
-
70
- var _curlTimeoutMs = null;
71
-
72
- function _getCurlTimeout() {
73
- if (_curlTimeoutMs !== null) return _curlTimeoutMs;
74
- var env = process.env.DELTA_CLI_DOWNLOAD_TIMEOUT;
75
- var t = env ? parseInt(env, 10) : 0;
76
- _curlTimeoutMs = t > 0 ? t : 60000;
77
- return _curlTimeoutMs;
78
- }
79
-
80
- // GitHub release download mirrors.
81
- // Format: [hostname, urlPrefix] — urlPrefix is prepended to the GitHub URL.
82
- var _MIRROR_LIST = [
83
- ["gh.ddlc.top", "https://gh.ddlc.top"],
84
- ["ghproxy.net", "https://ghproxy.net"],
85
- ["gh-proxy.com", "https://gh-proxy.com"],
86
- ];
87
-
88
- // A safe "discard" output path for curl. /dev/null does not exist on Windows
89
- // and makes curl fail with "client returned ERROR on write" (exit 23), which
90
- // silently broke mirror probing on Windows. Use a throwaway temp file instead.
91
- function discardOutputPath() {
92
- if (process.platform !== "win32") return "/dev/null";
93
- try {
94
- return path.join(os.tmpdir(), "delta-cli-probe-" + process.pid + ".out");
95
- } catch {
96
- return "delta-cli-probe-" + process.pid + ".out";
97
- }
98
- }
99
-
100
- function removeDiscardOutput(p) {
101
- if (process.platform === "win32" && p) {
102
- try { fs.unlinkSync(p); } catch {}
103
- }
104
- }
105
-
106
- // Quick connectivity check: fetch a small file (checksums.txt) from each
107
- // mirror and return only the ones that respond within the probe timeout.
108
- function probeMirrors(version, cb) {
109
- console.error("Probing " + _MIRROR_LIST.length + " download mirrors...");
110
- var probeUrl = "/https://github.com/" + REPO + "/releases/download/v" + version + "/checksums.txt";
111
- var results = [];
112
- var pending = _MIRROR_LIST.length;
113
- var done = false;
114
-
115
- function finish() {
116
- if (done) return;
117
- done = true;
118
- if (results.length > 0) {
119
- console.error("Found " + results.length + " available mirror(s)");
120
- } else {
121
- console.error("No mirror responded, falling back to GitHub source");
122
- }
123
- cb(results);
124
- }
125
-
126
- if (pending === 0) return finish();
127
-
128
- for (var i = 0; i < _MIRROR_LIST.length; i++) {
129
- (function(idx) {
130
- var entry = _MIRROR_LIST[idx];
131
- var host = entry[0];
132
- var prefix = entry[1];
133
- var testUrl = prefix + probeUrl;
134
- var discardPath = discardOutputPath();
135
- var args = [
136
- "--fail", "--location", "--silent", "--show-error",
137
- "--connect-timeout", "3", "--max-time", "5",
138
- "--output", discardPath, testUrl,
139
- ];
140
- var child;
141
- try {
142
- child = require("child_process").spawn("curl", args, { stdio: ["ignore", "pipe", "pipe"], timeout: 5000 });
143
- var stdout = "";
144
- var stderr = "";
145
- child.stdout.on("data", function(d) { stdout += d; });
146
- child.stderr.on("data", function(d) { stderr += d; });
147
- child.on("close", function(code) {
148
- removeDiscardOutput(discardPath);
149
- if (code === 0) {
150
- results.push(prefix + "/https://github.com/" + REPO + "/releases/download/v" + version + "/" + archiveName);
151
- }
152
- pending--;
153
- if (pending === 0) finish();
154
- });
155
- child.on("error", function() {
156
- removeDiscardOutput(discardPath);
157
- pending--;
158
- if (pending === 0) finish();
159
- });
160
- } catch (e) {
161
- removeDiscardOutput(discardPath);
162
- pending--;
163
- if (pending === 0) finish();
164
- }
165
- })(i);
166
- }
167
- // Safety timeout: if probes hang, continue without mirrors after 10s
168
- setTimeout(finish, 5000);
169
- }
170
-
171
- function releaseAssetUrls(version, assetName, cb) {
172
- var urls = [];
173
- var mirror = process.env.DELTA_CLI_MIRROR || "";
174
- if (mirror) {
175
- // The mirror proxies the full GitHub release URL by prefixing it (same
176
- // scheme the probed mirrors use, e.g. https://<mirror>/https://github.com/...).
177
- // A bare "https://<mirror>/yzailab/..." 404s on these proxy-style mirrors.
178
- urls.push("" + mirror.replace(/\/$/, "") + "/https://github.com/" + REPO + "/releases/download/v" + version + "/" + assetName);
179
- }
180
- // Probe mirrors in parallel first, then fallback
181
- probeMirrors(version, function(mirrorUrls) {
182
- for (var i = 0; i < mirrorUrls.length; i++) {
183
- urls.push(mirrorUrls[i]);
184
- }
185
- // GitHub source (last resort)
186
- urls.push(GITHUB_URL);
187
- cb(urls);
188
- });
189
- }
190
-
191
- function assertAllowedHost(url) {
192
- const { hostname } = new URL(url);
193
- const allowlist = new Set(DEFAULT_ALLOWED_HOSTS);
194
- (process.env.DELTA_CLI_MIRROR_ALLOWLIST || "")
195
- .split(",")
196
- .map((h) => h.trim().toLowerCase())
197
- .filter(Boolean)
198
- .forEach((h) => allowlist.add(h));
199
- for (const allowed of allowlist) {
200
- if (hostname === allowed || hostname.endsWith("." + allowed)) return;
201
- }
202
- for (const prefix of DEFAULT_ALLOWED_HOST_PREFIXES) {
203
- if (hostname.startsWith(prefix)) return;
204
- }
205
- throw new Error(`Download host not allowed: ${hostname}`);
206
- }
207
-
208
- // ── curl version detection (for --ssl-revoke-best-effort) ──────────────────
209
-
210
- function isCurlVersionSupported(versionOutput) {
211
- const match = String(versionOutput).match(/^\s*curl\s+(\d+)\.(\d+)\.(\d+)/i);
212
- if (!match) return false;
213
- const major = parseInt(match[1], 10);
214
- const minor = parseInt(match[2], 10);
215
- return major > 7 || (major === 7 && minor >= 70);
216
- }
217
-
218
- let _curlSupportsSslRevokeBestEffort;
219
-
220
- function curlSupportsSslRevokeBestEffort() {
221
- if (_curlSupportsSslRevokeBestEffort !== undefined) {
222
- return _curlSupportsSslRevokeBestEffort;
223
- }
224
- try {
225
- const output = execFileSync("curl", ["--version"], {
226
- stdio: ["ignore", "pipe", "ignore"],
227
- encoding: "utf8",
228
- timeout: 5000,
229
- });
230
- _curlSupportsSslRevokeBestEffort = isCurlVersionSupported(output);
231
- } catch {
232
- _curlSupportsSslRevokeBestEffort = false;
233
- }
234
- return _curlSupportsSslRevokeBestEffort;
235
- }
236
-
237
- // ── Download ───────────────────────────────────────────────────────────────
238
-
239
- function download(url, destPath) {
240
- assertAllowedHost(url);
241
- const args = [
242
- "--fail", "--location", "--silent", "--show-error",
243
- "--connect-timeout", "10",
244
- "--max-time", "45",
245
- "--speed-limit", "50000", "--speed-time", "10",
246
- "--max-redirs", "3",
247
- "--output", destPath,
248
- ];
249
- if (isWindows && curlSupportsSslRevokeBestEffort()) {
250
- args.unshift("--ssl-revoke-best-effort");
251
- }
252
- args.push(url);
253
- execFileSync("curl", args, { stdio: ["ignore", "ignore", "pipe"] });
254
- }
255
-
256
- // ── Extraction ─────────────────────────────────────────────────────────────
257
-
258
- function extractZipWindows(archivePath, destDir) {
259
- const psOpts = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"];
260
- const psEnv = {
261
- DELTA_CLI_ARCHIVE: archivePath,
262
- DELTA_CLI_DEST: destDir,
263
- };
264
- try {
265
- const dotnet =
266
- "$ErrorActionPreference='Stop';" +
267
- "Add-Type -AssemblyName System.IO.Compression.FileSystem;" +
268
- "[System.IO.Compression.ZipFile]::ExtractToDirectory($env:DELTA_CLI_ARCHIVE,$env:DELTA_CLI_DEST)";
269
- execFileSync("powershell.exe", [...psOpts, dotnet], { stdio: ["ignore", "inherit", "inherit"], env: psEnv });
270
- } catch (primaryErr) {
271
- try {
272
- const cmdlet =
273
- "$ErrorActionPreference='Stop';" +
274
- "Expand-Archive -LiteralPath $env:DELTA_CLI_ARCHIVE -DestinationPath $env:DELTA_CLI_DEST -Force";
275
- execFileSync("powershell.exe", [...psOpts, cmdlet], { stdio: ["ignore", "inherit", "inherit"], env: psEnv });
276
- } catch (secondErr) {
277
- try {
278
- execFileSync("tar", ["-xf", archivePath, "-C", destDir], { stdio: "ignore" });
279
- } catch (fallbackErr) {
280
- throw new Error(
281
- `Failed to extract ${archivePath}. ` +
282
- `.NET ZipFile: ${primaryErr.message}. ` +
283
- `Expand-Archive: ${secondErr.message}. ` +
284
- `tar: ${fallbackErr.message}`
285
- );
286
- }
287
- }
288
- }
289
- }
290
-
291
- // ── Checksum ───────────────────────────────────────────────────────────────
292
-
293
- function getExpectedChecksum(archiveName, checksumsDir) {
294
- const dir = checksumsDir || path.join(__dirname, "..");
295
- const checksumsPath = path.join(dir, "checksums.txt");
296
- if (!fs.existsSync(checksumsPath)) {
297
- console.error("[WARN] checksums.txt not found, skipping checksum verification");
298
- return null;
299
- }
300
- const content = fs.readFileSync(checksumsPath, "utf8");
301
- for (const line of content.split("\n")) {
302
- const trimmed = line.trim();
303
- if (!trimmed) continue;
304
- const match = trimmed.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
305
- if (!match) continue;
306
- const hash = match[1];
307
- const name = match[2];
308
- if (name === archiveName) return hash;
309
- }
310
- throw new Error(`Checksum entry not found for ${archiveName}`);
311
- }
312
-
313
- function verifyChecksum(archivePath, expectedHash) {
314
- if (expectedHash === null) return;
315
- const hash = crypto.createHash("sha256");
316
- const fd = fs.openSync(archivePath, "r");
317
- try {
318
- const buf = Buffer.alloc(64 * 1024);
319
- let bytesRead;
320
- while ((bytesRead = fs.readSync(fd, buf, 0, buf.length, null)) > 0) {
321
- hash.update(buf.subarray(0, bytesRead));
322
- }
323
- } finally {
324
- fs.closeSync(fd);
325
- }
326
- const actual = hash.digest("hex");
327
- if (actual.toLowerCase() !== expectedHash.toLowerCase()) {
328
- throw new Error(
329
- `[SECURITY] Checksum mismatch for ${path.basename(archivePath)}: expected ${expectedHash} but got ${actual}`
330
- );
331
- }
332
- }
333
-
334
- // ── Main install ───────────────────────────────────────────────────────────
335
-
336
- function install() {
337
- fs.mkdirSync(binDir, { recursive: true });
338
- var tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "delta-cli-"));
339
- var archivePath = path.join(tmpDir, archiveName);
340
-
341
- releaseAssetUrls(VERSION, archiveName, function(downloadUrls) {
342
- try {
343
- var lastErr;
344
- var downloaded = false;
345
- for (var i = 0; i < downloadUrls.length; i++) {
346
- try {
347
- console.error("Downloading from " + downloadUrls[i]);
348
- download(downloadUrls[i], archivePath);
349
- console.error("Download complete, verifying checksum...");
350
- const expectedHash = getExpectedChecksum(archiveName);
351
- verifyChecksum(archivePath, expectedHash);
352
- console.error("Checksum verified");
353
- downloaded = true;
354
- break;
355
- } catch (e) {
356
- console.error("Failed: " + e.message + " (" + downloadUrls[i] + ")");
357
- lastErr = e;
358
- }
359
- }
360
- if (!downloaded) throw lastErr;
361
-
362
- if (isWindows) {
363
- console.error("Extracting archive...");
364
- extractZipWindows(archivePath, tmpDir);
365
- } else {
366
- console.error("Extracting archive...");
367
- execFileSync("tar", ["-xzf", archivePath, "-C", tmpDir], { stdio: "ignore" });
368
- }
369
-
370
- const binaryName = NAME + (isWindows ? ".exe" : "");
371
- const extractedBinary = path.join(tmpDir, NAME + "-" + platform + "-" + arch);
372
- if (fs.existsSync(extractedBinary)) {
373
- fs.copyFileSync(extractedBinary, dest);
374
- } else {
375
- // Fallback: try the plain name (older release format)
376
- const plainBinary = path.join(tmpDir, binaryName);
377
- if (fs.existsSync(plainBinary)) {
378
- fs.copyFileSync(plainBinary, dest);
379
- } else {
380
- // Search in tmpDir
381
- const files = fs.readdirSync(tmpDir).filter(function(f) { return f.indexOf(NAME) !== -1 || f.indexOf(binaryName) !== -1; });
382
- if (files.length > 0) {
383
- fs.copyFileSync(path.join(tmpDir, files[0]), dest);
384
- } else {
385
- throw new Error("Binary not found in extracted archive. Files: " + fs.readdirSync(tmpDir).join(", "));
386
- }
387
- }
388
- }
389
- fs.chmodSync(dest, 0o755);
390
- ensureExecutable(path.join(__dirname, "run.js"));
391
- console.error("Installed to " + dest);
392
- } finally {
393
- fs.rmSync(tmpDir, { recursive: true, force: true });
394
- }
395
- });
396
- }
397
-
398
- function ensureExecutable(filePath) {
399
- try {
400
- if (fs.existsSync(filePath)) fs.chmodSync(filePath, 0o755);
401
- } catch {}
402
- }
403
-
404
- // ── Entry ──────────────────────────────────────────────────────────────────
405
-
406
- if (require.main === module) {
407
- if (!platform || !arch) {
408
- console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
409
- process.exit(1);
410
- }
411
-
412
- // npx postinstall guard: skip binary download in ephemeral npx context
413
- const isNpxPostinstall =
414
- process.env.npm_command === "exec" && !process.env.DELTA_CLI_RUN;
415
-
416
- if (isNpxPostinstall) {
417
- process.exit(0);
418
- }
419
-
420
- try {
421
- install();
422
- console.log(`${NAME} v${VERSION} installed successfully`);
423
- } catch (err) {
424
- console.error(`Failed to install ${NAME}:`, err.message);
425
- console.error(
426
- `\nIf you are behind a firewall or in a restricted network, try one of:\n` +
427
- ` # 1. Use a proxy:\n` +
428
- ` export https_proxy=http://your-proxy:port\n` +
429
- ` npm install -g @delta-infra/cli\n\n` +
430
- ` # 2. Point to a corporate npm mirror:\n` +
431
- ` npm install -g @delta-infra/cli --registry=https://your-corp-mirror/\n` +
432
- `\nOr manually download from:\n` +
433
- ` https://github.com/${REPO}/releases/tag/v${VERSION}`
434
- );
435
- process.exit(1);
436
- }
437
- }
438
-
439
- module.exports = {
440
- getExpectedChecksum, verifyChecksum, assertAllowedHost,
441
- isCurlVersionSupported, curlSupportsSslRevokeBestEffort,
442
- };
1
+ // Copyright (c) 2026 Delta Agent Cloud Authors
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ const fs = require("fs");
5
+ const path = require("path");
6
+ const { execFileSync } = require("child_process");
7
+ const os = require("os");
8
+ const crypto = require("crypto");
9
+
10
+ const PKG = "@delta-infra/cli";
11
+
12
+ // Resolve the version to download:
13
+ // env var > npm registry > local package.json (fallback)
14
+ function resolveVersion() {
15
+ if (process.env.DELTA_CLI_VERSION) return process.env.DELTA_CLI_VERSION.replace(/^v/, "");
16
+ try {
17
+ const out = require("child_process").execFileSync("npm", ["view", PKG, "version"], {
18
+ stdio: ["ignore", "pipe", "pipe"],
19
+ timeout: 15000,
20
+ encoding: "utf8",
21
+ });
22
+ const ver = out.trim();
23
+ if (/^\d+\.\d+\.\d+/.test(ver)) return ver;
24
+ } catch {}
25
+ return require("../package.json").version.replace(/-.*$/, "");
26
+ }
27
+
28
+ const VERSION = resolveVersion();
29
+ const NAME = "delta-cli";
30
+ const REPO = "yzailab/delta-infra-cli";
31
+ const DEFAULT_ALLOWED_HOSTS = new Set([
32
+ "github.com",
33
+ "gh-proxy.com",
34
+ "ghproxy.net",
35
+ "gh.ddlc.top",
36
+ "objects.githubusercontent.com",
37
+ "release-assets.githubusercontent.com",
38
+ "github-releases.githubusercontent.com",
39
+ "raw.githubusercontent.com",
40
+ "registry.npmmirror.com",
41
+ ]);
42
+ const DEFAULT_ALLOWED_HOST_PREFIXES = [
43
+ "github-production-release-asset-",
44
+ ];
45
+
46
+ const PLATFORM_MAP = {
47
+ darwin: "darwin",
48
+ linux: "linux",
49
+ win32: "windows",
50
+ };
51
+
52
+ const ARCH_MAP = {
53
+ x64: "amd64",
54
+ arm64: "arm64",
55
+ };
56
+
57
+ const platform = PLATFORM_MAP[process.platform];
58
+ const arch = ARCH_MAP[process.arch];
59
+
60
+ const isWindows = process.platform === "win32";
61
+ const ext = isWindows ? ".zip" : ".tar.gz";
62
+ const archiveName = `${NAME}-${platform}-${arch}${ext}`;
63
+ const GITHUB_URL = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
64
+
65
+ const binDir = path.join(__dirname, "..", "bin");
66
+ const dest = path.join(binDir, NAME + (isWindows ? ".exe" : ""));
67
+
68
+ // ── Mirror URL resolution ──────────────────────────────────────────────────
69
+
70
+ var _curlTimeoutMs = null;
71
+
72
+ function _getCurlTimeout() {
73
+ if (_curlTimeoutMs !== null) return _curlTimeoutMs;
74
+ var env = process.env.DELTA_CLI_DOWNLOAD_TIMEOUT;
75
+ var t = env ? parseInt(env, 10) : 0;
76
+ _curlTimeoutMs = t > 0 ? t : 60000;
77
+ return _curlTimeoutMs;
78
+ }
79
+
80
+ // GitHub release download mirrors.
81
+ // Format: [hostname, urlPrefix] — urlPrefix is prepended to the GitHub URL.
82
+ var _MIRROR_LIST = [
83
+ ["gh.ddlc.top", "https://gh.ddlc.top"],
84
+ ["ghproxy.net", "https://ghproxy.net"],
85
+ ["gh-proxy.com", "https://gh-proxy.com"],
86
+ ];
87
+
88
+ // A safe "discard" output path for curl. /dev/null does not exist on Windows
89
+ // and makes curl fail with "client returned ERROR on write" (exit 23), which
90
+ // silently broke mirror probing on Windows. Use a throwaway temp file instead.
91
+ function discardOutputPath() {
92
+ if (process.platform !== "win32") return "/dev/null";
93
+ try {
94
+ return path.join(os.tmpdir(), "delta-cli-probe-" + process.pid + ".out");
95
+ } catch {
96
+ return "delta-cli-probe-" + process.pid + ".out";
97
+ }
98
+ }
99
+
100
+ function removeDiscardOutput(p) {
101
+ if (process.platform === "win32" && p) {
102
+ try { fs.unlinkSync(p); } catch {}
103
+ }
104
+ }
105
+
106
+ // Quick connectivity check: fetch a small file (checksums.txt) from each
107
+ // mirror and return only the ones that respond within the probe timeout.
108
+ function probeMirrors(version, cb) {
109
+ console.error("Probing " + _MIRROR_LIST.length + " download mirrors...");
110
+ var probeUrl = "/https://github.com/" + REPO + "/releases/download/v" + version + "/checksums.txt";
111
+ var results = [];
112
+ var pending = _MIRROR_LIST.length;
113
+ var done = false;
114
+
115
+ function finish() {
116
+ if (done) return;
117
+ done = true;
118
+ if (results.length > 0) {
119
+ console.error("Found " + results.length + " available mirror(s)");
120
+ } else {
121
+ console.error("No mirror responded, falling back to GitHub source");
122
+ }
123
+ cb(results);
124
+ }
125
+
126
+ if (pending === 0) return finish();
127
+
128
+ for (var i = 0; i < _MIRROR_LIST.length; i++) {
129
+ (function(idx) {
130
+ var entry = _MIRROR_LIST[idx];
131
+ var host = entry[0];
132
+ var prefix = entry[1];
133
+ var testUrl = prefix + probeUrl;
134
+ var discardPath = discardOutputPath();
135
+ var args = [
136
+ "--fail", "--location", "--silent", "--show-error",
137
+ "--connect-timeout", "3", "--max-time", "5",
138
+ "--output", discardPath, testUrl,
139
+ ];
140
+ var child;
141
+ try {
142
+ child = require("child_process").spawn("curl", args, { stdio: ["ignore", "pipe", "pipe"], timeout: 5000 });
143
+ var stdout = "";
144
+ var stderr = "";
145
+ child.stdout.on("data", function(d) { stdout += d; });
146
+ child.stderr.on("data", function(d) { stderr += d; });
147
+ child.on("close", function(code) {
148
+ removeDiscardOutput(discardPath);
149
+ if (code === 0) {
150
+ results.push(prefix + "/https://github.com/" + REPO + "/releases/download/v" + version + "/" + archiveName);
151
+ }
152
+ pending--;
153
+ if (pending === 0) finish();
154
+ });
155
+ child.on("error", function() {
156
+ removeDiscardOutput(discardPath);
157
+ pending--;
158
+ if (pending === 0) finish();
159
+ });
160
+ } catch (e) {
161
+ removeDiscardOutput(discardPath);
162
+ pending--;
163
+ if (pending === 0) finish();
164
+ }
165
+ })(i);
166
+ }
167
+ // Safety timeout: if probes hang, continue without mirrors after 10s
168
+ setTimeout(finish, 5000);
169
+ }
170
+
171
+ function releaseAssetUrls(version, assetName, cb) {
172
+ var urls = [];
173
+ var mirror = process.env.DELTA_CLI_MIRROR || "";
174
+ if (mirror) {
175
+ // The mirror proxies the full GitHub release URL by prefixing it (same
176
+ // scheme the probed mirrors use, e.g. https://<mirror>/https://github.com/...).
177
+ // A bare "https://<mirror>/yzailab/..." 404s on these proxy-style mirrors.
178
+ urls.push("" + mirror.replace(/\/$/, "") + "/https://github.com/" + REPO + "/releases/download/v" + version + "/" + assetName);
179
+ }
180
+ // Probe mirrors in parallel first, then fallback
181
+ probeMirrors(version, function(mirrorUrls) {
182
+ for (var i = 0; i < mirrorUrls.length; i++) {
183
+ urls.push(mirrorUrls[i]);
184
+ }
185
+ // GitHub source (last resort)
186
+ urls.push(GITHUB_URL);
187
+ cb(urls);
188
+ });
189
+ }
190
+
191
+ function assertAllowedHost(url) {
192
+ const { hostname } = new URL(url);
193
+ const allowlist = new Set(DEFAULT_ALLOWED_HOSTS);
194
+ (process.env.DELTA_CLI_MIRROR_ALLOWLIST || "")
195
+ .split(",")
196
+ .map((h) => h.trim().toLowerCase())
197
+ .filter(Boolean)
198
+ .forEach((h) => allowlist.add(h));
199
+ for (const allowed of allowlist) {
200
+ if (hostname === allowed || hostname.endsWith("." + allowed)) return;
201
+ }
202
+ for (const prefix of DEFAULT_ALLOWED_HOST_PREFIXES) {
203
+ if (hostname.startsWith(prefix)) return;
204
+ }
205
+ throw new Error(`Download host not allowed: ${hostname}`);
206
+ }
207
+
208
+ // ── curl version detection (for --ssl-revoke-best-effort) ──────────────────
209
+
210
+ function isCurlVersionSupported(versionOutput) {
211
+ const match = String(versionOutput).match(/^\s*curl\s+(\d+)\.(\d+)\.(\d+)/i);
212
+ if (!match) return false;
213
+ const major = parseInt(match[1], 10);
214
+ const minor = parseInt(match[2], 10);
215
+ return major > 7 || (major === 7 && minor >= 70);
216
+ }
217
+
218
+ let _curlSupportsSslRevokeBestEffort;
219
+
220
+ function curlSupportsSslRevokeBestEffort() {
221
+ if (_curlSupportsSslRevokeBestEffort !== undefined) {
222
+ return _curlSupportsSslRevokeBestEffort;
223
+ }
224
+ try {
225
+ const output = execFileSync("curl", ["--version"], {
226
+ stdio: ["ignore", "pipe", "ignore"],
227
+ encoding: "utf8",
228
+ timeout: 5000,
229
+ });
230
+ _curlSupportsSslRevokeBestEffort = isCurlVersionSupported(output);
231
+ } catch {
232
+ _curlSupportsSslRevokeBestEffort = false;
233
+ }
234
+ return _curlSupportsSslRevokeBestEffort;
235
+ }
236
+
237
+ // ── Download ───────────────────────────────────────────────────────────────
238
+
239
+ function download(url, destPath) {
240
+ assertAllowedHost(url);
241
+ const args = [
242
+ "--fail", "--location", "--silent", "--show-error",
243
+ "--connect-timeout", "10",
244
+ "--max-time", "45",
245
+ "--speed-limit", "50000", "--speed-time", "10",
246
+ "--max-redirs", "3",
247
+ "--output", destPath,
248
+ ];
249
+ if (isWindows && curlSupportsSslRevokeBestEffort()) {
250
+ args.unshift("--ssl-revoke-best-effort");
251
+ }
252
+ args.push(url);
253
+ execFileSync("curl", args, { stdio: ["ignore", "ignore", "pipe"] });
254
+ }
255
+
256
+ // ── Extraction ─────────────────────────────────────────────────────────────
257
+
258
+ function extractZipWindows(archivePath, destDir) {
259
+ const psOpts = ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command"];
260
+ const psEnv = {
261
+ DELTA_CLI_ARCHIVE: archivePath,
262
+ DELTA_CLI_DEST: destDir,
263
+ };
264
+ try {
265
+ const dotnet =
266
+ "$ErrorActionPreference='Stop';" +
267
+ "Add-Type -AssemblyName System.IO.Compression.FileSystem;" +
268
+ "[System.IO.Compression.ZipFile]::ExtractToDirectory($env:DELTA_CLI_ARCHIVE,$env:DELTA_CLI_DEST)";
269
+ execFileSync("powershell.exe", [...psOpts, dotnet], { stdio: ["ignore", "inherit", "inherit"], env: psEnv });
270
+ } catch (primaryErr) {
271
+ try {
272
+ const cmdlet =
273
+ "$ErrorActionPreference='Stop';" +
274
+ "Expand-Archive -LiteralPath $env:DELTA_CLI_ARCHIVE -DestinationPath $env:DELTA_CLI_DEST -Force";
275
+ execFileSync("powershell.exe", [...psOpts, cmdlet], { stdio: ["ignore", "inherit", "inherit"], env: psEnv });
276
+ } catch (secondErr) {
277
+ try {
278
+ execFileSync("tar", ["-xf", archivePath, "-C", destDir], { stdio: "ignore" });
279
+ } catch (fallbackErr) {
280
+ throw new Error(
281
+ `Failed to extract ${archivePath}. ` +
282
+ `.NET ZipFile: ${primaryErr.message}. ` +
283
+ `Expand-Archive: ${secondErr.message}. ` +
284
+ `tar: ${fallbackErr.message}`
285
+ );
286
+ }
287
+ }
288
+ }
289
+ }
290
+
291
+ // ── Checksum ───────────────────────────────────────────────────────────────
292
+
293
+ function getExpectedChecksum(archiveName, checksumsDir) {
294
+ const dir = checksumsDir || path.join(__dirname, "..");
295
+ const checksumsPath = path.join(dir, "checksums.txt");
296
+ if (!fs.existsSync(checksumsPath)) {
297
+ console.error("[WARN] checksums.txt not found, skipping checksum verification");
298
+ return null;
299
+ }
300
+ const content = fs.readFileSync(checksumsPath, "utf8");
301
+ for (const line of content.split("\n")) {
302
+ const trimmed = line.trim();
303
+ if (!trimmed) continue;
304
+ const match = trimmed.match(/^([a-fA-F0-9]{64})\s+\*?(.+)$/);
305
+ if (!match) continue;
306
+ const hash = match[1];
307
+ const name = match[2];
308
+ if (name === archiveName) return hash;
309
+ }
310
+ throw new Error(`Checksum entry not found for ${archiveName}`);
311
+ }
312
+
313
+ function verifyChecksum(archivePath, expectedHash) {
314
+ if (expectedHash === null) return;
315
+ const hash = crypto.createHash("sha256");
316
+ const fd = fs.openSync(archivePath, "r");
317
+ try {
318
+ const buf = Buffer.alloc(64 * 1024);
319
+ let bytesRead;
320
+ while ((bytesRead = fs.readSync(fd, buf, 0, buf.length, null)) > 0) {
321
+ hash.update(buf.subarray(0, bytesRead));
322
+ }
323
+ } finally {
324
+ fs.closeSync(fd);
325
+ }
326
+ const actual = hash.digest("hex");
327
+ if (actual.toLowerCase() !== expectedHash.toLowerCase()) {
328
+ throw new Error(
329
+ `[SECURITY] Checksum mismatch for ${path.basename(archivePath)}: expected ${expectedHash} but got ${actual}`
330
+ );
331
+ }
332
+ }
333
+
334
+ // ── Main install ───────────────────────────────────────────────────────────
335
+
336
+ function install() {
337
+ fs.mkdirSync(binDir, { recursive: true });
338
+ var tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "delta-cli-"));
339
+ var archivePath = path.join(tmpDir, archiveName);
340
+
341
+ releaseAssetUrls(VERSION, archiveName, function(downloadUrls) {
342
+ try {
343
+ var lastErr;
344
+ var downloaded = false;
345
+ for (var i = 0; i < downloadUrls.length; i++) {
346
+ try {
347
+ console.error("Downloading from " + downloadUrls[i]);
348
+ download(downloadUrls[i], archivePath);
349
+ console.error("Download complete, verifying checksum...");
350
+ const expectedHash = getExpectedChecksum(archiveName);
351
+ verifyChecksum(archivePath, expectedHash);
352
+ console.error("Checksum verified");
353
+ downloaded = true;
354
+ break;
355
+ } catch (e) {
356
+ console.error("Failed: " + e.message + " (" + downloadUrls[i] + ")");
357
+ lastErr = e;
358
+ }
359
+ }
360
+ if (!downloaded) throw lastErr;
361
+
362
+ if (isWindows) {
363
+ console.error("Extracting archive...");
364
+ extractZipWindows(archivePath, tmpDir);
365
+ } else {
366
+ console.error("Extracting archive...");
367
+ execFileSync("tar", ["-xzf", archivePath, "-C", tmpDir], { stdio: "ignore" });
368
+ }
369
+
370
+ const binaryName = NAME + (isWindows ? ".exe" : "");
371
+ const extractedBinary = path.join(tmpDir, NAME + "-" + platform + "-" + arch);
372
+ if (fs.existsSync(extractedBinary)) {
373
+ fs.copyFileSync(extractedBinary, dest);
374
+ } else {
375
+ // Fallback: try the plain name (older release format)
376
+ const plainBinary = path.join(tmpDir, binaryName);
377
+ if (fs.existsSync(plainBinary)) {
378
+ fs.copyFileSync(plainBinary, dest);
379
+ } else {
380
+ // Search in tmpDir
381
+ const files = fs.readdirSync(tmpDir).filter(function(f) { return f.indexOf(NAME) !== -1 || f.indexOf(binaryName) !== -1; });
382
+ if (files.length > 0) {
383
+ fs.copyFileSync(path.join(tmpDir, files[0]), dest);
384
+ } else {
385
+ throw new Error("Binary not found in extracted archive. Files: " + fs.readdirSync(tmpDir).join(", "));
386
+ }
387
+ }
388
+ }
389
+ fs.chmodSync(dest, 0o755);
390
+ ensureExecutable(path.join(__dirname, "run.js"));
391
+ console.error("Installed to " + dest);
392
+ } finally {
393
+ fs.rmSync(tmpDir, { recursive: true, force: true });
394
+ }
395
+ });
396
+ }
397
+
398
+ function ensureExecutable(filePath) {
399
+ try {
400
+ if (fs.existsSync(filePath)) fs.chmodSync(filePath, 0o755);
401
+ } catch {}
402
+ }
403
+
404
+ // ── Entry ──────────────────────────────────────────────────────────────────
405
+
406
+ if (require.main === module) {
407
+ if (!platform || !arch) {
408
+ console.error(`Unsupported platform: ${process.platform}-${process.arch}`);
409
+ process.exit(1);
410
+ }
411
+
412
+ // npx postinstall guard: skip binary download in ephemeral npx context
413
+ const isNpxPostinstall =
414
+ process.env.npm_command === "exec" && !process.env.DELTA_CLI_RUN;
415
+
416
+ if (isNpxPostinstall) {
417
+ process.exit(0);
418
+ }
419
+
420
+ try {
421
+ install();
422
+ console.log(`${NAME} v${VERSION} installed successfully`);
423
+ } catch (err) {
424
+ console.error(`Failed to install ${NAME}:`, err.message);
425
+ console.error(
426
+ `\nIf you are behind a firewall or in a restricted network, try one of:\n` +
427
+ ` # 1. Use a proxy:\n` +
428
+ ` export https_proxy=http://your-proxy:port\n` +
429
+ ` npm install -g ${PKG}\n\n` +
430
+ ` # 2. Point to a corporate npm mirror:\n` +
431
+ ` npm install -g ${PKG} --registry=https://your-corp-mirror/\n` +
432
+ `\nOr manually download from:\n` +
433
+ ` https://github.com/${REPO}/releases/tag/v${VERSION}`
434
+ );
435
+ process.exit(1);
436
+ }
437
+ }
438
+
439
+ module.exports = {
440
+ getExpectedChecksum, verifyChecksum, assertAllowedHost,
441
+ isCurlVersionSupported, curlSupportsSslRevokeBestEffort,
442
+ };