@adhdev/daemon-standalone 0.7.38 → 0.7.39

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.js CHANGED
@@ -283,10 +283,10 @@ function mergeDefs(...defs) {
283
283
  function cloneDef(schema) {
284
284
  return mergeDefs(schema._zod.def);
285
285
  }
286
- function getElementAtPath(obj, path19) {
287
- if (!path19)
286
+ function getElementAtPath(obj, path18) {
287
+ if (!path18)
288
288
  return obj;
289
- return path19.reduce((acc, key) => acc?.[key], obj);
289
+ return path18.reduce((acc, key) => acc?.[key], obj);
290
290
  }
291
291
  function promiseAllObject(promisesObj) {
292
292
  const keys = Object.keys(promisesObj);
@@ -598,11 +598,11 @@ function aborted(x, startIndex = 0) {
598
598
  }
599
599
  return false;
600
600
  }
601
- function prefixIssues(path19, issues) {
601
+ function prefixIssues(path18, issues) {
602
602
  return issues.map((iss) => {
603
603
  var _a2;
604
604
  (_a2 = iss).path ?? (_a2.path = []);
605
- iss.path.unshift(path19);
605
+ iss.path.unshift(path18);
606
606
  return iss;
607
607
  });
608
608
  }
@@ -845,7 +845,7 @@ function formatError(error48, mapper = (issue2) => issue2.message) {
845
845
  }
846
846
  function treeifyError(error48, mapper = (issue2) => issue2.message) {
847
847
  const result = { errors: [] };
848
- const processError = (error49, path19 = []) => {
848
+ const processError = (error49, path18 = []) => {
849
849
  var _a2, _b;
850
850
  for (const issue2 of error49.issues) {
851
851
  if (issue2.code === "invalid_union" && issue2.errors.length) {
@@ -855,7 +855,7 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
855
855
  } else if (issue2.code === "invalid_element") {
856
856
  processError({ issues: issue2.issues }, issue2.path);
857
857
  } else {
858
- const fullpath = [...path19, ...issue2.path];
858
+ const fullpath = [...path18, ...issue2.path];
859
859
  if (fullpath.length === 0) {
860
860
  result.errors.push(mapper(issue2));
861
861
  continue;
@@ -887,8 +887,8 @@ function treeifyError(error48, mapper = (issue2) => issue2.message) {
887
887
  }
888
888
  function toDotPath(_path) {
889
889
  const segs = [];
890
- const path19 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
891
- for (const seg of path19) {
890
+ const path18 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
891
+ for (const seg of path18) {
892
892
  if (typeof seg === "number")
893
893
  segs.push(`[${seg}]`);
894
894
  else if (typeof seg === "symbol")
@@ -13652,13 +13652,13 @@ function resolveRef(ref, ctx) {
13652
13652
  if (!ref.startsWith("#")) {
13653
13653
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
13654
13654
  }
13655
- const path19 = ref.slice(1).split("/").filter(Boolean);
13656
- if (path19.length === 0) {
13655
+ const path18 = ref.slice(1).split("/").filter(Boolean);
13656
+ if (path18.length === 0) {
13657
13657
  return ctx.rootSchema;
13658
13658
  }
13659
13659
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
13660
- if (path19[0] === defsKey) {
13661
- const key = path19[1];
13660
+ if (path18[0] === defsKey) {
13661
+ const key = path18[1];
13662
13662
  if (!key || !ctx.defs[key]) {
13663
13663
  throw new Error(`Reference not found: ${ref}`);
13664
13664
  }
@@ -16085,8 +16085,8 @@ var init_acp = __esm({
16085
16085
  this.#requestHandler = requestHandler;
16086
16086
  this.#notificationHandler = notificationHandler;
16087
16087
  this.#stream = stream;
16088
- this.#closedPromise = new Promise((resolve13) => {
16089
- this.#abortController.signal.addEventListener("abort", () => resolve13());
16088
+ this.#closedPromise = new Promise((resolve12) => {
16089
+ this.#abortController.signal.addEventListener("abort", () => resolve12());
16090
16090
  });
16091
16091
  this.#receive();
16092
16092
  }
@@ -16235,8 +16235,8 @@ var init_acp = __esm({
16235
16235
  }
16236
16236
  async sendRequest(method, params) {
16237
16237
  const id = this.#nextRequestId++;
16238
- const responsePromise = new Promise((resolve13, reject) => {
16239
- this.#pendingResponses.set(id, { resolve: resolve13, reject });
16238
+ const responsePromise = new Promise((resolve12, reject) => {
16239
+ this.#pendingResponses.set(id, { resolve: resolve12, reject });
16240
16240
  });
16241
16241
  await this.#sendMessage({ jsonrpc: "2.0", id, method, params });
16242
16242
  return responsePromise;
@@ -16334,28 +16334,27 @@ var init_acp = __esm({
16334
16334
  // src/index.ts
16335
16335
  var import_http = require("http");
16336
16336
  var import_ws2 = require("ws");
16337
- var path18 = __toESM(require("path"));
16337
+ var path17 = __toESM(require("path"));
16338
16338
  var fs12 = __toESM(require("fs"));
16339
16339
  var os17 = __toESM(require("os"));
16340
16340
 
16341
16341
  // ../daemon-core/dist/index.mjs
16342
- var fs = __toESM(require("fs"), 1);
16343
- var os2 = __toESM(require("os"), 1);
16344
- var path = __toESM(require("path"), 1);
16345
- var import_crypto2 = require("crypto");
16346
16342
  var import_os = require("os");
16347
16343
  var import_path = require("path");
16348
16344
  var import_fs = require("fs");
16349
- var import_crypto3 = require("crypto");
16345
+ var import_crypto2 = require("crypto");
16350
16346
  var fs2 = __toESM(require("fs"), 1);
16351
- var path4 = __toESM(require("path"), 1);
16347
+ var path3 = __toESM(require("path"), 1);
16352
16348
  var os4 = __toESM(require("os"), 1);
16353
16349
  var os11 = __toESM(require("os"), 1);
16354
16350
  var os12 = __toESM(require("os"), 1);
16355
- var path10 = __toESM(require("path"), 1);
16351
+ var path9 = __toESM(require("path"), 1);
16356
16352
  var import_child_process = require("child_process");
16353
+ var fs = __toESM(require("fs"), 1);
16354
+ var os2 = __toESM(require("os"), 1);
16355
+ var path = __toESM(require("path"), 1);
16356
+ var import_crypto3 = require("crypto");
16357
16357
  var path22 = __toESM(require("path"), 1);
16358
- var path3 = __toESM(require("path"), 1);
16359
16358
  var import_child_process2 = require("child_process");
16360
16359
  var import_fs2 = require("fs");
16361
16360
  var import_os2 = require("os");
@@ -16367,17 +16366,17 @@ var import_ws = __toESM(require("ws"), 1);
16367
16366
  var http = __toESM(require("http"), 1);
16368
16367
  var crypto2 = __toESM(require("crypto"), 1);
16369
16368
  var fs3 = __toESM(require("fs"), 1);
16370
- var path5 = __toESM(require("path"), 1);
16369
+ var path4 = __toESM(require("path"), 1);
16371
16370
  var os5 = __toESM(require("os"), 1);
16372
16371
  var fs4 = __toESM(require("fs"), 1);
16373
- var path6 = __toESM(require("path"), 1);
16372
+ var path5 = __toESM(require("path"), 1);
16374
16373
  var os6 = __toESM(require("os"), 1);
16375
16374
  var import_child_process5 = require("child_process");
16376
16375
  var net2 = __toESM(require("net"), 1);
16377
16376
  var os8 = __toESM(require("os"), 1);
16378
- var path8 = __toESM(require("path"), 1);
16379
- var fs5 = __toESM(require("fs"), 1);
16380
16377
  var path7 = __toESM(require("path"), 1);
16378
+ var fs5 = __toESM(require("fs"), 1);
16379
+ var path6 = __toESM(require("path"), 1);
16381
16380
  var os7 = __toESM(require("os"), 1);
16382
16381
 
16383
16382
  // ../daemon-core/node_modules/chokidar/index.js
@@ -16470,7 +16469,7 @@ var ReaddirpStream = class extends import_node_stream.Readable {
16470
16469
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
16471
16470
  const statMethod = opts.lstat ? import_promises.lstat : import_promises.stat;
16472
16471
  if (wantBigintFsStats) {
16473
- this._stat = (path19) => statMethod(path19, { bigint: true });
16472
+ this._stat = (path18) => statMethod(path18, { bigint: true });
16474
16473
  } else {
16475
16474
  this._stat = statMethod;
16476
16475
  }
@@ -16495,8 +16494,8 @@ var ReaddirpStream = class extends import_node_stream.Readable {
16495
16494
  const par = this.parent;
16496
16495
  const fil = par && par.files;
16497
16496
  if (fil && fil.length > 0) {
16498
- const { path: path19, depth } = par;
16499
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path19));
16497
+ const { path: path18, depth } = par;
16498
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path18));
16500
16499
  const awaited = await Promise.all(slice);
16501
16500
  for (const entry of awaited) {
16502
16501
  if (!entry)
@@ -16536,20 +16535,20 @@ var ReaddirpStream = class extends import_node_stream.Readable {
16536
16535
  this.reading = false;
16537
16536
  }
16538
16537
  }
16539
- async _exploreDir(path19, depth) {
16538
+ async _exploreDir(path18, depth) {
16540
16539
  let files;
16541
16540
  try {
16542
- files = await (0, import_promises.readdir)(path19, this._rdOptions);
16541
+ files = await (0, import_promises.readdir)(path18, this._rdOptions);
16543
16542
  } catch (error48) {
16544
16543
  this._onError(error48);
16545
16544
  }
16546
- return { files, depth, path: path19 };
16545
+ return { files, depth, path: path18 };
16547
16546
  }
16548
- async _formatEntry(dirent, path19) {
16547
+ async _formatEntry(dirent, path18) {
16549
16548
  let entry;
16550
16549
  const basename7 = this._isDirent ? dirent.name : dirent;
16551
16550
  try {
16552
- const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path19, basename7));
16551
+ const fullPath = (0, import_node_path.resolve)((0, import_node_path.join)(path18, basename7));
16553
16552
  entry = { path: (0, import_node_path.relative)(this._root, fullPath), fullPath, basename: basename7 };
16554
16553
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
16555
16554
  } catch (err) {
@@ -16949,16 +16948,16 @@ var delFromSet = (main2, prop, item) => {
16949
16948
  };
16950
16949
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
16951
16950
  var FsWatchInstances = /* @__PURE__ */ new Map();
16952
- function createFsWatchInstance(path19, options, listener, errHandler, emitRaw) {
16951
+ function createFsWatchInstance(path18, options, listener, errHandler, emitRaw) {
16953
16952
  const handleEvent = (rawEvent, evPath) => {
16954
- listener(path19);
16955
- emitRaw(rawEvent, evPath, { watchedPath: path19 });
16956
- if (evPath && path19 !== evPath) {
16957
- fsWatchBroadcast(sp.resolve(path19, evPath), KEY_LISTENERS, sp.join(path19, evPath));
16953
+ listener(path18);
16954
+ emitRaw(rawEvent, evPath, { watchedPath: path18 });
16955
+ if (evPath && path18 !== evPath) {
16956
+ fsWatchBroadcast(sp.resolve(path18, evPath), KEY_LISTENERS, sp.join(path18, evPath));
16958
16957
  }
16959
16958
  };
16960
16959
  try {
16961
- return (0, import_node_fs.watch)(path19, {
16960
+ return (0, import_node_fs.watch)(path18, {
16962
16961
  persistent: options.persistent
16963
16962
  }, handleEvent);
16964
16963
  } catch (error48) {
@@ -16974,12 +16973,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
16974
16973
  listener(val1, val2, val3);
16975
16974
  });
16976
16975
  };
16977
- var setFsWatchListener = (path19, fullPath, options, handlers) => {
16976
+ var setFsWatchListener = (path18, fullPath, options, handlers) => {
16978
16977
  const { listener, errHandler, rawEmitter } = handlers;
16979
16978
  let cont = FsWatchInstances.get(fullPath);
16980
16979
  let watcher;
16981
16980
  if (!options.persistent) {
16982
- watcher = createFsWatchInstance(path19, options, listener, errHandler, rawEmitter);
16981
+ watcher = createFsWatchInstance(path18, options, listener, errHandler, rawEmitter);
16983
16982
  if (!watcher)
16984
16983
  return;
16985
16984
  return watcher.close.bind(watcher);
@@ -16990,7 +16989,7 @@ var setFsWatchListener = (path19, fullPath, options, handlers) => {
16990
16989
  addAndConvert(cont, KEY_RAW, rawEmitter);
16991
16990
  } else {
16992
16991
  watcher = createFsWatchInstance(
16993
- path19,
16992
+ path18,
16994
16993
  options,
16995
16994
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
16996
16995
  errHandler,
@@ -17005,7 +17004,7 @@ var setFsWatchListener = (path19, fullPath, options, handlers) => {
17005
17004
  cont.watcherUnusable = true;
17006
17005
  if (isWindows && error48.code === "EPERM") {
17007
17006
  try {
17008
- const fd = await (0, import_promises2.open)(path19, "r");
17007
+ const fd = await (0, import_promises2.open)(path18, "r");
17009
17008
  await fd.close();
17010
17009
  broadcastErr(error48);
17011
17010
  } catch (err) {
@@ -17036,7 +17035,7 @@ var setFsWatchListener = (path19, fullPath, options, handlers) => {
17036
17035
  };
17037
17036
  };
17038
17037
  var FsWatchFileInstances = /* @__PURE__ */ new Map();
17039
- var setFsWatchFileListener = (path19, fullPath, options, handlers) => {
17038
+ var setFsWatchFileListener = (path18, fullPath, options, handlers) => {
17040
17039
  const { listener, rawEmitter } = handlers;
17041
17040
  let cont = FsWatchFileInstances.get(fullPath);
17042
17041
  const copts = cont && cont.options;
@@ -17058,7 +17057,7 @@ var setFsWatchFileListener = (path19, fullPath, options, handlers) => {
17058
17057
  });
17059
17058
  const currmtime = curr.mtimeMs;
17060
17059
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
17061
- foreach(cont.listeners, (listener2) => listener2(path19, curr));
17060
+ foreach(cont.listeners, (listener2) => listener2(path18, curr));
17062
17061
  }
17063
17062
  })
17064
17063
  };
@@ -17088,13 +17087,13 @@ var NodeFsHandler = class {
17088
17087
  * @param listener on fs change
17089
17088
  * @returns closer for the watcher instance
17090
17089
  */
17091
- _watchWithNodeFs(path19, listener) {
17090
+ _watchWithNodeFs(path18, listener) {
17092
17091
  const opts = this.fsw.options;
17093
- const directory = sp.dirname(path19);
17094
- const basename7 = sp.basename(path19);
17092
+ const directory = sp.dirname(path18);
17093
+ const basename7 = sp.basename(path18);
17095
17094
  const parent = this.fsw._getWatchedDir(directory);
17096
17095
  parent.add(basename7);
17097
- const absolutePath = sp.resolve(path19);
17096
+ const absolutePath = sp.resolve(path18);
17098
17097
  const options = {
17099
17098
  persistent: opts.persistent
17100
17099
  };
@@ -17104,12 +17103,12 @@ var NodeFsHandler = class {
17104
17103
  if (opts.usePolling) {
17105
17104
  const enableBin = opts.interval !== opts.binaryInterval;
17106
17105
  options.interval = enableBin && isBinaryPath(basename7) ? opts.binaryInterval : opts.interval;
17107
- closer = setFsWatchFileListener(path19, absolutePath, options, {
17106
+ closer = setFsWatchFileListener(path18, absolutePath, options, {
17108
17107
  listener,
17109
17108
  rawEmitter: this.fsw._emitRaw
17110
17109
  });
17111
17110
  } else {
17112
- closer = setFsWatchListener(path19, absolutePath, options, {
17111
+ closer = setFsWatchListener(path18, absolutePath, options, {
17113
17112
  listener,
17114
17113
  errHandler: this._boundHandleError,
17115
17114
  rawEmitter: this.fsw._emitRaw
@@ -17131,7 +17130,7 @@ var NodeFsHandler = class {
17131
17130
  let prevStats = stats;
17132
17131
  if (parent.has(basename7))
17133
17132
  return;
17134
- const listener = async (path19, newStats) => {
17133
+ const listener = async (path18, newStats) => {
17135
17134
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file2, 5))
17136
17135
  return;
17137
17136
  if (!newStats || newStats.mtimeMs === 0) {
@@ -17145,11 +17144,11 @@ var NodeFsHandler = class {
17145
17144
  this.fsw._emit(EV.CHANGE, file2, newStats2);
17146
17145
  }
17147
17146
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
17148
- this.fsw._closeFile(path19);
17147
+ this.fsw._closeFile(path18);
17149
17148
  prevStats = newStats2;
17150
17149
  const closer2 = this._watchWithNodeFs(file2, listener);
17151
17150
  if (closer2)
17152
- this.fsw._addPathCloser(path19, closer2);
17151
+ this.fsw._addPathCloser(path18, closer2);
17153
17152
  } else {
17154
17153
  prevStats = newStats2;
17155
17154
  }
@@ -17181,7 +17180,7 @@ var NodeFsHandler = class {
17181
17180
  * @param item basename of this item
17182
17181
  * @returns true if no more processing is needed for this entry.
17183
17182
  */
17184
- async _handleSymlink(entry, directory, path19, item) {
17183
+ async _handleSymlink(entry, directory, path18, item) {
17185
17184
  if (this.fsw.closed) {
17186
17185
  return;
17187
17186
  }
@@ -17191,7 +17190,7 @@ var NodeFsHandler = class {
17191
17190
  this.fsw._incrReadyCount();
17192
17191
  let linkPath;
17193
17192
  try {
17194
- linkPath = await (0, import_promises2.realpath)(path19);
17193
+ linkPath = await (0, import_promises2.realpath)(path18);
17195
17194
  } catch (e) {
17196
17195
  this.fsw._emitReady();
17197
17196
  return true;
@@ -17201,12 +17200,12 @@ var NodeFsHandler = class {
17201
17200
  if (dir.has(item)) {
17202
17201
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
17203
17202
  this.fsw._symlinkPaths.set(full, linkPath);
17204
- this.fsw._emit(EV.CHANGE, path19, entry.stats);
17203
+ this.fsw._emit(EV.CHANGE, path18, entry.stats);
17205
17204
  }
17206
17205
  } else {
17207
17206
  dir.add(item);
17208
17207
  this.fsw._symlinkPaths.set(full, linkPath);
17209
- this.fsw._emit(EV.ADD, path19, entry.stats);
17208
+ this.fsw._emit(EV.ADD, path18, entry.stats);
17210
17209
  }
17211
17210
  this.fsw._emitReady();
17212
17211
  return true;
@@ -17236,9 +17235,9 @@ var NodeFsHandler = class {
17236
17235
  return;
17237
17236
  }
17238
17237
  const item = entry.path;
17239
- let path19 = sp.join(directory, item);
17238
+ let path18 = sp.join(directory, item);
17240
17239
  current.add(item);
17241
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path19, item)) {
17240
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path18, item)) {
17242
17241
  return;
17243
17242
  }
17244
17243
  if (this.fsw.closed) {
@@ -17247,11 +17246,11 @@ var NodeFsHandler = class {
17247
17246
  }
17248
17247
  if (item === target || !target && !previous.has(item)) {
17249
17248
  this.fsw._incrReadyCount();
17250
- path19 = sp.join(dir, sp.relative(dir, path19));
17251
- this._addToNodeFs(path19, initialAdd, wh, depth + 1);
17249
+ path18 = sp.join(dir, sp.relative(dir, path18));
17250
+ this._addToNodeFs(path18, initialAdd, wh, depth + 1);
17252
17251
  }
17253
17252
  }).on(EV.ERROR, this._boundHandleError);
17254
- return new Promise((resolve13, reject) => {
17253
+ return new Promise((resolve12, reject) => {
17255
17254
  if (!stream)
17256
17255
  return reject();
17257
17256
  stream.once(STR_END, () => {
@@ -17260,7 +17259,7 @@ var NodeFsHandler = class {
17260
17259
  return;
17261
17260
  }
17262
17261
  const wasThrottled = throttler ? throttler.clear() : false;
17263
- resolve13(void 0);
17262
+ resolve12(void 0);
17264
17263
  previous.getChildren().filter((item) => {
17265
17264
  return item !== directory && !current.has(item);
17266
17265
  }).forEach((item) => {
@@ -17317,13 +17316,13 @@ var NodeFsHandler = class {
17317
17316
  * @param depth Child path actually targeted for watch
17318
17317
  * @param target Child path actually targeted for watch
17319
17318
  */
17320
- async _addToNodeFs(path19, initialAdd, priorWh, depth, target) {
17319
+ async _addToNodeFs(path18, initialAdd, priorWh, depth, target) {
17321
17320
  const ready = this.fsw._emitReady;
17322
- if (this.fsw._isIgnored(path19) || this.fsw.closed) {
17321
+ if (this.fsw._isIgnored(path18) || this.fsw.closed) {
17323
17322
  ready();
17324
17323
  return false;
17325
17324
  }
17326
- const wh = this.fsw._getWatchHelpers(path19);
17325
+ const wh = this.fsw._getWatchHelpers(path18);
17327
17326
  if (priorWh) {
17328
17327
  wh.filterPath = (entry) => priorWh.filterPath(entry);
17329
17328
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -17339,8 +17338,8 @@ var NodeFsHandler = class {
17339
17338
  const follow = this.fsw.options.followSymlinks;
17340
17339
  let closer;
17341
17340
  if (stats.isDirectory()) {
17342
- const absPath = sp.resolve(path19);
17343
- const targetPath = follow ? await (0, import_promises2.realpath)(path19) : path19;
17341
+ const absPath = sp.resolve(path18);
17342
+ const targetPath = follow ? await (0, import_promises2.realpath)(path18) : path18;
17344
17343
  if (this.fsw.closed)
17345
17344
  return;
17346
17345
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -17350,29 +17349,29 @@ var NodeFsHandler = class {
17350
17349
  this.fsw._symlinkPaths.set(absPath, targetPath);
17351
17350
  }
17352
17351
  } else if (stats.isSymbolicLink()) {
17353
- const targetPath = follow ? await (0, import_promises2.realpath)(path19) : path19;
17352
+ const targetPath = follow ? await (0, import_promises2.realpath)(path18) : path18;
17354
17353
  if (this.fsw.closed)
17355
17354
  return;
17356
17355
  const parent = sp.dirname(wh.watchPath);
17357
17356
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
17358
17357
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
17359
- closer = await this._handleDir(parent, stats, initialAdd, depth, path19, wh, targetPath);
17358
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path18, wh, targetPath);
17360
17359
  if (this.fsw.closed)
17361
17360
  return;
17362
17361
  if (targetPath !== void 0) {
17363
- this.fsw._symlinkPaths.set(sp.resolve(path19), targetPath);
17362
+ this.fsw._symlinkPaths.set(sp.resolve(path18), targetPath);
17364
17363
  }
17365
17364
  } else {
17366
17365
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
17367
17366
  }
17368
17367
  ready();
17369
17368
  if (closer)
17370
- this.fsw._addPathCloser(path19, closer);
17369
+ this.fsw._addPathCloser(path18, closer);
17371
17370
  return false;
17372
17371
  } catch (error48) {
17373
17372
  if (this.fsw._handleError(error48)) {
17374
17373
  ready();
17375
- return path19;
17374
+ return path18;
17376
17375
  }
17377
17376
  }
17378
17377
  }
@@ -17415,24 +17414,24 @@ function createPattern(matcher) {
17415
17414
  }
17416
17415
  return () => false;
17417
17416
  }
17418
- function normalizePath(path19) {
17419
- if (typeof path19 !== "string")
17417
+ function normalizePath(path18) {
17418
+ if (typeof path18 !== "string")
17420
17419
  throw new Error("string expected");
17421
- path19 = sp2.normalize(path19);
17422
- path19 = path19.replace(/\\/g, "/");
17420
+ path18 = sp2.normalize(path18);
17421
+ path18 = path18.replace(/\\/g, "/");
17423
17422
  let prepend = false;
17424
- if (path19.startsWith("//"))
17423
+ if (path18.startsWith("//"))
17425
17424
  prepend = true;
17426
- path19 = path19.replace(DOUBLE_SLASH_RE, "/");
17425
+ path18 = path18.replace(DOUBLE_SLASH_RE, "/");
17427
17426
  if (prepend)
17428
- path19 = "/" + path19;
17429
- return path19;
17427
+ path18 = "/" + path18;
17428
+ return path18;
17430
17429
  }
17431
17430
  function matchPatterns(patterns, testString, stats) {
17432
- const path19 = normalizePath(testString);
17431
+ const path18 = normalizePath(testString);
17433
17432
  for (let index = 0; index < patterns.length; index++) {
17434
17433
  const pattern = patterns[index];
17435
- if (pattern(path19, stats)) {
17434
+ if (pattern(path18, stats)) {
17436
17435
  return true;
17437
17436
  }
17438
17437
  }
@@ -17470,19 +17469,19 @@ var toUnix = (string4) => {
17470
17469
  }
17471
17470
  return str;
17472
17471
  };
17473
- var normalizePathToUnix = (path19) => toUnix(sp2.normalize(toUnix(path19)));
17474
- var normalizeIgnored = (cwd = "") => (path19) => {
17475
- if (typeof path19 === "string") {
17476
- return normalizePathToUnix(sp2.isAbsolute(path19) ? path19 : sp2.join(cwd, path19));
17472
+ var normalizePathToUnix = (path18) => toUnix(sp2.normalize(toUnix(path18)));
17473
+ var normalizeIgnored = (cwd = "") => (path18) => {
17474
+ if (typeof path18 === "string") {
17475
+ return normalizePathToUnix(sp2.isAbsolute(path18) ? path18 : sp2.join(cwd, path18));
17477
17476
  } else {
17478
- return path19;
17477
+ return path18;
17479
17478
  }
17480
17479
  };
17481
- var getAbsolutePath = (path19, cwd) => {
17482
- if (sp2.isAbsolute(path19)) {
17483
- return path19;
17480
+ var getAbsolutePath = (path18, cwd) => {
17481
+ if (sp2.isAbsolute(path18)) {
17482
+ return path18;
17484
17483
  }
17485
- return sp2.join(cwd, path19);
17484
+ return sp2.join(cwd, path18);
17486
17485
  };
17487
17486
  var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
17488
17487
  var DirEntry = class {
@@ -17547,10 +17546,10 @@ var WatchHelper = class {
17547
17546
  dirParts;
17548
17547
  followSymlinks;
17549
17548
  statMethod;
17550
- constructor(path19, follow, fsw) {
17549
+ constructor(path18, follow, fsw) {
17551
17550
  this.fsw = fsw;
17552
- const watchPath = path19;
17553
- this.path = path19 = path19.replace(REPLACER_RE, "");
17551
+ const watchPath = path18;
17552
+ this.path = path18 = path18.replace(REPLACER_RE, "");
17554
17553
  this.watchPath = watchPath;
17555
17554
  this.fullWatchPath = sp2.resolve(watchPath);
17556
17555
  this.dirParts = [];
@@ -17690,20 +17689,20 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17690
17689
  this._closePromise = void 0;
17691
17690
  let paths = unifyPaths(paths_);
17692
17691
  if (cwd) {
17693
- paths = paths.map((path19) => {
17694
- const absPath = getAbsolutePath(path19, cwd);
17692
+ paths = paths.map((path18) => {
17693
+ const absPath = getAbsolutePath(path18, cwd);
17695
17694
  return absPath;
17696
17695
  });
17697
17696
  }
17698
- paths.forEach((path19) => {
17699
- this._removeIgnoredPath(path19);
17697
+ paths.forEach((path18) => {
17698
+ this._removeIgnoredPath(path18);
17700
17699
  });
17701
17700
  this._userIgnored = void 0;
17702
17701
  if (!this._readyCount)
17703
17702
  this._readyCount = 0;
17704
17703
  this._readyCount += paths.length;
17705
- Promise.all(paths.map(async (path19) => {
17706
- const res = await this._nodeFsHandler._addToNodeFs(path19, !_internal, void 0, 0, _origAdd);
17704
+ Promise.all(paths.map(async (path18) => {
17705
+ const res = await this._nodeFsHandler._addToNodeFs(path18, !_internal, void 0, 0, _origAdd);
17707
17706
  if (res)
17708
17707
  this._emitReady();
17709
17708
  return res;
@@ -17725,17 +17724,17 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17725
17724
  return this;
17726
17725
  const paths = unifyPaths(paths_);
17727
17726
  const { cwd } = this.options;
17728
- paths.forEach((path19) => {
17729
- if (!sp2.isAbsolute(path19) && !this._closers.has(path19)) {
17727
+ paths.forEach((path18) => {
17728
+ if (!sp2.isAbsolute(path18) && !this._closers.has(path18)) {
17730
17729
  if (cwd)
17731
- path19 = sp2.join(cwd, path19);
17732
- path19 = sp2.resolve(path19);
17730
+ path18 = sp2.join(cwd, path18);
17731
+ path18 = sp2.resolve(path18);
17733
17732
  }
17734
- this._closePath(path19);
17735
- this._addIgnoredPath(path19);
17736
- if (this._watched.has(path19)) {
17733
+ this._closePath(path18);
17734
+ this._addIgnoredPath(path18);
17735
+ if (this._watched.has(path18)) {
17737
17736
  this._addIgnoredPath({
17738
- path: path19,
17737
+ path: path18,
17739
17738
  recursive: true
17740
17739
  });
17741
17740
  }
@@ -17799,38 +17798,38 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17799
17798
  * @param stats arguments to be passed with event
17800
17799
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
17801
17800
  */
17802
- async _emit(event, path19, stats) {
17801
+ async _emit(event, path18, stats) {
17803
17802
  if (this.closed)
17804
17803
  return;
17805
17804
  const opts = this.options;
17806
17805
  if (isWindows)
17807
- path19 = sp2.normalize(path19);
17806
+ path18 = sp2.normalize(path18);
17808
17807
  if (opts.cwd)
17809
- path19 = sp2.relative(opts.cwd, path19);
17810
- const args = [path19];
17808
+ path18 = sp2.relative(opts.cwd, path18);
17809
+ const args = [path18];
17811
17810
  if (stats != null)
17812
17811
  args.push(stats);
17813
17812
  const awf = opts.awaitWriteFinish;
17814
17813
  let pw;
17815
- if (awf && (pw = this._pendingWrites.get(path19))) {
17814
+ if (awf && (pw = this._pendingWrites.get(path18))) {
17816
17815
  pw.lastChange = /* @__PURE__ */ new Date();
17817
17816
  return this;
17818
17817
  }
17819
17818
  if (opts.atomic) {
17820
17819
  if (event === EVENTS.UNLINK) {
17821
- this._pendingUnlinks.set(path19, [event, ...args]);
17820
+ this._pendingUnlinks.set(path18, [event, ...args]);
17822
17821
  setTimeout(() => {
17823
- this._pendingUnlinks.forEach((entry, path20) => {
17822
+ this._pendingUnlinks.forEach((entry, path19) => {
17824
17823
  this.emit(...entry);
17825
17824
  this.emit(EVENTS.ALL, ...entry);
17826
- this._pendingUnlinks.delete(path20);
17825
+ this._pendingUnlinks.delete(path19);
17827
17826
  });
17828
17827
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
17829
17828
  return this;
17830
17829
  }
17831
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path19)) {
17830
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path18)) {
17832
17831
  event = EVENTS.CHANGE;
17833
- this._pendingUnlinks.delete(path19);
17832
+ this._pendingUnlinks.delete(path18);
17834
17833
  }
17835
17834
  }
17836
17835
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -17848,16 +17847,16 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17848
17847
  this.emitWithAll(event, args);
17849
17848
  }
17850
17849
  };
17851
- this._awaitWriteFinish(path19, awf.stabilityThreshold, event, awfEmit);
17850
+ this._awaitWriteFinish(path18, awf.stabilityThreshold, event, awfEmit);
17852
17851
  return this;
17853
17852
  }
17854
17853
  if (event === EVENTS.CHANGE) {
17855
- const isThrottled = !this._throttle(EVENTS.CHANGE, path19, 50);
17854
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path18, 50);
17856
17855
  if (isThrottled)
17857
17856
  return this;
17858
17857
  }
17859
17858
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
17860
- const fullPath = opts.cwd ? sp2.join(opts.cwd, path19) : path19;
17859
+ const fullPath = opts.cwd ? sp2.join(opts.cwd, path18) : path18;
17861
17860
  let stats2;
17862
17861
  try {
17863
17862
  stats2 = await (0, import_promises3.stat)(fullPath);
@@ -17888,23 +17887,23 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17888
17887
  * @param timeout duration of time to suppress duplicate actions
17889
17888
  * @returns tracking object or false if action should be suppressed
17890
17889
  */
17891
- _throttle(actionType, path19, timeout) {
17890
+ _throttle(actionType, path18, timeout) {
17892
17891
  if (!this._throttled.has(actionType)) {
17893
17892
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
17894
17893
  }
17895
17894
  const action = this._throttled.get(actionType);
17896
17895
  if (!action)
17897
17896
  throw new Error("invalid throttle");
17898
- const actionPath = action.get(path19);
17897
+ const actionPath = action.get(path18);
17899
17898
  if (actionPath) {
17900
17899
  actionPath.count++;
17901
17900
  return false;
17902
17901
  }
17903
17902
  let timeoutObject;
17904
17903
  const clear = () => {
17905
- const item = action.get(path19);
17904
+ const item = action.get(path18);
17906
17905
  const count = item ? item.count : 0;
17907
- action.delete(path19);
17906
+ action.delete(path18);
17908
17907
  clearTimeout(timeoutObject);
17909
17908
  if (item)
17910
17909
  clearTimeout(item.timeoutObject);
@@ -17912,7 +17911,7 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17912
17911
  };
17913
17912
  timeoutObject = setTimeout(clear, timeout);
17914
17913
  const thr = { timeoutObject, clear, count: 0 };
17915
- action.set(path19, thr);
17914
+ action.set(path18, thr);
17916
17915
  return thr;
17917
17916
  }
17918
17917
  _incrReadyCount() {
@@ -17926,44 +17925,44 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17926
17925
  * @param event
17927
17926
  * @param awfEmit Callback to be called when ready for event to be emitted.
17928
17927
  */
17929
- _awaitWriteFinish(path19, threshold, event, awfEmit) {
17928
+ _awaitWriteFinish(path18, threshold, event, awfEmit) {
17930
17929
  const awf = this.options.awaitWriteFinish;
17931
17930
  if (typeof awf !== "object")
17932
17931
  return;
17933
17932
  const pollInterval = awf.pollInterval;
17934
17933
  let timeoutHandler;
17935
- let fullPath = path19;
17936
- if (this.options.cwd && !sp2.isAbsolute(path19)) {
17937
- fullPath = sp2.join(this.options.cwd, path19);
17934
+ let fullPath = path18;
17935
+ if (this.options.cwd && !sp2.isAbsolute(path18)) {
17936
+ fullPath = sp2.join(this.options.cwd, path18);
17938
17937
  }
17939
17938
  const now = /* @__PURE__ */ new Date();
17940
17939
  const writes = this._pendingWrites;
17941
17940
  function awaitWriteFinishFn(prevStat) {
17942
17941
  (0, import_node_fs2.stat)(fullPath, (err, curStat) => {
17943
- if (err || !writes.has(path19)) {
17942
+ if (err || !writes.has(path18)) {
17944
17943
  if (err && err.code !== "ENOENT")
17945
17944
  awfEmit(err);
17946
17945
  return;
17947
17946
  }
17948
17947
  const now2 = Number(/* @__PURE__ */ new Date());
17949
17948
  if (prevStat && curStat.size !== prevStat.size) {
17950
- writes.get(path19).lastChange = now2;
17949
+ writes.get(path18).lastChange = now2;
17951
17950
  }
17952
- const pw = writes.get(path19);
17951
+ const pw = writes.get(path18);
17953
17952
  const df = now2 - pw.lastChange;
17954
17953
  if (df >= threshold) {
17955
- writes.delete(path19);
17954
+ writes.delete(path18);
17956
17955
  awfEmit(void 0, curStat);
17957
17956
  } else {
17958
17957
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
17959
17958
  }
17960
17959
  });
17961
17960
  }
17962
- if (!writes.has(path19)) {
17963
- writes.set(path19, {
17961
+ if (!writes.has(path18)) {
17962
+ writes.set(path18, {
17964
17963
  lastChange: now,
17965
17964
  cancelWait: () => {
17966
- writes.delete(path19);
17965
+ writes.delete(path18);
17967
17966
  clearTimeout(timeoutHandler);
17968
17967
  return event;
17969
17968
  }
@@ -17974,8 +17973,8 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17974
17973
  /**
17975
17974
  * Determines whether user has asked to ignore this path.
17976
17975
  */
17977
- _isIgnored(path19, stats) {
17978
- if (this.options.atomic && DOT_RE.test(path19))
17976
+ _isIgnored(path18, stats) {
17977
+ if (this.options.atomic && DOT_RE.test(path18))
17979
17978
  return true;
17980
17979
  if (!this._userIgnored) {
17981
17980
  const { cwd } = this.options;
@@ -17985,17 +17984,17 @@ var FSWatcher = class extends import_node_events.EventEmitter {
17985
17984
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
17986
17985
  this._userIgnored = anymatch(list, void 0);
17987
17986
  }
17988
- return this._userIgnored(path19, stats);
17987
+ return this._userIgnored(path18, stats);
17989
17988
  }
17990
- _isntIgnored(path19, stat4) {
17991
- return !this._isIgnored(path19, stat4);
17989
+ _isntIgnored(path18, stat4) {
17990
+ return !this._isIgnored(path18, stat4);
17992
17991
  }
17993
17992
  /**
17994
17993
  * Provides a set of common helpers and properties relating to symlink handling.
17995
17994
  * @param path file or directory pattern being watched
17996
17995
  */
17997
- _getWatchHelpers(path19) {
17998
- return new WatchHelper(path19, this.options.followSymlinks, this);
17996
+ _getWatchHelpers(path18) {
17997
+ return new WatchHelper(path18, this.options.followSymlinks, this);
17999
17998
  }
18000
17999
  // Directory helpers
18001
18000
  // -----------------
@@ -18027,63 +18026,63 @@ var FSWatcher = class extends import_node_events.EventEmitter {
18027
18026
  * @param item base path of item/directory
18028
18027
  */
18029
18028
  _remove(directory, item, isDirectory) {
18030
- const path19 = sp2.join(directory, item);
18031
- const fullPath = sp2.resolve(path19);
18032
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path19) || this._watched.has(fullPath);
18033
- if (!this._throttle("remove", path19, 100))
18029
+ const path18 = sp2.join(directory, item);
18030
+ const fullPath = sp2.resolve(path18);
18031
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path18) || this._watched.has(fullPath);
18032
+ if (!this._throttle("remove", path18, 100))
18034
18033
  return;
18035
18034
  if (!isDirectory && this._watched.size === 1) {
18036
18035
  this.add(directory, item, true);
18037
18036
  }
18038
- const wp = this._getWatchedDir(path19);
18037
+ const wp = this._getWatchedDir(path18);
18039
18038
  const nestedDirectoryChildren = wp.getChildren();
18040
- nestedDirectoryChildren.forEach((nested) => this._remove(path19, nested));
18039
+ nestedDirectoryChildren.forEach((nested) => this._remove(path18, nested));
18041
18040
  const parent = this._getWatchedDir(directory);
18042
18041
  const wasTracked = parent.has(item);
18043
18042
  parent.remove(item);
18044
18043
  if (this._symlinkPaths.has(fullPath)) {
18045
18044
  this._symlinkPaths.delete(fullPath);
18046
18045
  }
18047
- let relPath = path19;
18046
+ let relPath = path18;
18048
18047
  if (this.options.cwd)
18049
- relPath = sp2.relative(this.options.cwd, path19);
18048
+ relPath = sp2.relative(this.options.cwd, path18);
18050
18049
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
18051
18050
  const event = this._pendingWrites.get(relPath).cancelWait();
18052
18051
  if (event === EVENTS.ADD)
18053
18052
  return;
18054
18053
  }
18055
- this._watched.delete(path19);
18054
+ this._watched.delete(path18);
18056
18055
  this._watched.delete(fullPath);
18057
18056
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
18058
- if (wasTracked && !this._isIgnored(path19))
18059
- this._emit(eventName, path19);
18060
- this._closePath(path19);
18057
+ if (wasTracked && !this._isIgnored(path18))
18058
+ this._emit(eventName, path18);
18059
+ this._closePath(path18);
18061
18060
  }
18062
18061
  /**
18063
18062
  * Closes all watchers for a path
18064
18063
  */
18065
- _closePath(path19) {
18066
- this._closeFile(path19);
18067
- const dir = sp2.dirname(path19);
18068
- this._getWatchedDir(dir).remove(sp2.basename(path19));
18064
+ _closePath(path18) {
18065
+ this._closeFile(path18);
18066
+ const dir = sp2.dirname(path18);
18067
+ this._getWatchedDir(dir).remove(sp2.basename(path18));
18069
18068
  }
18070
18069
  /**
18071
18070
  * Closes only file-specific watchers
18072
18071
  */
18073
- _closeFile(path19) {
18074
- const closers = this._closers.get(path19);
18072
+ _closeFile(path18) {
18073
+ const closers = this._closers.get(path18);
18075
18074
  if (!closers)
18076
18075
  return;
18077
18076
  closers.forEach((closer) => closer());
18078
- this._closers.delete(path19);
18077
+ this._closers.delete(path18);
18079
18078
  }
18080
- _addPathCloser(path19, closer) {
18079
+ _addPathCloser(path18, closer) {
18081
18080
  if (!closer)
18082
18081
  return;
18083
- let list = this._closers.get(path19);
18082
+ let list = this._closers.get(path18);
18084
18083
  if (!list) {
18085
18084
  list = [];
18086
- this._closers.set(path19, list);
18085
+ this._closers.set(path18, list);
18087
18086
  }
18088
18087
  list.push(closer);
18089
18088
  }
@@ -18113,12 +18112,12 @@ function watch(paths, options = {}) {
18113
18112
 
18114
18113
  // ../daemon-core/dist/index.mjs
18115
18114
  var fs6 = __toESM(require("fs"), 1);
18116
- var path9 = __toESM(require("path"), 1);
18115
+ var path8 = __toESM(require("path"), 1);
18117
18116
  var os9 = __toESM(require("os"), 1);
18118
18117
  var fs7 = __toESM(require("fs"), 1);
18119
18118
  var os10 = __toESM(require("os"), 1);
18120
18119
  var os13 = __toESM(require("os"), 1);
18121
- var path11 = __toESM(require("path"), 1);
18120
+ var path10 = __toESM(require("path"), 1);
18122
18121
  var crypto4 = __toESM(require("crypto"), 1);
18123
18122
  var import_chalk = __toESM(require("chalk"), 1);
18124
18123
  var crypto3 = __toESM(require("crypto"), 1);
@@ -18126,17 +18125,17 @@ var import_stream = require("stream");
18126
18125
  var import_child_process6 = require("child_process");
18127
18126
  init_acp();
18128
18127
  var fs8 = __toESM(require("fs"), 1);
18129
- var path12 = __toESM(require("path"), 1);
18128
+ var path11 = __toESM(require("path"), 1);
18130
18129
  var os14 = __toESM(require("os"), 1);
18131
18130
  var import_child_process7 = require("child_process");
18132
18131
  var import_os3 = require("os");
18133
18132
  var http2 = __toESM(require("http"), 1);
18134
18133
  var fs11 = __toESM(require("fs"), 1);
18135
- var path15 = __toESM(require("path"), 1);
18134
+ var path14 = __toESM(require("path"), 1);
18136
18135
  var fs9 = __toESM(require("fs"), 1);
18137
- var path13 = __toESM(require("path"), 1);
18136
+ var path12 = __toESM(require("path"), 1);
18138
18137
  var fs10 = __toESM(require("fs"), 1);
18139
- var path14 = __toESM(require("path"), 1);
18138
+ var path13 = __toESM(require("path"), 1);
18140
18139
  var os15 = __toESM(require("os"), 1);
18141
18140
 
18142
18141
  // ../session-host-core/dist/index.mjs
@@ -18206,8 +18205,8 @@ var SessionHostClient = class {
18206
18205
  }
18207
18206
  this.requestWaiters.clear();
18208
18207
  });
18209
- await new Promise((resolve13, reject) => {
18210
- socket.once("connect", () => resolve13());
18208
+ await new Promise((resolve12, reject) => {
18209
+ socket.once("connect", () => resolve12());
18211
18210
  socket.once("error", reject);
18212
18211
  });
18213
18212
  }
@@ -18226,7 +18225,7 @@ var SessionHostClient = class {
18226
18225
  requestId,
18227
18226
  request
18228
18227
  };
18229
- const response = await new Promise((resolve13, reject) => {
18228
+ const response = await new Promise((resolve12, reject) => {
18230
18229
  const timeout = setTimeout(() => {
18231
18230
  this.requestWaiters.delete(requestId);
18232
18231
  reject(new Error(`Session host request timed out after 30s (${request.type})`));
@@ -18234,7 +18233,7 @@ var SessionHostClient = class {
18234
18233
  this.requestWaiters.set(requestId, {
18235
18234
  resolve: (value) => {
18236
18235
  clearTimeout(timeout);
18237
- resolve13(value);
18236
+ resolve12(value);
18238
18237
  },
18239
18238
  reject: (error48) => {
18240
18239
  clearTimeout(timeout);
@@ -18253,12 +18252,12 @@ var SessionHostClient = class {
18253
18252
  waiter.reject(new Error("Session host client closed"));
18254
18253
  }
18255
18254
  this.requestWaiters.clear();
18256
- await new Promise((resolve13) => {
18255
+ await new Promise((resolve12) => {
18257
18256
  let settled = false;
18258
18257
  const done = () => {
18259
18258
  if (settled) return;
18260
18259
  settled = true;
18261
- resolve13();
18260
+ resolve12();
18262
18261
  };
18263
18262
  socket.once("close", done);
18264
18263
  socket.end();
@@ -18295,194 +18294,8 @@ var __copyProps2 = (to, from, except, desc) => {
18295
18294
  return to;
18296
18295
  };
18297
18296
  var __toCommonJS = (mod) => __copyProps2(__defProp2({}, "__esModule", { value: true }), mod);
18298
- function expandPath(p) {
18299
- const t = (p || "").trim();
18300
- if (!t) return "";
18301
- if (t.startsWith("~")) return path.join(os2.homedir(), t.slice(1).replace(/^\//, ""));
18302
- return path.resolve(t);
18303
- }
18304
- function validateWorkspacePath(absPath) {
18305
- try {
18306
- if (!absPath) return { ok: false, error: "Path required" };
18307
- if (!fs.existsSync(absPath)) return { ok: false, error: "Path does not exist" };
18308
- const st = fs.statSync(absPath);
18309
- if (!st.isDirectory()) return { ok: false, error: "Not a directory" };
18310
- return { ok: true };
18311
- } catch (e) {
18312
- return { ok: false, error: e?.message || "Invalid path" };
18313
- }
18314
- }
18315
- function defaultWorkspaceLabel(absPath) {
18316
- const base = path.basename(absPath) || absPath;
18317
- return base;
18318
- }
18319
- function migrateWorkspacesFromRecent(config2) {
18320
- if (!config2.workspaces) config2.workspaces = [];
18321
- if (config2.workspaces.length > 0) return config2;
18322
- const recent = config2.recentCliWorkspaces || [];
18323
- const now = Date.now();
18324
- for (const raw of recent) {
18325
- const abs = expandPath(raw);
18326
- if (!abs || validateWorkspacePath(abs).ok !== true) continue;
18327
- if (config2.workspaces.some((w) => path.resolve(w.path) === abs)) continue;
18328
- config2.workspaces.push({
18329
- id: (0, import_crypto2.randomUUID)(),
18330
- path: abs,
18331
- label: defaultWorkspaceLabel(abs),
18332
- addedAt: now
18333
- });
18334
- if (config2.workspaces.length >= MAX_WORKSPACES) break;
18335
- }
18336
- return config2;
18337
- }
18338
- function getDefaultWorkspacePath(config2) {
18339
- const id = config2.defaultWorkspaceId;
18340
- if (!id) return null;
18341
- const w = (config2.workspaces || []).find((x) => x.id === id);
18342
- if (!w) return null;
18343
- const abs = expandPath(w.path);
18344
- if (validateWorkspacePath(abs).ok !== true) return null;
18345
- return abs;
18346
- }
18347
- function getWorkspaceState(config2) {
18348
- const workspaces = [...config2.workspaces || []].sort((a, b) => b.addedAt - a.addedAt);
18349
- const defaultWorkspacePath = getDefaultWorkspacePath(config2);
18350
- return {
18351
- workspaces,
18352
- defaultWorkspaceId: config2.defaultWorkspaceId ?? null,
18353
- defaultWorkspacePath
18354
- };
18355
- }
18356
- function resolveLaunchDirectory(args, config2) {
18357
- const a = args || {};
18358
- if (a.dir != null && String(a.dir).trim()) {
18359
- const abs = expandPath(String(a.dir).trim());
18360
- if (abs && validateWorkspacePath(abs).ok === true) {
18361
- return { ok: true, path: abs, source: "dir" };
18362
- }
18363
- return {
18364
- ok: false,
18365
- code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
18366
- message: abs ? "Directory path is not valid or does not exist" : "Invalid directory path"
18367
- };
18368
- }
18369
- if (a.workspaceId) {
18370
- const w = (config2.workspaces || []).find((x) => x.id === a.workspaceId);
18371
- if (w) {
18372
- const abs = expandPath(w.path);
18373
- if (validateWorkspacePath(abs).ok === true) {
18374
- return { ok: true, path: abs, source: "workspaceId" };
18375
- }
18376
- }
18377
- return {
18378
- ok: false,
18379
- code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
18380
- message: "Saved workspace not found or path is no longer valid"
18381
- };
18382
- }
18383
- if (a.useDefaultWorkspace === true) {
18384
- const d = getDefaultWorkspacePath(config2);
18385
- if (d) return { ok: true, path: d, source: "defaultWorkspace" };
18386
- return {
18387
- ok: false,
18388
- code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
18389
- message: "No default workspace is set"
18390
- };
18391
- }
18392
- if (a.useHome === true) {
18393
- return { ok: true, path: os2.homedir(), source: "home" };
18394
- }
18395
- return {
18396
- ok: false,
18397
- code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
18398
- message: "Choose a directory, saved workspace, default workspace, or home before launching."
18399
- };
18400
- }
18401
- function resolveIdeWorkspaceFromArgs(args, config2) {
18402
- const ar = args || {};
18403
- if (ar.workspace) {
18404
- const abs = expandPath(ar.workspace);
18405
- if (abs && validateWorkspacePath(abs).ok === true) return abs;
18406
- }
18407
- if (ar.workspaceId) {
18408
- const w = (config2.workspaces || []).find((x) => x.id === ar.workspaceId);
18409
- if (w) {
18410
- const abs = expandPath(w.path);
18411
- if (validateWorkspacePath(abs).ok === true) return abs;
18412
- }
18413
- }
18414
- if (ar.useDefaultWorkspace === true) {
18415
- return getDefaultWorkspacePath(config2) || void 0;
18416
- }
18417
- return void 0;
18418
- }
18419
- function resolveIdeLaunchWorkspace(args, config2) {
18420
- const direct = resolveIdeWorkspaceFromArgs(args, config2);
18421
- if (direct) return direct;
18422
- if (args?.useDefaultWorkspace === false) return void 0;
18423
- return getDefaultWorkspacePath(config2) || void 0;
18424
- }
18425
- function findWorkspaceByPath(config2, rawPath) {
18426
- const abs = path.resolve(expandPath(rawPath));
18427
- if (!abs) return void 0;
18428
- return (config2.workspaces || []).find((w) => path.resolve(expandPath(w.path)) === abs);
18429
- }
18430
- function addWorkspaceEntry(config2, rawPath, label, options) {
18431
- const abs = expandPath(rawPath);
18432
- const createIfMissing = options?.createIfMissing === true;
18433
- if (!abs) return { error: "Path required" };
18434
- if (!fs.existsSync(abs) && createIfMissing) {
18435
- try {
18436
- fs.mkdirSync(abs, { recursive: true });
18437
- } catch (e) {
18438
- return { error: e?.message || "Could not create directory" };
18439
- }
18440
- }
18441
- const v = validateWorkspacePath(abs);
18442
- if (!v.ok) return { error: v.error };
18443
- const list = [...config2.workspaces || []];
18444
- if (list.some((w) => path.resolve(w.path) === abs)) {
18445
- return { error: "Workspace already in list" };
18446
- }
18447
- if (list.length >= MAX_WORKSPACES) {
18448
- return { error: `Maximum ${MAX_WORKSPACES} workspaces` };
18449
- }
18450
- const entry = {
18451
- id: (0, import_crypto2.randomUUID)(),
18452
- path: abs,
18453
- label: (label || "").trim() || defaultWorkspaceLabel(abs),
18454
- addedAt: Date.now()
18455
- };
18456
- list.push(entry);
18457
- return { config: { ...config2, workspaces: list }, entry };
18458
- }
18459
- function removeWorkspaceEntry(config2, id) {
18460
- const list = (config2.workspaces || []).filter((w) => w.id !== id);
18461
- if (list.length === (config2.workspaces || []).length) return { error: "Workspace not found" };
18462
- let defaultWorkspaceId = config2.defaultWorkspaceId;
18463
- if (defaultWorkspaceId === id) defaultWorkspaceId = null;
18464
- return { config: { ...config2, workspaces: list, defaultWorkspaceId } };
18465
- }
18466
- function setDefaultWorkspaceId(config2, id) {
18467
- if (id === null) {
18468
- return { config: { ...config2, defaultWorkspaceId: null } };
18469
- }
18470
- const w = (config2.workspaces || []).find((x) => x.id === id);
18471
- if (!w) return { error: "Workspace not found" };
18472
- const abs = expandPath(w.path);
18473
- if (validateWorkspacePath(abs).ok !== true) return { error: "Workspace path is no longer valid" };
18474
- return { config: { ...config2, defaultWorkspaceId: id } };
18475
- }
18476
- var MAX_WORKSPACES;
18477
- var init_workspaces = __esm2({
18478
- "src/config/workspaces.ts"() {
18479
- "use strict";
18480
- MAX_WORKSPACES = 50;
18481
- }
18482
- });
18483
18297
  var config_exports = {};
18484
18298
  __export2(config_exports, {
18485
- addCliHistory: () => addCliHistory,
18486
18299
  generateConnectionToken: () => generateConnectionToken,
18487
18300
  generateMachineId: () => generateMachineId,
18488
18301
  getConfigDir: () => getConfigDir,
@@ -18495,7 +18308,7 @@ __export2(config_exports, {
18495
18308
  updateConfig: () => updateConfig
18496
18309
  });
18497
18310
  function generateMachineId() {
18498
- return `${MACHINE_ID_PREFIX}${(0, import_crypto3.randomUUID)().replace(/-/g, "")}`;
18311
+ return `${MACHINE_ID_PREFIX}${(0, import_crypto2.randomUUID)().replace(/-/g, "")}`;
18499
18312
  }
18500
18313
  function isStableMachineId(machineId) {
18501
18314
  return typeof machineId === "string" && machineId.startsWith(MACHINE_ID_PREFIX);
@@ -18542,15 +18355,9 @@ function loadConfig() {
18542
18355
  merged.defaultWorkspaceId = merged.activeWorkspaceId;
18543
18356
  }
18544
18357
  delete merged.activeWorkspaceId;
18545
- const hadStoredWorkspaces = Array.isArray(parsed.workspaces) && parsed.workspaces.length > 0;
18546
18358
  const ensured = ensureMachineId(merged);
18547
18359
  const normalized = ensured.config;
18548
- migrateWorkspacesFromRecent(normalized);
18549
- let configChanged = ensured.changed;
18550
- if (!hadStoredWorkspaces && (normalized.workspaces?.length || 0) > 0) {
18551
- configChanged = true;
18552
- }
18553
- if (configChanged) {
18360
+ if (ensured.changed) {
18554
18361
  try {
18555
18362
  saveConfig(normalized);
18556
18363
  } catch {
@@ -18605,40 +18412,11 @@ function generateConnectionToken() {
18605
18412
  }
18606
18413
  return token;
18607
18414
  }
18608
- function addCliHistory(entry) {
18609
- const config2 = loadConfig();
18610
- const history = config2.cliHistory || [];
18611
- const argsKey = (entry.cliArgs || []).join(" ");
18612
- const category = entry.category || "cli";
18613
- const workspaceKey = entry.workspace || "";
18614
- const modelKey = entry.model || "";
18615
- const filtered = history.filter((h) => {
18616
- const hArgsKey = (h.cliArgs || []).join(" ");
18617
- return !((h.category || "cli") === category && h.cliType === entry.cliType && h.dir === entry.dir && hArgsKey === argsKey && (h.workspace || "") === workspaceKey && (h.model || "") === modelKey);
18618
- });
18619
- filtered.unshift({
18620
- ...entry,
18621
- category,
18622
- timestamp: Date.now(),
18623
- label: entry.label || (() => {
18624
- const base = `${entry.cliType} \xB7 ${entry.dir.split("/").filter(Boolean).pop() || "root"}`;
18625
- const suffix = [];
18626
- if (entry.workspace && entry.workspace !== entry.dir) suffix.push(entry.workspace.split("/").filter(Boolean).pop() || entry.workspace);
18627
- if (entry.model) suffix.push(`model=${entry.model}`);
18628
- if (argsKey) suffix.push(argsKey);
18629
- if (entry.newWindow) suffix.push("new window");
18630
- return suffix.length > 0 ? `${base} (${suffix.join(" \xB7 ")})` : base;
18631
- })()
18632
- });
18633
- config2.cliHistory = filtered.slice(0, 20);
18634
- saveConfig(config2);
18635
- }
18636
18415
  var DEFAULT_CONFIG;
18637
18416
  var MACHINE_ID_PREFIX;
18638
18417
  var init_config = __esm2({
18639
18418
  "src/config/config.ts"() {
18640
18419
  "use strict";
18641
- init_workspaces();
18642
18420
  DEFAULT_CONFIG = {
18643
18421
  serverUrl: "https://api.adhf.dev",
18644
18422
  apiToken: null,
@@ -18654,17 +18432,14 @@ var init_config = __esm2({
18654
18432
  setupDate: null,
18655
18433
  configuredCLIs: [],
18656
18434
  enabledIdes: [],
18657
- recentCliWorkspaces: [],
18658
18435
  workspaces: [],
18659
18436
  defaultWorkspaceId: null,
18660
- recentWorkspaceActivity: [],
18661
18437
  recentActivity: [],
18662
18438
  recentSessionReads: {},
18663
18439
  machineNickname: null,
18664
18440
  machineId: void 0,
18665
18441
  machineSecret: null,
18666
18442
  registeredMachineId: void 0,
18667
- cliHistory: [],
18668
18443
  providerSettings: {},
18669
18444
  ideSettings: {},
18670
18445
  disableUpstream: false
@@ -18679,7 +18454,7 @@ function checkDateRotation() {
18679
18454
  const today = getDateStr();
18680
18455
  if (today !== currentDate) {
18681
18456
  currentDate = today;
18682
- currentLogFile = path4.join(LOG_DIR, `daemon-${currentDate}.log`);
18457
+ currentLogFile = path3.join(LOG_DIR, `daemon-${currentDate}.log`);
18683
18458
  cleanOldLogs();
18684
18459
  }
18685
18460
  }
@@ -18693,7 +18468,7 @@ function cleanOldLogs() {
18693
18468
  const dateMatch = file2.match(/daemon-(\d{4}-\d{2}-\d{2})/);
18694
18469
  if (dateMatch && dateMatch[1] < cutoffStr) {
18695
18470
  try {
18696
- fs2.unlinkSync(path4.join(LOG_DIR, file2));
18471
+ fs2.unlinkSync(path3.join(LOG_DIR, file2));
18697
18472
  } catch {
18698
18473
  }
18699
18474
  }
@@ -18833,7 +18608,7 @@ var init_logger = __esm2({
18833
18608
  LEVEL_NUM = { debug: 0, info: 1, warn: 2, error: 3 };
18834
18609
  LEVEL_LABEL = { debug: "DBG", info: "INF", warn: "WRN", error: "ERR" };
18835
18610
  currentLevel = "info";
18836
- LOG_DIR = process.platform === "win32" ? path4.join(process.env.LOCALAPPDATA || process.env.APPDATA || path4.join(os4.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path4.join(os4.homedir(), "Library", "Logs", "adhdev") : path4.join(os4.homedir(), ".local", "share", "adhdev", "logs");
18611
+ LOG_DIR = process.platform === "win32" ? path3.join(process.env.LOCALAPPDATA || process.env.APPDATA || path3.join(os4.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path3.join(os4.homedir(), "Library", "Logs", "adhdev") : path3.join(os4.homedir(), ".local", "share", "adhdev", "logs");
18837
18612
  MAX_LOG_SIZE = 5 * 1024 * 1024;
18838
18613
  MAX_LOG_DAYS = 7;
18839
18614
  try {
@@ -18841,16 +18616,16 @@ var init_logger = __esm2({
18841
18616
  } catch {
18842
18617
  }
18843
18618
  currentDate = getDateStr();
18844
- currentLogFile = path4.join(LOG_DIR, `daemon-${currentDate}.log`);
18619
+ currentLogFile = path3.join(LOG_DIR, `daemon-${currentDate}.log`);
18845
18620
  cleanOldLogs();
18846
18621
  try {
18847
- const oldLog = path4.join(LOG_DIR, "daemon.log");
18622
+ const oldLog = path3.join(LOG_DIR, "daemon.log");
18848
18623
  if (fs2.existsSync(oldLog)) {
18849
18624
  const stat4 = fs2.statSync(oldLog);
18850
18625
  const oldDate = stat4.mtime.toISOString().slice(0, 10);
18851
- fs2.renameSync(oldLog, path4.join(LOG_DIR, `daemon-${oldDate}.log`));
18626
+ fs2.renameSync(oldLog, path3.join(LOG_DIR, `daemon-${oldDate}.log`));
18852
18627
  }
18853
- const oldLogBackup = path4.join(LOG_DIR, "daemon.log.old");
18628
+ const oldLogBackup = path3.join(LOG_DIR, "daemon.log.old");
18854
18629
  if (fs2.existsSync(oldLogBackup)) {
18855
18630
  fs2.unlinkSync(oldLogBackup);
18856
18631
  }
@@ -18882,7 +18657,7 @@ var init_logger = __esm2({
18882
18657
  }
18883
18658
  };
18884
18659
  interceptorInstalled = false;
18885
- LOG_PATH = path4.join(LOG_DIR, `daemon-${getDateStr()}.log`);
18660
+ LOG_PATH = path3.join(LOG_DIR, `daemon-${getDateStr()}.log`);
18886
18661
  }
18887
18662
  });
18888
18663
  function isModuleNotFoundError(error48, ref) {
@@ -19207,7 +18982,7 @@ function findBinary(name) {
19207
18982
  }
19208
18983
  }
19209
18984
  function isScriptBinary(binaryPath) {
19210
- if (!path10.isAbsolute(binaryPath)) return false;
18985
+ if (!path9.isAbsolute(binaryPath)) return false;
19211
18986
  try {
19212
18987
  const fs122 = __require("fs");
19213
18988
  const resolved = fs122.realpathSync(binaryPath);
@@ -19223,7 +18998,7 @@ function isScriptBinary(binaryPath) {
19223
18998
  }
19224
18999
  }
19225
19000
  function looksLikeMachOOrElf(filePath) {
19226
- if (!path10.isAbsolute(filePath)) return false;
19001
+ if (!path9.isAbsolute(filePath)) return false;
19227
19002
  try {
19228
19003
  const fs122 = __require("fs");
19229
19004
  const resolved = fs122.realpathSync(filePath);
@@ -19350,9 +19125,9 @@ var init_provider_cli_adapter = __esm2({
19350
19125
  if (os12.platform() !== "win32") {
19351
19126
  try {
19352
19127
  const fs122 = __require("fs");
19353
- const ptyDir = path10.resolve(path10.dirname(__require.resolve("node-pty")), "..");
19128
+ const ptyDir = path9.resolve(path9.dirname(__require.resolve("node-pty")), "..");
19354
19129
  const platformArch = `${os12.platform()}-${os12.arch()}`;
19355
- const helper = path10.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
19130
+ const helper = path9.join(ptyDir, "prebuilds", platformArch, "spawn-helper");
19356
19131
  if (fs122.existsSync(helper)) {
19357
19132
  const stat4 = fs122.statSync(helper);
19358
19133
  if (!(stat4.mode & 73)) {
@@ -19541,7 +19316,7 @@ var init_provider_cli_adapter = __esm2({
19541
19316
  LOG.info("CLI", `[${this.cliType}] Spawning in ${this.workingDir}`);
19542
19317
  let shellCmd;
19543
19318
  let shellArgs;
19544
- const useShellUnix = !isWin && (!!spawnConfig.shell || !path10.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
19319
+ const useShellUnix = !isWin && (!!spawnConfig.shell || !path9.isAbsolute(binaryPath) || isScriptBinary(binaryPath) || !looksLikeMachOOrElf(binaryPath));
19545
19320
  const useShell = isWin ? !!spawnConfig.shell : useShellUnix;
19546
19321
  if (useShell) {
19547
19322
  if (!spawnConfig.shell && !isWin) {
@@ -19966,7 +19741,7 @@ ${data.message || ""}`.trim();
19966
19741
  if (this.startupParseGate) {
19967
19742
  const deadline = Date.now() + 1e4;
19968
19743
  while (this.startupParseGate && Date.now() < deadline) {
19969
- await new Promise((resolve102) => setTimeout(resolve102, 50));
19744
+ await new Promise((resolve92) => setTimeout(resolve92, 50));
19970
19745
  }
19971
19746
  }
19972
19747
  if (!this.ready) throw new Error(`${this.cliName} not ready (status: ${this.currentStatus})`);
@@ -20134,17 +19909,17 @@ ${data.message || ""}`.trim();
20134
19909
  }
20135
19910
  }
20136
19911
  waitForStopped(timeoutMs) {
20137
- return new Promise((resolve102) => {
19912
+ return new Promise((resolve92) => {
20138
19913
  const startedAt = Date.now();
20139
19914
  const timer = setInterval(() => {
20140
19915
  if (!this.ptyProcess || this.currentStatus === "stopped") {
20141
19916
  clearInterval(timer);
20142
- resolve102(true);
19917
+ resolve92(true);
20143
19918
  return;
20144
19919
  }
20145
19920
  if (Date.now() - startedAt >= timeoutMs) {
20146
19921
  clearInterval(timer);
20147
- resolve102(false);
19922
+ resolve92(false);
20148
19923
  }
20149
19924
  }, 100);
20150
19925
  });
@@ -20334,52 +20109,173 @@ ${data.message || ""}`.trim();
20334
20109
  }
20335
20110
  });
20336
20111
  init_config();
20337
- init_workspaces();
20338
- init_workspaces();
20339
- var MAX_ACTIVITY = 30;
20340
- function normWorkspacePath(p) {
20112
+ var MAX_WORKSPACES = 50;
20113
+ function expandPath(p) {
20114
+ const t = (p || "").trim();
20115
+ if (!t) return "";
20116
+ if (t.startsWith("~")) return path.join(os2.homedir(), t.slice(1).replace(/^\//, ""));
20117
+ return path.resolve(t);
20118
+ }
20119
+ function validateWorkspacePath(absPath) {
20341
20120
  try {
20342
- return path22.resolve(expandPath(p));
20343
- } catch {
20344
- return path22.resolve(p);
20121
+ if (!absPath) return { ok: false, error: "Path required" };
20122
+ if (!fs.existsSync(absPath)) return { ok: false, error: "Path does not exist" };
20123
+ const st = fs.statSync(absPath);
20124
+ if (!st.isDirectory()) return { ok: false, error: "Not a directory" };
20125
+ return { ok: true };
20126
+ } catch (e) {
20127
+ return { ok: false, error: e?.message || "Invalid path" };
20128
+ }
20129
+ }
20130
+ function defaultWorkspaceLabel(absPath) {
20131
+ const base = path.basename(absPath) || absPath;
20132
+ return base;
20133
+ }
20134
+ function getDefaultWorkspacePath(config2) {
20135
+ const id = config2.defaultWorkspaceId;
20136
+ if (!id) return null;
20137
+ const w = (config2.workspaces || []).find((x) => x.id === id);
20138
+ if (!w) return null;
20139
+ const abs = expandPath(w.path);
20140
+ if (validateWorkspacePath(abs).ok !== true) return null;
20141
+ return abs;
20142
+ }
20143
+ function getWorkspaceState(config2) {
20144
+ const workspaces = [...config2.workspaces || []].sort((a, b) => b.addedAt - a.addedAt);
20145
+ const defaultWorkspacePath = getDefaultWorkspacePath(config2);
20146
+ return {
20147
+ workspaces,
20148
+ defaultWorkspaceId: config2.defaultWorkspaceId ?? null,
20149
+ defaultWorkspacePath
20150
+ };
20151
+ }
20152
+ function resolveLaunchDirectory(args, config2) {
20153
+ const a = args || {};
20154
+ if (a.dir != null && String(a.dir).trim()) {
20155
+ const abs = expandPath(String(a.dir).trim());
20156
+ if (abs && validateWorkspacePath(abs).ok === true) {
20157
+ return { ok: true, path: abs, source: "dir" };
20158
+ }
20159
+ return {
20160
+ ok: false,
20161
+ code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
20162
+ message: abs ? "Directory path is not valid or does not exist" : "Invalid directory path"
20163
+ };
20164
+ }
20165
+ if (a.workspaceId) {
20166
+ const w = (config2.workspaces || []).find((x) => x.id === a.workspaceId);
20167
+ if (w) {
20168
+ const abs = expandPath(w.path);
20169
+ if (validateWorkspacePath(abs).ok === true) {
20170
+ return { ok: true, path: abs, source: "workspaceId" };
20171
+ }
20172
+ }
20173
+ return {
20174
+ ok: false,
20175
+ code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
20176
+ message: "Saved workspace not found or path is no longer valid"
20177
+ };
20345
20178
  }
20179
+ if (a.useDefaultWorkspace === true) {
20180
+ const d = getDefaultWorkspacePath(config2);
20181
+ if (d) return { ok: true, path: d, source: "defaultWorkspace" };
20182
+ return {
20183
+ ok: false,
20184
+ code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
20185
+ message: "No default workspace is set"
20186
+ };
20187
+ }
20188
+ if (a.useHome === true) {
20189
+ return { ok: true, path: os2.homedir(), source: "home" };
20190
+ }
20191
+ return {
20192
+ ok: false,
20193
+ code: "WORKSPACE_LAUNCH_CONTEXT_REQUIRED",
20194
+ message: "Choose a directory, saved workspace, default workspace, or home before launching."
20195
+ };
20196
+ }
20197
+ function resolveIdeWorkspaceFromArgs(args, config2) {
20198
+ const ar = args || {};
20199
+ if (ar.workspace) {
20200
+ const abs = expandPath(ar.workspace);
20201
+ if (abs && validateWorkspacePath(abs).ok === true) return abs;
20202
+ }
20203
+ if (ar.workspaceId) {
20204
+ const w = (config2.workspaces || []).find((x) => x.id === ar.workspaceId);
20205
+ if (w) {
20206
+ const abs = expandPath(w.path);
20207
+ if (validateWorkspacePath(abs).ok === true) return abs;
20208
+ }
20209
+ }
20210
+ if (ar.useDefaultWorkspace === true) {
20211
+ return getDefaultWorkspacePath(config2) || void 0;
20212
+ }
20213
+ return void 0;
20346
20214
  }
20347
- function appendWorkspaceActivity(config2, rawPath, meta3) {
20348
- const abs = normWorkspacePath(rawPath);
20349
- if (!abs) return config2;
20350
- const prev = config2.recentWorkspaceActivity || [];
20351
- const filtered = prev.filter((e) => normWorkspacePath(e.path) !== abs);
20215
+ function resolveIdeLaunchWorkspace(args, config2) {
20216
+ const direct = resolveIdeWorkspaceFromArgs(args, config2);
20217
+ if (direct) return direct;
20218
+ if (args?.useDefaultWorkspace === false) return void 0;
20219
+ return getDefaultWorkspacePath(config2) || void 0;
20220
+ }
20221
+ function findWorkspaceByPath(config2, rawPath) {
20222
+ const abs = path.resolve(expandPath(rawPath));
20223
+ if (!abs) return void 0;
20224
+ return (config2.workspaces || []).find((w) => path.resolve(expandPath(w.path)) === abs);
20225
+ }
20226
+ function addWorkspaceEntry(config2, rawPath, label, options) {
20227
+ const abs = expandPath(rawPath);
20228
+ const createIfMissing = options?.createIfMissing === true;
20229
+ if (!abs) return { error: "Path required" };
20230
+ if (!fs.existsSync(abs) && createIfMissing) {
20231
+ try {
20232
+ fs.mkdirSync(abs, { recursive: true });
20233
+ } catch (e) {
20234
+ return { error: e?.message || "Could not create directory" };
20235
+ }
20236
+ }
20237
+ const v = validateWorkspacePath(abs);
20238
+ if (!v.ok) return { error: v.error };
20239
+ const list = [...config2.workspaces || []];
20240
+ if (list.some((w) => path.resolve(w.path) === abs)) {
20241
+ return { error: "Workspace already in list" };
20242
+ }
20243
+ if (list.length >= MAX_WORKSPACES) {
20244
+ return { error: `Maximum ${MAX_WORKSPACES} workspaces` };
20245
+ }
20352
20246
  const entry = {
20247
+ id: (0, import_crypto3.randomUUID)(),
20353
20248
  path: abs,
20354
- lastUsedAt: Date.now(),
20355
- kind: meta3?.kind,
20356
- agentType: meta3?.agentType
20249
+ label: (label || "").trim() || defaultWorkspaceLabel(abs),
20250
+ addedAt: Date.now()
20357
20251
  };
20358
- const recentWorkspaceActivity = [entry, ...filtered].slice(0, MAX_ACTIVITY);
20359
- return { ...config2, recentWorkspaceActivity };
20252
+ list.push(entry);
20253
+ return { config: { ...config2, workspaces: list }, entry };
20360
20254
  }
20361
- function getWorkspaceActivity(config2, limit = 20) {
20362
- const list = [...config2.recentWorkspaceActivity || []];
20363
- list.sort((a, b) => b.lastUsedAt - a.lastUsedAt);
20364
- return list.slice(0, limit);
20255
+ function removeWorkspaceEntry(config2, id) {
20256
+ const list = (config2.workspaces || []).filter((w) => w.id !== id);
20257
+ if (list.length === (config2.workspaces || []).length) return { error: "Workspace not found" };
20258
+ let defaultWorkspaceId = config2.defaultWorkspaceId;
20259
+ if (defaultWorkspaceId === id) defaultWorkspaceId = null;
20260
+ return { config: { ...config2, workspaces: list, defaultWorkspaceId } };
20365
20261
  }
20366
- function removeActivityForPath(config2, rawPath) {
20367
- const n = normWorkspacePath(rawPath);
20368
- return {
20369
- ...config2,
20370
- recentWorkspaceActivity: (config2.recentWorkspaceActivity || []).filter(
20371
- (e) => normWorkspacePath(e.path) !== n
20372
- )
20373
- };
20262
+ function setDefaultWorkspaceId(config2, id) {
20263
+ if (id === null) {
20264
+ return { config: { ...config2, defaultWorkspaceId: null } };
20265
+ }
20266
+ const w = (config2.workspaces || []).find((x) => x.id === id);
20267
+ if (!w) return { error: "Workspace not found" };
20268
+ const abs = expandPath(w.path);
20269
+ if (validateWorkspacePath(abs).ok !== true) return { error: "Workspace path is no longer valid" };
20270
+ return { config: { ...config2, defaultWorkspaceId: id } };
20374
20271
  }
20375
- init_workspaces();
20376
- var MAX_ACTIVITY2 = 30;
20272
+ var MAX_ACTIVITY = 30;
20377
20273
  function normalizeWorkspace(workspace) {
20378
20274
  if (!workspace) return "";
20379
20275
  try {
20380
- return path3.resolve(expandPath(workspace));
20276
+ return path22.resolve(expandPath(workspace));
20381
20277
  } catch {
20382
- return path3.resolve(workspace);
20278
+ return path22.resolve(workspace);
20383
20279
  }
20384
20280
  }
20385
20281
  function buildRecentActivityKey(entry) {
@@ -20395,7 +20291,7 @@ function appendRecentActivity(config2, entry) {
20395
20291
  const filtered = (config2.recentActivity || []).filter((item) => item.id !== nextEntry.id);
20396
20292
  return {
20397
20293
  ...config2,
20398
- recentActivity: [nextEntry, ...filtered].slice(0, MAX_ACTIVITY2)
20294
+ recentActivity: [nextEntry, ...filtered].slice(0, MAX_ACTIVITY)
20399
20295
  };
20400
20296
  }
20401
20297
  function getRecentActivity(config2, limit = 20) {
@@ -20514,15 +20410,15 @@ function parseVersion(raw) {
20514
20410
  return match ? match[1] : raw.split("\n")[0].slice(0, 100);
20515
20411
  }
20516
20412
  function execAsync(cmd, timeoutMs = 5e3) {
20517
- return new Promise((resolve102) => {
20413
+ return new Promise((resolve92) => {
20518
20414
  const child = (0, import_child_process3.exec)(cmd, { encoding: "utf-8", timeout: timeoutMs }, (err, stdout) => {
20519
20415
  if (err || !stdout?.trim()) {
20520
- resolve102(null);
20416
+ resolve92(null);
20521
20417
  } else {
20522
- resolve102(stdout.trim());
20418
+ resolve92(stdout.trim());
20523
20419
  }
20524
20420
  });
20525
- child.on("error", () => resolve102(null));
20421
+ child.on("error", () => resolve92(null));
20526
20422
  });
20527
20423
  }
20528
20424
  async function detectCLIs(providerLoader) {
@@ -20681,7 +20577,7 @@ var DaemonCdpManager = class {
20681
20577
  * Returns multiple entries if multiple IDE windows are open on same port
20682
20578
  */
20683
20579
  static listAllTargets(port) {
20684
- return new Promise((resolve102) => {
20580
+ return new Promise((resolve92) => {
20685
20581
  const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
20686
20582
  let data = "";
20687
20583
  res.on("data", (chunk) => data += chunk.toString());
@@ -20697,16 +20593,16 @@ var DaemonCdpManager = class {
20697
20593
  (t) => !isNonMain(t.title || "") && t.url?.includes("workbench.html") && !t.url?.includes("agent")
20698
20594
  );
20699
20595
  const fallbackPages = pages.filter((t) => !isNonMain(t.title || ""));
20700
- resolve102(mainPages.length > 0 ? mainPages : fallbackPages);
20596
+ resolve92(mainPages.length > 0 ? mainPages : fallbackPages);
20701
20597
  } catch {
20702
- resolve102([]);
20598
+ resolve92([]);
20703
20599
  }
20704
20600
  });
20705
20601
  });
20706
- req.on("error", () => resolve102([]));
20602
+ req.on("error", () => resolve92([]));
20707
20603
  req.setTimeout(2e3, () => {
20708
20604
  req.destroy();
20709
- resolve102([]);
20605
+ resolve92([]);
20710
20606
  });
20711
20607
  });
20712
20608
  }
@@ -20746,7 +20642,7 @@ var DaemonCdpManager = class {
20746
20642
  }
20747
20643
  }
20748
20644
  findTargetOnPort(port) {
20749
- return new Promise((resolve102) => {
20645
+ return new Promise((resolve92) => {
20750
20646
  const req = http.get(`http://127.0.0.1:${port}/json`, (res) => {
20751
20647
  let data = "";
20752
20648
  res.on("data", (chunk) => data += chunk.toString());
@@ -20757,7 +20653,7 @@ var DaemonCdpManager = class {
20757
20653
  (t) => (t.type === "page" || t.type === "browser" || t.type === "Page") && t.webSocketDebuggerUrl
20758
20654
  );
20759
20655
  if (pages.length === 0) {
20760
- resolve102(targets.find((t) => t.webSocketDebuggerUrl) || null);
20656
+ resolve92(targets.find((t) => t.webSocketDebuggerUrl) || null);
20761
20657
  return;
20762
20658
  }
20763
20659
  const mainPages = pages.filter((t) => !this.isNonMainTitle(t.title || ""));
@@ -20767,24 +20663,24 @@ var DaemonCdpManager = class {
20767
20663
  const specific = list.find((t) => t.id === this._targetId);
20768
20664
  if (specific) {
20769
20665
  this._pageTitle = specific.title || "";
20770
- resolve102(specific);
20666
+ resolve92(specific);
20771
20667
  } else {
20772
20668
  this.log(`[CDP] Target ${this._targetId} not found in page list`);
20773
- resolve102(null);
20669
+ resolve92(null);
20774
20670
  }
20775
20671
  return;
20776
20672
  }
20777
20673
  this._pageTitle = list[0]?.title || "";
20778
- resolve102(list[0]);
20674
+ resolve92(list[0]);
20779
20675
  } catch {
20780
- resolve102(null);
20676
+ resolve92(null);
20781
20677
  }
20782
20678
  });
20783
20679
  });
20784
- req.on("error", () => resolve102(null));
20680
+ req.on("error", () => resolve92(null));
20785
20681
  req.setTimeout(2e3, () => {
20786
20682
  req.destroy();
20787
- resolve102(null);
20683
+ resolve92(null);
20788
20684
  });
20789
20685
  });
20790
20686
  }
@@ -20795,7 +20691,7 @@ var DaemonCdpManager = class {
20795
20691
  this.extensionProviders = providers;
20796
20692
  }
20797
20693
  connectToTarget(wsUrl) {
20798
- return new Promise((resolve102) => {
20694
+ return new Promise((resolve92) => {
20799
20695
  this.ws = new import_ws.default(wsUrl);
20800
20696
  this.ws.on("open", async () => {
20801
20697
  this._connected = true;
@@ -20805,17 +20701,17 @@ var DaemonCdpManager = class {
20805
20701
  }
20806
20702
  this.connectBrowserWs().catch(() => {
20807
20703
  });
20808
- resolve102(true);
20704
+ resolve92(true);
20809
20705
  });
20810
20706
  this.ws.on("message", (data) => {
20811
20707
  try {
20812
20708
  const msg = JSON.parse(data.toString());
20813
20709
  if (msg.id && this.pending.has(msg.id)) {
20814
- const { resolve: resolve112, reject } = this.pending.get(msg.id);
20710
+ const { resolve: resolve102, reject } = this.pending.get(msg.id);
20815
20711
  this.pending.delete(msg.id);
20816
20712
  this.failureCount = 0;
20817
20713
  if (msg.error) reject(new Error(msg.error.message));
20818
- else resolve112(msg.result);
20714
+ else resolve102(msg.result);
20819
20715
  } else if (msg.method === "Runtime.executionContextCreated") {
20820
20716
  this.contexts.add(msg.params.context.id);
20821
20717
  } else if (msg.method === "Runtime.executionContextDestroyed") {
@@ -20838,7 +20734,7 @@ var DaemonCdpManager = class {
20838
20734
  this.ws.on("error", (err) => {
20839
20735
  this.log(`[CDP] WebSocket error: ${err.message}`);
20840
20736
  this._connected = false;
20841
- resolve102(false);
20737
+ resolve92(false);
20842
20738
  });
20843
20739
  });
20844
20740
  }
@@ -20852,7 +20748,7 @@ var DaemonCdpManager = class {
20852
20748
  return;
20853
20749
  }
20854
20750
  this.log(`[CDP] Connecting browser WS for target discovery...`);
20855
- await new Promise((resolve102, reject) => {
20751
+ await new Promise((resolve92, reject) => {
20856
20752
  this.browserWs = new import_ws.default(browserWsUrl);
20857
20753
  this.browserWs.on("open", async () => {
20858
20754
  this._browserConnected = true;
@@ -20862,16 +20758,16 @@ var DaemonCdpManager = class {
20862
20758
  } catch (e) {
20863
20759
  this.log(`[CDP] setDiscoverTargets failed: ${e.message}`);
20864
20760
  }
20865
- resolve102();
20761
+ resolve92();
20866
20762
  });
20867
20763
  this.browserWs.on("message", (data) => {
20868
20764
  try {
20869
20765
  const msg = JSON.parse(data.toString());
20870
20766
  if (msg.id && this.browserPending.has(msg.id)) {
20871
- const { resolve: resolve112, reject: reject2 } = this.browserPending.get(msg.id);
20767
+ const { resolve: resolve102, reject: reject2 } = this.browserPending.get(msg.id);
20872
20768
  this.browserPending.delete(msg.id);
20873
20769
  if (msg.error) reject2(new Error(msg.error.message));
20874
- else resolve112(msg.result);
20770
+ else resolve102(msg.result);
20875
20771
  }
20876
20772
  } catch {
20877
20773
  }
@@ -20891,31 +20787,31 @@ var DaemonCdpManager = class {
20891
20787
  }
20892
20788
  }
20893
20789
  getBrowserWsUrl() {
20894
- return new Promise((resolve102) => {
20790
+ return new Promise((resolve92) => {
20895
20791
  const req = http.get(`http://127.0.0.1:${this.port}/json/version`, (res) => {
20896
20792
  let data = "";
20897
20793
  res.on("data", (chunk) => data += chunk.toString());
20898
20794
  res.on("end", () => {
20899
20795
  try {
20900
20796
  const info = JSON.parse(data);
20901
- resolve102(info.webSocketDebuggerUrl || null);
20797
+ resolve92(info.webSocketDebuggerUrl || null);
20902
20798
  } catch {
20903
- resolve102(null);
20799
+ resolve92(null);
20904
20800
  }
20905
20801
  });
20906
20802
  });
20907
- req.on("error", () => resolve102(null));
20803
+ req.on("error", () => resolve92(null));
20908
20804
  req.setTimeout(3e3, () => {
20909
20805
  req.destroy();
20910
- resolve102(null);
20806
+ resolve92(null);
20911
20807
  });
20912
20808
  });
20913
20809
  }
20914
20810
  sendBrowser(method, params = {}, timeoutMs = 15e3) {
20915
- return new Promise((resolve102, reject) => {
20811
+ return new Promise((resolve92, reject) => {
20916
20812
  if (!this.browserWs || !this._browserConnected) return reject(new Error("Browser WS not connected"));
20917
20813
  const id = this.browserMsgId++;
20918
- this.browserPending.set(id, { resolve: resolve102, reject });
20814
+ this.browserPending.set(id, { resolve: resolve92, reject });
20919
20815
  this.browserWs.send(JSON.stringify({ id, method, params }));
20920
20816
  setTimeout(() => {
20921
20817
  if (this.browserPending.has(id)) {
@@ -20955,11 +20851,11 @@ var DaemonCdpManager = class {
20955
20851
  }
20956
20852
  // ─── CDP Protocol ────────────────────────────────────────
20957
20853
  sendInternal(method, params = {}, timeoutMs = 15e3) {
20958
- return new Promise((resolve102, reject) => {
20854
+ return new Promise((resolve92, reject) => {
20959
20855
  if (!this.ws || !this._connected) return reject(new Error("CDP not connected"));
20960
20856
  if (this.ws.readyState !== import_ws.default.OPEN) return reject(new Error("WebSocket not open"));
20961
20857
  const id = this.msgId++;
20962
- this.pending.set(id, { resolve: resolve102, reject });
20858
+ this.pending.set(id, { resolve: resolve92, reject });
20963
20859
  this.ws.send(JSON.stringify({ id, method, params }));
20964
20860
  setTimeout(() => {
20965
20861
  if (this.pending.has(id)) {
@@ -21208,7 +21104,7 @@ var DaemonCdpManager = class {
21208
21104
  const browserWs = this.browserWs;
21209
21105
  let msgId = this.browserMsgId;
21210
21106
  const sendWs = (method, params = {}, sessionId) => {
21211
- return new Promise((resolve102, reject) => {
21107
+ return new Promise((resolve92, reject) => {
21212
21108
  const mid = msgId++;
21213
21109
  this.browserMsgId = msgId;
21214
21110
  const handler = (raw) => {
@@ -21217,7 +21113,7 @@ var DaemonCdpManager = class {
21217
21113
  if (msg.id === mid) {
21218
21114
  browserWs.removeListener("message", handler);
21219
21115
  if (msg.error) reject(new Error(msg.error.message || JSON.stringify(msg.error)));
21220
- else resolve102(msg.result);
21116
+ else resolve92(msg.result);
21221
21117
  }
21222
21118
  } catch {
21223
21119
  }
@@ -21408,14 +21304,14 @@ var DaemonCdpManager = class {
21408
21304
  if (!ws || ws.readyState !== import_ws.default.OPEN) {
21409
21305
  throw new Error("CDP not connected");
21410
21306
  }
21411
- return new Promise((resolve102, reject) => {
21307
+ return new Promise((resolve92, reject) => {
21412
21308
  const id = getNextId();
21413
21309
  pendingMap.set(id, {
21414
21310
  resolve: (result) => {
21415
21311
  if (result?.result?.subtype === "error") {
21416
21312
  reject(new Error(result.result.description));
21417
21313
  } else {
21418
- resolve102(result?.result?.value);
21314
+ resolve92(result?.result?.value);
21419
21315
  }
21420
21316
  },
21421
21317
  reject
@@ -21447,10 +21343,10 @@ var DaemonCdpManager = class {
21447
21343
  throw new Error("CDP not connected");
21448
21344
  }
21449
21345
  const sendViaSession = (method, params = {}) => {
21450
- return new Promise((resolve102, reject) => {
21346
+ return new Promise((resolve92, reject) => {
21451
21347
  const pendingMap = this._browserConnected ? this.browserPending : this.pending;
21452
21348
  const id = this._browserConnected ? this.browserMsgId++ : this.msgId++;
21453
- pendingMap.set(id, { resolve: resolve102, reject });
21349
+ pendingMap.set(id, { resolve: resolve92, reject });
21454
21350
  ws.send(JSON.stringify({ id, sessionId, method, params }));
21455
21351
  setTimeout(() => {
21456
21352
  if (pendingMap.has(id)) {
@@ -22145,7 +22041,7 @@ var ExtensionProviderInstance = class {
22145
22041
  return title || this.agentName || this.provider.name;
22146
22042
  }
22147
22043
  };
22148
- var HISTORY_DIR = path5.join(os5.homedir(), ".adhdev", "history");
22044
+ var HISTORY_DIR = path4.join(os5.homedir(), ".adhdev", "history");
22149
22045
  var RETAIN_DAYS = 30;
22150
22046
  var ChatHistoryWriter = class {
22151
22047
  /** Last seen message count per agent (deduplication) */
@@ -22188,11 +22084,11 @@ var ChatHistoryWriter = class {
22188
22084
  });
22189
22085
  }
22190
22086
  if (newMessages.length === 0) return;
22191
- const dir = path5.join(HISTORY_DIR, this.sanitize(agentType));
22087
+ const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
22192
22088
  fs3.mkdirSync(dir, { recursive: true });
22193
22089
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
22194
22090
  const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
22195
- const filePath = path5.join(dir, `${filePrefix}${date5}.jsonl`);
22091
+ const filePath = path4.join(dir, `${filePrefix}${date5}.jsonl`);
22196
22092
  const lines = newMessages.map((m) => JSON.stringify(m)).join("\n") + "\n";
22197
22093
  fs3.appendFileSync(filePath, lines, "utf-8");
22198
22094
  const prevCount = this.lastSeenCounts.get(dedupKey) || 0;
@@ -22236,11 +22132,11 @@ ${next}`;
22236
22132
  this.lastSeenTerminal.set(dedupKey, next);
22237
22133
  return;
22238
22134
  }
22239
- const dir = path5.join(HISTORY_DIR, this.sanitize(agentType));
22135
+ const dir = path4.join(HISTORY_DIR, this.sanitize(agentType));
22240
22136
  fs3.mkdirSync(dir, { recursive: true });
22241
22137
  const date5 = (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
22242
22138
  const filePrefix = instanceId ? `${this.sanitize(instanceId)}_` : "";
22243
- const filePath = path5.join(dir, `${filePrefix}${date5}.terminal.log`);
22139
+ const filePath = path4.join(dir, `${filePrefix}${date5}.terminal.log`);
22244
22140
  fs3.appendFileSync(filePath, delta, "utf-8");
22245
22141
  this.lastSeenTerminal.set(dedupKey, next);
22246
22142
  if (!this.rotated) {
@@ -22264,10 +22160,10 @@ ${next}`;
22264
22160
  const cutoff = Date.now() - RETAIN_DAYS * 24 * 60 * 60 * 1e3;
22265
22161
  const agentDirs = fs3.readdirSync(HISTORY_DIR, { withFileTypes: true }).filter((d) => d.isDirectory());
22266
22162
  for (const dir of agentDirs) {
22267
- const dirPath = path5.join(HISTORY_DIR, dir.name);
22163
+ const dirPath = path4.join(HISTORY_DIR, dir.name);
22268
22164
  const files = fs3.readdirSync(dirPath).filter((f) => f.endsWith(".jsonl") || f.endsWith(".terminal.log"));
22269
22165
  for (const file2 of files) {
22270
- const filePath = path5.join(dirPath, file2);
22166
+ const filePath = path4.join(dirPath, file2);
22271
22167
  const stat4 = fs3.statSync(filePath);
22272
22168
  if (stat4.mtimeMs < cutoff) {
22273
22169
  fs3.unlinkSync(filePath);
@@ -22285,7 +22181,7 @@ ${next}`;
22285
22181
  function readChatHistory(agentType, offset = 0, limit = 30, instanceId) {
22286
22182
  try {
22287
22183
  const sanitized = agentType.replace(/[^a-zA-Z0-9_-]/g, "_");
22288
- const dir = path5.join(HISTORY_DIR, sanitized);
22184
+ const dir = path4.join(HISTORY_DIR, sanitized);
22289
22185
  if (!fs3.existsSync(dir)) return { messages: [], hasMore: false };
22290
22186
  const sanitizedInstance = instanceId?.replace(/[^a-zA-Z0-9_-]/g, "_");
22291
22187
  const files = fs3.readdirSync(dir).filter((f) => {
@@ -22299,7 +22195,7 @@ function readChatHistory(agentType, offset = 0, limit = 30, instanceId) {
22299
22195
  const needed = offset + limit + 1;
22300
22196
  for (const file2 of files) {
22301
22197
  if (allMessages.length >= needed) break;
22302
- const filePath = path5.join(dir, file2);
22198
+ const filePath = path4.join(dir, file2);
22303
22199
  const content = fs3.readFileSync(filePath, "utf-8");
22304
22200
  const lines = content.trim().split("\n").filter(Boolean);
22305
22201
  for (let i = lines.length - 1; i >= 0; i--) {
@@ -23189,9 +23085,16 @@ function buildSessionEntries(allStates, cdpManagers) {
23189
23085
  for (const state of acpStates) {
23190
23086
  sessions.push(buildAcpSession(state));
23191
23087
  }
23088
+ const extensionParentIds = new Set(
23089
+ sessions.filter((session) => session.transport === "cdp-webview" && !!session.parentId).map((session) => session.parentId)
23090
+ );
23091
+ for (const session of sessions) {
23092
+ if (session.transport === "cdp-page" && extensionParentIds.has(session.id)) {
23093
+ session.surfaceHidden = true;
23094
+ }
23095
+ }
23192
23096
  return sessions;
23193
23097
  }
23194
- init_config();
23195
23098
  init_logger();
23196
23099
  init_logger();
23197
23100
  var RECENT_SEND_WINDOW_MS = 1200;
@@ -24240,11 +24143,11 @@ function resolveSafePath(requestedPath) {
24240
24143
  const home = os6.homedir();
24241
24144
  let resolved;
24242
24145
  if (requestedPath.startsWith("~")) {
24243
- resolved = path6.join(home, requestedPath.slice(1));
24244
- } else if (path6.isAbsolute(requestedPath)) {
24146
+ resolved = path5.join(home, requestedPath.slice(1));
24147
+ } else if (path5.isAbsolute(requestedPath)) {
24245
24148
  resolved = requestedPath;
24246
24149
  } else {
24247
- resolved = path6.resolve(requestedPath);
24150
+ resolved = path5.resolve(requestedPath);
24248
24151
  }
24249
24152
  return resolved;
24250
24153
  }
@@ -24260,7 +24163,7 @@ async function handleFileRead(h, args) {
24260
24163
  async function handleFileWrite(h, args) {
24261
24164
  try {
24262
24165
  const filePath = resolveSafePath(args?.path);
24263
- fs4.mkdirSync(path6.dirname(filePath), { recursive: true });
24166
+ fs4.mkdirSync(path5.dirname(filePath), { recursive: true });
24264
24167
  fs4.writeFileSync(filePath, args?.content || "", "utf-8");
24265
24168
  return { success: true, path: filePath };
24266
24169
  } catch (e) {
@@ -24274,7 +24177,7 @@ async function handleFileList(h, args) {
24274
24177
  const files = entries.map((e) => ({
24275
24178
  name: e.name,
24276
24179
  type: e.isDirectory() ? "directory" : "file",
24277
- size: e.isFile() ? fs4.statSync(path6.join(dirPath, e.name)).size : void 0
24180
+ size: e.isFile() ? fs4.statSync(path5.join(dirPath, e.name)).size : void 0
24278
24181
  }));
24279
24182
  return { success: true, files, path: dirPath };
24280
24183
  } catch (e) {
@@ -24284,7 +24187,6 @@ async function handleFileList(h, args) {
24284
24187
  async function handleFileListBrowse(h, args) {
24285
24188
  return handleFileList(h, args);
24286
24189
  }
24287
- init_config();
24288
24190
  init_logger();
24289
24191
  async function handleFocusSession(h, args) {
24290
24192
  if (!h.agentStream || !h.getCdp()) return { success: false, error: "AgentStream or CDP not available" };
@@ -24438,13 +24340,12 @@ function handleGetIdeExtensions(h, args) {
24438
24340
  const loader = h.ctx.providerLoader;
24439
24341
  if (!loader) return { success: false, error: "ProviderLoader not initialized" };
24440
24342
  const allExtProviders = loader.getByCategory?.("extension") || [];
24441
- const config2 = loadConfig();
24442
24343
  if (ideType) {
24443
24344
  const extensions = allExtProviders.map((p) => ({
24444
24345
  type: p.type,
24445
24346
  name: p.name,
24446
24347
  extensionId: p.extensionId,
24447
- enabled: config2.ideSettings?.[ideType]?.extensions?.[p.type]?.enabled === true
24348
+ enabled: loader.getIdeExtensionEnabledState?.(ideType, p.type) === true
24448
24349
  }));
24449
24350
  return { success: true, ideType, extensions };
24450
24351
  }
@@ -24455,7 +24356,7 @@ function handleGetIdeExtensions(h, args) {
24455
24356
  type: p.type,
24456
24357
  name: p.name,
24457
24358
  extensionId: p.extensionId,
24458
- enabled: config2.ideSettings?.[ide]?.extensions?.[p.type]?.enabled === true
24359
+ enabled: loader.getIdeExtensionEnabledState?.(ide, p.type) === true
24459
24360
  }));
24460
24361
  }
24461
24362
  return { success: true, ideExtensions: result };
@@ -24476,7 +24377,6 @@ function handleSetIdeExtension(h, args) {
24476
24377
  return { success: false, error: "Failed to save setting" };
24477
24378
  }
24478
24379
  init_config();
24479
- init_workspaces();
24480
24380
  function handleWorkspaceList() {
24481
24381
  const config2 = loadConfig();
24482
24382
  const state = getWorkspaceState(config2);
@@ -24484,9 +24384,7 @@ function handleWorkspaceList() {
24484
24384
  success: true,
24485
24385
  workspaces: state.workspaces,
24486
24386
  defaultWorkspaceId: state.defaultWorkspaceId,
24487
- defaultWorkspacePath: state.defaultWorkspacePath,
24488
- legacyRecentPaths: config2.recentCliWorkspaces || [],
24489
- activity: getWorkspaceActivity(config2, 25)
24387
+ defaultWorkspacePath: state.defaultWorkspacePath
24490
24388
  };
24491
24389
  }
24492
24390
  function handleWorkspaceAdd(args) {
@@ -24497,10 +24395,9 @@ function handleWorkspaceAdd(args) {
24497
24395
  const config2 = loadConfig();
24498
24396
  const result = addWorkspaceEntry(config2, rawPath, label, { createIfMissing });
24499
24397
  if ("error" in result) return { success: false, error: result.error };
24500
- let cfg = appendWorkspaceActivity(result.config, result.entry.path, {});
24501
- saveConfig(cfg);
24502
- const state = getWorkspaceState(cfg);
24503
- return { success: true, entry: result.entry, ...state, activity: getWorkspaceActivity(cfg, 25) };
24398
+ saveConfig(result.config);
24399
+ const state = getWorkspaceState(result.config);
24400
+ return { success: true, entry: result.entry, ...state };
24504
24401
  }
24505
24402
  function handleWorkspaceRemove(args) {
24506
24403
  const id = (args?.id || "").trim();
@@ -24509,13 +24406,9 @@ function handleWorkspaceRemove(args) {
24509
24406
  const removed = (config2.workspaces || []).find((w) => w.id === id);
24510
24407
  const result = removeWorkspaceEntry(config2, id);
24511
24408
  if ("error" in result) return { success: false, error: result.error };
24512
- let cfg = result.config;
24513
- if (removed) {
24514
- cfg = removeActivityForPath(cfg, removed.path);
24515
- }
24516
- saveConfig(cfg);
24517
- const state = getWorkspaceState(cfg);
24518
- return { success: true, removedId: id, ...state, activity: getWorkspaceActivity(cfg, 25) };
24409
+ saveConfig(result.config);
24410
+ const state = getWorkspaceState(result.config);
24411
+ return { success: true, removedId: id, ...state };
24519
24412
  }
24520
24413
  function handleWorkspaceSetDefault(args) {
24521
24414
  const clear = args?.clear === true || args?.id === null || args?.id === "";
@@ -24527,8 +24420,7 @@ function handleWorkspaceSetDefault(args) {
24527
24420
  const state2 = getWorkspaceState(result2.config);
24528
24421
  return {
24529
24422
  success: true,
24530
- ...state2,
24531
- activity: getWorkspaceActivity(result2.config, 25)
24423
+ ...state2
24532
24424
  };
24533
24425
  }
24534
24426
  const pathArg = args?.path != null && String(args.path).trim() ? String(args.path).trim() : "";
@@ -24552,16 +24444,10 @@ function handleWorkspaceSetDefault(args) {
24552
24444
  }
24553
24445
  const result = setDefaultWorkspaceId(config2, nextId);
24554
24446
  if ("error" in result) return { success: false, error: result.error };
24555
- let out = result.config;
24556
- const ap = getDefaultWorkspacePath(out);
24557
- if (ap) {
24558
- out = appendWorkspaceActivity(out, ap, { kind: "default" });
24559
- }
24560
- saveConfig(out);
24561
- const state = getWorkspaceState(out);
24562
- return { success: true, ...state, activity: getWorkspaceActivity(out, 25) };
24447
+ saveConfig(result.config);
24448
+ const state = getWorkspaceState(result.config);
24449
+ return { success: true, ...state };
24563
24450
  }
24564
- init_workspaces();
24565
24451
  var COMMAND_DEBUG_LEVELS = /* @__PURE__ */ new Set([
24566
24452
  "pty_input",
24567
24453
  "pty_resize",
@@ -24888,22 +24774,7 @@ var DaemonCommandHandler = class {
24888
24774
  return handleFileList(this, args);
24889
24775
  case "file_list_browse":
24890
24776
  return handleFileListBrowse(this, args);
24891
- // ─── VSCode API commands (not available) ────
24892
- case "vscode_command_exec":
24893
- case "execute_vscode_command": {
24894
- const resolvedCmd = args?.commandId || args?.command;
24895
- if (resolvedCmd === "adhdev.captureCdpScreenshot") {
24896
- return handleScreenshot(this, args);
24897
- }
24898
- return { success: false, error: `VSCode command not available: ${resolvedCmd || cmd}` };
24899
- }
24900
24777
  // ─── Workspace cmds ──────────────
24901
- case "get_recent_workspaces":
24902
- return this.handleGetRecentWorkspaces(args);
24903
- case "get_cli_history": {
24904
- const config2 = loadConfig();
24905
- return { success: true, history: config2.cliHistory || [] };
24906
- }
24907
24778
  case "workspace_list":
24908
24779
  return handleWorkspaceList();
24909
24780
  case "workspace_add":
@@ -24911,7 +24782,6 @@ var DaemonCommandHandler = class {
24911
24782
  case "workspace_remove":
24912
24783
  return handleWorkspaceRemove(args);
24913
24784
  case "workspace_set_default":
24914
- case "workspace_set_active":
24915
24785
  return handleWorkspaceSetDefault(args);
24916
24786
  // ─── Script manage ───────────────────
24917
24787
  case "refresh_scripts":
@@ -24957,19 +24827,6 @@ var DaemonCommandHandler = class {
24957
24827
  }
24958
24828
  }
24959
24829
  // ─── Misc (kept in handler — too small to extract) ───────
24960
- async handleGetRecentWorkspaces(_args) {
24961
- const config2 = loadConfig();
24962
- const cliRecent = config2.recentCliWorkspaces || [];
24963
- const ws = getWorkspaceState(config2);
24964
- return {
24965
- success: true,
24966
- result: cliRecent,
24967
- workspaces: ws.workspaces,
24968
- defaultWorkspaceId: ws.defaultWorkspaceId,
24969
- defaultWorkspacePath: ws.defaultWorkspacePath,
24970
- activity: getWorkspaceActivity(config2, 25)
24971
- };
24972
- }
24973
24830
  async handleRefreshScripts(_args) {
24974
24831
  if (this._ctx.providerLoader) {
24975
24832
  await this._ctx.providerLoader.fetchLatest().catch(() => {
@@ -24987,7 +24844,7 @@ var DaemonCommandHandler = class {
24987
24844
  try {
24988
24845
  const http3 = await import("http");
24989
24846
  const postData = JSON.stringify(body);
24990
- const result = await new Promise((resolve102, reject) => {
24847
+ const result = await new Promise((resolve92, reject) => {
24991
24848
  const req = http3.request({
24992
24849
  hostname: "127.0.0.1",
24993
24850
  port: 19280,
@@ -24999,9 +24856,9 @@ var DaemonCommandHandler = class {
24999
24856
  res.on("data", (chunk) => data += chunk);
25000
24857
  res.on("end", () => {
25001
24858
  try {
25002
- resolve102(JSON.parse(data));
24859
+ resolve92(JSON.parse(data));
25003
24860
  } catch {
25004
- resolve102({ raw: data });
24861
+ resolve92({ raw: data });
25005
24862
  }
25006
24863
  });
25007
24864
  });
@@ -25019,15 +24876,15 @@ var DaemonCommandHandler = class {
25019
24876
  if (!providerType) return { success: false, error: "providerType required" };
25020
24877
  try {
25021
24878
  const http3 = await import("http");
25022
- const result = await new Promise((resolve102, reject) => {
24879
+ const result = await new Promise((resolve92, reject) => {
25023
24880
  http3.get(`http://127.0.0.1:19280/api/providers/${providerType}/${endpoint}`, (res) => {
25024
24881
  let data = "";
25025
24882
  res.on("data", (chunk) => data += chunk);
25026
24883
  res.on("end", () => {
25027
24884
  try {
25028
- resolve102(JSON.parse(data));
24885
+ resolve92(JSON.parse(data));
25029
24886
  } catch {
25030
- resolve102({ raw: data });
24887
+ resolve92({ raw: data });
25031
24888
  }
25032
24889
  });
25033
24890
  }).on("error", reject);
@@ -25041,7 +24898,7 @@ var DaemonCommandHandler = class {
25041
24898
  try {
25042
24899
  const http3 = await import("http");
25043
24900
  const postData = JSON.stringify(args || {});
25044
- const result = await new Promise((resolve102, reject) => {
24901
+ const result = await new Promise((resolve92, reject) => {
25045
24902
  const req = http3.request({
25046
24903
  hostname: "127.0.0.1",
25047
24904
  port: 19280,
@@ -25053,9 +24910,9 @@ var DaemonCommandHandler = class {
25053
24910
  res.on("data", (chunk) => data += chunk);
25054
24911
  res.on("end", () => {
25055
24912
  try {
25056
- resolve102(JSON.parse(data));
24913
+ resolve92(JSON.parse(data));
25057
24914
  } catch {
25058
- resolve102({ raw: data });
24915
+ resolve92({ raw: data });
25059
24916
  }
25060
24917
  });
25061
24918
  });
@@ -25087,12 +24944,12 @@ var ProviderLoader = class _ProviderLoader {
25087
24944
  static META_FILE = ".meta.json";
25088
24945
  constructor(options) {
25089
24946
  this.logFn = options?.logFn || LOG.forComponent("Provider").asLogFn();
25090
- const defaultProvidersDir = path7.join(os7.homedir(), ".adhdev", "providers");
24947
+ const defaultProvidersDir = path6.join(os7.homedir(), ".adhdev", "providers");
25091
24948
  if (options?.userDir) {
25092
24949
  this.userDir = options.userDir;
25093
24950
  this.log(`Config 'providerDir' applied: ${this.userDir}`);
25094
24951
  } else {
25095
- const localRepoPath = path7.resolve(__dirname, "../../../../../adhdev-providers");
24952
+ const localRepoPath = path6.resolve(__dirname, "../../../../../adhdev-providers");
25096
24953
  if (fs5.existsSync(localRepoPath)) {
25097
24954
  this.userDir = localRepoPath;
25098
24955
  this.log(`Auto-detected local public repository: ${this.userDir} (Dev workspace speedup)`);
@@ -25101,7 +24958,7 @@ var ProviderLoader = class _ProviderLoader {
25101
24958
  this.log(`Using default user providers directory: ${this.userDir}`);
25102
24959
  }
25103
24960
  }
25104
- this.upstreamDir = path7.join(defaultProvidersDir, ".upstream");
24961
+ this.upstreamDir = path6.join(defaultProvidersDir, ".upstream");
25105
24962
  this.disableUpstream = options?.disableUpstream ?? false;
25106
24963
  }
25107
24964
  log(msg) {
@@ -25131,7 +24988,7 @@ var ProviderLoader = class _ProviderLoader {
25131
24988
  * Canonical provider directory shape for a given root.
25132
24989
  */
25133
24990
  getProviderDir(root, category, type) {
25134
- return path7.join(root, category, type);
24991
+ return path6.join(root, category, type);
25135
24992
  }
25136
24993
  /**
25137
24994
  * Canonical user override directory for a provider.
@@ -25158,7 +25015,7 @@ var ProviderLoader = class _ProviderLoader {
25158
25015
  resolveProviderFile(type, ...segments) {
25159
25016
  const dir = this.findProviderDirInternal(type);
25160
25017
  if (!dir) return null;
25161
- return path7.join(dir, ...segments);
25018
+ return path6.join(dir, ...segments);
25162
25019
  }
25163
25020
  /**
25164
25021
  * Load all providers (3-tier priority)
@@ -25196,7 +25053,7 @@ var ProviderLoader = class _ProviderLoader {
25196
25053
  if (!fs5.existsSync(this.upstreamDir)) return false;
25197
25054
  try {
25198
25055
  return fs5.readdirSync(this.upstreamDir).some(
25199
- (d) => fs5.statSync(path7.join(this.upstreamDir, d)).isDirectory()
25056
+ (d) => fs5.statSync(path6.join(this.upstreamDir, d)).isDirectory()
25200
25057
  );
25201
25058
  } catch {
25202
25059
  return false;
@@ -25281,16 +25138,23 @@ var ProviderLoader = class _ProviderLoader {
25281
25138
  isEnabled(type, ideType) {
25282
25139
  if (!ideType) return true;
25283
25140
  try {
25284
- const { loadConfig: loadConfig2 } = (init_config(), __toCommonJS(config_exports));
25285
- const config2 = loadConfig2();
25286
- const baseIdeType = ideType.split("_")[0];
25287
- const val = config2.ideSettings?.[baseIdeType]?.extensions?.[type]?.enabled;
25288
- return val === true;
25141
+ return this.getIdeExtensionEnabledState(ideType, type);
25289
25142
  } catch {
25290
25143
  return false;
25291
25144
  }
25292
25145
  }
25293
25146
  /**
25147
+ * Resolve per-IDE extension enabled state using the same normalization
25148
+ * that runtime attach/remove uses.
25149
+ */
25150
+ getIdeExtensionEnabledState(ideType, extensionType) {
25151
+ const { loadConfig: loadConfig2 } = (init_config(), __toCommonJS(config_exports));
25152
+ const config2 = loadConfig2();
25153
+ const baseIdeType = ideType.split("_")[0];
25154
+ const val = config2.ideSettings?.[baseIdeType]?.extensions?.[extensionType]?.enabled;
25155
+ return val === true;
25156
+ }
25157
+ /**
25294
25158
  * Save IDE extension enabled setting
25295
25159
  */
25296
25160
  setIdeExtensionEnabled(ideType, extensionType, enabled) {
@@ -25488,14 +25352,14 @@ var ProviderLoader = class _ProviderLoader {
25488
25352
  this.log(` [loadScriptsFromDir] ${type}: providerDir not found`);
25489
25353
  return null;
25490
25354
  }
25491
- const dir = path7.join(providerDir, scriptDir);
25355
+ const dir = path6.join(providerDir, scriptDir);
25492
25356
  if (!fs5.existsSync(dir)) {
25493
25357
  this.log(` [loadScriptsFromDir] ${type}: dir not found: ${dir}`);
25494
25358
  return null;
25495
25359
  }
25496
25360
  const cached2 = this.scriptsCache.get(dir);
25497
25361
  if (cached2) return cached2;
25498
- const scriptsJs = path7.join(dir, "scripts.js");
25362
+ const scriptsJs = path6.join(dir, "scripts.js");
25499
25363
  if (fs5.existsSync(scriptsJs)) {
25500
25364
  try {
25501
25365
  delete __require.cache[__require.resolve(scriptsJs)];
@@ -25534,7 +25398,7 @@ var ProviderLoader = class _ProviderLoader {
25534
25398
  });
25535
25399
  const handleChange = (filePath) => {
25536
25400
  if (filePath.endsWith(".js") || filePath.endsWith(".json")) {
25537
- this.log(`File changed: ${path7.basename(filePath)}, reloading...`);
25401
+ this.log(`File changed: ${path6.basename(filePath)}, reloading...`);
25538
25402
  this.reload();
25539
25403
  }
25540
25404
  };
@@ -25589,7 +25453,7 @@ var ProviderLoader = class _ProviderLoader {
25589
25453
  }
25590
25454
  const https = __require("https");
25591
25455
  const { execSync: execSync7 } = __require("child_process");
25592
- const metaPath = path7.join(this.upstreamDir, _ProviderLoader.META_FILE);
25456
+ const metaPath = path6.join(this.upstreamDir, _ProviderLoader.META_FILE);
25593
25457
  let prevEtag = "";
25594
25458
  let prevTimestamp = 0;
25595
25459
  try {
@@ -25606,7 +25470,7 @@ var ProviderLoader = class _ProviderLoader {
25606
25470
  return { updated: false };
25607
25471
  }
25608
25472
  try {
25609
- const etag = await new Promise((resolve102, reject) => {
25473
+ const etag = await new Promise((resolve92, reject) => {
25610
25474
  const options = {
25611
25475
  method: "HEAD",
25612
25476
  hostname: "github.com",
@@ -25624,7 +25488,7 @@ var ProviderLoader = class _ProviderLoader {
25624
25488
  headers: { "User-Agent": "adhdev-launcher" },
25625
25489
  timeout: 1e4
25626
25490
  }, (res2) => {
25627
- resolve102(res2.headers.etag || res2.headers["last-modified"] || "");
25491
+ resolve92(res2.headers.etag || res2.headers["last-modified"] || "");
25628
25492
  });
25629
25493
  req2.on("error", reject);
25630
25494
  req2.on("timeout", () => {
@@ -25633,7 +25497,7 @@ var ProviderLoader = class _ProviderLoader {
25633
25497
  });
25634
25498
  req2.end();
25635
25499
  } else {
25636
- resolve102(res.headers.etag || res.headers["last-modified"] || "");
25500
+ resolve92(res.headers.etag || res.headers["last-modified"] || "");
25637
25501
  }
25638
25502
  });
25639
25503
  req.on("error", reject);
@@ -25649,17 +25513,17 @@ var ProviderLoader = class _ProviderLoader {
25649
25513
  return { updated: false };
25650
25514
  }
25651
25515
  this.log("Downloading latest providers from GitHub...");
25652
- const tmpTar = path7.join(os7.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
25653
- const tmpExtract = path7.join(os7.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
25516
+ const tmpTar = path6.join(os7.tmpdir(), `adhdev-providers-${Date.now()}.tar.gz`);
25517
+ const tmpExtract = path6.join(os7.tmpdir(), `adhdev-providers-extract-${Date.now()}`);
25654
25518
  await this.downloadFile(_ProviderLoader.GITHUB_TARBALL_URL, tmpTar);
25655
25519
  fs5.mkdirSync(tmpExtract, { recursive: true });
25656
25520
  execSync7(`tar -xzf "${tmpTar}" -C "${tmpExtract}"`, { timeout: 3e4 });
25657
25521
  const extracted = fs5.readdirSync(tmpExtract);
25658
25522
  const rootDir = extracted.find(
25659
- (d) => fs5.statSync(path7.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
25523
+ (d) => fs5.statSync(path6.join(tmpExtract, d)).isDirectory() && d.startsWith("adhdev-providers")
25660
25524
  );
25661
25525
  if (!rootDir) throw new Error("Unexpected tarball structure");
25662
- const sourceDir = path7.join(tmpExtract, rootDir);
25526
+ const sourceDir = path6.join(tmpExtract, rootDir);
25663
25527
  const backupDir = this.upstreamDir + ".bak";
25664
25528
  if (fs5.existsSync(this.upstreamDir)) {
25665
25529
  if (fs5.existsSync(backupDir)) fs5.rmSync(backupDir, { recursive: true, force: true });
@@ -25697,7 +25561,7 @@ var ProviderLoader = class _ProviderLoader {
25697
25561
  downloadFile(url2, destPath) {
25698
25562
  const https = __require("https");
25699
25563
  const http3 = __require("http");
25700
- return new Promise((resolve102, reject) => {
25564
+ return new Promise((resolve92, reject) => {
25701
25565
  const doRequest = (reqUrl, redirectCount = 0) => {
25702
25566
  if (redirectCount > 5) {
25703
25567
  reject(new Error("Too many redirects"));
@@ -25717,7 +25581,7 @@ var ProviderLoader = class _ProviderLoader {
25717
25581
  res.pipe(ws);
25718
25582
  ws.on("finish", () => {
25719
25583
  ws.close();
25720
- resolve102();
25584
+ resolve92();
25721
25585
  });
25722
25586
  ws.on("error", reject);
25723
25587
  });
@@ -25734,8 +25598,8 @@ var ProviderLoader = class _ProviderLoader {
25734
25598
  copyDirRecursive(src, dest) {
25735
25599
  fs5.mkdirSync(dest, { recursive: true });
25736
25600
  for (const entry of fs5.readdirSync(src, { withFileTypes: true })) {
25737
- const srcPath = path7.join(src, entry.name);
25738
- const destPath = path7.join(dest, entry.name);
25601
+ const srcPath = path6.join(src, entry.name);
25602
+ const destPath = path6.join(dest, entry.name);
25739
25603
  if (entry.isDirectory()) {
25740
25604
  this.copyDirRecursive(srcPath, destPath);
25741
25605
  } else {
@@ -25746,7 +25610,7 @@ var ProviderLoader = class _ProviderLoader {
25746
25610
  /** .meta.json save */
25747
25611
  writeMeta(metaPath, etag, timestamp) {
25748
25612
  try {
25749
- fs5.mkdirSync(path7.dirname(metaPath), { recursive: true });
25613
+ fs5.mkdirSync(path6.dirname(metaPath), { recursive: true });
25750
25614
  fs5.writeFileSync(metaPath, JSON.stringify({
25751
25615
  etag,
25752
25616
  timestamp,
@@ -25763,7 +25627,7 @@ var ProviderLoader = class _ProviderLoader {
25763
25627
  const scan = (d) => {
25764
25628
  try {
25765
25629
  for (const entry of fs5.readdirSync(d, { withFileTypes: true })) {
25766
- if (entry.isDirectory()) scan(path7.join(d, entry.name));
25630
+ if (entry.isDirectory()) scan(path6.join(d, entry.name));
25767
25631
  else if (entry.name === "provider.json") count++;
25768
25632
  }
25769
25633
  } catch {
@@ -25862,17 +25726,17 @@ var ProviderLoader = class _ProviderLoader {
25862
25726
  for (const root of searchRoots) {
25863
25727
  if (!fs5.existsSync(root)) continue;
25864
25728
  const candidate = this.getProviderDir(root, cat, type);
25865
- if (fs5.existsSync(path7.join(candidate, "provider.json"))) return candidate;
25866
- const catDir = path7.join(root, cat);
25729
+ if (fs5.existsSync(path6.join(candidate, "provider.json"))) return candidate;
25730
+ const catDir = path6.join(root, cat);
25867
25731
  if (fs5.existsSync(catDir)) {
25868
25732
  try {
25869
25733
  for (const entry of fs5.readdirSync(catDir, { withFileTypes: true })) {
25870
25734
  if (!entry.isDirectory()) continue;
25871
- const jsonPath = path7.join(catDir, entry.name, "provider.json");
25735
+ const jsonPath = path6.join(catDir, entry.name, "provider.json");
25872
25736
  if (fs5.existsSync(jsonPath)) {
25873
25737
  try {
25874
25738
  const data = JSON.parse(fs5.readFileSync(jsonPath, "utf-8"));
25875
- if (data.type === type) return path7.join(catDir, entry.name);
25739
+ if (data.type === type) return path6.join(catDir, entry.name);
25876
25740
  } catch {
25877
25741
  }
25878
25742
  }
@@ -25889,7 +25753,7 @@ var ProviderLoader = class _ProviderLoader {
25889
25753
  * (template substitution is NOT applied here — scripts.js handles that)
25890
25754
  */
25891
25755
  buildScriptWrappersFromDir(dir) {
25892
- const scriptsJs = path7.join(dir, "scripts.js");
25756
+ const scriptsJs = path6.join(dir, "scripts.js");
25893
25757
  if (fs5.existsSync(scriptsJs)) {
25894
25758
  try {
25895
25759
  delete __require.cache[__require.resolve(scriptsJs)];
@@ -25903,7 +25767,7 @@ var ProviderLoader = class _ProviderLoader {
25903
25767
  for (const file2 of fs5.readdirSync(dir)) {
25904
25768
  if (!file2.endsWith(".js")) continue;
25905
25769
  const scriptName = toCamel(file2.replace(".js", ""));
25906
- const filePath = path7.join(dir, file2);
25770
+ const filePath = path6.join(dir, file2);
25907
25771
  result[scriptName] = (...args) => {
25908
25772
  try {
25909
25773
  let content = fs5.readFileSync(filePath, "utf-8");
@@ -25963,7 +25827,7 @@ var ProviderLoader = class _ProviderLoader {
25963
25827
  }
25964
25828
  const hasJson = entries.some((e) => e.name === "provider.json");
25965
25829
  if (hasJson) {
25966
- const jsonPath = path7.join(d, "provider.json");
25830
+ const jsonPath = path6.join(d, "provider.json");
25967
25831
  try {
25968
25832
  const raw = fs5.readFileSync(jsonPath, "utf-8");
25969
25833
  const mod = JSON.parse(raw);
@@ -25976,7 +25840,7 @@ var ProviderLoader = class _ProviderLoader {
25976
25840
  delete mod.extensionIdPattern_flags;
25977
25841
  }
25978
25842
  const hasCompatibility = Array.isArray(mod.compatibility);
25979
- const scriptsPath = path7.join(d, "scripts.js");
25843
+ const scriptsPath = path6.join(d, "scripts.js");
25980
25844
  if (!hasCompatibility && fs5.existsSync(scriptsPath)) {
25981
25845
  try {
25982
25846
  delete __require.cache[__require.resolve(scriptsPath)];
@@ -26002,7 +25866,7 @@ var ProviderLoader = class _ProviderLoader {
26002
25866
  if (!entry.isDirectory()) continue;
26003
25867
  if (entry.name.startsWith("_") || entry.name.startsWith(".")) continue;
26004
25868
  if (excludeDirs && d === dir && excludeDirs.includes(entry.name)) continue;
26005
- scan(path7.join(d, entry.name));
25869
+ scan(path6.join(d, entry.name));
26006
25870
  }
26007
25871
  }
26008
25872
  };
@@ -26080,17 +25944,17 @@ async function findFreePort(ports) {
26080
25944
  throw new Error("No free port found");
26081
25945
  }
26082
25946
  function checkPortFree(port) {
26083
- return new Promise((resolve102) => {
25947
+ return new Promise((resolve92) => {
26084
25948
  const server = net2.createServer();
26085
25949
  server.unref();
26086
- server.on("error", () => resolve102(false));
25950
+ server.on("error", () => resolve92(false));
26087
25951
  server.listen(port, "127.0.0.1", () => {
26088
- server.close(() => resolve102(true));
25952
+ server.close(() => resolve92(true));
26089
25953
  });
26090
25954
  });
26091
25955
  }
26092
25956
  async function isCdpActive(port) {
26093
- return new Promise((resolve102) => {
25957
+ return new Promise((resolve92) => {
26094
25958
  const req = __require("http").get(`http://127.0.0.1:${port}/json/version`, {
26095
25959
  timeout: 2e3
26096
25960
  }, (res) => {
@@ -26099,16 +25963,16 @@ async function isCdpActive(port) {
26099
25963
  res.on("end", () => {
26100
25964
  try {
26101
25965
  const info = JSON.parse(data);
26102
- resolve102(!!info["WebKit-Version"] || !!info["Browser"]);
25966
+ resolve92(!!info["WebKit-Version"] || !!info["Browser"]);
26103
25967
  } catch {
26104
- resolve102(false);
25968
+ resolve92(false);
26105
25969
  }
26106
25970
  });
26107
25971
  });
26108
- req.on("error", () => resolve102(false));
25972
+ req.on("error", () => resolve92(false));
26109
25973
  req.on("timeout", () => {
26110
25974
  req.destroy();
26111
- resolve102(false);
25975
+ resolve92(false);
26112
25976
  });
26113
25977
  });
26114
25978
  }
@@ -26227,8 +26091,8 @@ function detectCurrentWorkspace(ideId) {
26227
26091
  const appNameMap = getMacAppIdentifiers();
26228
26092
  const appName = appNameMap[ideId];
26229
26093
  if (appName) {
26230
- const storagePath = path8.join(
26231
- process.env.APPDATA || path8.join(os8.homedir(), "AppData", "Roaming"),
26094
+ const storagePath = path7.join(
26095
+ process.env.APPDATA || path7.join(os8.homedir(), "AppData", "Roaming"),
26232
26096
  appName,
26233
26097
  "storage.json"
26234
26098
  );
@@ -26392,10 +26256,8 @@ async function launchLinux(ide, port, workspace, newWindow) {
26392
26256
  (0, import_child_process5.spawn)(cli, args, { detached: true, stdio: "ignore" }).unref();
26393
26257
  }
26394
26258
  init_config();
26395
- init_workspaces();
26396
- init_config();
26397
26259
  init_logger();
26398
- var LOG_DIR2 = process.platform === "win32" ? path9.join(process.env.LOCALAPPDATA || process.env.APPDATA || path9.join(os9.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path9.join(os9.homedir(), "Library", "Logs", "adhdev") : path9.join(os9.homedir(), ".local", "share", "adhdev", "logs");
26260
+ var LOG_DIR2 = process.platform === "win32" ? path8.join(process.env.LOCALAPPDATA || process.env.APPDATA || path8.join(os9.homedir(), "AppData", "Local"), "adhdev", "logs") : process.platform === "darwin" ? path8.join(os9.homedir(), "Library", "Logs", "adhdev") : path8.join(os9.homedir(), ".local", "share", "adhdev", "logs");
26399
26261
  var MAX_FILE_SIZE = 5 * 1024 * 1024;
26400
26262
  var MAX_DAYS = 7;
26401
26263
  try {
@@ -26433,13 +26295,13 @@ function getDateStr2() {
26433
26295
  return (/* @__PURE__ */ new Date()).toISOString().slice(0, 10);
26434
26296
  }
26435
26297
  var currentDate2 = getDateStr2();
26436
- var currentFile = path9.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
26298
+ var currentFile = path8.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
26437
26299
  var writeCount2 = 0;
26438
26300
  function checkRotation() {
26439
26301
  const today = getDateStr2();
26440
26302
  if (today !== currentDate2) {
26441
26303
  currentDate2 = today;
26442
- currentFile = path9.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
26304
+ currentFile = path8.join(LOG_DIR2, `commands-${currentDate2}.jsonl`);
26443
26305
  cleanOldFiles();
26444
26306
  }
26445
26307
  }
@@ -26453,7 +26315,7 @@ function cleanOldFiles() {
26453
26315
  const dateMatch = file2.match(/commands-(\d{4}-\d{2}-\d{2})/);
26454
26316
  if (dateMatch && dateMatch[1] < cutoffStr) {
26455
26317
  try {
26456
- fs6.unlinkSync(path9.join(LOG_DIR2, file2));
26318
+ fs6.unlinkSync(path8.join(LOG_DIR2, file2));
26457
26319
  } catch {
26458
26320
  }
26459
26321
  }
@@ -26626,18 +26488,6 @@ var DaemonCommandRouter = class {
26626
26488
  };
26627
26489
  LOG.info("LaunchIDE", `target=${ideKey || "auto"}`);
26628
26490
  const result = await launchWithCdp(launchArgs);
26629
- if (result.success && (result.ideId || ideKey)) {
26630
- try {
26631
- addCliHistory({
26632
- category: "ide",
26633
- cliType: result.ideId || ideKey,
26634
- dir: resolvedWorkspace || "",
26635
- workspace: resolvedWorkspace || "",
26636
- newWindow: args?.newWindow === true
26637
- });
26638
- } catch {
26639
- }
26640
- }
26641
26491
  if (result.success && result.port && result.ideId && !this.deps.cdpManagers.has(result.ideId)) {
26642
26492
  const logFn = this.deps.getCdpLogFn ? this.deps.getCdpLogFn(result.ideId) : LOG.forComponent(`CDP:${result.ideId}`).asLogFn();
26643
26493
  const provider = this.deps.providerLoader.getMeta(result.ideId);
@@ -26654,11 +26504,7 @@ var DaemonCommandRouter = class {
26654
26504
  this.deps.onIdeConnected?.();
26655
26505
  if (result.success && resolvedWorkspace) {
26656
26506
  try {
26657
- let next = appendWorkspaceActivity(loadConfig(), resolvedWorkspace, {
26658
- kind: "ide",
26659
- agentType: result.ideId
26660
- });
26661
- next = appendRecentActivity(next, {
26507
+ const next = appendRecentActivity(loadConfig(), {
26662
26508
  kind: "ide",
26663
26509
  providerType: result.ideId || ideKey,
26664
26510
  providerName: result.ideId || ideKey,
@@ -26736,9 +26582,9 @@ var DaemonCommandRouter = class {
26736
26582
  setTimeout(() => {
26737
26583
  LOG.info("Upgrade", "Restarting daemon with new version...");
26738
26584
  try {
26739
- const path162 = __require("path");
26585
+ const path152 = __require("path");
26740
26586
  const fs122 = __require("fs");
26741
- const pidFile = path162.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "daemon.pid");
26587
+ const pidFile = path152.join(process.env.HOME || process.env.USERPROFILE || "", ".adhdev", "daemon.pid");
26742
26588
  if (fs122.existsSync(pidFile)) fs122.unlinkSync(pidFile);
26743
26589
  } catch {
26744
26590
  }
@@ -26831,7 +26677,6 @@ var DaemonCommandRouter = class {
26831
26677
  };
26832
26678
  init_logger();
26833
26679
  init_config();
26834
- init_workspaces();
26835
26680
  init_terminal_screen();
26836
26681
  function buildDetectedIdeInfos(detectedIdes, cdpManagers) {
26837
26682
  return detectedIdes.filter((ide) => ide.installed !== false).map((ide) => ({
@@ -26885,7 +26730,9 @@ function getUnreadState(hasContentChange, status, lastUsedAt, lastSeenAt, lastRo
26885
26730
  return { unread, inboxBucket: unread ? "task_complete" : "idle" };
26886
26731
  }
26887
26732
  function buildRecentSessions(sessions, recentActivity, readState) {
26888
- const live = sessions.filter((session) => !session.parentId && session.status !== "stopped").map((session) => {
26733
+ const visibleKeys = /* @__PURE__ */ new Set();
26734
+ const hiddenKeys = /* @__PURE__ */ new Set();
26735
+ const live = sessions.filter((session) => !session.surfaceHidden && session.status !== "stopped").map((session) => {
26889
26736
  const kind = getSessionKind(session);
26890
26737
  const recentKey = buildRecentActivityKey({
26891
26738
  kind,
@@ -26915,11 +26762,21 @@ function buildRecentSessions(sessions, recentActivity, readState) {
26915
26762
  lastUsedAt,
26916
26763
  unread,
26917
26764
  lastSeenAt,
26918
- inboxBucket
26765
+ inboxBucket,
26766
+ surfaceHidden: false
26919
26767
  };
26920
26768
  });
26921
- const seen = new Set(live.map((item) => `${item.kind}:${item.providerType}:${item.workspace || ""}`));
26922
- const persisted = recentActivity.filter((item) => !seen.has(`${item.kind}:${item.providerType}:${item.workspace || ""}`)).map((item) => {
26769
+ for (const item of live) {
26770
+ visibleKeys.add(`${item.kind}:${item.providerType}:${item.workspace || ""}`);
26771
+ }
26772
+ for (const session of sessions) {
26773
+ if (!session.surfaceHidden) continue;
26774
+ hiddenKeys.add(`${getSessionKind(session)}:${session.providerType}:${session.workspace || ""}`);
26775
+ }
26776
+ const persisted = recentActivity.filter((item) => {
26777
+ const key = `${item.kind}:${item.providerType}:${item.workspace || ""}`;
26778
+ return !visibleKeys.has(key) && !hiddenKeys.has(key);
26779
+ }).map((item) => {
26923
26780
  const lastSeenAt = readState[item.id] || 0;
26924
26781
  const unread = item.lastUsedAt > lastSeenAt;
26925
26782
  return {
@@ -26935,7 +26792,8 @@ function buildRecentSessions(sessions, recentActivity, readState) {
26935
26792
  lastUsedAt: item.lastUsedAt,
26936
26793
  unread,
26937
26794
  lastSeenAt,
26938
- inboxBucket: unread ? "task_complete" : "idle"
26795
+ inboxBucket: unread ? "task_complete" : "idle",
26796
+ surfaceHidden: false
26939
26797
  };
26940
26798
  });
26941
26799
  return [...live, ...persisted].sort((a, b) => b.lastUsedAt - a.lastUsedAt).slice(0, 12);
@@ -26959,7 +26817,7 @@ function buildStatusSnapshot(options) {
26959
26817
  });
26960
26818
  const lastSeenAt = getRecentSessionSeenAt(cfg, recentKey);
26961
26819
  const lastUsedAt = getSessionLastUsedAt(session);
26962
- const { unread, inboxBucket } = getUnreadState(
26820
+ const { unread, inboxBucket } = session.surfaceHidden ? { unread: false, inboxBucket: "idle" } : getUnreadState(
26963
26821
  getSessionMessageUpdatedAt(session) > 0,
26964
26822
  session.status,
26965
26823
  lastUsedAt,
@@ -26996,7 +26854,6 @@ function buildStatusSnapshot(options) {
26996
26854
  workspaces: wsState.workspaces,
26997
26855
  defaultWorkspaceId: wsState.defaultWorkspaceId,
26998
26856
  defaultWorkspacePath: wsState.defaultWorkspacePath,
26999
- workspaceActivity: getWorkspaceActivity(cfg, 15),
27000
26857
  recentSessions: buildRecentSessions(sessions, recentActivity, readState),
27001
26858
  terminalBackend,
27002
26859
  availableProviders: buildAvailableProviders(options.providerLoader)
@@ -27005,7 +26862,6 @@ function buildStatusSnapshot(options) {
27005
26862
  init_logger();
27006
26863
  init_provider_cli_adapter();
27007
26864
  init_config();
27008
- init_workspaces();
27009
26865
  init_provider_cli_adapter();
27010
26866
  init_logger();
27011
26867
  var CliProviderInstance = class {
@@ -27669,13 +27525,13 @@ var AcpProviderInstance = class {
27669
27525
  }
27670
27526
  this.currentStatus = "waiting_approval";
27671
27527
  this.detectStatusTransition();
27672
- const approved = await new Promise((resolve102) => {
27673
- this.permissionResolvers.push(resolve102);
27528
+ const approved = await new Promise((resolve92) => {
27529
+ this.permissionResolvers.push(resolve92);
27674
27530
  setTimeout(() => {
27675
- const idx = this.permissionResolvers.indexOf(resolve102);
27531
+ const idx = this.permissionResolvers.indexOf(resolve92);
27676
27532
  if (idx >= 0) {
27677
27533
  this.permissionResolvers.splice(idx, 1);
27678
- resolve102(false);
27534
+ resolve92(false);
27679
27535
  }
27680
27536
  }, 3e5);
27681
27537
  });
@@ -28148,24 +28004,6 @@ var DaemonCliManager = class {
28148
28004
  const hash2 = __require("crypto").createHash("md5").update(__require("path").resolve(dir)).digest("hex").slice(0, 8);
28149
28005
  return `${cliType}_${hash2}`;
28150
28006
  }
28151
- persistRecentDir(cliType, dir) {
28152
- try {
28153
- const normalizedType = this.providerLoader.resolveAlias(cliType);
28154
- const provider = this.providerLoader.getByAlias(cliType);
28155
- const actKind = provider?.category === "acp" ? "acp" : "cli";
28156
- let next = loadConfig();
28157
- console.log(colorize("cyan", ` \u{1F4C2} Saving recent workspace: ${dir}`));
28158
- const recent = next.recentCliWorkspaces || [];
28159
- if (!recent.includes(dir)) {
28160
- next = { ...next, recentCliWorkspaces: [dir, ...recent].slice(0, 10) };
28161
- }
28162
- next = appendWorkspaceActivity(next, dir, { kind: actKind, agentType: normalizedType });
28163
- saveConfig(next);
28164
- console.log(colorize("green", ` \u2713 Recent workspace saved: ${dir}`));
28165
- } catch (e) {
28166
- console.error(colorize("red", ` \u2717 Failed to save recent workspace: ${e}`));
28167
- }
28168
- }
28169
28007
  persistRecentActivity(entry) {
28170
28008
  try {
28171
28009
  saveConfig(appendRecentActivity(loadConfig(), entry));
@@ -28255,7 +28093,7 @@ var DaemonCliManager = class {
28255
28093
  async startSession(cliType, workingDir, cliArgs, initialModel) {
28256
28094
  const trimmed = (workingDir || "").trim();
28257
28095
  if (!trimmed) throw new Error("working directory required");
28258
- const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path11.resolve(trimmed);
28096
+ const resolvedDir = trimmed.startsWith("~") ? trimmed.replace(/^~/, os13.homedir()) : path10.resolve(trimmed);
28259
28097
  const normalizedType = this.providerLoader.resolveAlias(cliType);
28260
28098
  const provider = this.providerLoader.getByAlias(cliType);
28261
28099
  const key = crypto4.randomUUID();
@@ -28326,11 +28164,6 @@ ${installInfo}`
28326
28164
  LOG.warn("CLI", `[ACP] Initial model set failed: ${e?.message}`);
28327
28165
  }
28328
28166
  }
28329
- try {
28330
- addCliHistory({ category: "acp", cliType: normalizedType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
28331
- } catch (e) {
28332
- LOG.warn("CLI", `ACP history save failed: ${e?.message}`);
28333
- }
28334
28167
  this.persistRecentActivity({
28335
28168
  kind: "acp",
28336
28169
  providerType: normalizedType,
@@ -28397,11 +28230,6 @@ ${installInfo}`
28397
28230
  this.adapters.set(key, adapter);
28398
28231
  console.log(colorize("green", ` \u2713 CLI started: ${cliInfo.displayName} v${cliInfo.version || "unknown"} in ${resolvedDir}`));
28399
28232
  }
28400
- try {
28401
- addCliHistory({ category: "cli", cliType, dir: resolvedDir, workspace: resolvedDir, cliArgs, model: initialModel });
28402
- } catch (e) {
28403
- LOG.warn("CLI", `CLI history save failed: ${e?.message}`);
28404
- }
28405
28233
  this.persistRecentActivity({
28406
28234
  kind: "cli",
28407
28235
  providerType: normalizedType,
@@ -28554,7 +28382,6 @@ ${installInfo}`
28554
28382
  newKey = k;
28555
28383
  }
28556
28384
  }
28557
- this.persistRecentDir(cliType, dir);
28558
28385
  return { success: true, cliType, dir, id: newKey, launchSource };
28559
28386
  }
28560
28387
  case "stop_cli": {
@@ -28597,7 +28424,6 @@ ${installInfo}`
28597
28424
  const found = this.findAdapter(cliType, { instanceKey: args?.targetSessionId, dir });
28598
28425
  if (found) await this.stopSession(found.key);
28599
28426
  await this.startSession(cliType, dir);
28600
- this.persistRecentDir(cliType, dir);
28601
28427
  return { success: true, restarted: true };
28602
28428
  }
28603
28429
  case "agent_command": {
@@ -29403,7 +29229,7 @@ var ProviderInstanceManager = class {
29403
29229
  this.eventListeners = [];
29404
29230
  }
29405
29231
  };
29406
- var ARCHIVE_PATH = path12.join(os14.homedir(), ".adhdev", "version-history.json");
29232
+ var ARCHIVE_PATH = path11.join(os14.homedir(), ".adhdev", "version-history.json");
29407
29233
  var MAX_ENTRIES_PER_PROVIDER = 20;
29408
29234
  var VersionArchive = class {
29409
29235
  history = {};
@@ -29450,7 +29276,7 @@ var VersionArchive = class {
29450
29276
  }
29451
29277
  save() {
29452
29278
  try {
29453
- fs8.mkdirSync(path12.dirname(ARCHIVE_PATH), { recursive: true });
29279
+ fs8.mkdirSync(path11.dirname(ARCHIVE_PATH), { recursive: true });
29454
29280
  fs8.writeFileSync(ARCHIVE_PATH, JSON.stringify(this.history, null, 2));
29455
29281
  } catch {
29456
29282
  }
@@ -29491,7 +29317,7 @@ function checkPathExists2(paths) {
29491
29317
  for (const p of paths) {
29492
29318
  if (p.includes("*")) {
29493
29319
  const home = os14.homedir();
29494
- const resolved = p.replace(/\*/g, home.split(path12.sep).pop() || "");
29320
+ const resolved = p.replace(/\*/g, home.split(path11.sep).pop() || "");
29495
29321
  if (fs8.existsSync(resolved)) return resolved;
29496
29322
  } else {
29497
29323
  if (fs8.existsSync(p)) return p;
@@ -29501,7 +29327,7 @@ function checkPathExists2(paths) {
29501
29327
  }
29502
29328
  function getMacAppVersion(appPath) {
29503
29329
  if ((0, import_os3.platform)() !== "darwin" || !appPath.endsWith(".app")) return null;
29504
- const plistPath = path12.join(appPath, "Contents", "Info.plist");
29330
+ const plistPath = path11.join(appPath, "Contents", "Info.plist");
29505
29331
  if (!fs8.existsSync(plistPath)) return null;
29506
29332
  const raw = runCommand(`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${plistPath}"`);
29507
29333
  return raw || null;
@@ -29528,7 +29354,7 @@ async function detectAllVersions(loader, archive) {
29528
29354
  const cliBin = provider.cli ? findBinary2(provider.cli) : null;
29529
29355
  let resolvedBin = cliBin;
29530
29356
  if (!resolvedBin && appPath && currentOs === "darwin") {
29531
- const bundled = path12.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
29357
+ const bundled = path11.join(appPath, "Contents", "Resources", "app", "bin", provider.cli || "");
29532
29358
  if (provider.cli && fs8.existsSync(bundled)) resolvedBin = bundled;
29533
29359
  }
29534
29360
  info.installed = !!(appPath || resolvedBin);
@@ -30071,17 +29897,17 @@ async function handleScriptHints(ctx, type, _req, res) {
30071
29897
  return;
30072
29898
  }
30073
29899
  let scriptsPath = "";
30074
- const directScripts = path13.join(dir, "scripts.js");
29900
+ const directScripts = path12.join(dir, "scripts.js");
30075
29901
  if (fs9.existsSync(directScripts)) {
30076
29902
  scriptsPath = directScripts;
30077
29903
  } else {
30078
- const scriptsDir = path13.join(dir, "scripts");
29904
+ const scriptsDir = path12.join(dir, "scripts");
30079
29905
  if (fs9.existsSync(scriptsDir)) {
30080
29906
  const versions = fs9.readdirSync(scriptsDir).filter((d) => {
30081
- return fs9.statSync(path13.join(scriptsDir, d)).isDirectory();
29907
+ return fs9.statSync(path12.join(scriptsDir, d)).isDirectory();
30082
29908
  }).sort().reverse();
30083
29909
  for (const ver of versions) {
30084
- const p = path13.join(scriptsDir, ver, "scripts.js");
29910
+ const p = path12.join(scriptsDir, ver, "scripts.js");
30085
29911
  if (fs9.existsSync(p)) {
30086
29912
  scriptsPath = p;
30087
29913
  break;
@@ -31149,22 +30975,22 @@ function getLatestScriptVersionDir(scriptsDir) {
31149
30975
  if (!fs10.existsSync(scriptsDir)) return null;
31150
30976
  const versions = fs10.readdirSync(scriptsDir).filter((d) => {
31151
30977
  try {
31152
- return fs10.statSync(path14.join(scriptsDir, d)).isDirectory();
30978
+ return fs10.statSync(path13.join(scriptsDir, d)).isDirectory();
31153
30979
  } catch {
31154
30980
  return false;
31155
30981
  }
31156
30982
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
31157
30983
  if (versions.length === 0) return null;
31158
- return path14.join(scriptsDir, versions[0]);
30984
+ return path13.join(scriptsDir, versions[0]);
31159
30985
  }
31160
30986
  function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
31161
- const canonicalUserDir = path14.resolve(ctx.providerLoader.getUserProviderDir(category, type));
31162
- const desiredDir = requestedDir ? path14.resolve(requestedDir) : canonicalUserDir;
31163
- const upstreamRoot = path14.resolve(ctx.providerLoader.getUpstreamDir());
31164
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path14.sep}`)) {
30987
+ const canonicalUserDir = path13.resolve(ctx.providerLoader.getUserProviderDir(category, type));
30988
+ const desiredDir = requestedDir ? path13.resolve(requestedDir) : canonicalUserDir;
30989
+ const upstreamRoot = path13.resolve(ctx.providerLoader.getUpstreamDir());
30990
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path13.sep}`)) {
31165
30991
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
31166
30992
  }
31167
- if (path14.basename(desiredDir) !== type) {
30993
+ if (path13.basename(desiredDir) !== type) {
31168
30994
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
31169
30995
  }
31170
30996
  const sourceDir = ctx.findProviderDir(type);
@@ -31172,11 +30998,11 @@ function resolveAutoImplWritableProviderDir(ctx, category, type, requestedDir) {
31172
30998
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
31173
30999
  }
31174
31000
  if (!fs10.existsSync(desiredDir)) {
31175
- fs10.mkdirSync(path14.dirname(desiredDir), { recursive: true });
31001
+ fs10.mkdirSync(path13.dirname(desiredDir), { recursive: true });
31176
31002
  fs10.cpSync(sourceDir, desiredDir, { recursive: true });
31177
31003
  ctx.log(`Auto-implement writable copy created: ${desiredDir}`);
31178
31004
  }
31179
- const providerJson = path14.join(desiredDir, "provider.json");
31005
+ const providerJson = path13.join(desiredDir, "provider.json");
31180
31006
  if (!fs10.existsSync(providerJson)) {
31181
31007
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
31182
31008
  }
@@ -31199,13 +31025,13 @@ function loadAutoImplReferenceScripts(ctx, referenceType) {
31199
31025
  const refDir = ctx.findProviderDir(referenceType);
31200
31026
  if (!refDir || !fs10.existsSync(refDir)) return {};
31201
31027
  const referenceScripts = {};
31202
- const scriptsDir = path14.join(refDir, "scripts");
31028
+ const scriptsDir = path13.join(refDir, "scripts");
31203
31029
  const latestDir = getLatestScriptVersionDir(scriptsDir);
31204
31030
  if (!latestDir) return referenceScripts;
31205
31031
  for (const file2 of fs10.readdirSync(latestDir)) {
31206
31032
  if (!file2.endsWith(".js")) continue;
31207
31033
  try {
31208
- referenceScripts[file2] = fs10.readFileSync(path14.join(latestDir, file2), "utf-8");
31034
+ referenceScripts[file2] = fs10.readFileSync(path13.join(latestDir, file2), "utf-8");
31209
31035
  } catch {
31210
31036
  }
31211
31037
  }
@@ -31256,9 +31082,9 @@ async function handleAutoImplement(ctx, type, req, res) {
31256
31082
  });
31257
31083
  const referenceScripts = loadAutoImplReferenceScripts(ctx, resolvedReference);
31258
31084
  const prompt = buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domContext, referenceScripts, comment, resolvedReference);
31259
- const tmpDir = path14.join(os15.tmpdir(), "adhdev-autoimpl");
31085
+ const tmpDir = path13.join(os15.tmpdir(), "adhdev-autoimpl");
31260
31086
  if (!fs10.existsSync(tmpDir)) fs10.mkdirSync(tmpDir, { recursive: true });
31261
- const promptFile = path14.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
31087
+ const promptFile = path13.join(tmpDir, `prompt-${type}-${Date.now()}.md`);
31262
31088
  fs10.writeFileSync(promptFile, prompt, "utf-8");
31263
31089
  ctx.log(`Auto-implement prompt written to ${promptFile} (${prompt.length} chars)`);
31264
31090
  const agentProvider = ctx.providerLoader.resolve(agent) || ctx.providerLoader.getMeta(agent);
@@ -31629,7 +31455,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
31629
31455
  setMode: "set_mode.js"
31630
31456
  };
31631
31457
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
31632
- const scriptsDir = path14.join(providerDir, "scripts");
31458
+ const scriptsDir = path13.join(providerDir, "scripts");
31633
31459
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
31634
31460
  if (latestScriptsDir) {
31635
31461
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -31640,7 +31466,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
31640
31466
  for (const file2 of fs10.readdirSync(latestScriptsDir)) {
31641
31467
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
31642
31468
  try {
31643
- const content = fs10.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
31469
+ const content = fs10.readFileSync(path13.join(latestScriptsDir, file2), "utf-8");
31644
31470
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
31645
31471
  lines.push("```javascript");
31646
31472
  lines.push(content);
@@ -31657,7 +31483,7 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
31657
31483
  lines.push("");
31658
31484
  for (const file2 of refFiles) {
31659
31485
  try {
31660
- const content = fs10.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
31486
+ const content = fs10.readFileSync(path13.join(latestScriptsDir, file2), "utf-8");
31661
31487
  lines.push(`### \`${file2}\` \u{1F512}`);
31662
31488
  lines.push("```javascript");
31663
31489
  lines.push(content);
@@ -31698,10 +31524,10 @@ function buildAutoImplPrompt(ctx, type, provider, providerDir, functions, domCon
31698
31524
  lines.push("");
31699
31525
  }
31700
31526
  }
31701
- const docsDir = path14.join(providerDir, "../../docs");
31527
+ const docsDir = path13.join(providerDir, "../../docs");
31702
31528
  const loadGuide = (name) => {
31703
31529
  try {
31704
- const p = path14.join(docsDir, name);
31530
+ const p = path13.join(docsDir, name);
31705
31531
  if (fs10.existsSync(p)) return fs10.readFileSync(p, "utf-8");
31706
31532
  } catch {
31707
31533
  }
@@ -31875,7 +31701,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
31875
31701
  parseApproval: "parse_approval.js"
31876
31702
  };
31877
31703
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
31878
- const scriptsDir = path14.join(providerDir, "scripts");
31704
+ const scriptsDir = path13.join(providerDir, "scripts");
31879
31705
  const latestScriptsDir = getLatestScriptVersionDir(scriptsDir);
31880
31706
  if (latestScriptsDir) {
31881
31707
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -31887,7 +31713,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
31887
31713
  if (!file2.endsWith(".js")) continue;
31888
31714
  if (!targetFileNames.has(file2)) continue;
31889
31715
  try {
31890
- const content = fs10.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
31716
+ const content = fs10.readFileSync(path13.join(latestScriptsDir, file2), "utf-8");
31891
31717
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
31892
31718
  lines.push("```javascript");
31893
31719
  lines.push(content);
@@ -31903,7 +31729,7 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
31903
31729
  lines.push("");
31904
31730
  for (const file2 of refFiles) {
31905
31731
  try {
31906
- const content = fs10.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
31732
+ const content = fs10.readFileSync(path13.join(latestScriptsDir, file2), "utf-8");
31907
31733
  lines.push(`### \`${file2}\` \u{1F512}`);
31908
31734
  lines.push("```javascript");
31909
31735
  lines.push(content);
@@ -31936,10 +31762,10 @@ function buildCliAutoImplPrompt(ctx, type, provider, providerDir, functions, ref
31936
31762
  lines.push("");
31937
31763
  }
31938
31764
  }
31939
- const docsDir = path14.join(providerDir, "../../docs");
31765
+ const docsDir = path13.join(providerDir, "../../docs");
31940
31766
  const loadGuide = (name) => {
31941
31767
  try {
31942
- const p = path14.join(docsDir, name);
31768
+ const p = path13.join(docsDir, name);
31943
31769
  if (fs10.existsSync(p)) return fs10.readFileSync(p, "utf-8");
31944
31770
  } catch {
31945
31771
  }
@@ -32195,8 +32021,8 @@ var DevServer = class _DevServer {
32195
32021
  }
32196
32022
  getEndpointList() {
32197
32023
  return this.routes.map((r) => {
32198
- const path162 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
32199
- return `${r.method.padEnd(5)} ${path162}`;
32024
+ const path152 = typeof r.pattern === "string" ? r.pattern : r.pattern.source.replace(/\\\//g, "/").replace(/\(\[.*?\]\+\)/g, ":type").replace(/[\^$]/g, "");
32025
+ return `${r.method.padEnd(5)} ${path152}`;
32200
32026
  });
32201
32027
  }
32202
32028
  async start(port = DEV_SERVER_PORT) {
@@ -32227,15 +32053,15 @@ var DevServer = class _DevServer {
32227
32053
  this.json(res, 500, { error: e.message });
32228
32054
  }
32229
32055
  });
32230
- return new Promise((resolve102, reject) => {
32056
+ return new Promise((resolve92, reject) => {
32231
32057
  this.server.listen(port, "127.0.0.1", () => {
32232
32058
  this.log(`Dev server listening on http://127.0.0.1:${port}`);
32233
- resolve102();
32059
+ resolve92();
32234
32060
  });
32235
32061
  this.server.on("error", (e) => {
32236
32062
  if (e.code === "EADDRINUSE") {
32237
32063
  this.log(`Port ${port} in use, skipping dev server`);
32238
- resolve102();
32064
+ resolve92();
32239
32065
  } else {
32240
32066
  reject(e);
32241
32067
  }
@@ -32318,20 +32144,20 @@ var DevServer = class _DevServer {
32318
32144
  child.stderr?.on("data", (d) => {
32319
32145
  stderr += d.toString().slice(0, 2e3);
32320
32146
  });
32321
- await new Promise((resolve102) => {
32147
+ await new Promise((resolve92) => {
32322
32148
  const timer = setTimeout(() => {
32323
32149
  child.kill();
32324
- resolve102();
32150
+ resolve92();
32325
32151
  }, 3e3);
32326
32152
  child.on("exit", () => {
32327
32153
  clearTimeout(timer);
32328
- resolve102();
32154
+ resolve92();
32329
32155
  });
32330
32156
  child.stdout?.once("data", () => {
32331
32157
  setTimeout(() => {
32332
32158
  child.kill();
32333
32159
  clearTimeout(timer);
32334
- resolve102();
32160
+ resolve92();
32335
32161
  }, 500);
32336
32162
  });
32337
32163
  });
@@ -32478,12 +32304,12 @@ var DevServer = class _DevServer {
32478
32304
  // ─── DevConsole SPA ───
32479
32305
  getConsoleDistDir() {
32480
32306
  const candidates = [
32481
- path15.resolve(__dirname, "../../web-devconsole/dist"),
32482
- path15.resolve(__dirname, "../../../web-devconsole/dist"),
32483
- path15.join(process.cwd(), "packages/web-devconsole/dist")
32307
+ path14.resolve(__dirname, "../../web-devconsole/dist"),
32308
+ path14.resolve(__dirname, "../../../web-devconsole/dist"),
32309
+ path14.join(process.cwd(), "packages/web-devconsole/dist")
32484
32310
  ];
32485
32311
  for (const dir of candidates) {
32486
- if (fs11.existsSync(path15.join(dir, "index.html"))) return dir;
32312
+ if (fs11.existsSync(path14.join(dir, "index.html"))) return dir;
32487
32313
  }
32488
32314
  return null;
32489
32315
  }
@@ -32493,7 +32319,7 @@ var DevServer = class _DevServer {
32493
32319
  this.json(res, 500, { error: "DevConsole not found. Run: npm run build -w packages/web-devconsole" });
32494
32320
  return;
32495
32321
  }
32496
- const htmlPath = path15.join(distDir, "index.html");
32322
+ const htmlPath = path14.join(distDir, "index.html");
32497
32323
  try {
32498
32324
  const html = fs11.readFileSync(htmlPath, "utf-8");
32499
32325
  res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" });
@@ -32518,15 +32344,15 @@ var DevServer = class _DevServer {
32518
32344
  this.json(res, 404, { error: "Not found" });
32519
32345
  return;
32520
32346
  }
32521
- const safePath = path15.normalize(pathname).replace(/^\.\.\//, "");
32522
- const filePath = path15.join(distDir, safePath);
32347
+ const safePath = path14.normalize(pathname).replace(/^\.\.\//, "");
32348
+ const filePath = path14.join(distDir, safePath);
32523
32349
  if (!filePath.startsWith(distDir)) {
32524
32350
  this.json(res, 403, { error: "Forbidden" });
32525
32351
  return;
32526
32352
  }
32527
32353
  try {
32528
32354
  const content = fs11.readFileSync(filePath);
32529
- const ext = path15.extname(filePath);
32355
+ const ext = path14.extname(filePath);
32530
32356
  const contentType = _DevServer.MIME_MAP[ext] || "application/octet-stream";
32531
32357
  res.writeHead(200, { "Content-Type": contentType, "Cache-Control": "public, max-age=31536000, immutable" });
32532
32358
  res.end(content);
@@ -32639,9 +32465,9 @@ var DevServer = class _DevServer {
32639
32465
  const rel = prefix ? `${prefix}/${entry.name}` : entry.name;
32640
32466
  if (entry.isDirectory()) {
32641
32467
  files.push({ path: rel, size: 0, type: "dir" });
32642
- scan(path15.join(d, entry.name), rel);
32468
+ scan(path14.join(d, entry.name), rel);
32643
32469
  } else {
32644
- const stat4 = fs11.statSync(path15.join(d, entry.name));
32470
+ const stat4 = fs11.statSync(path14.join(d, entry.name));
32645
32471
  files.push({ path: rel, size: stat4.size, type: "file" });
32646
32472
  }
32647
32473
  }
@@ -32664,7 +32490,7 @@ var DevServer = class _DevServer {
32664
32490
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
32665
32491
  return;
32666
32492
  }
32667
- const fullPath = path15.resolve(dir, path15.normalize(filePath));
32493
+ const fullPath = path14.resolve(dir, path14.normalize(filePath));
32668
32494
  if (!fullPath.startsWith(dir)) {
32669
32495
  this.json(res, 403, { error: "Forbidden" });
32670
32496
  return;
@@ -32689,14 +32515,14 @@ var DevServer = class _DevServer {
32689
32515
  this.json(res, 404, { error: `Provider directory not found: ${type}` });
32690
32516
  return;
32691
32517
  }
32692
- const fullPath = path15.resolve(dir, path15.normalize(filePath));
32518
+ const fullPath = path14.resolve(dir, path14.normalize(filePath));
32693
32519
  if (!fullPath.startsWith(dir)) {
32694
32520
  this.json(res, 403, { error: "Forbidden" });
32695
32521
  return;
32696
32522
  }
32697
32523
  try {
32698
32524
  if (fs11.existsSync(fullPath)) fs11.copyFileSync(fullPath, fullPath + ".bak");
32699
- fs11.mkdirSync(path15.dirname(fullPath), { recursive: true });
32525
+ fs11.mkdirSync(path14.dirname(fullPath), { recursive: true });
32700
32526
  fs11.writeFileSync(fullPath, content, "utf-8");
32701
32527
  this.log(`File saved: ${fullPath} (${content.length} chars)`);
32702
32528
  this.providerLoader.reload();
@@ -32713,7 +32539,7 @@ var DevServer = class _DevServer {
32713
32539
  return;
32714
32540
  }
32715
32541
  for (const name of ["scripts.js", "provider.json"]) {
32716
- const p = path15.join(dir, name);
32542
+ const p = path14.join(dir, name);
32717
32543
  if (fs11.existsSync(p)) {
32718
32544
  const source = fs11.readFileSync(p, "utf-8");
32719
32545
  this.json(res, 200, { type, path: p, source, lines: source.split("\n").length });
@@ -32734,8 +32560,8 @@ var DevServer = class _DevServer {
32734
32560
  this.json(res, 404, { error: `Provider not found: ${type}` });
32735
32561
  return;
32736
32562
  }
32737
- const target = fs11.existsSync(path15.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
32738
- const targetPath = path15.join(dir, target);
32563
+ const target = fs11.existsSync(path14.join(dir, "scripts.js")) ? "scripts.js" : "provider.json";
32564
+ const targetPath = path14.join(dir, target);
32739
32565
  try {
32740
32566
  if (fs11.existsSync(targetPath)) fs11.copyFileSync(targetPath, targetPath + ".bak");
32741
32567
  fs11.writeFileSync(targetPath, source, "utf-8");
@@ -32840,14 +32666,14 @@ var DevServer = class _DevServer {
32840
32666
  child.stderr?.on("data", (d) => {
32841
32667
  stderr += d.toString();
32842
32668
  });
32843
- await new Promise((resolve102) => {
32669
+ await new Promise((resolve92) => {
32844
32670
  const timer = setTimeout(() => {
32845
32671
  child.kill();
32846
- resolve102();
32672
+ resolve92();
32847
32673
  }, timeout);
32848
32674
  child.on("exit", () => {
32849
32675
  clearTimeout(timer);
32850
- resolve102();
32676
+ resolve92();
32851
32677
  });
32852
32678
  });
32853
32679
  const elapsed = Date.now() - start;
@@ -32895,7 +32721,7 @@ var DevServer = class _DevServer {
32895
32721
  }
32896
32722
  let targetDir;
32897
32723
  targetDir = this.providerLoader.getUserProviderDir(category, type);
32898
- const jsonPath = path15.join(targetDir, "provider.json");
32724
+ const jsonPath = path14.join(targetDir, "provider.json");
32899
32725
  if (fs11.existsSync(jsonPath)) {
32900
32726
  this.json(res, 409, { error: `Provider already exists at ${targetDir}`, path: targetDir });
32901
32727
  return;
@@ -32907,8 +32733,8 @@ var DevServer = class _DevServer {
32907
32733
  const createdFiles = ["provider.json"];
32908
32734
  if (result.files) {
32909
32735
  for (const [relPath, content] of Object.entries(result.files)) {
32910
- const fullPath = path15.join(targetDir, relPath);
32911
- fs11.mkdirSync(path15.dirname(fullPath), { recursive: true });
32736
+ const fullPath = path14.join(targetDir, relPath);
32737
+ fs11.mkdirSync(path14.dirname(fullPath), { recursive: true });
32912
32738
  fs11.writeFileSync(fullPath, content, "utf-8");
32913
32739
  createdFiles.push(relPath);
32914
32740
  }
@@ -32961,22 +32787,22 @@ var DevServer = class _DevServer {
32961
32787
  if (!fs11.existsSync(scriptsDir)) return null;
32962
32788
  const versions = fs11.readdirSync(scriptsDir).filter((d) => {
32963
32789
  try {
32964
- return fs11.statSync(path15.join(scriptsDir, d)).isDirectory();
32790
+ return fs11.statSync(path14.join(scriptsDir, d)).isDirectory();
32965
32791
  } catch {
32966
32792
  return false;
32967
32793
  }
32968
32794
  }).sort((a, b) => b.localeCompare(a, void 0, { numeric: true, sensitivity: "base" }));
32969
32795
  if (versions.length === 0) return null;
32970
- return path15.join(scriptsDir, versions[0]);
32796
+ return path14.join(scriptsDir, versions[0]);
32971
32797
  }
32972
32798
  resolveAutoImplWritableProviderDir(category, type, requestedDir) {
32973
- const canonicalUserDir = path15.resolve(this.providerLoader.getUserProviderDir(category, type));
32974
- const desiredDir = requestedDir ? path15.resolve(requestedDir) : canonicalUserDir;
32975
- const upstreamRoot = path15.resolve(this.providerLoader.getUpstreamDir());
32976
- if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path15.sep}`)) {
32799
+ const canonicalUserDir = path14.resolve(this.providerLoader.getUserProviderDir(category, type));
32800
+ const desiredDir = requestedDir ? path14.resolve(requestedDir) : canonicalUserDir;
32801
+ const upstreamRoot = path14.resolve(this.providerLoader.getUpstreamDir());
32802
+ if (desiredDir === upstreamRoot || desiredDir.startsWith(`${upstreamRoot}${path14.sep}`)) {
32977
32803
  return { dir: null, reason: `Refusing to write into upstream provider directory: ${desiredDir}` };
32978
32804
  }
32979
- if (path15.basename(desiredDir) !== type) {
32805
+ if (path14.basename(desiredDir) !== type) {
32980
32806
  return { dir: null, reason: `Requested writable provider directory must end with '${type}': ${desiredDir}` };
32981
32807
  }
32982
32808
  const sourceDir = this.findProviderDir(type);
@@ -32984,11 +32810,11 @@ var DevServer = class _DevServer {
32984
32810
  return { dir: null, reason: `Provider source directory not found for '${type}'` };
32985
32811
  }
32986
32812
  if (!fs11.existsSync(desiredDir)) {
32987
- fs11.mkdirSync(path15.dirname(desiredDir), { recursive: true });
32813
+ fs11.mkdirSync(path14.dirname(desiredDir), { recursive: true });
32988
32814
  fs11.cpSync(sourceDir, desiredDir, { recursive: true });
32989
32815
  this.log(`Auto-implement writable copy created: ${desiredDir}`);
32990
32816
  }
32991
- const providerJson = path15.join(desiredDir, "provider.json");
32817
+ const providerJson = path14.join(desiredDir, "provider.json");
32992
32818
  if (!fs11.existsSync(providerJson)) {
32993
32819
  return { dir: null, reason: `provider.json not found in writable provider directory: ${desiredDir}` };
32994
32820
  }
@@ -33036,7 +32862,7 @@ var DevServer = class _DevServer {
33036
32862
  setMode: "set_mode.js"
33037
32863
  };
33038
32864
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
33039
- const scriptsDir = path15.join(providerDir, "scripts");
32865
+ const scriptsDir = path14.join(providerDir, "scripts");
33040
32866
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
33041
32867
  if (latestScriptsDir) {
33042
32868
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -33047,7 +32873,7 @@ var DevServer = class _DevServer {
33047
32873
  for (const file2 of fs11.readdirSync(latestScriptsDir)) {
33048
32874
  if (file2.endsWith(".js") && targetFileNames.has(file2)) {
33049
32875
  try {
33050
- const content = fs11.readFileSync(path15.join(latestScriptsDir, file2), "utf-8");
32876
+ const content = fs11.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
33051
32877
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
33052
32878
  lines.push("```javascript");
33053
32879
  lines.push(content);
@@ -33064,7 +32890,7 @@ var DevServer = class _DevServer {
33064
32890
  lines.push("");
33065
32891
  for (const file2 of refFiles) {
33066
32892
  try {
33067
- const content = fs11.readFileSync(path15.join(latestScriptsDir, file2), "utf-8");
32893
+ const content = fs11.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
33068
32894
  lines.push(`### \`${file2}\` \u{1F512}`);
33069
32895
  lines.push("```javascript");
33070
32896
  lines.push(content);
@@ -33105,10 +32931,10 @@ var DevServer = class _DevServer {
33105
32931
  lines.push("");
33106
32932
  }
33107
32933
  }
33108
- const docsDir = path15.join(providerDir, "../../docs");
32934
+ const docsDir = path14.join(providerDir, "../../docs");
33109
32935
  const loadGuide = (name) => {
33110
32936
  try {
33111
- const p = path15.join(docsDir, name);
32937
+ const p = path14.join(docsDir, name);
33112
32938
  if (fs11.existsSync(p)) return fs11.readFileSync(p, "utf-8");
33113
32939
  } catch {
33114
32940
  }
@@ -33282,7 +33108,7 @@ var DevServer = class _DevServer {
33282
33108
  parseApproval: "parse_approval.js"
33283
33109
  };
33284
33110
  const targetFileNames = new Set(functions.map((fn) => funcToFile[fn]).filter(Boolean));
33285
- const scriptsDir = path15.join(providerDir, "scripts");
33111
+ const scriptsDir = path14.join(providerDir, "scripts");
33286
33112
  const latestScriptsDir = this.getLatestScriptVersionDir(scriptsDir);
33287
33113
  if (latestScriptsDir) {
33288
33114
  lines.push(`Scripts version directory: \`${latestScriptsDir}\``);
@@ -33294,7 +33120,7 @@ var DevServer = class _DevServer {
33294
33120
  if (!file2.endsWith(".js")) continue;
33295
33121
  if (!targetFileNames.has(file2)) continue;
33296
33122
  try {
33297
- const content = fs11.readFileSync(path15.join(latestScriptsDir, file2), "utf-8");
33123
+ const content = fs11.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
33298
33124
  lines.push(`### \`${file2}\` \u270F\uFE0F EDIT`);
33299
33125
  lines.push("```javascript");
33300
33126
  lines.push(content);
@@ -33310,7 +33136,7 @@ var DevServer = class _DevServer {
33310
33136
  lines.push("");
33311
33137
  for (const file2 of refFiles) {
33312
33138
  try {
33313
- const content = fs11.readFileSync(path15.join(latestScriptsDir, file2), "utf-8");
33139
+ const content = fs11.readFileSync(path14.join(latestScriptsDir, file2), "utf-8");
33314
33140
  lines.push(`### \`${file2}\` \u{1F512}`);
33315
33141
  lines.push("```javascript");
33316
33142
  lines.push(content);
@@ -33343,10 +33169,10 @@ var DevServer = class _DevServer {
33343
33169
  lines.push("");
33344
33170
  }
33345
33171
  }
33346
- const docsDir = path15.join(providerDir, "../../docs");
33172
+ const docsDir = path14.join(providerDir, "../../docs");
33347
33173
  const loadGuide = (name) => {
33348
33174
  try {
33349
- const p = path15.join(docsDir, name);
33175
+ const p = path14.join(docsDir, name);
33350
33176
  if (fs11.existsSync(p)) return fs11.readFileSync(p, "utf-8");
33351
33177
  } catch {
33352
33178
  }
@@ -33503,14 +33329,14 @@ data: ${JSON.stringify(msg.data)}
33503
33329
  res.end(JSON.stringify(data, null, 2));
33504
33330
  }
33505
33331
  async readBody(req) {
33506
- return new Promise((resolve102) => {
33332
+ return new Promise((resolve92) => {
33507
33333
  let body = "";
33508
33334
  req.on("data", (chunk) => body += chunk);
33509
33335
  req.on("end", () => {
33510
33336
  try {
33511
- resolve102(JSON.parse(body));
33337
+ resolve92(JSON.parse(body));
33512
33338
  } catch {
33513
- resolve102({});
33339
+ resolve92({});
33514
33340
  }
33515
33341
  });
33516
33342
  });
@@ -33919,7 +33745,7 @@ async function waitForReady(endpoint, timeoutMs = STARTUP_TIMEOUT_MS) {
33919
33745
  const deadline = Date.now() + timeoutMs;
33920
33746
  while (Date.now() < deadline) {
33921
33747
  if (await canConnect(endpoint)) return;
33922
- await new Promise((resolve102) => setTimeout(resolve102, STARTUP_POLL_MS));
33748
+ await new Promise((resolve92) => setTimeout(resolve92, STARTUP_POLL_MS));
33923
33749
  }
33924
33750
  throw new Error(`Session host did not become ready within ${timeoutMs}ms`);
33925
33751
  }
@@ -34201,12 +34027,12 @@ async function shutdownDaemonComponents(components) {
34201
34027
 
34202
34028
  // src/session-host.ts
34203
34029
  var import_child_process8 = require("child_process");
34204
- var path16 = __toESM(require("path"));
34030
+ var path15 = __toESM(require("path"));
34205
34031
  var SESSION_HOST_APP_NAME = process.env.ADHDEV_SESSION_HOST_NAME || "adhdev";
34206
34032
  function resolveSessionHostEntry() {
34207
34033
  const localCandidates = [
34208
- path16.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
34209
- path16.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
34034
+ path15.resolve(__dirname, "../vendor/session-host-daemon/index.js"),
34035
+ path15.resolve(__dirname, "../../vendor/session-host-daemon/index.js")
34210
34036
  ];
34211
34037
  for (const candidate of localCandidates) {
34212
34038
  if (require("fs").existsSync(candidate)) {
@@ -34224,9 +34050,9 @@ async function runSessionHostCli(args) {
34224
34050
  ADHDEV_SESSION_HOST_NAME: SESSION_HOST_APP_NAME
34225
34051
  }
34226
34052
  });
34227
- return await new Promise((resolve13, reject) => {
34053
+ return await new Promise((resolve12, reject) => {
34228
34054
  child.on("error", reject);
34229
- child.on("exit", (code) => resolve13(code ?? 0));
34055
+ child.on("exit", (code) => resolve12(code ?? 0));
34230
34056
  });
34231
34057
  }
34232
34058
  async function ensureSessionHostReady2() {
@@ -34333,8 +34159,8 @@ var AdhMuxControlClient = class {
34333
34159
  }
34334
34160
  this.waiters.clear();
34335
34161
  });
34336
- await new Promise((resolve13, reject) => {
34337
- socket.once("connect", () => resolve13());
34162
+ await new Promise((resolve12, reject) => {
34163
+ socket.once("connect", () => resolve12());
34338
34164
  socket.once("error", reject);
34339
34165
  });
34340
34166
  }
@@ -34343,8 +34169,8 @@ var AdhMuxControlClient = class {
34343
34169
  if (!this.socket) throw new Error("adhmux control socket unavailable");
34344
34170
  const requestId = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
34345
34171
  const envelope = { kind: "request", requestId, request };
34346
- const response = await new Promise((resolve13, reject) => {
34347
- this.waiters.set(requestId, { resolve: resolve13, reject });
34172
+ const response = await new Promise((resolve12, reject) => {
34173
+ this.waiters.set(requestId, { resolve: resolve12, reject });
34348
34174
  this.socket?.write(serializeEnvelope2(envelope));
34349
34175
  });
34350
34176
  return response;
@@ -34363,12 +34189,12 @@ var AdhMuxControlClient = class {
34363
34189
  waiter.reject(new Error("adhmux control client closed"));
34364
34190
  }
34365
34191
  this.waiters.clear();
34366
- await new Promise((resolve13) => {
34192
+ await new Promise((resolve12) => {
34367
34193
  let settled = false;
34368
34194
  const done = () => {
34369
34195
  if (settled) return;
34370
34196
  settled = true;
34371
- resolve13();
34197
+ resolve12();
34372
34198
  };
34373
34199
  socket.once("close", done);
34374
34200
  socket.end();
@@ -34426,8 +34252,8 @@ var pkgVersion = process.env.ADHDEV_PKG_VERSION || "unknown";
34426
34252
  if (pkgVersion === "unknown") {
34427
34253
  try {
34428
34254
  const possiblePaths = [
34429
- path18.join(__dirname, "..", "package.json"),
34430
- path18.join(__dirname, "package.json")
34255
+ path17.join(__dirname, "..", "package.json"),
34256
+ path17.join(__dirname, "package.json")
34431
34257
  ];
34432
34258
  for (const candidate of possiblePaths) {
34433
34259
  try {
@@ -34563,9 +34389,9 @@ var StandaloneServer = class {
34563
34389
  this.scheduleBroadcastStatus();
34564
34390
  }, STATUS_INTERVAL);
34565
34391
  this.running = true;
34566
- await new Promise((resolve13) => {
34392
+ await new Promise((resolve12) => {
34567
34393
  this.httpServer.listen(port, host, () => {
34568
- resolve13();
34394
+ resolve12();
34569
34395
  });
34570
34396
  });
34571
34397
  console.log("");
@@ -34759,9 +34585,9 @@ var StandaloneServer = class {
34759
34585
  }
34760
34586
  if (publicDir) {
34761
34587
  const filePath = url2 === "/" ? "/index.html" : url2;
34762
- const fullPath = path18.join(publicDir, filePath);
34588
+ const fullPath = path17.join(publicDir, filePath);
34763
34589
  if (fs12.existsSync(fullPath) && fs12.statSync(fullPath).isFile()) {
34764
- const ext = path18.extname(fullPath);
34590
+ const ext = path17.extname(fullPath);
34765
34591
  const mimeTypes = {
34766
34592
  ".html": "text/html",
34767
34593
  ".js": "application/javascript",
@@ -34776,7 +34602,7 @@ var StandaloneServer = class {
34776
34602
  fs12.createReadStream(fullPath).pipe(res);
34777
34603
  return;
34778
34604
  }
34779
- const indexPath = path18.join(publicDir, "index.html");
34605
+ const indexPath = path17.join(publicDir, "index.html");
34780
34606
  if (fs12.existsSync(indexPath) && !url2.startsWith("/api/")) {
34781
34607
  res.writeHead(200, { "Content-Type": "text/html" });
34782
34608
  fs12.createReadStream(indexPath).pipe(res);
@@ -35124,12 +34950,12 @@ Runtime commands:
35124
34950
  }
35125
34951
  if (!options.publicDir) {
35126
34952
  const candidates = [
35127
- path18.join(__dirname, "../../web-standalone/dist"),
35128
- path18.join(__dirname, "../public"),
35129
- path18.join(process.cwd(), "public")
34953
+ path17.join(__dirname, "../../web-standalone/dist"),
34954
+ path17.join(__dirname, "../public"),
34955
+ path17.join(process.cwd(), "public")
35130
34956
  ];
35131
34957
  for (const candidate of candidates) {
35132
- if (fs12.existsSync(path18.join(candidate, "index.html"))) {
34958
+ if (fs12.existsSync(path17.join(candidate, "index.html"))) {
35133
34959
  options.publicDir = candidate;
35134
34960
  break;
35135
34961
  }