@leonmw/agw 0.0.0-dev.aaebd2910a50 → 0.0.0-dev.b9a0f78692b7

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 (2) hide show
  1. package/bin/agw.js +85 -16
  2. package/package.json +4 -4
package/bin/agw.js CHANGED
@@ -5,6 +5,8 @@ const fs = require("node:fs");
5
5
  const os = require("node:os");
6
6
  const path = require("node:path");
7
7
 
8
+ const MAIN_PACKAGE_NAME = "@leonmw/agw";
9
+
8
10
  const platformPackageMap = {
9
11
  "linux-x64": { packageName: "@leonmw/agw-linux-x64", binaryPath: "bin/agw" },
10
12
  "darwin-arm64": { packageName: "@leonmw/agw-darwin-arm64", binaryPath: "bin/agw" },
@@ -16,6 +18,65 @@ function getPackageForHost() {
16
18
  return platformPackageMap[key] ?? null;
17
19
  }
18
20
 
21
+ function tryResolveHostBinaryPath(match) {
22
+ const candidates = [];
23
+
24
+ try {
25
+ candidates.push(require.resolve(`${match.packageName}/${match.binaryPath}`));
26
+ } catch {
27
+ // Try fallback locations below.
28
+ }
29
+
30
+ try {
31
+ const pkgJsonPath = require.resolve(`${match.packageName}/package.json`);
32
+ candidates.push(path.join(path.dirname(pkgJsonPath), match.binaryPath));
33
+ } catch {
34
+ // Try fallback locations below.
35
+ }
36
+
37
+ // Nested under @leonmw/agw/node_modules/@leonmw/agw-<platform>
38
+ candidates.push(path.join(__dirname, "..", "node_modules", match.packageName, match.binaryPath));
39
+
40
+ // Hoisted sibling under node_modules/@leonmw/agw-<platform>
41
+ candidates.push(path.join(__dirname, "..", "..", match.packageName, match.binaryPath));
42
+
43
+ for (const candidate of candidates) {
44
+ if (candidate && fs.existsSync(candidate)) {
45
+ return candidate;
46
+ }
47
+ }
48
+
49
+ return null;
50
+ }
51
+
52
+ function runNpmGlobalInstall(packageSpec) {
53
+ const updateResult = spawnSync("npm", ["install", "-g", packageSpec], {
54
+ stdio: "inherit",
55
+ shell: process.platform === "win32"
56
+ });
57
+ if (updateResult.error) {
58
+ throw updateResult.error;
59
+ }
60
+ return updateResult.status ?? 1;
61
+ }
62
+
63
+ function tryHandleMissingBinaryUpdate(args) {
64
+ if (args[0]?.toLowerCase() !== "update") {
65
+ return null;
66
+ }
67
+
68
+ const hasHelp = args.some((a) => a === "--help" || a === "-h" || a === "-?" || a === "/?");
69
+ if (hasHelp) {
70
+ return null;
71
+ }
72
+
73
+ const useDev = args.includes("--dev");
74
+ const distTag = useDev ? "dev" : "latest";
75
+ const packageSpec = `${MAIN_PACKAGE_NAME}@${distTag}`;
76
+ console.log(`Platform binary missing; reinstalling ${packageSpec}...`);
77
+ return runNpmGlobalInstall(packageSpec);
78
+ }
79
+
19
80
  function resolveHostBinaryPath() {
20
81
  const match = getPackageForHost();
21
82
  if (!match) {
@@ -23,17 +84,32 @@ function resolveHostBinaryPath() {
23
84
  throw new Error(`Unsupported platform '${process.platform}-${process.arch}'. Supported: ${supported}.`);
24
85
  }
25
86
 
26
- try {
27
- return require.resolve(`${match.packageName}/${match.binaryPath}`);
28
- } catch {
29
- throw new Error(
30
- `Missing platform binary package '${match.packageName}'. Reinstall with 'npm i -g @leonmw/agw'.`
31
- );
87
+ const resolved = tryResolveHostBinaryPath(match);
88
+ if (resolved) {
89
+ return resolved;
32
90
  }
91
+
92
+ const windowsHint = process.platform === "win32"
93
+ ? " If another 'agw' session is running, close it first (Windows locks agw.exe during npm install)."
94
+ : "";
95
+ throw new Error(
96
+ `Missing platform binary package '${match.packageName}'. Reinstall with 'npm i -g ${MAIN_PACKAGE_NAME}' (or 'agw update --dev').${windowsHint}`
97
+ );
33
98
  }
34
99
 
35
100
  function run() {
36
- const binaryPath = resolveHostBinaryPath();
101
+ const args = process.argv.slice(2);
102
+ const match = getPackageForHost();
103
+ let binaryPath = match ? tryResolveHostBinaryPath(match) : null;
104
+
105
+ if (!binaryPath) {
106
+ const fallbackStatus = tryHandleMissingBinaryUpdate(args);
107
+ if (fallbackStatus !== null) {
108
+ process.exit(fallbackStatus);
109
+ }
110
+ binaryPath = resolveHostBinaryPath();
111
+ }
112
+
37
113
  const handoffFile = process.platform === "win32"
38
114
  ? path.join(os.tmpdir(), `agw-update-${process.pid}-${Date.now()}.txt`)
39
115
  : null;
@@ -41,7 +117,7 @@ function run() {
41
117
  ? { ...process.env, AGW_UPDATE_HANDOFF_FILE: handoffFile }
42
118
  : process.env;
43
119
 
44
- const result = spawnSync(binaryPath, process.argv.slice(2), {
120
+ const result = spawnSync(binaryPath, args, {
45
121
  stdio: "inherit",
46
122
  env
47
123
  });
@@ -63,14 +139,7 @@ function run() {
63
139
  }
64
140
 
65
141
  if (packageSpec) {
66
- const updateResult = spawnSync("npm", ["install", "-g", packageSpec], {
67
- stdio: "inherit",
68
- shell: true
69
- });
70
- if (updateResult.error) {
71
- throw updateResult.error;
72
- }
73
- process.exit(updateResult.status ?? 1);
142
+ process.exit(runNpmGlobalInstall(packageSpec));
74
143
  }
75
144
  }
76
145
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leonmw/agw",
3
- "version": "0.0.0-dev.aaebd2910a50",
3
+ "version": "0.0.0-dev.b9a0f78692b7",
4
4
  "description": "Run Antigravity CLI in Docker with strict isolation, persistent state, and profile management.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -11,9 +11,9 @@
11
11
  "bin/"
12
12
  ],
13
13
  "optionalDependencies": {
14
- "@leonmw/agw-linux-x64": "0.0.0-dev.aaebd2910a50",
15
- "@leonmw/agw-darwin-arm64": "0.0.0-dev.aaebd2910a50",
16
- "@leonmw/agw-win32-x64": "0.0.0-dev.aaebd2910a50"
14
+ "@leonmw/agw-linux-x64": "0.0.0-dev.b9a0f78692b7",
15
+ "@leonmw/agw-darwin-arm64": "0.0.0-dev.b9a0f78692b7",
16
+ "@leonmw/agw-win32-x64": "0.0.0-dev.b9a0f78692b7"
17
17
  },
18
18
  "engines": {
19
19
  "node": ">=18"