agent-web-os 0.1.3 → 0.1.4
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/dist/index.cjs +159 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +159 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -60304,6 +60304,7 @@ var ALMOSTNODE_INTERNAL_ROOT = "/.almostnode";
|
|
|
60304
60304
|
var ALMOSTNODE_NODE_VERSION = "v20.0.0";
|
|
60305
60305
|
var ALMOSTNODE_NPM_VERSION = "9.6.4";
|
|
60306
60306
|
var NODE_EXEC_PATH = "/usr/local/bin/node";
|
|
60307
|
+
var GLOBAL_NODE_MODULES_ROOT = "/usr/local/lib/node_modules";
|
|
60307
60308
|
var DEFAULT_PATH = "/usr/local/bin:/usr/bin:/bin:/node_modules/.bin";
|
|
60308
60309
|
var NPM_USAGE = [
|
|
60309
60310
|
"Usage: npm <command>",
|
|
@@ -60936,6 +60937,19 @@ var AlmostNodeSession = class {
|
|
|
60936
60937
|
this.vitePreviewUrl = null;
|
|
60937
60938
|
this.vitePreviewListener?.(null);
|
|
60938
60939
|
}
|
|
60940
|
+
resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir) {
|
|
60941
|
+
if (typeof pkgJson.bin === "string") {
|
|
60942
|
+
const inferredBinName = typeof pkgJson.name === "string" ? pkgJson.name.split("/").pop() ?? pkgJson.name : packageName.split("/").pop() ?? packageName;
|
|
60943
|
+
if (binName === inferredBinName) {
|
|
60944
|
+
return normalizePath(posixPath.join(pkgDir, pkgJson.bin));
|
|
60945
|
+
}
|
|
60946
|
+
}
|
|
60947
|
+
if (typeof pkgJson.bin === "object" && pkgJson.bin !== null && binName in pkgJson.bin) {
|
|
60948
|
+
const namedBins = pkgJson.bin;
|
|
60949
|
+
return normalizePath(posixPath.join(pkgDir, namedBins[binName]));
|
|
60950
|
+
}
|
|
60951
|
+
return null;
|
|
60952
|
+
}
|
|
60939
60953
|
async resolveNpmBinPath(binName, cwd) {
|
|
60940
60954
|
const candidatePackageNames = [binName];
|
|
60941
60955
|
const packageJsonResult = await this.readPackageJson(cwd);
|
|
@@ -60958,21 +60972,96 @@ var AlmostNodeSession = class {
|
|
|
60958
60972
|
continue;
|
|
60959
60973
|
}
|
|
60960
60974
|
const pkgDir = normalizePath(posixPath.join(cwd, "node_modules", packageName));
|
|
60961
|
-
|
|
60962
|
-
|
|
60963
|
-
|
|
60964
|
-
|
|
60975
|
+
const result = this.resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir);
|
|
60976
|
+
if (result) return result;
|
|
60977
|
+
} catch {
|
|
60978
|
+
}
|
|
60979
|
+
}
|
|
60980
|
+
const globalResult = await this.resolveGlobalBinPath(binName);
|
|
60981
|
+
if (globalResult) return globalResult;
|
|
60982
|
+
return null;
|
|
60983
|
+
}
|
|
60984
|
+
async resolveGlobalBinPath(binName) {
|
|
60985
|
+
try {
|
|
60986
|
+
const globalModulesDir = GLOBAL_NODE_MODULES_ROOT;
|
|
60987
|
+
if (!this._vfs.existsSync(globalModulesDir)) return null;
|
|
60988
|
+
const globalPackages = this._vfs.readdirSync(globalModulesDir);
|
|
60989
|
+
for (const entry of globalPackages) {
|
|
60990
|
+
const packageName = entry;
|
|
60991
|
+
const pkgJsonPath = normalizePath(posixPath.join(globalModulesDir, packageName, "package.json"));
|
|
60992
|
+
if (!this._vfs.existsSync(pkgJsonPath)) {
|
|
60993
|
+
if (entry.startsWith("@")) {
|
|
60994
|
+
try {
|
|
60995
|
+
const scopeDir = normalizePath(posixPath.join(globalModulesDir, entry));
|
|
60996
|
+
const scopedPackages = this._vfs.readdirSync(scopeDir);
|
|
60997
|
+
for (const scopedPkg of scopedPackages) {
|
|
60998
|
+
const scopedName = `${entry}/${scopedPkg}`;
|
|
60999
|
+
const scopedPkgJsonPath = normalizePath(posixPath.join(globalModulesDir, scopedName, "package.json"));
|
|
61000
|
+
if (!this._vfs.existsSync(scopedPkgJsonPath)) continue;
|
|
61001
|
+
const raw = this._vfs.readFileSync(scopedPkgJsonPath, "utf8");
|
|
61002
|
+
const pkgJson = this.parseCachedPackageJson(scopedPkgJsonPath, raw);
|
|
61003
|
+
if (!pkgJson) continue;
|
|
61004
|
+
const pkgDir = normalizePath(posixPath.join(globalModulesDir, scopedName));
|
|
61005
|
+
const result = this.resolveBinFromPackageJson(binName, scopedName, pkgJson, pkgDir);
|
|
61006
|
+
if (result) return result;
|
|
61007
|
+
}
|
|
61008
|
+
} catch {
|
|
61009
|
+
}
|
|
60965
61010
|
}
|
|
61011
|
+
continue;
|
|
60966
61012
|
}
|
|
60967
|
-
|
|
60968
|
-
const
|
|
60969
|
-
|
|
61013
|
+
try {
|
|
61014
|
+
const raw = this._vfs.readFileSync(pkgJsonPath, "utf8");
|
|
61015
|
+
const pkgJson = this.parseCachedPackageJson(pkgJsonPath, raw);
|
|
61016
|
+
if (!pkgJson) continue;
|
|
61017
|
+
const pkgDir = normalizePath(posixPath.join(globalModulesDir, packageName));
|
|
61018
|
+
const result = this.resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir);
|
|
61019
|
+
if (result) return result;
|
|
61020
|
+
} catch {
|
|
60970
61021
|
}
|
|
60971
|
-
} catch {
|
|
60972
61022
|
}
|
|
61023
|
+
} catch {
|
|
60973
61024
|
}
|
|
60974
61025
|
return null;
|
|
60975
61026
|
}
|
|
61027
|
+
extractBinNames(pkgJson) {
|
|
61028
|
+
if (typeof pkgJson.bin === "string") {
|
|
61029
|
+
const name = typeof pkgJson.name === "string" ? pkgJson.name.split("/").pop() ?? "" : "";
|
|
61030
|
+
return name ? [name] : [];
|
|
61031
|
+
}
|
|
61032
|
+
if (typeof pkgJson.bin === "object" && pkgJson.bin !== null) {
|
|
61033
|
+
return Object.keys(pkgJson.bin);
|
|
61034
|
+
}
|
|
61035
|
+
return [];
|
|
61036
|
+
}
|
|
61037
|
+
async registerGlobalBinCommands(packageName) {
|
|
61038
|
+
if (!this.binCommandRegistrar) return;
|
|
61039
|
+
const pkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, packageName, "package.json"));
|
|
61040
|
+
if (!this._vfs.existsSync(pkgJsonPath)) return;
|
|
61041
|
+
try {
|
|
61042
|
+
const raw = this._vfs.readFileSync(pkgJsonPath, "utf8");
|
|
61043
|
+
const pkgJson = this.parseCachedPackageJson(pkgJsonPath, raw);
|
|
61044
|
+
if (!pkgJson) return;
|
|
61045
|
+
const binNames = this.extractBinNames(pkgJson);
|
|
61046
|
+
for (const binName of binNames) {
|
|
61047
|
+
if (this.registeredBinCommands.has(binName)) continue;
|
|
61048
|
+
this.registeredBinCommands.add(binName);
|
|
61049
|
+
this.binCommandRegistrar(binName, async (args, ctx) => {
|
|
61050
|
+
const resolvedPath2 = await this.resolveGlobalBinPath(binName) ?? await this.resolveNpmBinPath(binName, normalizePath(ctx.cwd));
|
|
61051
|
+
if (!resolvedPath2) {
|
|
61052
|
+
return {
|
|
61053
|
+
stdout: "",
|
|
61054
|
+
stderr: `bash: ${binName}: command not found
|
|
61055
|
+
`,
|
|
61056
|
+
exitCode: 127
|
|
61057
|
+
};
|
|
61058
|
+
}
|
|
61059
|
+
return this.executeNode([resolvedPath2, ...args], ctx);
|
|
61060
|
+
});
|
|
61061
|
+
}
|
|
61062
|
+
} catch {
|
|
61063
|
+
}
|
|
61064
|
+
}
|
|
60976
61065
|
async resolveAndRegisterBinCommands(command, cwd) {
|
|
60977
61066
|
if (!this.binCommandRegistrar) {
|
|
60978
61067
|
return;
|
|
@@ -61341,6 +61430,7 @@ var AlmostNodeSession = class {
|
|
|
61341
61430
|
PATH: Array.from(/* @__PURE__ */ new Set([
|
|
61342
61431
|
normalizePath(posixPath.join(cwd, "node_modules/.bin")),
|
|
61343
61432
|
"/node_modules/.bin",
|
|
61433
|
+
`${GLOBAL_NODE_MODULES_ROOT}/.bin`,
|
|
61344
61434
|
...(baseEnv.PATH?.trim() || DEFAULT_PATH).split(":").filter(Boolean)
|
|
61345
61435
|
])).join(":")
|
|
61346
61436
|
};
|
|
@@ -61415,26 +61505,30 @@ var AlmostNodeSession = class {
|
|
|
61415
61505
|
case "install":
|
|
61416
61506
|
case "i":
|
|
61417
61507
|
case "add": {
|
|
61508
|
+
const isGlobal = args.includes("-g") || args.includes("--global");
|
|
61418
61509
|
const packageSpecs = args.slice(1).filter((arg) => !arg.startsWith("-"));
|
|
61419
61510
|
let stdout = "";
|
|
61420
61511
|
try {
|
|
61421
|
-
|
|
61422
|
-
|
|
61423
|
-
|
|
61424
|
-
|
|
61425
|
-
|
|
61426
|
-
|
|
61427
|
-
|
|
61428
|
-
|
|
61429
|
-
const
|
|
61430
|
-
|
|
61431
|
-
|
|
61432
|
-
|
|
61433
|
-
|
|
61434
|
-
|
|
61435
|
-
|
|
61436
|
-
|
|
61437
|
-
|
|
61512
|
+
if (isGlobal) {
|
|
61513
|
+
if (packageSpecs.length === 0) {
|
|
61514
|
+
result = { stdout: "", stderr: "npm ERR! npm install -g requires a package name\n", exitCode: 1 };
|
|
61515
|
+
break;
|
|
61516
|
+
}
|
|
61517
|
+
await ensureEsbuildWasm();
|
|
61518
|
+
this._vfs.mkdirSync(GLOBAL_NODE_MODULES_ROOT, { recursive: true });
|
|
61519
|
+
await ensureObservableDirectory(this.fs, GLOBAL_NODE_MODULES_ROOT);
|
|
61520
|
+
const globalPkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, "..", "package.json"));
|
|
61521
|
+
if (!this._vfs.existsSync(globalPkgJsonPath)) {
|
|
61522
|
+
const minimalPkg = JSON.stringify({ name: "global", version: "0.0.0", private: true }, null, 2);
|
|
61523
|
+
this._vfs.mkdirSync(posixPath.dirname(globalPkgJsonPath), { recursive: true });
|
|
61524
|
+
this._vfs.writeFileSync(globalPkgJsonPath, minimalPkg);
|
|
61525
|
+
await this.withSuppressedObservableMirroring(async () => {
|
|
61526
|
+
await ensureObservableDirectory(this.fs, posixPath.dirname(globalPkgJsonPath));
|
|
61527
|
+
await this.fs.writeFile(globalPkgJsonPath, minimalPkg);
|
|
61528
|
+
});
|
|
61529
|
+
}
|
|
61530
|
+
const globalCwd = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, ".."));
|
|
61531
|
+
const packageManager = new PackageManager(this.vfs, { cwd: globalCwd });
|
|
61438
61532
|
for (const packageSpec of packageSpecs) {
|
|
61439
61533
|
const installResult = await packageManager.install(packageSpec, {
|
|
61440
61534
|
save: true,
|
|
@@ -61445,9 +61539,48 @@ var AlmostNodeSession = class {
|
|
|
61445
61539
|
});
|
|
61446
61540
|
stdout += `added ${installResult.added.length} packages
|
|
61447
61541
|
`;
|
|
61542
|
+
const installedPkgName = packageSpec.replace(/@[^/]*$/, "") || packageSpec;
|
|
61543
|
+
await this.registerGlobalBinCommands(installedPkgName);
|
|
61544
|
+
for (const added of installResult.added) {
|
|
61545
|
+
const addedName = typeof added === "string" ? String(added).replace(/@[^/]*$/, "") : added?.name;
|
|
61546
|
+
if (addedName && addedName !== installedPkgName) {
|
|
61547
|
+
await this.registerGlobalBinCommands(addedName);
|
|
61548
|
+
}
|
|
61549
|
+
}
|
|
61550
|
+
}
|
|
61551
|
+
result = { stdout, stderr: "", exitCode: 0 };
|
|
61552
|
+
} else {
|
|
61553
|
+
const packageJsonResult = await this.readPackageJson(cwd);
|
|
61554
|
+
if ("error" in packageJsonResult) {
|
|
61555
|
+
result = packageJsonResult.error;
|
|
61556
|
+
break;
|
|
61557
|
+
}
|
|
61558
|
+
await ensureEsbuildWasm();
|
|
61559
|
+
const packageManager = new PackageManager(this.vfs, { cwd });
|
|
61560
|
+
if (packageSpecs.length === 0) {
|
|
61561
|
+
const installResult = await packageManager.installFromPackageJson({
|
|
61562
|
+
onProgress: (message) => {
|
|
61563
|
+
stdout += `${message}
|
|
61564
|
+
`;
|
|
61565
|
+
}
|
|
61566
|
+
});
|
|
61567
|
+
stdout += `added ${installResult.added.length} packages
|
|
61568
|
+
`;
|
|
61569
|
+
} else {
|
|
61570
|
+
for (const packageSpec of packageSpecs) {
|
|
61571
|
+
const installResult = await packageManager.install(packageSpec, {
|
|
61572
|
+
save: true,
|
|
61573
|
+
onProgress: (message) => {
|
|
61574
|
+
stdout += `${message}
|
|
61575
|
+
`;
|
|
61576
|
+
}
|
|
61577
|
+
});
|
|
61578
|
+
stdout += `added ${installResult.added.length} packages
|
|
61579
|
+
`;
|
|
61580
|
+
}
|
|
61448
61581
|
}
|
|
61582
|
+
result = { stdout, stderr: "", exitCode: 0 };
|
|
61449
61583
|
}
|
|
61450
|
-
result = { stdout, stderr: "", exitCode: 0 };
|
|
61451
61584
|
} catch (error) {
|
|
61452
61585
|
result = {
|
|
61453
61586
|
stdout,
|