agent-web-os 0.1.10 → 0.1.12

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
@@ -61106,56 +61106,232 @@ var AlmostNodeSession = class {
61106
61106
  return null;
61107
61107
  }
61108
61108
  /**
61109
- * Patch lru-cache installations so the CJS entry doesn't crash in
61110
- * the browser runtime. lru-cache v11's CJS unconditionally calls
61111
- * `require("node:diagnostics_channel").tracingChannel()` at the
61112
- * module scope. If that throws inside the browser WASM sandbox the
61113
- * entire module fails and `exports.LRUCache` is never assigned,
61114
- * leading to "TypeError: LRUCache is not a constructor".
61109
+ * Replace lru-cache CJS entry points with a browser-safe implementation.
61115
61110
  *
61116
- * The fix: wrap the `require("node:diagnostics_channel")` call in a
61117
- * try/catch with a no-op fallback so LRUCache initialises safely.
61111
+ * lru-cache v11's minified CJS uses `require("node:diagnostics_channel")`
61112
+ * and private class fields (`static #t`) which can fail inside the browser
61113
+ * WASM runtime's `eval()` context, leaving `exports.LRUCache` undefined
61114
+ * ("TypeError: LRUCache is not a constructor").
61115
+ *
61116
+ * The fix: overwrite the CJS entry with a clean Map-based LRU cache that
61117
+ * covers the full API surface used by lru-cache consumers (hosted-git-info,
61118
+ * path-scurry, glob, etc.) without any diagnostics_channel dependency or
61119
+ * private class fields.
61118
61120
  */
