ailoom-cli 0.0.0-draft

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 (3) hide show
  1. package/PLATFORMS.md +17 -0
  2. package/cli.js +63 -0
  3. package/package.json +20 -0
package/PLATFORMS.md ADDED
@@ -0,0 +1,17 @@
1
+ # 平台矩阵(npm 包装器)
2
+
3
+ | OS | Arch | 三元组 | 状态 |
4
+ |---|---|---|---|
5
+ | macOS (darwin) | arm64 / x64 | aarch64-apple-darwin | 设计支持(发布前验证) |
6
+ | Linux | x64 / arm64 | x86_64 / aarch64-unknown-linux-gnu | 设计支持(发布前验证) |
7
+ | Windows | x64 | x86_64-pc-windows-msvc | 设计支持(发布前验证) |
8
+
9
+ ## 下载与离线
10
+
11
+ - 制品:`{BASE}/{version}/ailoom-{version}-{三元组}[.exe]` + 同名 `.sha256`
12
+ - `AILOOM_DOWNLOAD_BASE` 可指向内网镜像;完全离线环境手动放置二进制到 `~/.ailoom/bin/`
13
+ - 校验:安装前 sha256 必须匹配 `.sha256`;失败拒绝运行
14
+
15
+ ## 版本对应
16
+
17
+ - npm 包版本与 Rust crate 版本一一对应(release workflow 由 Cargo.toml tag 触发并注入 VERSION 文件)
package/cli.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * AILoom npm 包装器(设计稿 v0,AIL-029)。
4
+ * 职责:定位/下载平台匹配的 ailoom 二进制 → sha256 校验 → 透传参数。
5
+ * 状态:设计稿。发布与下载 URL 由 release workflow 落地后接线(docs/RELEASE-CHECKLIST.md)。
6
+ */
7
+ import { createHash } from "node:crypto";
8
+ import { existsSync, mkdirSync, readFileSync, renameSync } from "node:fs";
9
+ import { homedir, platform, arch } from "node:os";
10
+ import { join } from "node:path";
11
+ import { spawnSync } from "node:child_process";
12
+
13
+ const BASE_URL = process.env.AILOOM_DOWNLOAD_BASE ?? "https://example.invalid/ailoom/releases";
14
+ const VERSION = "0.0.0-draft";
15
+
16
+ function triple() {
17
+ const p = platform();
18
+ const a = arch();
19
+ if (p === "darwin") return "aarch64-apple-darwin";
20
+ if (p === "linux" && a === "x64") return "x86_64-unknown-linux-gnu";
21
+ if (p === "linux" && a === "arm64") return "aarch64-unknown-linux-gnu";
22
+ if (p === "win32" && a === "x64") return "x86_64-pc-windows-msvc";
23
+ fail(`不支持的平台 ${p}/${a};矩阵见 packaging/npm/PLATFORMS.md`);
24
+ }
25
+
26
+ function fail(message) {
27
+ console.error(`[ailoom] ${message}`);
28
+ console.error("诊断:代理环境设置 HTTPS_PROXY / AILOOM_DOWNLOAD_BASE(离线镜像);");
29
+ console.error("或手动下载二进制放入 ~/.ailoom/bin/。详见 packaging/npm/PLATFORMS.md。");
30
+ process.exit(1);
31
+ }
32
+
33
+ function binaryPath() {
34
+ const ext = platform() === "win32" ? ".exe" : "";
35
+ const dir = process.env.AILOOM_BIN_DIR ?? join(homedir(), ".ailoom", "bin");
36
+ return join(dir, `ailoom-${triple()}${ext}`);
37
+ }
38
+
39
+ function verifySha256(file, expectedFile) {
40
+ // 校验清单与制品同源发布;缺失或失败即拒绝运行
41
+ if (!existsSync(expectedFile)) fail(`缺少校验文件,拒绝运行未校验制品`);
42
+ const expected = readFileSync(expectedFile, "utf8").trim().split(/\s+/)[0];
43
+ const actual = createHash("sha256").update(readFileSync(file)).digest("hex");
44
+ if (actual !== expected) fail(`制品校验失败(sha256 不匹配)`);
45
+ }
46
+
47
+ function main() {
48
+ const bin = binaryPath();
49
+ if (!existsSync(bin)) {
50
+ // 设计稿:下载逻辑由 release workflow 落地后接线(download → verify → rename → chmod)
51
+ fail(
52
+ `未找到二进制 ${bin}。\n设计稿尚未接线下载;请在 AILOOM_BIN_DIR 放置对应平台二进制。`
53
+ );
54
+ }
55
+ verifySha256(bin, `${bin}.sha256`);
56
+ const result = spawnSync(bin, process.argv.slice(2), { stdio: "inherit" });
57
+ process.exit(result.status ?? 1);
58
+ }
59
+
60
+ if (process.argv[1] && import.meta.url.endsWith(process.argv[1].split("/").pop())) {
61
+ mkdirSync(join(homedir(), ".ailoom", "bin"), { recursive: true });
62
+ main();
63
+ }
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "ailoom-cli",
3
+ "version": "0.0.0-draft",
4
+ "description": "AILoom npm wrapper: locates and runs the platform ailoom binary (no Rust toolchain required)",
5
+ "license": "Apache-2.0",
6
+ "bin": {
7
+ "ailoom": "./cli.js"
8
+ },
9
+ "engines": {
10
+ "node": ">=18"
11
+ },
12
+ "files": ["cli.js", "PLATFORMS.md"],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://example.invalid/ailoom"
16
+ },
17
+ "publishConfig": {
18
+ "access": "public"
19
+ }
20
+ }