agent-web-os 0.1.3 → 0.1.5

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 CHANGED
@@ -42349,19 +42349,6 @@ function assertObservableInMemoryFs(value) {
42349
42349
  }
42350
42350
  return value;
42351
42351
  }
42352
- function formatChangeEventForLog(event) {
42353
- const previousPathSuffix = event.previousPath ? ` (from ${event.previousPath})` : "";
42354
- return `[ObservableInMemoryFs] ${event.event} ${event.entryType} ${event.path}${previousPathSuffix}`;
42355
- }
42356
- function normalizeEntryType(stat) {
42357
- if (stat.isDirectory) {
42358
- return "directory";
42359
- }
42360
- if (stat.isSymbolicLink) {
42361
- return "symlink";
42362
- }
42363
- return "file";
42364
- }
42365
42352
  async function readPathState(fs, path2) {
42366
42353
  const exists = await fs.exists(path2);
42367
42354
  if (!exists) {
@@ -42374,35 +42361,19 @@ async function readPathState(fs, path2) {
42374
42361
  };
42375
42362
  }
42376
42363
  const stat = await fs.lstat(path2);
42364
+ const entryType = stat.isDirectory ? "directory" : stat.isSymbolicLink ? "symlink" : "file";
42377
42365
  return {
42378
42366
  exists: true,
42379
- entryType: normalizeEntryType(stat)
42367
+ entryType
42380
42368
  };
42381
42369
  }
42382
42370
  function mapAddEvent(entryType) {
42383
42371
  return entryType === "directory" ? "addDir" : "add";
42384
42372
  }
42385
- function mapUnlinkEvent(entryType) {
42386
- return entryType === "directory" ? "unlinkDir" : "unlink";
42387
- }
42388
42373
  function normalizeFsPathForLogScope(fsPath) {
42389
42374
  const normalized = posixPath.normalize(fsPath);
42390
42375
  return normalized === "." ? "/" : normalized;
42391
42376
  }