61119
61121
  patchLruCacheInNodeModules(nodeModulesDir) {
61120
- const patchFile = (filePath) => {
61121
- if (!this._vfs.existsSync(filePath)) return;
61122
- const src = this._vfs.readFileSync(filePath, "utf8");
61123
- if (!src.includes('require("node:diagnostics_channel")')) return;
61124
- const patched = src.replace(
61125
- 'require("node:diagnostics_channel")',
61126
- '(function(){try{var _dc=require("node:diagnostics_channel");var _ch=_dc.channel("lru-cache:_test");if(typeof _dc.tracingChannel==="function")_dc.tracingChannel("lru-cache:_test");return _dc}catch(_e){return{channel:function(){return{hasSubscribers:false,publish:function(){},subscribe:function(){},unsubscribe:function(){}}},tracingChannel:function(){return{hasSubscribers:false,subscribe:function(){},unsubscribe:function(){}}}}}})()'
61127
- );
61128
- if (patched !== src) {
61129
- this._vfs.writeFileSync(filePath, patched);
61122
+ const lruCacheShim = `"use strict";
61123
+ Object.defineProperty(exports, "__esModule", { value: true });
61124
+ exports.LRUCache = void 0;
61125
+ var LRUCache = (function () {
61126
+ function LRUCache(options) {
61127
+ if (typeof options === "number") options = { max: options };
61128
+ if (!options) options = {};
61129
+ this._max = options.max || Infinity;
61130
+ this._maxSize = options.maxSize || 0;
61131
+ this._sizeCalculation = options.sizeCalculation || null;
61132
+ this._dispose = options.dispose || null;
61133
+ this._allowStale = !!options.allowStale;
61134
+ this._ttl = options.ttl || 0;
61135
+ this._noUpdateTTL = !!options.noUpdateTTL;
61136
+ this._map = new Map();
61137
+ this._order = [];
61138
+ this._sizes = new Map();
61139
+ this._totalSize = 0;
61140
+ this._timers = new Map();
61141
+ }
61142
+ Object.defineProperty(LRUCache.prototype, "size", { get: function () { return this._map.size; } });
61143
+ Object.defineProperty(LRUCache.prototype, "max", { get: function () { return this._max; } });
61144
+ Object.defineProperty(LRUCache.prototype, "maxSize", { get: function () { return this._maxSize; } });
61145
+ Object.defineProperty(LRUCache.prototype, "calculatedSize", { get: function () { return this._totalSize; } });
61146
+ LRUCache.prototype._touch = function (key) {
61147
+ var idx = this._order.indexOf(key);
61148
+ if (idx > -1) this._order.splice(idx, 1);
61149
+ this._order.push(key);
61150
+ };
61151
+ LRUCache.prototype._evict = function () {
61152
+ while (this._order.length > 0 && (this._map.size > this._max || (this._maxSize > 0 && this._totalSize > this._maxSize))) {
61153
+ var oldest = this._order.shift();
61154
+ if (oldest !== undefined && this._map.has(oldest)) {
61155
+ var val = this._map.get(oldest);
61156
+ this._map.delete(oldest);
61157
+ if (this._sizes.has(oldest)) { this._totalSize -= this._sizes.get(oldest); this._sizes.delete(oldest); }
61158
+ if (this._timers.has(oldest)) { clearTimeout(this._timers.get(oldest)); this._timers.delete(oldest); }
61159
+ if (this._dispose) this._dispose(val, oldest, "evict");
61160
+ }
61161
+ }
61162
+ };
61163
+ LRUCache.prototype._isStale = function (key) {
61164
+ return false; // TTL timers handle expiry via delete
61165
+ };
61166
+ LRUCache.prototype.set = function (key, value, options) {
61167
+ if (value === undefined) { this.delete(key); return this; }
61168
+ var opts = options || {};
61169
+ var size = 0;
61170
+ if (this._maxSize > 0) {
61171
+ size = opts.size || 0;
61172
+ if (!size && this._sizeCalculation) size = this._sizeCalculation(value, key);
61173
+ if (size > this._maxSize) return this;
61174
+ }
61175
+ if (this._map.has(key)) {
61176
+ var old = this._map.get(key);
61177
+ if (this._sizes.has(key)) { this._totalSize -= this._sizes.get(key); }
61178
+ if (this._timers.has(key)) { clearTimeout(this._timers.get(key)); this._timers.delete(key); }
61179
+ if (this._dispose && !opts.noDisposeOnSet) this._dispose(old, key, "set");
61180
+ }
61181
+ this._map.set(key, value);
61182
+ this._touch(key);
61183
+ if (this._maxSize > 0 && size > 0) { this._sizes.set(key, size); this._totalSize += size; }
61184
+ var ttl = opts.ttl !== undefined ? opts.ttl : this._ttl;
61185
+ if (ttl > 0) {
61186
+ var self = this;
61187
+ this._timers.set(key, setTimeout(function () { self.delete(key); }, ttl));
61188
+ }
61189
+ this._evict();
61190
+ return this;
61191
+ };
61192
+ LRUCache.prototype.get = function (key, options) {
61193
+ if (!this._map.has(key)) return undefined;
61194
+ var value = this._map.get(key);
61195
+ this._touch(key);
61196
+ return value;
61197
+ };
61198
+ LRUCache.prototype.peek = function (key) {
61199
+ return this._map.get(key);
61200
+ };
61201
+ LRUCache.prototype.has = function (key) {
61202
+ return this._map.has(key);
61203
+ };
61204
+ LRUCache.prototype.delete = function (key) {
61205
+ if (!this._map.has(key)) return false;
61206
+ var val = this._map.get(key);
61207
+ this._map.delete(key);
61208
+ var idx = this._order.indexOf(key);
61209
+ if (idx > -1) this._order.splice(idx, 1);
61210
+ if (this._sizes.has(key)) { this._totalSize -= this._sizes.get(key); this._sizes.delete(key); }
61211
+ if (this._timers.has(key)) { clearTimeout(this._timers.get(key)); this._timers.delete(key); }
61212
+ if (this._dispose) this._dispose(val, key, "delete");
61213
+ return true;
61214
+ };
61215
+ LRUCache.prototype.clear = function () {
61216
+ var self = this;
61217
+ if (this._dispose) {
61218
+ this._map.forEach(function (val, key) { self._dispose(val, key, "delete"); });
61219
+ }
61220
+ this._timers.forEach(function (t) { clearTimeout(t); });
61221
+ this._map.clear();
61222
+ this._order.length = 0;
61223
+ this._sizes.clear();
61224
+ this._totalSize = 0;
61225
+ this._timers.clear();
61226
+ };
61227
+ LRUCache.prototype.keys = function () { return this._map.keys(); };
61228
+ LRUCache.prototype.values = function () { return this._map.values(); };
61229
+ LRUCache.prototype.entries = function () { return this._map.entries(); };
61230
+ LRUCache.prototype.find = function (fn, options) {
61231
+ for (var it = this._map.entries(), r; !(r = it.next()).done;) {
61232
+ if (fn(r.value[1], r.value[0], this)) return this.get(r.value[0], options);
61233
+ }
61234
+ };
61235
+ LRUCache.prototype.forEach = function (fn, thisArg) {
61236
+ var self = this;
61237
+ this._map.forEach(function (val, key) { fn.call(thisArg || self, val, key, self); });
61238
+ };
61239
+ LRUCache.prototype.dump = function () { return []; };
61240
+ LRUCache.prototype.load = function (arr) {
61241
+ this.clear();
61242
+ for (var i = 0; i < arr.length; i++) { this.set(arr[i][0], arr[i][1].value, arr[i][1]); }
61243
+ };
61244
+ LRUCache.prototype.pop = function () {
61245
+ if (this._order.length === 0) return undefined;
61246
+ var oldest = this._order[0];
61247
+ var val = this._map.get(oldest);
61248
+ this.delete(oldest);
61249
+ return val;
61250
+ };
61251
+ LRUCache.prototype.purgeStale = function () { return false; };
61252
+ LRUCache.prototype.getRemainingTTL = function (key) { return this._map.has(key) ? Infinity : 0; };
61253
+ LRUCache.prototype.info = function (key) {
61254
+ if (!this._map.has(key)) return undefined;
61255
+ return { value: this._map.get(key) };
61256
+ };
61257
+ LRUCache.prototype[Symbol.iterator] = function () { return this._map.entries(); };
61258
+ LRUCache.prototype[Symbol.toStringTag] = "LRUCache";
61259
+ return LRUCache;
61260
+ })();
61261
+ exports.LRUCache = LRUCache;
61262
+ `;
61263
+ const patchDir = (lruDir) => {
61264
+ const cjsPaths = [
61265
+ normalizePath(posixPath.join(lruDir, "dist", "commonjs", "index.min.js")),
61266
+ normalizePath(posixPath.join(lruDir, "dist", "commonjs", "index.js")),
61267
+ // Also try the package root index (lru-cache v7 style)
61268
+ normalizePath(posixPath.join(lruDir, "index.js"))
61269
+ ];
61270
+ let patched = false;
61271
+ for (const p of cjsPaths) {
61272
+ if (this._vfs.existsSync(p)) {
61273
+ this._vfs.writeFileSync(p, lruCacheShim);
61274
+ patched = true;
61275
+ }
61276
+ }
61277
+ if (!patched) {
61278
+ const pkgPath = normalizePath(posixPath.join(lruDir, "package.json"));
61279
+ if (this._vfs.existsSync(pkgPath)) {
61280
+ try {
61281
+ const pkg = JSON.parse(this._vfs.readFileSync(pkgPath, "utf8"));
61282
+ const mainField = pkg.main || pkg.exports?.["."]?.require?.default || pkg.exports?.["."]?.require;
61283
+ if (mainField && typeof mainField === "string") {
61284
+ const mainPath = normalizePath(posixPath.join(lruDir, mainField));
61285
+ if (this._vfs.existsSync(mainPath)) {
61286
+ this._vfs.writeFileSync(mainPath, lruCacheShim);
61287
+ patched = true;
61288
+ }
61289
+ }
61290
+ } catch {
61291
+ }
61292
+ }
61130
61293
  }
61294
+ return patched;
61131
61295
  };
61296
+ let patchCount = 0;
61132
61297
  const walkNodeModules = (nmDir) => {
61133
61298
  if (!this._vfs.existsSync(nmDir)) return;
61134
- for (const entry of this._vfs.readdirSync(nmDir)) {
61299
+ let entries;
61300
+ try {
61301
+ entries = this._vfs.readdirSync(nmDir);
61302
+ } catch {
61303
+ return;
61304
+ }
61305
+ for (const entry of entries) {
61135
61306
  if (entry === "lru-cache") {
61136
- const cjsEntry = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.min.js"));
61137
- patchFile(cjsEntry);
61138
- const cjsIndex = normalizePath(posixPath.join(nmDir, "lru-cache", "dist", "commonjs", "index.js"));
61139
- patchFile(cjsIndex);
61140
- }
61141
- const nestedNm = normalizePath(posixPath.join(nmDir, entry, "node_modules"));
61142
- if (this._vfs.existsSync(nestedNm)) {
61143
- walkNodeModules(nestedNm);
61307
+ const lruDir = normalizePath(posixPath.join(nmDir, "lru-cache"));
61308
+ if (patchDir(lruDir)) patchCount++;
61144
61309
  }
61145
61310
  if (entry.startsWith("@")) {
61146
61311
  const scopeDir = normalizePath(posixPath.join(nmDir, entry));
61147
- if (this._vfs.existsSync(scopeDir)) {
61312
+ try {
61148
61313
  for (const scopedEntry of this._vfs.readdirSync(scopeDir)) {
61149
- const nestedNm2 = normalizePath(posixPath.join(scopeDir, scopedEntry, "node_modules"));
61150
- if (this._vfs.existsSync(nestedNm2)) {
61151
- walkNodeModules(nestedNm2);
61314
+ const nestedNm = normalizePath(posixPath.join(scopeDir, scopedEntry, "node_modules"));
61315
+ if (this._vfs.existsSync(nestedNm)) {
61316
+ walkNodeModules(nestedNm);
61152
61317
  }
61153
61318
  }
61319
+ } catch {
61320
+ }
61321
+ } else {
61322
+ const nestedNm = normalizePath(posixPath.join(nmDir, entry, "node_modules"));
61323
+ if (this._vfs.existsSync(nestedNm)) {
61324
+ walkNodeModules(nestedNm);
61154
61325
  }
61155
61326
  }
61156
61327
  }
61157
61328
  };
61158
61329
  walkNodeModules(nodeModulesDir);
61330
+ if (patchCount === 0) {
61331
+ console.warn(`[agent-web-os] lru-cache patch: no lru-cache found in ${nodeModulesDir}`);
61332
+ } else {
61333
+ console.log(`[agent-web-os] lru-cache patch: patched ${patchCount} installation(s) in ${nodeModulesDir}`);
61334
+ }
61159
61335
  }
61160
61336
  async registerGlobalBinCommands(packageName) {
61161
61337
  if (!this.binCommandRegistrar) return;
@@ -62277,7 +62453,7 @@ async function executeBrowserBash(session, command, options2 = {}) {
62277
62453
  }
62278
62454
 
62279
62455
  // src/index.ts
62280
- var AGENT_WEB_OS_VERSION = "0.1.10";
62456
+ var AGENT_WEB_OS_VERSION = "0.1.12";
62281
62457
  console.log(`[agent-web-os] v${AGENT_WEB_OS_VERSION}`);
62282
62458
  var getServerBridge2 = getServerBridge;
62283
62459
  var resetServerBridge2 = resetServerBridge;