@leonmw/agw 0.0.0-dev.6f293f8ce174
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/bin/agw.js +155 -0
- package/package.json +24 -0
package/bin/agw.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawnSync } = require("node:child_process");
|
|
4
|
+
const fs = require("node:fs");
|
|
5
|
+
const os = require("node:os");
|
|
6
|
+
const path = require("node:path");
|
|
7
|
+
|
|
8
|
+
const MAIN_PACKAGE_NAME = "@leonmw/agw";
|
|
9
|
+
|
|
10
|
+
const platformPackageMap = {
|
|
11
|
+
"linux-x64": { packageName: "@leonmw/agw-linux-x64", binaryPath: "bin/agw" },
|
|
12
|
+
"darwin-arm64": { packageName: "@leonmw/agw-darwin-arm64", binaryPath: "bin/agw" },
|
|
13
|
+
"win32-x64": { packageName: "@leonmw/agw-win32-x64", binaryPath: "bin/agw.exe" }
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function getPackageForHost() {
|
|
17
|
+
const key = `${process.platform}-${process.arch}`;
|
|
18
|
+
return platformPackageMap[key] ?? null;
|
|
19
|
+
}
|
|
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", "--prefer-online", 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
|
+
|
|
80
|
+
function resolveHostBinaryPath() {
|
|
81
|
+
const match = getPackageForHost();
|
|
82
|
+
if (!match) {
|
|
83
|
+
const supported = Object.keys(platformPackageMap).join(", ");
|
|
84
|
+
throw new Error(`Unsupported platform '${process.platform}-${process.arch}'. Supported: ${supported}.`);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const resolved = tryResolveHostBinaryPath(match);
|
|
88
|
+
if (resolved) {
|
|
89
|
+
return resolved;
|
|
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
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function run() {
|
|
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
|
+
|
|
113
|
+
const handoffFile = process.platform === "win32"
|
|
114
|
+
? path.join(os.tmpdir(), `agw-update-${process.pid}-${Date.now()}.txt`)
|
|
115
|
+
: null;
|
|
116
|
+
const env = handoffFile
|
|
117
|
+
? { ...process.env, AGW_UPDATE_HANDOFF_FILE: handoffFile }
|
|
118
|
+
: process.env;
|
|
119
|
+
|
|
120
|
+
const result = spawnSync(binaryPath, args, {
|
|
121
|
+
stdio: "inherit",
|
|
122
|
+
env
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
if (result.error) {
|
|
126
|
+
throw result.error;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (handoffFile && fs.existsSync(handoffFile)) {
|
|
130
|
+
let packageSpec = "";
|
|
131
|
+
try {
|
|
132
|
+
packageSpec = fs.readFileSync(handoffFile, "utf8").trim();
|
|
133
|
+
} finally {
|
|
134
|
+
try {
|
|
135
|
+
fs.unlinkSync(handoffFile);
|
|
136
|
+
} catch {
|
|
137
|
+
// Best effort cleanup
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (packageSpec) {
|
|
142
|
+
process.exit(runNpmGlobalInstall(packageSpec));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
process.exit(result.status ?? 1);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
run();
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
153
|
+
console.error(`agw launcher error: ${message}`);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@leonmw/agw",
|
|
3
|
+
"version": "0.0.0-dev.6f293f8ce174",
|
|
4
|
+
"description": "Run Antigravity CLI in Docker with strict isolation, persistent state, and profile management.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"bin": {
|
|
7
|
+
"agw": "bin/agw.js",
|
|
8
|
+
"agy-wrap": "bin/agw.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin/"
|
|
12
|
+
],
|
|
13
|
+
"optionalDependencies": {
|
|
14
|
+
"@leonmw/agw-linux-x64": "0.0.0-dev.6f293f8ce174",
|
|
15
|
+
"@leonmw/agw-darwin-arm64": "0.0.0-dev.6f293f8ce174",
|
|
16
|
+
"@leonmw/agw-win32-x64": "0.0.0-dev.6f293f8ce174"
|
|
17
|
+
},
|
|
18
|
+
"engines": {
|
|
19
|
+
"node": ">=18"
|
|
20
|
+
},
|
|
21
|
+
"publishConfig": {
|
|
22
|
+
"access": "public"
|
|
23
|
+
}
|
|
24
|
+
}
|