42392
- function createWorkspacePathFilter(workspaceRoot) {
42393
- const normalizedWorkspaceRoot = normalizeFsPathForLogScope(workspaceRoot);
42394
- return (fsPath) => {
42395
- const normalizedPath = normalizeFsPathForLogScope(fsPath);
42396
- if (normalizedPath !== normalizedWorkspaceRoot && !normalizedPath.startsWith(`${normalizedWorkspaceRoot}/`)) {
42397
- return false;
42398
- }
42399
- const relativePath = posixPath.relative(normalizedWorkspaceRoot, normalizedPath);
42400
- if (!relativePath || relativePath === ".") {
42401
- return true;
42402
- }
42403
- return relativePath.split("/").every((segment) => segment.length > 0 && !segment.startsWith("."));
42404
- };
42405
- }
42406
42377
  var ObservableInMemoryFs = class extends Ir {
42407
42378
  listeners;
42408
42379
  lazyPaths = /* @__PURE__ */ new Set();
@@ -42414,7 +42385,18 @@ var ObservableInMemoryFs = class extends Ir {
42414
42385
  constructor(options2) {
42415
42386
  super();
42416
42387
  this.consoleLogChanges = options2?.consoleLogChanges ?? false;
42417
- this.isLoggableWorkspacePath = createWorkspacePathFilter(options2?.workspaceRoot ?? "/");
42388
+ const normalizedWorkspaceRoot = normalizeFsPathForLogScope(options2?.workspaceRoot ?? "/");
42389
+ this.isLoggableWorkspacePath = (fsPath) => {
42390
+ const normalizedPath = normalizeFsPathForLogScope(fsPath);
42391
+ if (normalizedPath !== normalizedWorkspaceRoot && !normalizedPath.startsWith(`${normalizedWorkspaceRoot}/`)) {
42392
+ return false;
42393
+ }
42394
+ const relativePath = posixPath.relative(normalizedWorkspaceRoot, normalizedPath);
42395
+ if (!relativePath || relativePath === ".") {
42396
+ return true;
42397
+ }
42398
+ return relativePath.split("/").every((segment) => segment.length > 0 && !segment.startsWith("."));
42399
+ };
42418
42400
  }
42419
42401
  isPathLazy(filePath) {
42420
42402
  return this.lazyPaths.has(normalizeFsPathForLogScope(filePath));
@@ -42486,7 +42468,7 @@ var ObservableInMemoryFs = class extends Ir {
42486
42468
  emit(event, options2) {
42487
42469
  const shouldConsoleLog = options2?.shouldConsoleLog ?? this.shouldConsoleLogChangeEvent(event);
42488
42470
  if (this.consoleLogChanges && shouldConsoleLog && !this.areConsoleLogsSuppressed()) {
42489
- console.log(formatChangeEventForLog(event));
42471
+ console.log(`[ObservableInMemoryFs] ${event.event} ${event.entryType} ${event.path}${event.previousPath ? ` (from ${event.previousPath})` : ""}`);
42490
42472
  }
42491
42473
  if (!this.listeners) {
42492
42474
  return;
@@ -42563,7 +42545,7 @@ var ObservableInMemoryFs = class extends Ir {
42563
42545
  return;
42564
42546
  }
42565
42547
  this.emit({
42566
- event: mapUnlinkEvent(previous.entryType),
42548
+ event: previous.entryType === "directory" ? "unlinkDir" : "unlink",
42567
42549
  path: path2,
42568
42550
  entryType: previous.entryType
42569
42551
  }, options2);
@@ -60304,6 +60286,7 @@ var ALMOSTNODE_INTERNAL_ROOT = "/.almostnode";
60304
60286
  var ALMOSTNODE_NODE_VERSION = "v20.0.0";
60305
60287
  var ALMOSTNODE_NPM_VERSION = "9.6.4";
60306
60288
  var NODE_EXEC_PATH = "/usr/local/bin/node";
60289
+ var GLOBAL_NODE_MODULES_ROOT = "/usr/local/lib/node_modules";
60307
60290
  var DEFAULT_PATH = "/usr/local/bin:/usr/bin:/bin:/node_modules/.bin";
60308
60291
  var NPM_USAGE = [
60309
60292
  "Usage: npm <command>",
@@ -60588,6 +60571,66 @@ var AlmostNodeSession = class {
60588
60571
  constructor(fs) {
60589
60572
  this.fs = fs;
60590
60573
  this._vfs.mkdirSync(ALMOSTNODE_INTERNAL_ROOT, { recursive: true });
60574
+ this._vfs.mkdirSync("/node_modules/constants", { recursive: true });
60575
+ this._vfs.writeFileSync("/node_modules/constants/package.json", JSON.stringify({
60576
+ name: "constants",
60577
+ version: "0.0.1",
60578
+ main: "index.js"
60579
+ }));
60580
+ this._vfs.writeFileSync("/node_modules/constants/index.js", [
60581
+ "// Node.js `constants` shim (os.constants + fs.constants)",
60582
+ "var os = require('os');",
60583
+ "var constants = {};",
60584
+ "if (os.constants) {",
60585
+ " if (os.constants.signals) Object.assign(constants, os.constants.signals);",
60586
+ " if (os.constants.errno) Object.assign(constants, os.constants.errno);",
60587
+ " if (os.constants.priority) Object.assign(constants, os.constants.priority);",
60588
+ "}",
60589
+ "// Common fs.constants used by npm packages",
60590
+ "constants.O_RDONLY = 0;",
60591
+ "constants.O_WRONLY = 1;",
60592
+ "constants.O_RDWR = 2;",
60593
+ "constants.O_CREAT = 64;",
60594
+ "constants.O_EXCL = 128;",
60595
+ "constants.O_TRUNC = 512;",
60596
+ "constants.O_APPEND = 1024;",
60597
+ "constants.O_DIRECTORY = 65536;",
60598
+ "constants.O_NOFOLLOW = 131072;",
60599
+ "constants.O_SYNC = 1052672;",
60600
+ "constants.O_SYMLINK = 2097152;",
60601
+ "constants.O_NONBLOCK = 2048;",
60602
+ "constants.S_IFMT = 61440;",
60603
+ "constants.S_IFREG = 32768;",
60604
+ "constants.S_IFDIR = 16384;",
60605
+ "constants.S_IFCHR = 8192;",
60606
+ "constants.S_IFBLK = 24576;",
60607
+ "constants.S_IFIFO = 4096;",
60608
+ "constants.S_IFLNK = 40960;",
60609
+ "constants.S_IFSOCK = 49152;",
60610
+ "constants.S_IRWXU = 448;",
60611
+ "constants.S_IRUSR = 256;",
60612
+ "constants.S_IWUSR = 128;",
60613
+ "constants.S_IXUSR = 64;",
60614
+ "constants.S_IRWXG = 56;",
60615
+ "constants.S_IRGRP = 32;",
60616
+ "constants.S_IWGRP = 16;",
60617
+ "constants.S_IXGRP = 8;",
60618
+ "constants.S_IRWXO = 7;",
60619
+ "constants.S_IROTH = 4;",
60620
+ "constants.S_IWOTH = 2;",
60621
+ "constants.S_IXOTH = 1;",
60622
+ "constants.F_OK = 0;",
60623
+ "constants.R_OK = 4;",
60624
+ "constants.W_OK = 2;",
60625
+ "constants.X_OK = 1;",
60626
+ "constants.COPYFILE_EXCL = 1;",
60627
+ "constants.COPYFILE_FICLONE = 2;",
60628
+ "constants.COPYFILE_FICLONE_FORCE = 4;",
60629
+ "constants.UV_FS_COPYFILE_EXCL = 1;",
60630
+ "constants.UV_FS_COPYFILE_FICLONE = 2;",
60631
+ "constants.UV_FS_COPYFILE_FICLONE_FORCE = 4;",
60632
+ "module.exports = constants;"
60633
+ ].join("\n"));
60591
60634
  this.disposeObservableSubscription = this.fs.subscribe((event) => {
60592
60635
  void this.trackOperation((async () => {
60593
60636
  if (!this.initialized || this.suppressObservableMirrorCount > 0) {
@@ -60660,14 +60703,6 @@ var AlmostNodeSession = class {
60660
60703
  * package directory directly.
60661
60704
  */
60662
60705
  resolveBarePkgEntryCache = /* @__PURE__ */ new Map();
60663
- /**
60664
- * Packages whose imports are handled by the browser import map.
60665
- * These are NOT rewritten to /node_modules/... paths.
60666
- * Now empty: react/react-dom are served from node_modules via our
60667
- * CJS→ESM shim, which supports the actual installed version rather
60668
- * than the outdated esm.sh CDN pinned in almostnode's import map.
60669
- */
60670
- importMapPackages = /* @__PURE__ */ new Set();
60671
60706
  parseCachedPackageJson(packageJsonPath, raw) {
60672
60707
  const cached = this.parsedPackageJsonCache.get(packageJsonPath);
60673
60708
  if (cached && cached.raw === raw) {
@@ -60716,7 +60751,6 @@ var AlmostNodeSession = class {
60716
60751
  subPath = specifier.slice(slashIdx + 1);
60717
60752
  }
60718
60753
  }
60719
- if (this.importMapPackages.has(pkgName)) return null;
60720
60754
  const nodeModulesPath = `${root2}/node_modules/${pkgName}`;
60721
60755
  const pkgJsonPath = `${nodeModulesPath}/package.json`;
60722
60756
  let pkgJson = null;
@@ -60936,6 +60970,19 @@ var AlmostNodeSession = class {
60936
60970
  this.vitePreviewUrl = null;
60937
60971
  this.vitePreviewListener?.(null);
60938
60972
  }
60973
+ resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir) {
60974
+ if (typeof pkgJson.bin === "string") {
60975
+ const inferredBinName = typeof pkgJson.name === "string" ? pkgJson.name.split("/").pop() ?? pkgJson.name : packageName.split("/").pop() ?? packageName;
60976
+ if (binName === inferredBinName) {
60977
+ return normalizePath(posixPath.join(pkgDir, pkgJson.bin));
60978
+ }
60979
+ }
60980
+ if (typeof pkgJson.bin === "object" && pkgJson.bin !== null && binName in pkgJson.bin) {
60981
+ const namedBins = pkgJson.bin;
60982
+ return normalizePath(posixPath.join(pkgDir, namedBins[binName]));
60983
+ }
60984
+ return null;
60985
+ }
60939
60986
  async resolveNpmBinPath(binName, cwd) {
60940
60987
  const candidatePackageNames = [binName];
60941
60988
  const packageJsonResult = await this.readPackageJson(cwd);
@@ -60958,21 +61005,94 @@ var AlmostNodeSession = class {
60958
61005
  continue;
60959
61006
  }
60960
61007
  const pkgDir = normalizePath(posixPath.join(cwd, "node_modules", packageName));
60961
- if (typeof pkgJson.bin === "string") {
60962
- const inferredBinName = typeof pkgJson.name === "string" ? pkgJson.name.split("/").pop() ?? pkgJson.name : packageName.split("/").pop() ?? packageName;
60963
- if (binName === inferredBinName) {
60964
- return normalizePath(posixPath.join(pkgDir, pkgJson.bin));
61008
+ const result = this.resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir);
61009
+ if (result) return result;
61010
+ } catch {
61011
+ }
61012
+ }
61013
+ const globalResult = await this.resolveGlobalBinPath(binName);
61014
+ if (globalResult) return globalResult;
61015
+ return null;
61016
+ }
61017
+ async resolveGlobalBinPath(binName) {
61018
+ try {
61019
+ const globalModulesDir = GLOBAL_NODE_MODULES_ROOT;
61020
+ if (!this._vfs.existsSync(globalModulesDir)) return null;
61021
+ const globalPackages = this._vfs.readdirSync(globalModulesDir);
61022
+ for (const entry of globalPackages) {
61023
+ const packageName = entry;
61024
+ const pkgJsonPath = normalizePath(posixPath.join(globalModulesDir, packageName, "package.json"));
61025
+ if (!this._vfs.existsSync(pkgJsonPath)) {
61026
+ if (entry.startsWith("@")) {
61027
+ try {
61028
+ const scopeDir = normalizePath(posixPath.join(globalModulesDir, entry));
61029
+ const scopedPackages = this._vfs.readdirSync(scopeDir);
61030
+ for (const scopedPkg of scopedPackages) {
61031
+ const scopedName = `${entry}/${scopedPkg}`;
61032
+ const scopedPkgJsonPath = normalizePath(posixPath.join(globalModulesDir, scopedName, "package.json"));
61033
+ if (!this._vfs.existsSync(scopedPkgJsonPath)) continue;
61034
+ const raw = this._vfs.readFileSync(scopedPkgJsonPath, "utf8");
61035
+ const pkgJson = this.parseCachedPackageJson(scopedPkgJsonPath, raw);
61036
+ if (!pkgJson) continue;
61037
+ const pkgDir = normalizePath(posixPath.join(globalModulesDir, scopedName));
61038
+ const result = this.resolveBinFromPackageJson(binName, scopedName, pkgJson, pkgDir);
61039
+ if (result) return result;
61040
+ }
61041
+ } catch {
61042
+ }
60965
61043
  }
61044
+ continue;
60966
61045
  }
60967
- if (typeof pkgJson.bin === "object" && pkgJson.bin !== null && binName in pkgJson.bin) {
60968
- const namedBins = pkgJson.bin;
60969
- return normalizePath(posixPath.join(pkgDir, namedBins[binName]));
61046
+ try {
61047
+ const raw = this._vfs.readFileSync(pkgJsonPath, "utf8");
61048
+ const pkgJson = this.parseCachedPackageJson(pkgJsonPath, raw);
61049
+ if (!pkgJson) continue;
61050
+ const pkgDir = normalizePath(posixPath.join(globalModulesDir, packageName));
61051
+ const result = this.resolveBinFromPackageJson(binName, packageName, pkgJson, pkgDir);
61052
+ if (result) return result;
61053
+ } catch {
60970
61054
  }
60971
- } catch {
60972
61055
  }
61056
+ } catch {
60973
61057
  }
60974
61058
  return null;
60975
61059
  }
61060
+ async registerGlobalBinCommands(packageName) {
61061
+ if (!this.binCommandRegistrar) return;
61062
+ const pkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, packageName, "package.json"));
61063
+ if (!this._vfs.existsSync(pkgJsonPath)) return;
61064
+ try {
61065
+ const raw = this._vfs.readFileSync(pkgJsonPath, "utf8");
61066
+ const pkgJson = this.parseCachedPackageJson(pkgJsonPath, raw);
61067
+ if (!pkgJson) return;
61068
+ let binNames;
61069
+ if (typeof pkgJson.bin === "string") {
61070
+ const name = typeof pkgJson.name === "string" ? pkgJson.name.split("/").pop() ?? "" : "";
61071
+ binNames = name ? [name] : [];
61072
+ } else if (typeof pkgJson.bin === "object" && pkgJson.bin !== null) {
61073
+ binNames = Object.keys(pkgJson.bin);
61074
+ } else {
61075
+ binNames = [];
61076
+ }
61077
+ for (const binName of binNames) {
61078
+ if (this.registeredBinCommands.has(binName)) continue;
61079
+ this.registeredBinCommands.add(binName);
61080
+ this.binCommandRegistrar(binName, async (args, ctx) => {
61081
+ const resolvedPath2 = await this.resolveGlobalBinPath(binName) ?? await this.resolveNpmBinPath(binName, normalizePath(ctx.cwd));
61082
+ if (!resolvedPath2) {
61083
+ return {
61084
+ stdout: "",
61085
+ stderr: `bash: ${binName}: command not found
61086
+ `,
61087
+ exitCode: 127
61088
+ };
61089
+ }
61090
+ return this.executeNode([resolvedPath2, ...args], ctx);
61091
+ });
61092
+ }
61093
+ } catch {
61094
+ }
61095
+ }
60976
61096
  async resolveAndRegisterBinCommands(command, cwd) {
60977
61097
  if (!this.binCommandRegistrar) {
60978
61098
  return;
@@ -61341,6 +61461,7 @@ var AlmostNodeSession = class {
61341
61461
  PATH: Array.from(/* @__PURE__ */ new Set([
61342
61462
  normalizePath(posixPath.join(cwd, "node_modules/.bin")),
61343
61463
  "/node_modules/.bin",
61464
+ `${GLOBAL_NODE_MODULES_ROOT}/.bin`,
61344
61465
  ...(baseEnv.PATH?.trim() || DEFAULT_PATH).split(":").filter(Boolean)
61345
61466
  ])).join(":")
61346
61467
  };
@@ -61415,26 +61536,30 @@ var AlmostNodeSession = class {
61415
61536
  case "install":
61416
61537
  case "i":
61417
61538
  case "add": {
61539
+ const isGlobal = args.includes("-g") || args.includes("--global");
61418
61540
  const packageSpecs = args.slice(1).filter((arg) => !arg.startsWith("-"));
61419
61541
  let stdout = "";
61420
61542
  try {
61421
- const packageJsonResult = await this.readPackageJson(cwd);
61422
- if ("error" in packageJsonResult) {
61423
- result = packageJsonResult.error;
61424
- break;
61425
- }
61426
- await ensureEsbuildWasm();
61427
- const packageManager = new PackageManager(this.vfs, { cwd });
61428
- if (packageSpecs.length === 0) {
61429
- const installResult = await packageManager.installFromPackageJson({
61430
- onProgress: (message) => {
61431
- stdout += `${message}
61432
- `;
61433
- }
61434
- });
61435
- stdout += `added ${installResult.added.length} packages
61436
- `;
61437
- } else {
61543
+ if (isGlobal) {
61544
+ if (packageSpecs.length === 0) {
61545
+ result = { stdout: "", stderr: "npm ERR! npm install -g requires a package name\n", exitCode: 1 };
61546
+ break;
61547
+ }
61548
+ await ensureEsbuildWasm();
61549
+ this._vfs.mkdirSync(GLOBAL_NODE_MODULES_ROOT, { recursive: true });
61550
+ await ensureObservableDirectory(this.fs, GLOBAL_NODE_MODULES_ROOT);
61551
+ const globalPkgJsonPath = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, "..", "package.json"));
61552
+ if (!this._vfs.existsSync(globalPkgJsonPath)) {
61553
+ const minimalPkg = JSON.stringify({ name: "global", version: "0.0.0", private: true }, null, 2);
61554
+ this._vfs.mkdirSync(posixPath.dirname(globalPkgJsonPath), { recursive: true });
61555
+ this._vfs.writeFileSync(globalPkgJsonPath, minimalPkg);
61556
+ await this.withSuppressedObservableMirroring(async () => {
61557
+ await ensureObservableDirectory(this.fs, posixPath.dirname(globalPkgJsonPath));
61558
+ await this.fs.writeFile(globalPkgJsonPath, minimalPkg);
61559
+ });
61560
+ }
61561
+ const globalCwd = normalizePath(posixPath.join(GLOBAL_NODE_MODULES_ROOT, ".."));
61562
+ const packageManager = new PackageManager(this.vfs, { cwd: globalCwd });
61438
61563
  for (const packageSpec of packageSpecs) {
61439
61564
  const installResult = await packageManager.install(packageSpec, {
61440
61565
  save: true,
@@ -61445,9 +61570,48 @@ var AlmostNodeSession = class {
61445
61570
  });
61446
61571
  stdout += `added ${installResult.added.length} packages
61447
61572
  `;
61573
+ const installedPkgName = packageSpec.replace(/@[^/]*$/, "") || packageSpec;
61574
+ await this.registerGlobalBinCommands(installedPkgName);
61575
+ for (const added of installResult.added) {
61576
+ const addedName = typeof added === "string" ? String(added).replace(/@[^/]*$/, "") : added?.name;
61577
+ if (addedName && addedName !== installedPkgName) {
61578
+ await this.registerGlobalBinCommands(addedName);
61579
+ }
61580
+ }
61581
+ }
61582
+ result = { stdout, stderr: "", exitCode: 0 };
61583
+ } else {
61584
+ const packageJsonResult = await this.readPackageJson(cwd);
61585
+ if ("error" in packageJsonResult) {
61586
+ result = packageJsonResult.error;
61587
+ break;
61588
+ }
61589
+ await ensureEsbuildWasm();
61590
+ const packageManager = new PackageManager(this.vfs, { cwd });
61591
+ if (packageSpecs.length === 0) {
61592
+ const installResult = await packageManager.installFromPackageJson({
61593
+ onProgress: (message) => {
61594
+ stdout += `${message}
61595
+ `;
61596
+ }
61597
+ });
61598
+ stdout += `added ${installResult.added.length} packages
61599
+ `;
61600
+ } else {
61601
+ for (const packageSpec of packageSpecs) {
61602
+ const installResult = await packageManager.install(packageSpec, {
61603
+ save: true,
61604
+ onProgress: (message) => {
61605
+ stdout += `${message}
61606
+ `;
61607
+ }
61608
+ });
61609
+ stdout += `added ${installResult.added.length} packages
61610
+ `;
61611
+ }
61448
61612
  }
61613
+ result = { stdout, stderr: "", exitCode: 0 };
61449
61614
  }
61450
- result = { stdout, stderr: "", exitCode: 0 };
61451
61615
  } catch (error) {
61452
61616
  result = {
61453
61617
  stdout,