@yuanchuan/aivo 0.14.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yuanchuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # @yuanchuan/aivo
2
+
3
+ npm wrapper for the [`aivo`](https://github.com/yuanchuan/aivo) Rust CLI.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install -g @yuanchuan/aivo
9
+ ```
10
+
11
+ This package downloads the matching prebuilt binary for your platform during install.
12
+
13
+ ## Update
14
+
15
+ ```bash
16
+ npm install -g @yuanchuan/aivo@latest
17
+ ```
18
+
19
+ Or:
20
+
21
+ ```bash
22
+ npm update -g @yuanchuan/aivo
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ ```bash
28
+ aivo --version
29
+ aivo chat
30
+ ```
package/bin/aivo.js ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require("node:child_process");
4
+ const fs = require("node:fs");
5
+ const { getInstalledBinaryPath } = require("../lib/paths");
6
+
7
+ const binaryPath = getInstalledBinaryPath();
8
+
9
+ if (!fs.existsSync(binaryPath)) {
10
+ console.error("aivo binary is not installed.");
11
+ console.error("Reinstall with: npm install -g @yuanchuan/aivo");
12
+ process.exit(1);
13
+ }
14
+
15
+ const child = spawn(binaryPath, process.argv.slice(2), {
16
+ stdio: "inherit"
17
+ });
18
+
19
+ child.on("exit", (code, signal) => {
20
+ if (signal) {
21
+ process.kill(process.pid, signal);
22
+ return;
23
+ }
24
+
25
+ process.exit(code ?? 1);
26
+ });
27
+
28
+ child.on("error", (error) => {
29
+ console.error(`Failed to launch aivo: ${error.message}`);
30
+ process.exit(1);
31
+ });
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ const { createHash } = require("node:crypto");
4
+
5
+ function normalizeSha256(value) {
6
+ const trimmed = value.trim().toLowerCase();
7
+ if (!/^[a-f0-9]{64}$/.test(trimmed)) {
8
+ return null;
9
+ }
10
+ return trimmed;
11
+ }
12
+
13
+ function parseChecksumText(text, expectedName) {
14
+ let fallbackHash = null;
15
+
16
+ for (const rawLine of text.split(/\r?\n/)) {
17
+ const line = rawLine.trim();
18
+ if (!line || line.startsWith("#")) {
19
+ continue;
20
+ }
21
+
22
+ const bsdMatch = line.match(/^SHA256 \((.+)\) = ([a-fA-F0-9]{64})$/);
23
+ if (bsdMatch) {
24
+ const [, name, hash] = bsdMatch;
25
+ if (!expectedName || name.endsWith(expectedName)) {
26
+ return normalizeSha256(hash);
27
+ }
28
+ continue;
29
+ }
30
+
31
+ const parts = line.split(/\s+/);
32
+ const hash = normalizeSha256(parts[0] || "");
33
+ if (!hash) {
34
+ continue;
35
+ }
36
+
37
+ const remainder = line.slice(parts[0].length).trim().replace(/^\*\s*/, "");
38
+ if (!remainder) {
39
+ fallbackHash = hash;
40
+ continue;
41
+ }
42
+
43
+ if (remainder === expectedName || remainder.endsWith(`/${expectedName}`)) {
44
+ return hash;
45
+ }
46
+ }
47
+
48
+ return fallbackHash;
49
+ }
50
+
51
+ function sha256(buffer) {
52
+ return createHash("sha256").update(buffer).digest("hex");
53
+ }
54
+
55
+ module.exports = {
56
+ normalizeSha256,
57
+ parseChecksumText,
58
+ sha256
59
+ };
package/lib/paths.js ADDED
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+
3
+ const path = require("node:path");
4
+ const { resolvePlatformAsset } = require("./platform");
5
+
6
+ function getPackageRoot() {
7
+ return path.resolve(__dirname, "..");
8
+ }
9
+
10
+ function getNativeDir() {
11
+ return path.join(getPackageRoot(), "native");
12
+ }
13
+
14
+ function getInstalledBinaryPath(platform = process.platform, arch = process.arch) {
15
+ const { binaryName } = resolvePlatformAsset(platform, arch);
16
+ return path.join(getNativeDir(), binaryName);
17
+ }
18
+
19
+ module.exports = {
20
+ getInstalledBinaryPath,
21
+ getNativeDir,
22
+ getPackageRoot
23
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ const PLATFORM_ASSETS = {
4
+ darwin: {
5
+ arm64: "aivo-darwin-arm64",
6
+ x64: "aivo-darwin-x64"
7
+ },
8
+ linux: {
9
+ arm64: "aivo-linux-arm64",
10
+ x64: "aivo-linux-x64"
11
+ },
12
+ win32: {
13
+ x64: "aivo-windows-x64.exe"
14
+ }
15
+ };
16
+
17
+ function resolvePlatformAsset(platform = process.platform, arch = process.arch) {
18
+ const platformAssets = PLATFORM_ASSETS[platform];
19
+ const assetName = platformAssets && platformAssets[arch];
20
+
21
+ if (!assetName) {
22
+ throw new Error(
23
+ `Unsupported platform: ${platform}-${arch}. ` +
24
+ "Supported targets: darwin-arm64, darwin-x64, linux-arm64, linux-x64, win32-x64."
25
+ );
26
+ }
27
+
28
+ return {
29
+ assetName,
30
+ binaryName: platform === "win32" ? "aivo.exe" : "aivo"
31
+ };
32
+ }
33
+
34
+ module.exports = {
35
+ PLATFORM_ASSETS,
36
+ resolvePlatformAsset
37
+ };
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@yuanchuan/aivo",
3
+ "version": "0.14.0",
4
+ "description": "npm wrapper for the aivo CLI",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/yuanchuan/aivo.git",
9
+ "directory": "npm"
10
+ },
11
+ "homepage": "https://github.com/yuanchuan/aivo",
12
+ "bin": {
13
+ "aivo": "bin/aivo.js"
14
+ },
15
+ "files": [
16
+ "bin",
17
+ "lib",
18
+ "scripts",
19
+ "README.md",
20
+ "LICENSE"
21
+ ],
22
+ "scripts": {
23
+ "postinstall": "node scripts/postinstall.js",
24
+ "test": "node --test"
25
+ },
26
+ "keywords": [
27
+ "aivo",
28
+ "cli",
29
+ "ai",
30
+ "rust"
31
+ ],
32
+ "engines": {
33
+ "node": ">=18"
34
+ },
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
+ }
@@ -0,0 +1,97 @@
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 { parseChecksumText, sha256 } = require("../lib/checksum");
8
+ const { getInstalledBinaryPath, getNativeDir, getPackageRoot } = require("../lib/paths");
9
+ const { resolvePlatformAsset } = require("../lib/platform");
10
+
11
+ const pkg = require(path.join(getPackageRoot(), "package.json"));
12
+
13
+ async function main() {
14
+ if (process.env.AIVO_SKIP_POSTINSTALL === "1") {
15
+ return;
16
+ }
17
+
18
+ const { assetName } = resolvePlatformAsset();
19
+ const version = pkg.version;
20
+ const baseUrl =
21
+ process.env.AIVO_INSTALL_BASE_URL ||
22
+ `https://github.com/yuanchuan/aivo/releases/download/v${version}`;
23
+ const checksumUrl = `${baseUrl}/${assetName}.sha256`;
24
+ const binaryUrl = `${baseUrl}/${assetName}`;
25
+
26
+ const checksumText = await downloadText(checksumUrl);
27
+ const expectedSha = parseChecksumText(checksumText, assetName);
28
+
29
+ if (!expectedSha) {
30
+ throw new Error(`Checksum asset for ${assetName} could not be parsed.`);
31
+ }
32
+
33
+ const binary = await downloadBuffer(binaryUrl);
34
+ const actualSha = sha256(binary);
35
+ if (actualSha !== expectedSha) {
36
+ throw new Error(`Checksum verification failed for ${assetName}.`);
37
+ }
38
+
39
+ const nativeDir = getNativeDir();
40
+ const binaryPath = getInstalledBinaryPath();
41
+ fs.mkdirSync(nativeDir, { recursive: true });
42
+ fs.writeFileSync(binaryPath, binary);
43
+
44
+ if (process.platform !== "win32") {
45
+ fs.chmodSync(binaryPath, 0o755);
46
+ }
47
+
48
+ console.log(`Installed aivo ${version} (${assetName})`);
49
+ }
50
+
51
+ function downloadText(url) {
52
+ return downloadBuffer(url).then((buffer) => buffer.toString("utf8"));
53
+ }
54
+
55
+ function downloadBuffer(url, redirectCount = 0) {
56
+ return new Promise((resolve, reject) => {
57
+ const request = https.get(
58
+ url,
59
+ {
60
+ headers: {
61
+ "User-Agent": "@yuanchuan/aivo-installer"
62
+ }
63
+ },
64
+ (response) => {
65
+ const status = response.statusCode || 0;
66
+
67
+ if (
68
+ status >= 300 &&
69
+ status < 400 &&
70
+ response.headers.location &&
71
+ redirectCount < 5
72
+ ) {
73
+ response.resume();
74
+ resolve(downloadBuffer(response.headers.location, redirectCount + 1));
75
+ return;
76
+ }
77
+
78
+ if (status < 200 || status >= 300) {
79
+ reject(new Error(`Download failed: ${status} ${url}`));
80
+ response.resume();
81
+ return;
82
+ }
83
+
84
+ const chunks = [];
85
+ response.on("data", (chunk) => chunks.push(chunk));
86
+ response.on("end", () => resolve(Buffer.concat(chunks)));
87
+ }
88
+ );
89
+
90
+ request.on("error", reject);
91
+ });
92
+ }
93
+
94
+ main().catch((error) => {
95
+ console.error(error.message);
96
+ process.exitCode = 1;
97
+ });