@awebai/aw 0.11.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.
Files changed (3) hide show
  1. package/bin/aw +39 -0
  2. package/install.js +134 -0
  3. package/package.json +28 -0
package/bin/aw ADDED
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ const { execFileSync } = require("child_process");
4
+ const os = require("os");
5
+ const path = require("path");
6
+
7
+ const PLATFORMS = {
8
+ "linux x64": { pkg: "@awebai/aw-linux-x64", bin: "bin/aw" },
9
+ "linux arm64": { pkg: "@awebai/aw-linux-arm64", bin: "bin/aw" },
10
+ "darwin x64": { pkg: "@awebai/aw-darwin-x64", bin: "bin/aw" },
11
+ "darwin arm64": { pkg: "@awebai/aw-darwin-arm64", bin: "bin/aw" },
12
+ "win32 x64": { pkg: "@awebai/aw-windows-x64", bin: "bin/aw.exe" },
13
+ "win32 arm64": { pkg: "@awebai/aw-windows-arm64", bin: "bin/aw.exe" },
14
+ };
15
+
16
+ const key = `${process.platform} ${os.arch()}`;
17
+ const platform = PLATFORMS[key];
18
+ if (!platform) {
19
+ console.error(`Error: Unsupported platform: ${key}`);
20
+ console.error("Visit https://github.com/awebai/aw for installation alternatives.");
21
+ process.exit(1);
22
+ }
23
+
24
+ let binPath;
25
+ try {
26
+ binPath = require.resolve(`${platform.pkg}/${platform.bin}`);
27
+ } catch {
28
+ console.error(`Error: Could not find the aw binary for ${key}.`);
29
+ console.error("The platform-specific package may not have been installed.");
30
+ console.error("Try: npm install @awebai/aw --force");
31
+ process.exit(1);
32
+ }
33
+
34
+ try {
35
+ const result = execFileSync(binPath, process.argv.slice(2), { stdio: "inherit" });
36
+ } catch (e) {
37
+ if (e.status !== null) process.exit(e.status);
38
+ throw e;
39
+ }
package/install.js ADDED
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ const fs = require("fs");
3
+ const os = require("os");
4
+ const path = require("path");
5
+ const { execFileSync } = require("child_process");
6
+
7
+ const PLATFORMS = {
8
+ "linux x64": { pkg: "@awebai/aw-linux-x64", bin: "bin/aw" },
9
+ "linux arm64": { pkg: "@awebai/aw-linux-arm64", bin: "bin/aw" },
10
+ "darwin x64": { pkg: "@awebai/aw-darwin-x64", bin: "bin/aw" },
11
+ "darwin arm64": { pkg: "@awebai/aw-darwin-arm64", bin: "bin/aw" },
12
+ "win32 x64": { pkg: "@awebai/aw-windows-x64", bin: "bin/aw.exe" },
13
+ "win32 arm64": { pkg: "@awebai/aw-windows-arm64", bin: "bin/aw.exe" },
14
+ };
15
+
16
+ function main() {
17
+ const key = `${process.platform} ${os.arch()}`;
18
+ const platform = PLATFORMS[key];
19
+
20
+ if (!platform) {
21
+ console.error(`[aw] Warning: unsupported platform ${key}, bin/aw JS wrapper will be used`);
22
+ return;
23
+ }
24
+
25
+ // Locate the platform binary
26
+ let binPath;
27
+ try {
28
+ binPath = require.resolve(`${platform.pkg}/${platform.bin}`);
29
+ } catch {
30
+ // Platform package not installed (--no-optional). Try direct npm install as fallback.
31
+ try {
32
+ console.error(`[aw] Platform package not found, attempting direct install of ${platform.pkg}...`);
33
+ const version = require(path.join(__dirname, "package.json")).version;
34
+ const installDir = path.join(__dirname, "npm-install");
35
+ fs.mkdirSync(installDir, { recursive: true });
36
+ fs.writeFileSync(path.join(installDir, "package.json"), "{}");
37
+ execFileSync("npm", [
38
+ "install", "--loglevel=error", "--prefer-offline",
39
+ "--no-audit", "--progress=false",
40
+ `${platform.pkg}@${version}`
41
+ ], { cwd: installDir, stdio: "pipe" });
42
+ binPath = path.join(installDir, "node_modules", platform.pkg, platform.bin);
43
+ } catch (e) {
44
+ // Final fallback: try downloading the tarball directly from npm registry
45
+ try {
46
+ binPath = downloadFromRegistry(platform, key);
47
+ } catch {
48
+ console.error(`[aw] Warning: could not install platform package. The JS wrapper will be used.`);
49
+ return;
50
+ }
51
+ }
52
+ }
53
+
54
+ // On Unix (not Yarn), try to hard-link the native binary over the JS launcher
55
+ const toPath = path.join(__dirname, "bin", "aw");
56
+ if (process.platform !== "win32" && !isYarn()) {
57
+ try {
58
+ const tempPath = toPath + ".tmp";
59
+ fs.linkSync(binPath, tempPath);
60
+ fs.renameSync(tempPath, toPath);
61
+ return; // Success: bin/aw is now the native binary
62
+ } catch {
63
+ // Fall through: leave JS wrapper in place
64
+ }
65
+ }
66
+
67
+ // Verify the binary is accessible via the JS wrapper
68
+ try {
69
+ execFileSync(binPath, ["version"], { stdio: "pipe" });
70
+ } catch {
71
+ // Binary exists but couldn't run version check — that's OK
72
+ }
73
+ }
74
+
75
+ function downloadFromRegistry(platform, key) {
76
+ const version = require(path.join(__dirname, "package.json")).version;
77
+ const suffix = platform.pkg.replace("@awebai/", "");
78
+ const url = `https://registry.npmjs.org/@awebai/${suffix}/-/${suffix}-${version}.tgz`;
79
+
80
+ console.error(`[aw] Downloading ${url}...`);
81
+
82
+ // Synchronous download using child_process
83
+ const tgzPath = path.join(__dirname, `${suffix}.tgz`);
84
+ execFileSync("node", ["-e", [
85
+ 'const https = require("https");',
86
+ 'const fs = require("fs");',
87
+ "function fetch(url) {",
88
+ " return new Promise((resolve, reject) => {",
89
+ " https.get(url, res => {",
90
+ " if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location)",
91
+ " return fetch(res.headers.location).then(resolve, reject);",
92
+ " if (res.statusCode !== 200)",
93
+ ' return reject(new Error("HTTP " + res.statusCode));',
94
+ " const chunks = [];",
95
+ ' res.on("data", c => chunks.push(c));',
96
+ ' res.on("end", () => resolve(Buffer.concat(chunks)));',
97
+ " }).on(\"error\", reject);",
98
+ " });",
99
+ "}",
100
+ `fetch(${JSON.stringify(url)}).then(buf => fs.writeFileSync(${JSON.stringify(tgzPath)}, buf));`,
101
+ ].join("\n")], { stdio: "pipe" });
102
+
103
+ // Extract the binary from the tarball
104
+ const tar = execFileSync("tar", ["tzf", tgzPath], { stdio: "pipe" }).toString();
105
+ const binEntry = tar.split("\n").find(e => e.endsWith(platform.bin.split("/").pop()));
106
+ if (!binEntry) throw new Error("Binary not found in tarball");
107
+
108
+ const extractDir = path.join(__dirname, "npm-extract");
109
+ fs.mkdirSync(extractDir, { recursive: true });
110
+ execFileSync("tar", ["xzf", tgzPath, "-C", extractDir], { stdio: "pipe" });
111
+
112
+ const extractedBin = path.join(extractDir, binEntry);
113
+ const targetBin = path.join(__dirname, "bin", process.platform === "win32" ? "aw.exe" : "aw");
114
+ fs.copyFileSync(extractedBin, targetBin);
115
+ fs.chmodSync(targetBin, 0o755);
116
+
117
+ // Cleanup
118
+ try { fs.unlinkSync(tgzPath); } catch {}
119
+ try { fs.rmSync(extractDir, { recursive: true }); } catch {}
120
+
121
+ return targetBin;
122
+ }
123
+
124
+ function isYarn() {
125
+ const agent = process.env.npm_config_user_agent || "";
126
+ return /\byarn\//.test(agent);
127
+ }
128
+
129
+ try {
130
+ main();
131
+ } catch (e) {
132
+ // Postinstall must never fail the overall install
133
+ console.error(`[aw] Warning: postinstall encountered an error: ${e.message}`);
134
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@awebai/aw",
3
+ "version": "0.11.0",
4
+ "description": "CLI for the aWeb agent coordination protocol",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/awebai/aw.git"
8
+ },
9
+ "license": "MIT",
10
+ "bin": {
11
+ "aw": "bin/aw"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node install.js"
15
+ },
16
+ "engines": {
17
+ "node": ">=16"
18
+ },
19
+ "preferUnplugged": true,
20
+ "optionalDependencies": {
21
+ "@awebai/aw-linux-x64": "0.11.0",
22
+ "@awebai/aw-linux-arm64": "0.11.0",
23
+ "@awebai/aw-darwin-x64": "0.11.0",
24
+ "@awebai/aw-darwin-arm64": "0.11.0",
25
+ "@awebai/aw-windows-x64": "0.11.0",
26
+ "@awebai/aw-windows-arm64": "0.11.0"
27
+ }
28
+ }