duclaw-cli 1.8.15 → 1.8.17

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/bundle.js CHANGED
@@ -115,7 +115,7 @@ var require_package = __commonJS({
115
115
  var require_main = __commonJS({
116
116
  "node_modules/.pnpm/dotenv@17.3.1/node_modules/dotenv/lib/main.js"(exports2, module2) {
117
117
  var fs3 = require("fs");
118
- var path18 = require("path");
118
+ var path19 = require("path");
119
119
  var os = require("os");
120
120
  var crypto2 = require("crypto");
121
121
  var packageJson = require_package();
@@ -261,7 +261,7 @@ var require_main = __commonJS({
261
261
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
262
262
  }
263
263
  } else {
264
- possibleVaultPath = path18.resolve(process.cwd(), ".env.vault");
264
+ possibleVaultPath = path19.resolve(process.cwd(), ".env.vault");
265
265
  }
266
266
  if (fs3.existsSync(possibleVaultPath)) {
267
267
  return possibleVaultPath;
@@ -269,7 +269,7 @@ var require_main = __commonJS({
269
269
  return null;
270
270
  }
271
271
  function _resolveHome(envPath) {
272
- return envPath[0] === "~" ? path18.join(os.homedir(), envPath.slice(1)) : envPath;
272
+ return envPath[0] === "~" ? path19.join(os.homedir(), envPath.slice(1)) : envPath;
273
273
  }
274
274
  function _configVault(options) {
275
275
  const debug = parseBoolean(process.env.DOTENV_CONFIG_DEBUG || options && options.debug);
@@ -286,7 +286,7 @@ var require_main = __commonJS({
286
286
  return { parsed };
287
287
  }
288
288
  function configDotenv(options) {
289
- const dotenvPath = path18.resolve(process.cwd(), ".env");
289
+ const dotenvPath = path19.resolve(process.cwd(), ".env");
290
290
  let encoding = "utf8";
291
291
  let processEnv = process.env;
292
292
  if (options && options.processEnv != null) {
@@ -314,13 +314,13 @@ var require_main = __commonJS({
314
314
  }
315
315
  let lastError;
316
316
  const parsedAll = {};
317
- for (const path19 of optionPaths) {
317
+ for (const path20 of optionPaths) {
318
318
  try {
319
- const parsed = DotenvModule.parse(fs3.readFileSync(path19, { encoding }));
319
+ const parsed = DotenvModule.parse(fs3.readFileSync(path20, { encoding }));
320
320
  DotenvModule.populate(parsedAll, parsed, options);
321
321
  } catch (e) {
322
322
  if (debug) {
323
- _debug(`Failed to load ${path19} ${e.message}`);
323
+ _debug(`Failed to load ${path20} ${e.message}`);
324
324
  }
325
325
  lastError = e;
326
326
  }
@@ -333,7 +333,7 @@ var require_main = __commonJS({
333
333
  const shortPaths = [];
334
334
  for (const filePath of optionPaths) {
335
335
  try {
336
- const relative4 = path18.relative(process.cwd(), filePath);
336
+ const relative4 = path19.relative(process.cwd(), filePath);
337
337
  shortPaths.push(relative4);
338
338
  } catch (e) {
339
339
  if (debug) {
@@ -8237,8 +8237,8 @@ var require_MODULE_LOAD = __commonJS({
8237
8237
  * @param moduleArguments - Optional arguments to pass to the module
8238
8238
  * @see https://redis.io/commands/module-load/
8239
8239
  */
8240
- parseCommand(parser, path18, moduleArguments) {
8241
- parser.push("MODULE", "LOAD", path18);
8240
+ parseCommand(parser, path19, moduleArguments) {
8241
+ parser.push("MODULE", "LOAD", path19);
8242
8242
  if (moduleArguments) {
8243
8243
  parser.push(...moduleArguments);
8244
8244
  }
@@ -23539,10 +23539,10 @@ var require_ARRAPPEND = __commonJS({
23539
23539
  * @param json - The first value to append
23540
23540
  * @param jsons - Additional values to append
23541
23541
  */
23542
- parseCommand(parser, key, path18, json, ...jsons) {
23542
+ parseCommand(parser, key, path19, json, ...jsons) {
23543
23543
  parser.push("JSON.ARRAPPEND");
23544
23544
  parser.pushKey(key);
23545
- parser.push(path18, (0, generic_transformers_1.transformRedisJsonArgument)(json));
23545
+ parser.push(path19, (0, generic_transformers_1.transformRedisJsonArgument)(json));
23546
23546
  for (let i = 0; i < jsons.length; i++) {
23547
23547
  parser.push((0, generic_transformers_1.transformRedisJsonArgument)(jsons[i]));
23548
23548
  }
@@ -23572,10 +23572,10 @@ var require_ARRINDEX = __commonJS({
23572
23572
  * @param options.range.start - Starting index for the search
23573
23573
  * @param options.range.stop - Optional ending index for the search
23574
23574
  */
23575
- parseCommand(parser, key, path18, json, options) {
23575
+ parseCommand(parser, key, path19, json, options) {
23576
23576
  parser.push("JSON.ARRINDEX");
23577
23577
  parser.pushKey(key);
23578
- parser.push(path18, (0, generic_transformers_1.transformRedisJsonArgument)(json));
23578
+ parser.push(path19, (0, generic_transformers_1.transformRedisJsonArgument)(json));
23579
23579
  if (options?.range) {
23580
23580
  parser.push(options.range.start.toString());
23581
23581
  if (options.range.stop !== void 0) {
@@ -23607,10 +23607,10 @@ var require_ARRINSERT = __commonJS({
23607
23607
  * @param json - The first value to insert
23608
23608
  * @param jsons - Additional values to insert
23609
23609
  */
23610
- parseCommand(parser, key, path18, index, json, ...jsons) {
23610
+ parseCommand(parser, key, path19, index, json, ...jsons) {
23611
23611
  parser.push("JSON.ARRINSERT");
23612
23612
  parser.pushKey(key);
23613
- parser.push(path18, index.toString(), (0, generic_transformers_1.transformRedisJsonArgument)(json));
23613
+ parser.push(path19, index.toString(), (0, generic_transformers_1.transformRedisJsonArgument)(json));
23614
23614
  for (let i = 0; i < jsons.length; i++) {
23615
23615
  parser.push((0, generic_transformers_1.transformRedisJsonArgument)(jsons[i]));
23616
23616
  }
@@ -23700,10 +23700,10 @@ var require_ARRTRIM = __commonJS({
23700
23700
  * @param start - Starting index (inclusive)
23701
23701
  * @param stop - Ending index (inclusive)
23702
23702
  */
23703
- parseCommand(parser, key, path18, start, stop) {
23703
+ parseCommand(parser, key, path19, start, stop) {
23704
23704
  parser.push("JSON.ARRTRIM");
23705
23705
  parser.pushKey(key);
23706
- parser.push(path18, start.toString(), stop.toString());
23706
+ parser.push(path19, start.toString(), stop.toString());
23707
23707
  },
23708
23708
  transformReply: void 0
23709
23709
  };
@@ -23868,10 +23868,10 @@ var require_MERGE3 = __commonJS({
23868
23868
  * @param path - Path to merge into
23869
23869
  * @param value - JSON value to merge
23870
23870
  */
23871
- parseCommand(parser, key, path18, value) {
23871
+ parseCommand(parser, key, path19, value) {
23872
23872
  parser.push("JSON.MERGE");
23873
23873
  parser.pushKey(key);
23874
- parser.push(path18, (0, generic_transformers_1.transformRedisJsonArgument)(value));
23874
+ parser.push(path19, (0, generic_transformers_1.transformRedisJsonArgument)(value));
23875
23875
  },
23876
23876
  transformReply: void 0
23877
23877
  };
@@ -23894,10 +23894,10 @@ var require_MGET2 = __commonJS({
23894
23894
  * @param keys - Array of keys containing JSON documents
23895
23895
  * @param path - Path to retrieve from each document
23896
23896
  */
23897
- parseCommand(parser, keys, path18) {
23897
+ parseCommand(parser, keys, path19) {
23898
23898
  parser.push("JSON.MGET");
23899
23899
  parser.pushKeys(keys);
23900
- parser.push(path18);
23900
+ parser.push(path19);
23901
23901
  },
23902
23902
  transformReply(reply) {
23903
23903
  return reply.map((json) => (0, generic_transformers_1.transformRedisJsonNullReply)(json));
@@ -23952,10 +23952,10 @@ var require_NUMINCRBY = __commonJS({
23952
23952
  * @param path - Path to the numeric value
23953
23953
  * @param by - Amount to increment by
23954
23954
  */
23955
- parseCommand(parser, key, path18, by) {
23955
+ parseCommand(parser, key, path19, by) {
23956
23956
  parser.push("JSON.NUMINCRBY");
23957
23957
  parser.pushKey(key);
23958
- parser.push(path18, by.toString());
23958
+ parser.push(path19, by.toString());
23959
23959
  },
23960
23960
  transformReply: {
23961
23961
  2: (reply) => {
@@ -23987,10 +23987,10 @@ var require_NUMMULTBY = __commonJS({
23987
23987
  * @param path - Path to the numeric value
23988
23988
  * @param by - Amount to multiply by
23989
23989
  */
23990
- parseCommand(parser, key, path18, by) {
23990
+ parseCommand(parser, key, path19, by) {
23991
23991
  parser.push("JSON.NUMMULTBY");
23992
23992
  parser.pushKey(key);
23993
- parser.push(path18, by.toString());
23993
+ parser.push(path19, by.toString());
23994
23994
  },
23995
23995
  transformReply: NUMINCRBY_1.default.transformReply
23996
23996
  };
@@ -24074,10 +24074,10 @@ var require_SET2 = __commonJS({
24074
24074
  * @deprecated options.NX - Use options.condition instead
24075
24075
  * @deprecated options.XX - Use options.condition instead
24076
24076
  */
24077
- parseCommand(parser, key, path18, json, options) {
24077
+ parseCommand(parser, key, path19, json, options) {
24078
24078
  parser.push("JSON.SET");
24079
24079
  parser.pushKey(key);
24080
- parser.push(path18, (0, generic_transformers_1.transformRedisJsonArgument)(json));
24080
+ parser.push(path19, (0, generic_transformers_1.transformRedisJsonArgument)(json));
24081
24081
  if (options?.condition) {
24082
24082
  parser.push(options?.condition);
24083
24083
  } else if (options?.NX) {
@@ -24165,10 +24165,10 @@ var require_TOGGLE = __commonJS({
24165
24165
  * @param key - The key containing the JSON document
24166
24166
  * @param path - Path to the boolean value
24167
24167
  */
24168
- parseCommand(parser, key, path18) {
24168
+ parseCommand(parser, key, path19) {
24169
24169
  parser.push("JSON.TOGGLE");
24170
24170
  parser.pushKey(key);
24171
- parser.push(path18);
24171
+ parser.push(path19);
24172
24172
  },
24173
24173
  transformReply: void 0
24174
24174
  };
@@ -30242,7 +30242,7 @@ function printHelp() {
30242
30242
  `);
30243
30243
  }
30244
30244
  function printVersion() {
30245
- console.log(`duclaw-cli v${true ? "1.8.15" : "unknown"}`);
30245
+ console.log(`duclaw-cli v${true ? "1.8.17" : "unknown"}`);
30246
30246
  }
30247
30247
  function getDuclawTemplate() {
30248
30248
  return {
@@ -30983,7 +30983,7 @@ var ReaddirpStream = class extends import_node_stream.Readable {
30983
30983
  this._directoryFilter = normalizeFilter(opts.directoryFilter);
30984
30984
  const statMethod = opts.lstat ? import_promises2.lstat : import_promises2.stat;
30985
30985
  if (wantBigintFsStats) {
30986
- this._stat = (path18) => statMethod(path18, { bigint: true });
30986
+ this._stat = (path19) => statMethod(path19, { bigint: true });
30987
30987
  } else {
30988
30988
  this._stat = statMethod;
30989
30989
  }
@@ -31008,8 +31008,8 @@ var ReaddirpStream = class extends import_node_stream.Readable {
31008
31008
  const par = this.parent;
31009
31009
  const fil = par && par.files;
31010
31010
  if (fil && fil.length > 0) {
31011
- const { path: path18, depth } = par;
31012
- const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path18));
31011
+ const { path: path19, depth } = par;
31012
+ const slice = fil.splice(0, batch).map((dirent) => this._formatEntry(dirent, path19));
31013
31013
  const awaited = await Promise.all(slice);
31014
31014
  for (const entry of awaited) {
31015
31015
  if (!entry)
@@ -31049,20 +31049,20 @@ var ReaddirpStream = class extends import_node_stream.Readable {
31049
31049
  this.reading = false;
31050
31050
  }
31051
31051
  }
31052
- async _exploreDir(path18, depth) {
31052
+ async _exploreDir(path19, depth) {
31053
31053
  let files;
31054
31054
  try {
31055
- files = await (0, import_promises2.readdir)(path18, this._rdOptions);
31055
+ files = await (0, import_promises2.readdir)(path19, this._rdOptions);
31056
31056
  } catch (error) {
31057
31057
  this._onError(error);
31058
31058
  }
31059
- return { files, depth, path: path18 };
31059
+ return { files, depth, path: path19 };
31060
31060
  }
31061
- async _formatEntry(dirent, path18) {
31061
+ async _formatEntry(dirent, path19) {
31062
31062
  let entry;
31063
31063
  const basename4 = this._isDirent ? dirent.name : dirent;
31064
31064
  try {
31065
- const fullPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(path18, basename4));
31065
+ const fullPath = (0, import_node_path2.resolve)((0, import_node_path2.join)(path19, basename4));
31066
31066
  entry = { path: (0, import_node_path2.relative)(this._root, fullPath), fullPath, basename: basename4 };
31067
31067
  entry[this._statsProp] = this._isDirent ? dirent : await this._stat(fullPath);
31068
31068
  } catch (err) {
@@ -31462,16 +31462,16 @@ var delFromSet = (main2, prop, item) => {
31462
31462
  };
31463
31463
  var isEmptySet = (val) => val instanceof Set ? val.size === 0 : !val;
31464
31464
  var FsWatchInstances = /* @__PURE__ */ new Map();
31465
- function createFsWatchInstance(path18, options, listener, errHandler, emitRaw) {
31465
+ function createFsWatchInstance(path19, options, listener, errHandler, emitRaw) {
31466
31466
  const handleEvent = (rawEvent, evPath) => {
31467
- listener(path18);
31468
- emitRaw(rawEvent, evPath, { watchedPath: path18 });
31469
- if (evPath && path18 !== evPath) {
31470
- fsWatchBroadcast(sp.resolve(path18, evPath), KEY_LISTENERS, sp.join(path18, evPath));
31467
+ listener(path19);
31468
+ emitRaw(rawEvent, evPath, { watchedPath: path19 });
31469
+ if (evPath && path19 !== evPath) {
31470
+ fsWatchBroadcast(sp.resolve(path19, evPath), KEY_LISTENERS, sp.join(path19, evPath));
31471
31471
  }
31472
31472
  };
31473
31473
  try {
31474
- return (0, import_node_fs.watch)(path18, {
31474
+ return (0, import_node_fs.watch)(path19, {
31475
31475
  persistent: options.persistent
31476
31476
  }, handleEvent);
31477
31477
  } catch (error) {
@@ -31487,12 +31487,12 @@ var fsWatchBroadcast = (fullPath, listenerType, val1, val2, val3) => {
31487
31487
  listener(val1, val2, val3);
31488
31488
  });
31489
31489
  };
31490
- var setFsWatchListener = (path18, fullPath, options, handlers) => {
31490
+ var setFsWatchListener = (path19, fullPath, options, handlers) => {
31491
31491
  const { listener, errHandler, rawEmitter } = handlers;
31492
31492
  let cont = FsWatchInstances.get(fullPath);
31493
31493
  let watcher;
31494
31494
  if (!options.persistent) {
31495
- watcher = createFsWatchInstance(path18, options, listener, errHandler, rawEmitter);
31495
+ watcher = createFsWatchInstance(path19, options, listener, errHandler, rawEmitter);
31496
31496
  if (!watcher)
31497
31497
  return;
31498
31498
  return watcher.close.bind(watcher);
@@ -31503,7 +31503,7 @@ var setFsWatchListener = (path18, fullPath, options, handlers) => {
31503
31503
  addAndConvert(cont, KEY_RAW, rawEmitter);
31504
31504
  } else {
31505
31505
  watcher = createFsWatchInstance(
31506
- path18,
31506
+ path19,
31507
31507
  options,
31508
31508
  fsWatchBroadcast.bind(null, fullPath, KEY_LISTENERS),
31509
31509
  errHandler,
@@ -31518,7 +31518,7 @@ var setFsWatchListener = (path18, fullPath, options, handlers) => {
31518
31518
  cont.watcherUnusable = true;
31519
31519
  if (isWindows && error.code === "EPERM") {
31520
31520
  try {
31521
- const fd = await (0, import_promises3.open)(path18, "r");
31521
+ const fd = await (0, import_promises3.open)(path19, "r");
31522
31522
  await fd.close();
31523
31523
  broadcastErr(error);
31524
31524
  } catch (err) {
@@ -31549,7 +31549,7 @@ var setFsWatchListener = (path18, fullPath, options, handlers) => {
31549
31549
  };
31550
31550
  };
31551
31551
  var FsWatchFileInstances = /* @__PURE__ */ new Map();
31552
- var setFsWatchFileListener = (path18, fullPath, options, handlers) => {
31552
+ var setFsWatchFileListener = (path19, fullPath, options, handlers) => {
31553
31553
  const { listener, rawEmitter } = handlers;
31554
31554
  let cont = FsWatchFileInstances.get(fullPath);
31555
31555
  const copts = cont && cont.options;
@@ -31571,7 +31571,7 @@ var setFsWatchFileListener = (path18, fullPath, options, handlers) => {
31571
31571
  });
31572
31572
  const currmtime = curr.mtimeMs;
31573
31573
  if (curr.size !== prev.size || currmtime > prev.mtimeMs || currmtime === 0) {
31574
- foreach(cont.listeners, (listener2) => listener2(path18, curr));
31574
+ foreach(cont.listeners, (listener2) => listener2(path19, curr));
31575
31575
  }
31576
31576
  })
31577
31577
  };
@@ -31601,13 +31601,13 @@ var NodeFsHandler = class {
31601
31601
  * @param listener on fs change
31602
31602
  * @returns closer for the watcher instance
31603
31603
  */
31604
- _watchWithNodeFs(path18, listener) {
31604
+ _watchWithNodeFs(path19, listener) {
31605
31605
  const opts = this.fsw.options;
31606
- const directory = sp.dirname(path18);
31607
- const basename4 = sp.basename(path18);
31606
+ const directory = sp.dirname(path19);
31607
+ const basename4 = sp.basename(path19);
31608
31608
  const parent = this.fsw._getWatchedDir(directory);
31609
31609
  parent.add(basename4);
31610
- const absolutePath = sp.resolve(path18);
31610
+ const absolutePath = sp.resolve(path19);
31611
31611
  const options = {
31612
31612
  persistent: opts.persistent
31613
31613
  };
@@ -31617,12 +31617,12 @@ var NodeFsHandler = class {
31617
31617
  if (opts.usePolling) {
31618
31618
  const enableBin = opts.interval !== opts.binaryInterval;
31619
31619
  options.interval = enableBin && isBinaryPath(basename4) ? opts.binaryInterval : opts.interval;
31620
- closer = setFsWatchFileListener(path18, absolutePath, options, {
31620
+ closer = setFsWatchFileListener(path19, absolutePath, options, {
31621
31621
  listener,
31622
31622
  rawEmitter: this.fsw._emitRaw
31623
31623
  });
31624
31624
  } else {
31625
- closer = setFsWatchListener(path18, absolutePath, options, {
31625
+ closer = setFsWatchListener(path19, absolutePath, options, {
31626
31626
  listener,
31627
31627
  errHandler: this._boundHandleError,
31628
31628
  rawEmitter: this.fsw._emitRaw
@@ -31644,7 +31644,7 @@ var NodeFsHandler = class {
31644
31644
  let prevStats = stats;
31645
31645
  if (parent.has(basename4))
31646
31646
  return;
31647
- const listener = async (path18, newStats) => {
31647
+ const listener = async (path19, newStats) => {
31648
31648
  if (!this.fsw._throttle(THROTTLE_MODE_WATCH, file, 5))
31649
31649
  return;
31650
31650
  if (!newStats || newStats.mtimeMs === 0) {
@@ -31658,11 +31658,11 @@ var NodeFsHandler = class {
31658
31658
  this.fsw._emit(EV.CHANGE, file, newStats2);
31659
31659
  }
31660
31660
  if ((isMacos || isLinux || isFreeBSD) && prevStats.ino !== newStats2.ino) {
31661
- this.fsw._closeFile(path18);
31661
+ this.fsw._closeFile(path19);
31662
31662
  prevStats = newStats2;
31663
31663
  const closer2 = this._watchWithNodeFs(file, listener);
31664
31664
  if (closer2)
31665
- this.fsw._addPathCloser(path18, closer2);
31665
+ this.fsw._addPathCloser(path19, closer2);
31666
31666
  } else {
31667
31667
  prevStats = newStats2;
31668
31668
  }
@@ -31694,7 +31694,7 @@ var NodeFsHandler = class {
31694
31694
  * @param item basename of this item
31695
31695
  * @returns true if no more processing is needed for this entry.
31696
31696
  */
31697
- async _handleSymlink(entry, directory, path18, item) {
31697
+ async _handleSymlink(entry, directory, path19, item) {
31698
31698
  if (this.fsw.closed) {
31699
31699
  return;
31700
31700
  }
@@ -31704,7 +31704,7 @@ var NodeFsHandler = class {
31704
31704
  this.fsw._incrReadyCount();
31705
31705
  let linkPath;
31706
31706
  try {
31707
- linkPath = await (0, import_promises3.realpath)(path18);
31707
+ linkPath = await (0, import_promises3.realpath)(path19);
31708
31708
  } catch (e) {
31709
31709
  this.fsw._emitReady();
31710
31710
  return true;
@@ -31714,12 +31714,12 @@ var NodeFsHandler = class {
31714
31714
  if (dir.has(item)) {
31715
31715
  if (this.fsw._symlinkPaths.get(full) !== linkPath) {
31716
31716
  this.fsw._symlinkPaths.set(full, linkPath);
31717
- this.fsw._emit(EV.CHANGE, path18, entry.stats);
31717
+ this.fsw._emit(EV.CHANGE, path19, entry.stats);
31718
31718
  }
31719
31719
  } else {
31720
31720
  dir.add(item);
31721
31721
  this.fsw._symlinkPaths.set(full, linkPath);
31722
- this.fsw._emit(EV.ADD, path18, entry.stats);
31722
+ this.fsw._emit(EV.ADD, path19, entry.stats);
31723
31723
  }
31724
31724
  this.fsw._emitReady();
31725
31725
  return true;
@@ -31749,9 +31749,9 @@ var NodeFsHandler = class {
31749
31749
  return;
31750
31750
  }
31751
31751
  const item = entry.path;
31752
- let path18 = sp.join(directory, item);
31752
+ let path19 = sp.join(directory, item);
31753
31753
  current.add(item);
31754
- if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path18, item)) {
31754
+ if (entry.stats.isSymbolicLink() && await this._handleSymlink(entry, directory, path19, item)) {
31755
31755
  return;
31756
31756
  }
31757
31757
  if (this.fsw.closed) {
@@ -31760,8 +31760,8 @@ var NodeFsHandler = class {
31760
31760
  }
31761
31761
  if (item === target || !target && !previous.has(item)) {
31762
31762
  this.fsw._incrReadyCount();
31763
- path18 = sp.join(dir, sp.relative(dir, path18));
31764
- this._addToNodeFs(path18, initialAdd, wh, depth + 1);
31763
+ path19 = sp.join(dir, sp.relative(dir, path19));
31764
+ this._addToNodeFs(path19, initialAdd, wh, depth + 1);
31765
31765
  }
31766
31766
  }).on(EV.ERROR, this._boundHandleError);
31767
31767
  return new Promise((resolve11, reject) => {
@@ -31830,13 +31830,13 @@ var NodeFsHandler = class {
31830
31830
  * @param depth Child path actually targeted for watch
31831
31831
  * @param target Child path actually targeted for watch
31832
31832
  */
31833
- async _addToNodeFs(path18, initialAdd, priorWh, depth, target) {
31833
+ async _addToNodeFs(path19, initialAdd, priorWh, depth, target) {
31834
31834
  const ready = this.fsw._emitReady;
31835
- if (this.fsw._isIgnored(path18) || this.fsw.closed) {
31835
+ if (this.fsw._isIgnored(path19) || this.fsw.closed) {
31836
31836
  ready();
31837
31837
  return false;
31838
31838
  }
31839
- const wh = this.fsw._getWatchHelpers(path18);
31839
+ const wh = this.fsw._getWatchHelpers(path19);
31840
31840
  if (priorWh) {
31841
31841
  wh.filterPath = (entry) => priorWh.filterPath(entry);
31842
31842
  wh.filterDir = (entry) => priorWh.filterDir(entry);
@@ -31852,8 +31852,8 @@ var NodeFsHandler = class {
31852
31852
  const follow = this.fsw.options.followSymlinks;
31853
31853
  let closer;
31854
31854
  if (stats.isDirectory()) {
31855
- const absPath = sp.resolve(path18);
31856
- const targetPath = follow ? await (0, import_promises3.realpath)(path18) : path18;
31855
+ const absPath = sp.resolve(path19);
31856
+ const targetPath = follow ? await (0, import_promises3.realpath)(path19) : path19;
31857
31857
  if (this.fsw.closed)
31858
31858
  return;
31859
31859
  closer = await this._handleDir(wh.watchPath, stats, initialAdd, depth, target, wh, targetPath);
@@ -31863,29 +31863,29 @@ var NodeFsHandler = class {
31863
31863
  this.fsw._symlinkPaths.set(absPath, targetPath);
31864
31864
  }
31865
31865
  } else if (stats.isSymbolicLink()) {
31866
- const targetPath = follow ? await (0, import_promises3.realpath)(path18) : path18;
31866
+ const targetPath = follow ? await (0, import_promises3.realpath)(path19) : path19;
31867
31867
  if (this.fsw.closed)
31868
31868
  return;
31869
31869
  const parent = sp.dirname(wh.watchPath);
31870
31870
  this.fsw._getWatchedDir(parent).add(wh.watchPath);
31871
31871
  this.fsw._emit(EV.ADD, wh.watchPath, stats);
31872
- closer = await this._handleDir(parent, stats, initialAdd, depth, path18, wh, targetPath);
31872
+ closer = await this._handleDir(parent, stats, initialAdd, depth, path19, wh, targetPath);
31873
31873
  if (this.fsw.closed)
31874
31874
  return;
31875
31875
  if (targetPath !== void 0) {
31876
- this.fsw._symlinkPaths.set(sp.resolve(path18), targetPath);
31876
+ this.fsw._symlinkPaths.set(sp.resolve(path19), targetPath);
31877
31877
  }
31878
31878
  } else {
31879
31879
  closer = this._handleFile(wh.watchPath, stats, initialAdd);
31880
31880
  }
31881
31881
  ready();
31882
31882
  if (closer)
31883
- this.fsw._addPathCloser(path18, closer);
31883
+ this.fsw._addPathCloser(path19, closer);
31884
31884
  return false;
31885
31885
  } catch (error) {
31886
31886
  if (this.fsw._handleError(error)) {
31887
31887
  ready();
31888
- return path18;
31888
+ return path19;
31889
31889
  }
31890
31890
  }
31891
31891
  }
@@ -31928,24 +31928,24 @@ function createPattern(matcher) {
31928
31928
  }
31929
31929
  return () => false;
31930
31930
  }
31931
- function normalizePath(path18) {
31932
- if (typeof path18 !== "string")
31931
+ function normalizePath(path19) {
31932
+ if (typeof path19 !== "string")
31933
31933
  throw new Error("string expected");
31934
- path18 = sp2.normalize(path18);
31935
- path18 = path18.replace(/\\/g, "/");
31934
+ path19 = sp2.normalize(path19);
31935
+ path19 = path19.replace(/\\/g, "/");
31936
31936
  let prepend = false;
31937
- if (path18.startsWith("//"))
31937
+ if (path19.startsWith("//"))
31938
31938
  prepend = true;
31939
- path18 = path18.replace(DOUBLE_SLASH_RE, "/");
31939
+ path19 = path19.replace(DOUBLE_SLASH_RE, "/");
31940
31940
  if (prepend)
31941
- path18 = "/" + path18;
31942
- return path18;
31941
+ path19 = "/" + path19;
31942
+ return path19;
31943
31943
  }
31944
31944
  function matchPatterns(patterns, testString, stats) {
31945
- const path18 = normalizePath(testString);
31945
+ const path19 = normalizePath(testString);
31946
31946
  for (let index = 0; index < patterns.length; index++) {
31947
31947
  const pattern = patterns[index];
31948
- if (pattern(path18, stats)) {
31948
+ if (pattern(path19, stats)) {
31949
31949
  return true;
31950
31950
  }
31951
31951
  }
@@ -31983,19 +31983,19 @@ var toUnix = (string) => {
31983
31983
  }
31984
31984
  return str;
31985
31985
  };
31986
- var normalizePathToUnix = (path18) => toUnix(sp2.normalize(toUnix(path18)));
31987
- var normalizeIgnored = (cwd = "") => (path18) => {
31988
- if (typeof path18 === "string") {
31989
- return normalizePathToUnix(sp2.isAbsolute(path18) ? path18 : sp2.join(cwd, path18));
31986
+ var normalizePathToUnix = (path19) => toUnix(sp2.normalize(toUnix(path19)));
31987
+ var normalizeIgnored = (cwd = "") => (path19) => {
31988
+ if (typeof path19 === "string") {
31989
+ return normalizePathToUnix(sp2.isAbsolute(path19) ? path19 : sp2.join(cwd, path19));
31990
31990
  } else {
31991
- return path18;
31991
+ return path19;
31992
31992
  }
31993
31993
  };
31994
- var getAbsolutePath = (path18, cwd) => {
31995
- if (sp2.isAbsolute(path18)) {
31996
- return path18;
31994
+ var getAbsolutePath = (path19, cwd) => {
31995
+ if (sp2.isAbsolute(path19)) {
31996
+ return path19;
31997
31997
  }
31998
- return sp2.join(cwd, path18);
31998
+ return sp2.join(cwd, path19);
31999
31999
  };
32000
32000
  var EMPTY_SET = Object.freeze(/* @__PURE__ */ new Set());
32001
32001
  var DirEntry = class {
@@ -32060,10 +32060,10 @@ var WatchHelper = class {
32060
32060
  dirParts;
32061
32061
  followSymlinks;
32062
32062
  statMethod;
32063
- constructor(path18, follow, fsw) {
32063
+ constructor(path19, follow, fsw) {
32064
32064
  this.fsw = fsw;
32065
- const watchPath = path18;
32066
- this.path = path18 = path18.replace(REPLACER_RE, "");
32065
+ const watchPath = path19;
32066
+ this.path = path19 = path19.replace(REPLACER_RE, "");
32067
32067
  this.watchPath = watchPath;
32068
32068
  this.fullWatchPath = sp2.resolve(watchPath);
32069
32069
  this.dirParts = [];
@@ -32203,20 +32203,20 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32203
32203
  this._closePromise = void 0;
32204
32204
  let paths = unifyPaths(paths_);
32205
32205
  if (cwd) {
32206
- paths = paths.map((path18) => {
32207
- const absPath = getAbsolutePath(path18, cwd);
32206
+ paths = paths.map((path19) => {
32207
+ const absPath = getAbsolutePath(path19, cwd);
32208
32208
  return absPath;
32209
32209
  });
32210
32210
  }
32211
- paths.forEach((path18) => {
32212
- this._removeIgnoredPath(path18);
32211
+ paths.forEach((path19) => {
32212
+ this._removeIgnoredPath(path19);
32213
32213
  });
32214
32214
  this._userIgnored = void 0;
32215
32215
  if (!this._readyCount)
32216
32216
  this._readyCount = 0;
32217
32217
  this._readyCount += paths.length;
32218
- Promise.all(paths.map(async (path18) => {
32219
- const res = await this._nodeFsHandler._addToNodeFs(path18, !_internal, void 0, 0, _origAdd);
32218
+ Promise.all(paths.map(async (path19) => {
32219
+ const res = await this._nodeFsHandler._addToNodeFs(path19, !_internal, void 0, 0, _origAdd);
32220
32220
  if (res)
32221
32221
  this._emitReady();
32222
32222
  return res;
@@ -32238,17 +32238,17 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32238
32238
  return this;
32239
32239
  const paths = unifyPaths(paths_);
32240
32240
  const { cwd } = this.options;
32241
- paths.forEach((path18) => {
32242
- if (!sp2.isAbsolute(path18) && !this._closers.has(path18)) {
32241
+ paths.forEach((path19) => {
32242
+ if (!sp2.isAbsolute(path19) && !this._closers.has(path19)) {
32243
32243
  if (cwd)
32244
- path18 = sp2.join(cwd, path18);
32245
- path18 = sp2.resolve(path18);
32244
+ path19 = sp2.join(cwd, path19);
32245
+ path19 = sp2.resolve(path19);
32246
32246
  }
32247
- this._closePath(path18);
32248
- this._addIgnoredPath(path18);
32249
- if (this._watched.has(path18)) {
32247
+ this._closePath(path19);
32248
+ this._addIgnoredPath(path19);
32249
+ if (this._watched.has(path19)) {
32250
32250
  this._addIgnoredPath({
32251
- path: path18,
32251
+ path: path19,
32252
32252
  recursive: true
32253
32253
  });
32254
32254
  }
@@ -32312,38 +32312,38 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32312
32312
  * @param stats arguments to be passed with event
32313
32313
  * @returns the error if defined, otherwise the value of the FSWatcher instance's `closed` flag
32314
32314
  */
32315
- async _emit(event, path18, stats) {
32315
+ async _emit(event, path19, stats) {
32316
32316
  if (this.closed)
32317
32317
  return;
32318
32318
  const opts = this.options;
32319
32319
  if (isWindows)
32320
- path18 = sp2.normalize(path18);
32320
+ path19 = sp2.normalize(path19);
32321
32321
  if (opts.cwd)
32322
- path18 = sp2.relative(opts.cwd, path18);
32323
- const args = [path18];
32322
+ path19 = sp2.relative(opts.cwd, path19);
32323
+ const args = [path19];
32324
32324
  if (stats != null)
32325
32325
  args.push(stats);
32326
32326
  const awf = opts.awaitWriteFinish;
32327
32327
  let pw;
32328
- if (awf && (pw = this._pendingWrites.get(path18))) {
32328
+ if (awf && (pw = this._pendingWrites.get(path19))) {
32329
32329
  pw.lastChange = /* @__PURE__ */ new Date();
32330
32330
  return this;
32331
32331
  }
32332
32332
  if (opts.atomic) {
32333
32333
  if (event === EVENTS.UNLINK) {
32334
- this._pendingUnlinks.set(path18, [event, ...args]);
32334
+ this._pendingUnlinks.set(path19, [event, ...args]);
32335
32335
  setTimeout(() => {
32336
- this._pendingUnlinks.forEach((entry, path19) => {
32336
+ this._pendingUnlinks.forEach((entry, path20) => {
32337
32337
  this.emit(...entry);
32338
32338
  this.emit(EVENTS.ALL, ...entry);
32339
- this._pendingUnlinks.delete(path19);
32339
+ this._pendingUnlinks.delete(path20);
32340
32340
  });
32341
32341
  }, typeof opts.atomic === "number" ? opts.atomic : 100);
32342
32342
  return this;
32343
32343
  }
32344
- if (event === EVENTS.ADD && this._pendingUnlinks.has(path18)) {
32344
+ if (event === EVENTS.ADD && this._pendingUnlinks.has(path19)) {
32345
32345
  event = EVENTS.CHANGE;
32346
- this._pendingUnlinks.delete(path18);
32346
+ this._pendingUnlinks.delete(path19);
32347
32347
  }
32348
32348
  }
32349
32349
  if (awf && (event === EVENTS.ADD || event === EVENTS.CHANGE) && this._readyEmitted) {
@@ -32361,16 +32361,16 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32361
32361
  this.emitWithAll(event, args);
32362
32362
  }
32363
32363
  };
32364
- this._awaitWriteFinish(path18, awf.stabilityThreshold, event, awfEmit);
32364
+ this._awaitWriteFinish(path19, awf.stabilityThreshold, event, awfEmit);
32365
32365
  return this;
32366
32366
  }
32367
32367
  if (event === EVENTS.CHANGE) {
32368
- const isThrottled = !this._throttle(EVENTS.CHANGE, path18, 50);
32368
+ const isThrottled = !this._throttle(EVENTS.CHANGE, path19, 50);
32369
32369
  if (isThrottled)
32370
32370
  return this;
32371
32371
  }
32372
32372
  if (opts.alwaysStat && stats === void 0 && (event === EVENTS.ADD || event === EVENTS.ADD_DIR || event === EVENTS.CHANGE)) {
32373
- const fullPath = opts.cwd ? sp2.join(opts.cwd, path18) : path18;
32373
+ const fullPath = opts.cwd ? sp2.join(opts.cwd, path19) : path19;
32374
32374
  let stats2;
32375
32375
  try {
32376
32376
  stats2 = await (0, import_promises4.stat)(fullPath);
@@ -32401,23 +32401,23 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32401
32401
  * @param timeout duration of time to suppress duplicate actions
32402
32402
  * @returns tracking object or false if action should be suppressed
32403
32403
  */
32404
- _throttle(actionType, path18, timeout) {
32404
+ _throttle(actionType, path19, timeout) {
32405
32405
  if (!this._throttled.has(actionType)) {
32406
32406
  this._throttled.set(actionType, /* @__PURE__ */ new Map());
32407
32407
  }
32408
32408
  const action = this._throttled.get(actionType);
32409
32409
  if (!action)
32410
32410
  throw new Error("invalid throttle");
32411
- const actionPath = action.get(path18);
32411
+ const actionPath = action.get(path19);
32412
32412
  if (actionPath) {
32413
32413
  actionPath.count++;
32414
32414
  return false;
32415
32415
  }
32416
32416
  let timeoutObject;
32417
32417
  const clear = () => {
32418
- const item = action.get(path18);
32418
+ const item = action.get(path19);
32419
32419
  const count = item ? item.count : 0;
32420
- action.delete(path18);
32420
+ action.delete(path19);
32421
32421
  clearTimeout(timeoutObject);
32422
32422
  if (item)
32423
32423
  clearTimeout(item.timeoutObject);
@@ -32425,7 +32425,7 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32425
32425
  };
32426
32426
  timeoutObject = setTimeout(clear, timeout);
32427
32427
  const thr = { timeoutObject, clear, count: 0 };
32428
- action.set(path18, thr);
32428
+ action.set(path19, thr);
32429
32429
  return thr;
32430
32430
  }
32431
32431
  _incrReadyCount() {
@@ -32439,44 +32439,44 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32439
32439
  * @param event
32440
32440
  * @param awfEmit Callback to be called when ready for event to be emitted.
32441
32441
  */
32442
- _awaitWriteFinish(path18, threshold, event, awfEmit) {
32442
+ _awaitWriteFinish(path19, threshold, event, awfEmit) {
32443
32443
  const awf = this.options.awaitWriteFinish;
32444
32444
  if (typeof awf !== "object")
32445
32445
  return;
32446
32446
  const pollInterval = awf.pollInterval;
32447
32447
  let timeoutHandler;
32448
- let fullPath = path18;
32449
- if (this.options.cwd && !sp2.isAbsolute(path18)) {
32450
- fullPath = sp2.join(this.options.cwd, path18);
32448
+ let fullPath = path19;
32449
+ if (this.options.cwd && !sp2.isAbsolute(path19)) {
32450
+ fullPath = sp2.join(this.options.cwd, path19);
32451
32451
  }
32452
32452
  const now = /* @__PURE__ */ new Date();
32453
32453
  const writes = this._pendingWrites;
32454
32454
  function awaitWriteFinishFn(prevStat) {
32455
32455
  (0, import_node_fs2.stat)(fullPath, (err, curStat) => {
32456
- if (err || !writes.has(path18)) {
32456
+ if (err || !writes.has(path19)) {
32457
32457
  if (err && err.code !== "ENOENT")
32458
32458
  awfEmit(err);
32459
32459
  return;
32460
32460
  }
32461
32461
  const now2 = Number(/* @__PURE__ */ new Date());
32462
32462
  if (prevStat && curStat.size !== prevStat.size) {
32463
- writes.get(path18).lastChange = now2;
32463
+ writes.get(path19).lastChange = now2;
32464
32464
  }
32465
- const pw = writes.get(path18);
32465
+ const pw = writes.get(path19);
32466
32466
  const df = now2 - pw.lastChange;
32467
32467
  if (df >= threshold) {
32468
- writes.delete(path18);
32468
+ writes.delete(path19);
32469
32469
  awfEmit(void 0, curStat);
32470
32470
  } else {
32471
32471
  timeoutHandler = setTimeout(awaitWriteFinishFn, pollInterval, curStat);
32472
32472
  }
32473
32473
  });
32474
32474
  }
32475
- if (!writes.has(path18)) {
32476
- writes.set(path18, {
32475
+ if (!writes.has(path19)) {
32476
+ writes.set(path19, {
32477
32477
  lastChange: now,
32478
32478
  cancelWait: () => {
32479
- writes.delete(path18);
32479
+ writes.delete(path19);
32480
32480
  clearTimeout(timeoutHandler);
32481
32481
  return event;
32482
32482
  }
@@ -32487,8 +32487,8 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32487
32487
  /**
32488
32488
  * Determines whether user has asked to ignore this path.
32489
32489
  */
32490
- _isIgnored(path18, stats) {
32491
- if (this.options.atomic && DOT_RE.test(path18))
32490
+ _isIgnored(path19, stats) {
32491
+ if (this.options.atomic && DOT_RE.test(path19))
32492
32492
  return true;
32493
32493
  if (!this._userIgnored) {
32494
32494
  const { cwd } = this.options;
@@ -32498,17 +32498,17 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32498
32498
  const list = [...ignoredPaths.map(normalizeIgnored(cwd)), ...ignored];
32499
32499
  this._userIgnored = anymatch(list, void 0);
32500
32500
  }
32501
- return this._userIgnored(path18, stats);
32501
+ return this._userIgnored(path19, stats);
32502
32502
  }
32503
- _isntIgnored(path18, stat10) {
32504
- return !this._isIgnored(path18, stat10);
32503
+ _isntIgnored(path19, stat10) {
32504
+ return !this._isIgnored(path19, stat10);
32505
32505
  }
32506
32506
  /**
32507
32507
  * Provides a set of common helpers and properties relating to symlink handling.
32508
32508
  * @param path file or directory pattern being watched
32509
32509
  */
32510
- _getWatchHelpers(path18) {
32511
- return new WatchHelper(path18, this.options.followSymlinks, this);
32510
+ _getWatchHelpers(path19) {
32511
+ return new WatchHelper(path19, this.options.followSymlinks, this);
32512
32512
  }
32513
32513
  // Directory helpers
32514
32514
  // -----------------
@@ -32540,63 +32540,63 @@ var FSWatcher = class extends import_node_events.EventEmitter {
32540
32540
  * @param item base path of item/directory
32541
32541
  */
32542
32542
  _remove(directory, item, isDirectory) {
32543
- const path18 = sp2.join(directory, item);
32544
- const fullPath = sp2.resolve(path18);
32545
- isDirectory = isDirectory != null ? isDirectory : this._watched.has(path18) || this._watched.has(fullPath);
32546
- if (!this._throttle("remove", path18, 100))
32543
+ const path19 = sp2.join(directory, item);
32544
+ const fullPath = sp2.resolve(path19);
32545
+ isDirectory = isDirectory != null ? isDirectory : this._watched.has(path19) || this._watched.has(fullPath);
32546
+ if (!this._throttle("remove", path19, 100))
32547
32547
  return;
32548
32548
  if (!isDirectory && this._watched.size === 1) {
32549
32549
  this.add(directory, item, true);
32550
32550
  }
32551
- const wp = this._getWatchedDir(path18);
32551
+ const wp = this._getWatchedDir(path19);
32552
32552
  const nestedDirectoryChildren = wp.getChildren();
32553
- nestedDirectoryChildren.forEach((nested) => this._remove(path18, nested));
32553
+ nestedDirectoryChildren.forEach((nested) => this._remove(path19, nested));
32554
32554
  const parent = this._getWatchedDir(directory);
32555
32555
  const wasTracked = parent.has(item);
32556
32556
  parent.remove(item);
32557
32557
  if (this._symlinkPaths.has(fullPath)) {
32558
32558
  this._symlinkPaths.delete(fullPath);
32559
32559
  }
32560
- let relPath = path18;
32560
+ let relPath = path19;
32561
32561
  if (this.options.cwd)
32562
- relPath = sp2.relative(this.options.cwd, path18);
32562
+ relPath = sp2.relative(this.options.cwd, path19);
32563
32563
  if (this.options.awaitWriteFinish && this._pendingWrites.has(relPath)) {
32564
32564
  const event = this._pendingWrites.get(relPath).cancelWait();
32565
32565
  if (event === EVENTS.ADD)
32566
32566
  return;
32567
32567
  }
32568
- this._watched.delete(path18);
32568
+ this._watched.delete(path19);
32569
32569
  this._watched.delete(fullPath);
32570
32570
  const eventName = isDirectory ? EVENTS.UNLINK_DIR : EVENTS.UNLINK;
32571
- if (wasTracked && !this._isIgnored(path18))
32572
- this._emit(eventName, path18);
32573
- this._closePath(path18);
32571
+ if (wasTracked && !this._isIgnored(path19))
32572
+ this._emit(eventName, path19);
32573
+ this._closePath(path19);
32574
32574
  }
32575
32575
  /**
32576
32576
  * Closes all watchers for a path
32577
32577
  */
32578
- _closePath(path18) {
32579
- this._closeFile(path18);
32580
- const dir = sp2.dirname(path18);
32581
- this._getWatchedDir(dir).remove(sp2.basename(path18));
32578
+ _closePath(path19) {
32579
+ this._closeFile(path19);
32580
+ const dir = sp2.dirname(path19);
32581
+ this._getWatchedDir(dir).remove(sp2.basename(path19));
32582
32582
  }
32583
32583
  /**
32584
32584
  * Closes only file-specific watchers
32585
32585
  */
32586
- _closeFile(path18) {
32587
- const closers = this._closers.get(path18);
32586
+ _closeFile(path19) {
32587
+ const closers = this._closers.get(path19);
32588
32588
  if (!closers)
32589
32589
  return;
32590
32590
  closers.forEach((closer) => closer());
32591
- this._closers.delete(path18);
32591
+ this._closers.delete(path19);
32592
32592
  }
32593
- _addPathCloser(path18, closer) {
32593
+ _addPathCloser(path19, closer) {
32594
32594
  if (!closer)
32595
32595
  return;
32596
- let list = this._closers.get(path18);
32596
+ let list = this._closers.get(path19);
32597
32597
  if (!list) {
32598
32598
  list = [];
32599
- this._closers.set(path18, list);
32599
+ this._closers.set(path19, list);
32600
32600
  }
32601
32601
  list.push(closer);
32602
32602
  }
@@ -32630,7 +32630,7 @@ var import_node_cron = __toESM(require_node_cron());
32630
32630
 
32631
32631
  // src/agent/createAgent.ts
32632
32632
  var import_node_crypto11 = require("node:crypto");
32633
- var import_node_fs6 = require("node:fs");
32633
+ var import_node_fs7 = require("node:fs");
32634
32634
 
32635
32635
  // src/background/BackgroundManager.ts
32636
32636
  var import_child_process = require("child_process");
@@ -34060,12 +34060,12 @@ function encodeURIPath(str) {
34060
34060
  return str.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
34061
34061
  }
34062
34062
  var EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
34063
- var createPathTagFunction = (pathEncoder = encodeURIPath) => function path18(statics, ...params) {
34063
+ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path19(statics, ...params) {
34064
34064
  if (statics.length === 1)
34065
34065
  return statics[0];
34066
34066
  let postPath = false;
34067
34067
  const invalidSegments = [];
34068
- const path19 = statics.reduce((previousValue, currentValue, index) => {
34068
+ const path20 = statics.reduce((previousValue, currentValue, index) => {
34069
34069
  if (/[?#]/.test(currentValue)) {
34070
34070
  postPath = true;
34071
34071
  }
@@ -34082,7 +34082,7 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path18(sta
34082
34082
  }
34083
34083
  return previousValue + currentValue + (index === params.length ? "" : encoded);
34084
34084
  }, "");
34085
- const pathOnly = path19.split(/[?#]/, 1)[0];
34085
+ const pathOnly = path20.split(/[?#]/, 1)[0];
34086
34086
  const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
34087
34087
  let match2;
34088
34088
  while ((match2 = invalidSegmentPattern.exec(pathOnly)) !== null) {
@@ -34103,10 +34103,10 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path18(sta
34103
34103
  }, "");
34104
34104
  throw new AnthropicError(`Path parameters result in path with invalid segments:
34105
34105
  ${invalidSegments.map((e) => e.error).join("\n")}
34106
- ${path19}
34106
+ ${path20}
34107
34107
  ${underline}`);
34108
34108
  }
34109
- return path19;
34109
+ return path20;
34110
34110
  };
34111
34111
  var path4 = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
34112
34112
 
@@ -37217,9 +37217,9 @@ var BaseAnthropic = class {
37217
37217
  makeStatusError(status, error, message, headers) {
37218
37218
  return APIError.generate(status, error, message, headers);
37219
37219
  }
37220
- buildURL(path18, query, defaultBaseURL) {
37220
+ buildURL(path19, query, defaultBaseURL) {
37221
37221
  const baseURL = !__classPrivateFieldGet(this, _BaseAnthropic_instances, "m", _BaseAnthropic_baseURLOverridden).call(this) && defaultBaseURL || this.baseURL;
37222
- const url = isAbsoluteURL(path18) ? new URL(path18) : new URL(baseURL + (baseURL.endsWith("/") && path18.startsWith("/") ? path18.slice(1) : path18));
37222
+ const url = isAbsoluteURL(path19) ? new URL(path19) : new URL(baseURL + (baseURL.endsWith("/") && path19.startsWith("/") ? path19.slice(1) : path19));
37223
37223
  const defaultQuery = this.defaultQuery();
37224
37224
  if (!isEmptyObj(defaultQuery)) {
37225
37225
  query = { ...defaultQuery, ...query };
@@ -37250,24 +37250,24 @@ var BaseAnthropic = class {
37250
37250
  */
37251
37251
  async prepareRequest(request, { url, options }) {
37252
37252
  }
37253
- get(path18, opts) {
37254
- return this.methodRequest("get", path18, opts);
37253
+ get(path19, opts) {
37254
+ return this.methodRequest("get", path19, opts);
37255
37255
  }
37256
- post(path18, opts) {
37257
- return this.methodRequest("post", path18, opts);
37256
+ post(path19, opts) {
37257
+ return this.methodRequest("post", path19, opts);
37258
37258
  }
37259
- patch(path18, opts) {
37260
- return this.methodRequest("patch", path18, opts);
37259
+ patch(path19, opts) {
37260
+ return this.methodRequest("patch", path19, opts);
37261
37261
  }
37262
- put(path18, opts) {
37263
- return this.methodRequest("put", path18, opts);
37262
+ put(path19, opts) {
37263
+ return this.methodRequest("put", path19, opts);
37264
37264
  }
37265
- delete(path18, opts) {
37266
- return this.methodRequest("delete", path18, opts);
37265
+ delete(path19, opts) {
37266
+ return this.methodRequest("delete", path19, opts);
37267
37267
  }
37268
- methodRequest(method, path18, opts) {
37268
+ methodRequest(method, path19, opts) {
37269
37269
  return this.request(Promise.resolve(opts).then((opts2) => {
37270
- return { method, path: path18, ...opts2 };
37270
+ return { method, path: path19, ...opts2 };
37271
37271
  }));
37272
37272
  }
37273
37273
  request(options, remainingRetries = null) {
@@ -37371,8 +37371,8 @@ var BaseAnthropic = class {
37371
37371
  }));
37372
37372
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime: startTime2 };
37373
37373
  }
37374
- getAPIList(path18, Page2, opts) {
37375
- return this.requestAPIList(Page2, opts && "then" in opts ? opts.then((opts2) => ({ method: "get", path: path18, ...opts2 })) : { method: "get", path: path18, ...opts });
37374
+ getAPIList(path19, Page2, opts) {
37375
+ return this.requestAPIList(Page2, opts && "then" in opts ? opts.then((opts2) => ({ method: "get", path: path19, ...opts2 })) : { method: "get", path: path19, ...opts });
37376
37376
  }
37377
37377
  requestAPIList(Page2, options) {
37378
37378
  const request = this.makeRequest(options, null, void 0);
@@ -37460,8 +37460,8 @@ var BaseAnthropic = class {
37460
37460
  }
37461
37461
  async buildRequest(inputOptions, { retryCount = 0 } = {}) {
37462
37462
  const options = { ...inputOptions };
37463
- const { method, path: path18, query, defaultBaseURL } = options;
37464
- const url = this.buildURL(path18, query, defaultBaseURL);
37463
+ const { method, path: path19, query, defaultBaseURL } = options;
37464
+ const url = this.buildURL(path19, query, defaultBaseURL);
37465
37465
  if ("timeout" in options)
37466
37466
  validatePositiveInteger("timeout", options.timeout);
37467
37467
  options.timeout = options.timeout ?? this.timeout;
@@ -38248,6 +38248,38 @@ var clearMessages = async (storage, userId, date, cronTitle) => {
38248
38248
  await storage.del(key);
38249
38249
  };
38250
38250
 
38251
+ // src/runtime/activity.ts
38252
+ async function reportRuntimeActivity(input) {
38253
+ const baseUrl = process.env.DUCLAW_CONTROL_PLANE_BASE_URL?.replace(/\/$/, "");
38254
+ const token = process.env.DUCLAW_CONTROL_PLANE_METERING_TOKEN;
38255
+ const tenantId = process.env.DUCLAW_TENANT_ID;
38256
+ if (!baseUrl || !token || !tenantId) return;
38257
+ try {
38258
+ const response = await fetch(`${baseUrl}/internal/runtime/activity`, {
38259
+ method: "POST",
38260
+ signal: AbortSignal.timeout(2500),
38261
+ headers: {
38262
+ authorization: `Bearer ${token}`,
38263
+ "content-type": "application/json"
38264
+ },
38265
+ body: JSON.stringify({
38266
+ tenantId,
38267
+ kind: input.kind,
38268
+ status: input.status,
38269
+ toolName: input.toolName,
38270
+ toolCallId: input.toolCallId ?? null,
38271
+ occurredAt: (/* @__PURE__ */ new Date()).toISOString(),
38272
+ metadata: input.metadata ?? {}
38273
+ })
38274
+ });
38275
+ if (!response.ok) {
38276
+ console.warn(`[runtime-activity] \u4E0A\u62A5\u5931\u8D25: tool=${input.toolName} status=${input.status} http=${response.status}`);
38277
+ }
38278
+ } catch (err) {
38279
+ console.warn(`[runtime-activity] \u4E0A\u62A5\u5F02\u5E38: tool=${input.toolName} status=${input.status} error=${err.message}`);
38280
+ }
38281
+ }
38282
+
38251
38283
  // src/tools/ToolExecutor.ts
38252
38284
  var createToolExecutor = (registry2) => {
38253
38285
  return {
@@ -38260,10 +38292,46 @@ var createToolExecutor = (registry2) => {
38260
38292
  throw new Error(`[ToolExecutor] \u5DE5\u5177 ${name} \u7F3A\u5C11\u5FC5\u586B\u53C2\u6570: ${key}`);
38261
38293
  }
38262
38294
  }
38295
+ const toolCallId = typeof userRequest?.metadata?.toolCallId === "string" ? userRequest.metadata.toolCallId : null;
38296
+ await reportRuntimeActivity({
38297
+ kind: "tool_use",
38298
+ toolName: name,
38299
+ status: "started",
38300
+ toolCallId,
38301
+ metadata: {
38302
+ platform: userRequest?.platform,
38303
+ requestId: userRequest?.requestId,
38304
+ departmentAgentId: userRequest?.departmentAgentId
38305
+ }
38306
+ });
38263
38307
  try {
38264
- return await tool.execute(input ?? {}, userRequest);
38308
+ const result = await tool.execute(input ?? {}, userRequest);
38309
+ await reportRuntimeActivity({
38310
+ kind: "tool_use",
38311
+ toolName: name,
38312
+ status: "completed",
38313
+ toolCallId,
38314
+ metadata: {
38315
+ platform: userRequest?.platform,
38316
+ requestId: userRequest?.requestId,
38317
+ departmentAgentId: userRequest?.departmentAgentId
38318
+ }
38319
+ });
38320
+ return result;
38265
38321
  } catch (error) {
38266
38322
  const err = error;
38323
+ await reportRuntimeActivity({
38324
+ kind: "tool_use",
38325
+ toolName: name,
38326
+ status: "failed",
38327
+ toolCallId,
38328
+ metadata: {
38329
+ platform: userRequest?.platform,
38330
+ requestId: userRequest?.requestId,
38331
+ departmentAgentId: userRequest?.departmentAgentId,
38332
+ error: err.message
38333
+ }
38334
+ });
38267
38335
  return `\u5DE5\u5177\u6267\u884C\u5931\u8D25 [${name}], reason: ${err.message}`;
38268
38336
  }
38269
38337
  },
@@ -39495,16 +39563,16 @@ var Diff = class {
39495
39563
  }
39496
39564
  }
39497
39565
  }
39498
- addToPath(path18, added, removed, oldPosInc, options) {
39499
- const last = path18.lastComponent;
39566
+ addToPath(path19, added, removed, oldPosInc, options) {
39567
+ const last = path19.lastComponent;
39500
39568
  if (last && !options.oneChangePerToken && last.added === added && last.removed === removed) {
39501
39569
  return {
39502
- oldPos: path18.oldPos + oldPosInc,
39570
+ oldPos: path19.oldPos + oldPosInc,
39503
39571
  lastComponent: { count: last.count + 1, added, removed, previousComponent: last.previousComponent }
39504
39572
  };
39505
39573
  } else {
39506
39574
  return {
39507
- oldPos: path18.oldPos + oldPosInc,
39575
+ oldPos: path19.oldPos + oldPosInc,
39508
39576
  lastComponent: { count: 1, added, removed, previousComponent: last }
39509
39577
  };
39510
39578
  }
@@ -42433,29 +42501,231 @@ ${replies}`;
42433
42501
  };
42434
42502
 
42435
42503
  // src/department/learning.ts
42504
+ var import_node_fs4 = require("node:fs");
42505
+ var import_node_path12 = __toESM(require("node:path"));
42506
+ var import_node_crypto6 = require("node:crypto");
42507
+
42508
+ // src/skill/SkillValidator.ts
42436
42509
  var import_node_fs3 = require("node:fs");
42437
42510
  var import_node_path11 = __toESM(require("node:path"));
42438
- var import_node_crypto6 = require("node:crypto");
42439
- var ensureDir = (dir) => (0, import_node_fs3.mkdirSync)(dir, { recursive: true });
42511
+ var SKILL_NAME_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
42512
+ var REQUIRED_SECTIONS = [
42513
+ /(^|\n)##\s+(when to use|何时使用|trigger|triggers)\b/i,
42514
+ /(^|\n)##\s+(steps|workflow|procedure|执行步骤|工作流)\b/i
42515
+ ];
42516
+ var stripYamlQuotes = (value) => {
42517
+ const trimmed = value.trim();
42518
+ if (trimmed.startsWith(`"`) && trimmed.endsWith(`"`) || trimmed.startsWith(`'`) && trimmed.endsWith(`'`)) {
42519
+ return trimmed.slice(1, -1).trim();
42520
+ }
42521
+ return trimmed;
42522
+ };
42523
+ var addError = (errors, code, message) => {
42524
+ errors.push({ code, message });
42525
+ };
42526
+ var addWarning = (warnings, code, message) => {
42527
+ warnings.push({ code, message });
42528
+ };
42529
+ var isValidSkillName = (name) => {
42530
+ return SKILL_NAME_PATTERN.test(name) && !name.includes(`--`);
42531
+ };
42532
+ var assertSafeSkillTarget = (rootDir, skillName) => {
42533
+ if (!isValidSkillName(skillName)) {
42534
+ throw new Error(`Invalid skill name "${skillName}". Use lowercase letters, digits, and single hyphens only.`);
42535
+ }
42536
+ const root = import_node_path11.default.resolve(rootDir);
42537
+ const target = import_node_path11.default.resolve(root, skillName);
42538
+ if (target !== import_node_path11.default.join(root, skillName) || !target.startsWith(root + import_node_path11.default.sep)) {
42539
+ throw new Error(`Invalid skill install target for "${skillName}".`);
42540
+ }
42541
+ return target;
42542
+ };
42543
+ var parseSkillDocument = (skillMd) => {
42544
+ const fmMatch = skillMd.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
42545
+ if (!fmMatch) return null;
42546
+ const frontmatter = {};
42547
+ for (const rawLine of fmMatch[1].split(/\r?\n/)) {
42548
+ const line = rawLine.trim();
42549
+ if (!line || line.startsWith(`#`)) continue;
42550
+ const match2 = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
42551
+ if (!match2) {
42552
+ frontmatter[`__invalid__${Object.keys(frontmatter).length}`] = line;
42553
+ continue;
42554
+ }
42555
+ frontmatter[match2[1]] = stripYamlQuotes(match2[2]);
42556
+ }
42557
+ return {
42558
+ name: frontmatter.name ?? ``,
42559
+ description: frontmatter.description ?? ``,
42560
+ body: skillMd.slice(fmMatch[0].length).trim(),
42561
+ frontmatter
42562
+ };
42563
+ };
42564
+ var validateSkillDocument = (input) => {
42565
+ const errors = [];
42566
+ const warnings = [];
42567
+ const skillMd = input.skillMd;
42568
+ if (!skillMd || !skillMd.trim()) {
42569
+ addError(errors, `empty_skill_md`, `SKILL.md content is required.`);
42570
+ return { ok: false, errors, warnings };
42571
+ }
42572
+ const parsed = parseSkillDocument(skillMd);
42573
+ if (!parsed) {
42574
+ addError(errors, `missing_frontmatter`, `SKILL.md must start with YAML frontmatter delimited by "---".`);
42575
+ return { ok: false, errors, warnings };
42576
+ }
42577
+ const invalidFrontmatterLines = Object.keys(parsed.frontmatter).filter((key) => key.startsWith(`__invalid__`));
42578
+ if (invalidFrontmatterLines.length > 0) {
42579
+ addError(errors, `invalid_frontmatter`, `Frontmatter must contain simple "key: value" lines.`);
42580
+ }
42581
+ if (!parsed.name) {
42582
+ addError(errors, `missing_name`, `Frontmatter field "name" is required.`);
42583
+ } else if (!isValidSkillName(parsed.name)) {
42584
+ addError(errors, `invalid_name`, `Skill name "${parsed.name}" must be kebab-case, under 64 characters, and path-safe.`);
42585
+ }
42586
+ if (!parsed.description) {
42587
+ addError(errors, `missing_description`, `Frontmatter field "description" is required.`);
42588
+ } else if (parsed.description.length > 500) {
42589
+ addWarning(warnings, `long_description`, `Skill description is long; keep trigger metadata concise.`);
42590
+ }
42591
+ if (input.skillName && parsed.name && input.skillName !== parsed.name) {
42592
+ addError(errors, `name_mismatch`, `Input skillName "${input.skillName}" must match frontmatter name "${parsed.name}".`);
42593
+ }
42594
+ if (input.description && parsed.description && input.description !== parsed.description) {
42595
+ addError(errors, `description_mismatch`, `Input description must match frontmatter description.`);
42596
+ }
42597
+ if (!parsed.body) {
42598
+ addError(errors, `empty_body`, `SKILL.md body is required.`);
42599
+ } else {
42600
+ if (!/(^|\n)#\s+\S/.test(parsed.body)) {
42601
+ addWarning(warnings, `missing_title`, `Skill body should start with a Markdown H1 title.`);
42602
+ }
42603
+ for (const sectionPattern of REQUIRED_SECTIONS) {
42604
+ if (!sectionPattern.test(parsed.body)) {
42605
+ addWarning(warnings, `missing_recommended_section`, `Skill body should include when-to-use and execution workflow sections.`);
42606
+ break;
42607
+ }
42608
+ }
42609
+ }
42610
+ if (input.baseDir) {
42611
+ const normalizedBase = import_node_path11.default.resolve(input.baseDir);
42612
+ for (const match2 of parsed.body.matchAll(/\]\(([^)]+)\)/g)) {
42613
+ const href = match2[1].trim();
42614
+ if (!href || /^[a-z][a-z0-9+.-]*:/i.test(href) || href.startsWith(`#`)) continue;
42615
+ const target = import_node_path11.default.resolve(normalizedBase, href.split(`#`)[0]);
42616
+ if (!target.startsWith(normalizedBase + import_node_path11.default.sep) && target !== normalizedBase) {
42617
+ addError(errors, `unsafe_reference`, `Relative link "${href}" escapes the skill directory.`);
42618
+ } else if (!(0, import_node_fs3.existsSync)(target)) {
42619
+ addError(errors, `missing_reference`, `Relative link "${href}" does not exist in the skill directory.`);
42620
+ }
42621
+ }
42622
+ }
42623
+ return {
42624
+ ok: errors.length === 0,
42625
+ skill: parsed,
42626
+ errors,
42627
+ warnings
42628
+ };
42629
+ };
42630
+ var mergeIssues = (target, source) => {
42631
+ target.errors.push(...source.errors);
42632
+ target.warnings.push(...source.warnings);
42633
+ };
42634
+ var validateScriptsDirectory = (skillDir, warnings) => {
42635
+ const scriptsDir = import_node_path11.default.join(skillDir, `scripts`);
42636
+ if (!(0, import_node_fs3.existsSync)(scriptsDir)) return;
42637
+ const entries = (0, import_node_fs3.readdirSync)(scriptsDir, { withFileTypes: true }).filter((entry) => entry.isFile());
42638
+ if (entries.length === 0) {
42639
+ addWarning(warnings, `empty_scripts_dir`, `scripts/ exists but contains no files.`);
42640
+ }
42641
+ };
42642
+ var validateSkillDirectory = (skillDir, options = {}) => {
42643
+ const errors = [];
42644
+ const warnings = [];
42645
+ const normalizedSkillDir = import_node_path11.default.resolve(skillDir);
42646
+ const skillMdPath = import_node_path11.default.join(normalizedSkillDir, `SKILL.md`);
42647
+ if (!(0, import_node_fs3.existsSync)(normalizedSkillDir) || !(0, import_node_fs3.statSync)(normalizedSkillDir).isDirectory()) {
42648
+ addError(errors, `missing_skill_dir`, `Skill directory does not exist: ${normalizedSkillDir}`);
42649
+ return { ok: false, errors, warnings, skillDir: normalizedSkillDir, skillMdPath };
42650
+ }
42651
+ if (!(0, import_node_fs3.existsSync)(skillMdPath) || !(0, import_node_fs3.statSync)(skillMdPath).isFile()) {
42652
+ addError(errors, `missing_skill_md`, `Skill directory must contain SKILL.md.`);
42653
+ return { ok: false, errors, warnings, skillDir: normalizedSkillDir, skillMdPath };
42654
+ }
42655
+ const raw2 = (0, import_node_fs3.readFileSync)(skillMdPath, `utf-8`);
42656
+ const documentResult = validateSkillDocument({
42657
+ skillName: options.expectedName ?? import_node_path11.default.basename(normalizedSkillDir),
42658
+ skillMd: raw2,
42659
+ baseDir: normalizedSkillDir
42660
+ });
42661
+ mergeIssues({ errors, warnings }, documentResult);
42662
+ validateScriptsDirectory(normalizedSkillDir, warnings);
42663
+ return {
42664
+ ok: errors.length === 0,
42665
+ skill: documentResult.skill,
42666
+ errors,
42667
+ warnings,
42668
+ skillDir: normalizedSkillDir,
42669
+ skillMdPath
42670
+ };
42671
+ };
42672
+ var smokeTestSkillDirectory = (skillDir, options = {}) => {
42673
+ const directoryResult = validateSkillDirectory(skillDir, options);
42674
+ const errors = [...directoryResult.errors];
42675
+ const warnings = [...directoryResult.warnings];
42676
+ let detail;
42677
+ if (directoryResult.ok && directoryResult.skill) {
42678
+ detail = `Base directory for this skill: ${directoryResult.skillDir}
42679
+
42680
+ ${directoryResult.skill.body}`;
42681
+ if (!detail.includes(directoryResult.skillDir)) {
42682
+ addError(errors, `smoke_missing_base_dir`, `Skill detail does not include its base directory.`);
42683
+ }
42684
+ if (!detail.includes(directoryResult.skill.body)) {
42685
+ addError(errors, `smoke_missing_body`, `Skill detail does not include the SKILL.md body.`);
42686
+ }
42687
+ if (detail.length < 80) {
42688
+ addWarning(warnings, `smoke_short_detail`, `Skill detail is unusually short.`);
42689
+ }
42690
+ }
42691
+ return {
42692
+ ...directoryResult,
42693
+ ok: errors.length === 0,
42694
+ errors,
42695
+ warnings,
42696
+ detail
42697
+ };
42698
+ };
42699
+ var formatSkillValidationIssues = (result) => {
42700
+ const lines = [
42701
+ ...result.errors.map((issue) => `- [${issue.code}] ${issue.message}`),
42702
+ ...result.warnings.map((issue) => `- [warning:${issue.code}] ${issue.message}`)
42703
+ ];
42704
+ return lines.join(`
42705
+ `);
42706
+ };
42707
+
42708
+ // src/department/learning.ts
42709
+ var ensureDir = (dir) => (0, import_node_fs4.mkdirSync)(dir, { recursive: true });
42440
42710
  var readJsonArray = (filePath) => {
42441
- if (!(0, import_node_fs3.existsSync)(filePath)) return [];
42442
- return JSON.parse((0, import_node_fs3.readFileSync)(filePath, "utf-8"));
42711
+ if (!(0, import_node_fs4.existsSync)(filePath)) return [];
42712
+ return JSON.parse((0, import_node_fs4.readFileSync)(filePath, "utf-8"));
42443
42713
  };
42444
42714
  var writeJsonArray = (filePath, records) => {
42445
- ensureDir(import_node_path11.default.dirname(filePath));
42446
- (0, import_node_fs3.writeFileSync)(filePath, JSON.stringify(records, null, " "), "utf-8");
42715
+ ensureDir(import_node_path12.default.dirname(filePath));
42716
+ (0, import_node_fs4.writeFileSync)(filePath, JSON.stringify(records, null, " "), "utf-8");
42447
42717
  };
42448
42718
  var departmentMemoryPath = (departmentName) => {
42449
- return import_node_path11.default.join(getDepartmentWorkSpaceDir(departmentName), "department-memory.json");
42719
+ return import_node_path12.default.join(getDepartmentWorkSpaceDir(departmentName), "department-memory.json");
42450
42720
  };
42451
42721
  var departmentSkillPath = (departmentName) => {
42452
- return import_node_path11.default.join(getDepartmentWorkSpaceDir(departmentName), "department-skills.json");
42722
+ return import_node_path12.default.join(getDepartmentWorkSpaceDir(departmentName), "department-skills.json");
42453
42723
  };
42454
42724
  var departmentSkillDir = (departmentName, skillName) => {
42455
- return import_node_path11.default.join(getDepartmentWorkSpaceDir(departmentName), "skills", skillName);
42725
+ return assertSafeSkillTarget(import_node_path12.default.join(getDepartmentWorkSpaceDir(departmentName), "skills"), skillName);
42456
42726
  };
42457
42727
  var proposalsPath = () => {
42458
- return import_node_path11.default.join(getDepartmentBaseDir(), "department-proposals.json");
42728
+ return import_node_path12.default.join(getDepartmentBaseDir(), "department-proposals.json");
42459
42729
  };
42460
42730
  var getDepartmentNameForHead = (request) => {
42461
42731
  const mailboxId = request?.departmentAgentId;
@@ -42507,6 +42777,15 @@ var listDepartmentSkills = (departmentName) => {
42507
42777
  return readJsonArray(departmentSkillPath(departmentName)).sort((a, b) => b.updatedAt - a.updatedAt);
42508
42778
  };
42509
42779
  var proposeDepartmentSkill = (departmentName, input) => {
42780
+ const validation = validateSkillDocument({
42781
+ skillName: input.skillName,
42782
+ description: input.description,
42783
+ skillMd: input.skillMd
42784
+ });
42785
+ if (!validation.ok) {
42786
+ throw new Error(`[departmentSkill] Skill \u8349\u7A3F\u6821\u9A8C\u5931\u8D25\uFF1A
42787
+ ${formatSkillValidationIssues(validation)}`);
42788
+ }
42510
42789
  const records = listDepartmentSkills(departmentName);
42511
42790
  if (records.some((record) => record.skillName === input.skillName && record.status !== "dropped")) {
42512
42791
  return null;
@@ -42533,8 +42812,23 @@ var keepDepartmentSkill = (departmentName, id) => {
42533
42812
  if (idx < 0) return null;
42534
42813
  records[idx] = { ...records[idx], status: "active", updatedAt: Date.now() };
42535
42814
  const skillDir = departmentSkillDir(departmentName, records[idx].skillName);
42815
+ const validation = validateSkillDocument({
42816
+ skillName: records[idx].skillName,
42817
+ description: records[idx].description,
42818
+ skillMd: records[idx].skillMd,
42819
+ baseDir: skillDir
42820
+ });
42821
+ if (!validation.ok) {
42822
+ throw new Error(`[departmentSkill] Skill \u8349\u7A3F\u6821\u9A8C\u5931\u8D25\uFF0C\u62D2\u7EDD\u4FDD\u7559\uFF1A
42823
+ ${formatSkillValidationIssues(validation)}`);
42824
+ }
42536
42825
  ensureDir(skillDir);
42537
- (0, import_node_fs3.writeFileSync)(import_node_path11.default.join(skillDir, "SKILL.md"), records[idx].skillMd, "utf-8");
42826
+ (0, import_node_fs4.writeFileSync)(import_node_path12.default.join(skillDir, "SKILL.md"), records[idx].skillMd, "utf-8");
42827
+ const smokeTest = smokeTestSkillDirectory(skillDir, { expectedName: records[idx].skillName });
42828
+ if (!smokeTest.ok) {
42829
+ throw new Error(`[departmentSkill] Skill smoke test \u5931\u8D25\uFF1A
42830
+ ${formatSkillValidationIssues(smokeTest)}`);
42831
+ }
42538
42832
  writeJsonArray(departmentSkillPath(departmentName), records);
42539
42833
  return records[idx];
42540
42834
  };
@@ -42695,14 +42989,18 @@ var departmentSkillPropose = {
42695
42989
  async execute(input, userRequest) {
42696
42990
  const departmentName = requireDepartmentHead(userRequest);
42697
42991
  if (!departmentName) return `[departmentSkillPropose] \u53EA\u6709 Department Head \u53EF\u4EE5\u63D0\u4EA4\u90E8\u95E8 Skill \u8349\u7A3F`;
42698
- const skill = proposeDepartmentSkill(departmentName, {
42699
- skillName: input.skillName,
42700
- description: input.description,
42701
- skillMd: input.skillMd,
42702
- createdByMailboxId: userRequest?.departmentAgentId
42703
- });
42704
- if (!skill) return `[departmentSkillPropose] \u540C\u540D\u90E8\u95E8 Skill \u5DF2\u5B58\u5728\u6216\u5F85\u786E\u8BA4: ${input.skillName}`;
42705
- return `[departmentSkillPropose] \u5DF2\u63D0\u4EA4\u90E8\u95E8 Skill \u8349\u7A3F: ${JSON.stringify(skill)}`;
42992
+ try {
42993
+ const skill = proposeDepartmentSkill(departmentName, {
42994
+ skillName: input.skillName,
42995
+ description: input.description,
42996
+ skillMd: input.skillMd,
42997
+ createdByMailboxId: userRequest?.departmentAgentId
42998
+ });
42999
+ if (!skill) return `[departmentSkillPropose] \u540C\u540D\u90E8\u95E8 Skill \u5DF2\u5B58\u5728\u6216\u5F85\u786E\u8BA4: ${input.skillName}`;
43000
+ return `[departmentSkillPropose] \u5DF2\u63D0\u4EA4\u90E8\u95E8 Skill \u8349\u7A3F: ${JSON.stringify(skill)}`;
43001
+ } catch (err) {
43002
+ return `[departmentSkillPropose] ${err.message}`;
43003
+ }
42706
43004
  }
42707
43005
  };
42708
43006
  var departmentSkillKeep = {
@@ -42718,9 +43016,13 @@ var departmentSkillKeep = {
42718
43016
  async execute(input, userRequest) {
42719
43017
  const departmentName = requireDepartmentHead(userRequest);
42720
43018
  if (!departmentName) return `[departmentSkillKeep] \u53EA\u6709 Department Head \u53EF\u4EE5\u4FDD\u7559\u90E8\u95E8 Skill`;
42721
- const skill = keepDepartmentSkill(departmentName, input.id);
42722
- if (!skill) return `[departmentSkillKeep] \u672A\u627E\u5230\u90E8\u95E8 Skill: ${input.id}`;
42723
- return `[departmentSkillKeep] \u5DF2\u4FDD\u7559\u90E8\u95E8 Skill: ${JSON.stringify(skill)}`;
43019
+ try {
43020
+ const skill = keepDepartmentSkill(departmentName, input.id);
43021
+ if (!skill) return `[departmentSkillKeep] \u672A\u627E\u5230\u90E8\u95E8 Skill: ${input.id}`;
43022
+ return `[departmentSkillKeep] \u5DF2\u4FDD\u7559\u90E8\u95E8 Skill: ${JSON.stringify(skill)}`;
43023
+ } catch (err) {
43024
+ return `[departmentSkillKeep] ${err.message}`;
43025
+ }
42724
43026
  }
42725
43027
  };
42726
43028
  var departmentSkillDrop = {
@@ -42874,7 +43176,7 @@ var mailboxFollowup = {
42874
43176
  // src/tools/tools/Bash.ts
42875
43177
  var import_node_child_process = require("node:child_process");
42876
43178
  var import_node_crypto7 = require("node:crypto");
42877
- var import_node_fs4 = require("node:fs");
43179
+ var import_node_fs5 = require("node:fs");
42878
43180
  var DESCRIPTION29 = `\u5728\u7CFB\u7EDF shell \u4E2D\u6267\u884C\u547D\u4EE4\u3002
42879
43181
 
42880
43182
  \u7528\u9014\uFF1A
@@ -42910,7 +43212,7 @@ var sessions = /* @__PURE__ */ new Map();
42910
43212
  function findExecutableShell2() {
42911
43213
  for (const shell of SHELL_CANDIDATES2) {
42912
43214
  try {
42913
- (0, import_node_fs4.accessSync)(shell, import_node_fs4.constants.X_OK);
43215
+ (0, import_node_fs5.accessSync)(shell, import_node_fs5.constants.X_OK);
42914
43216
  return shell;
42915
43217
  } catch {
42916
43218
  }
@@ -42919,11 +43221,11 @@ function findExecutableShell2() {
42919
43221
  }
42920
43222
  function validateCwd(cwd) {
42921
43223
  try {
42922
- const stat10 = (0, import_node_fs4.statSync)(cwd);
43224
+ const stat10 = (0, import_node_fs5.statSync)(cwd);
42923
43225
  if (!stat10.isDirectory()) {
42924
43226
  return `[bash] \u9519\u8BEF: cwd \u4E0D\u662F\u76EE\u5F55: ${cwd}`;
42925
43227
  }
42926
- (0, import_node_fs4.accessSync)(cwd, import_node_fs4.constants.R_OK | import_node_fs4.constants.X_OK);
43228
+ (0, import_node_fs5.accessSync)(cwd, import_node_fs5.constants.R_OK | import_node_fs5.constants.X_OK);
42927
43229
  return null;
42928
43230
  } catch (err) {
42929
43231
  const code = err.code;
@@ -43688,9 +43990,9 @@ var readDreamHistoryLimit = () => {
43688
43990
  };
43689
43991
 
43690
43992
  // src/skillForge/SkillForgeEngine.ts
43691
- var import_node_fs5 = require("node:fs");
43993
+ var import_node_fs6 = require("node:fs");
43692
43994
  var import_node_os2 = require("node:os");
43693
- var import_node_path12 = require("node:path");
43995
+ var import_node_path13 = require("node:path");
43694
43996
  var import_node_crypto8 = require("node:crypto");
43695
43997
  var SkillForgeEngine = class {
43696
43998
  proposalStorage;
@@ -43699,8 +44001,8 @@ var SkillForgeEngine = class {
43699
44001
  constructor(deps) {
43700
44002
  this.proposalStorage = deps.proposalStorage;
43701
44003
  const opt = deps.options ?? {};
43702
- this.draftRoot = opt.draftRoot ?? (0, import_node_path12.join)((0, import_node_os2.homedir)(), ".duclaw", "skill-proposals");
43703
- this.skillsInstallDir = opt.skillsInstallDir ?? (0, import_node_path12.join)((0, import_node_os2.homedir)(), ".agents", "skills");
44004
+ this.draftRoot = opt.draftRoot ?? (0, import_node_path13.join)((0, import_node_os2.homedir)(), ".duclaw", "skill-proposals");
44005
+ this.skillsInstallDir = opt.skillsInstallDir ?? (0, import_node_path13.join)((0, import_node_os2.homedir)(), ".agents", "skills");
43704
44006
  }
43705
44007
  // ---------- 公开方法 ----------
43706
44008
  /**
@@ -43712,6 +44014,11 @@ var SkillForgeEngine = class {
43712
44014
  if (!skillName || !description || !skillMd) {
43713
44015
  throw new Error(`[skillForge] propose \u53C2\u6570\u4E0D\u5B8C\u6574\uFF1AskillName/description/skillMd \u5747\u5FC5\u586B`);
43714
44016
  }
44017
+ const validation = validateSkillDocument({ skillName, description, skillMd });
44018
+ if (!validation.ok) {
44019
+ throw new Error(`[skillForge] Skill \u8349\u7A3F\u6821\u9A8C\u5931\u8D25\uFF1A
44020
+ ${formatSkillValidationIssues(validation)}`);
44021
+ }
43715
44022
  const existingSkills = SkillRegistry_default();
43716
44023
  if (existingSkills.some((s) => s.name === skillName)) {
43717
44024
  return null;
@@ -43721,9 +44028,18 @@ var SkillForgeEngine = class {
43721
44028
  return null;
43722
44029
  }
43723
44030
  const id = (0, import_node_crypto8.randomBytes)(4).toString("hex");
43724
- const draftDir = (0, import_node_path12.join)(this.draftRoot, userId, id);
43725
- (0, import_node_fs5.mkdirSync)(draftDir, { recursive: true });
43726
- (0, import_node_fs5.writeFileSync)((0, import_node_path12.join)(draftDir, "SKILL.md"), skillMd, "utf-8");
44031
+ const draftDir = (0, import_node_path13.join)(this.draftRoot, userId, id);
44032
+ (0, import_node_fs6.mkdirSync)(draftDir, { recursive: true });
44033
+ (0, import_node_fs6.writeFileSync)((0, import_node_path13.join)(draftDir, "SKILL.md"), skillMd, "utf-8");
44034
+ const directoryValidation = validateSkillDirectory(draftDir, { expectedName: skillName });
44035
+ if (!directoryValidation.ok) {
44036
+ try {
44037
+ (0, import_node_fs6.rmSync)(draftDir, { recursive: true, force: true });
44038
+ } catch {
44039
+ }
44040
+ throw new Error(`[skillForge] Skill \u76EE\u5F55\u6821\u9A8C\u5931\u8D25\uFF1A
44041
+ ${formatSkillValidationIssues(directoryValidation)}`);
44042
+ }
43727
44043
  const proposal = {
43728
44044
  id,
43729
44045
  userId,
@@ -43741,17 +44057,38 @@ var SkillForgeEngine = class {
43741
44057
  const list = await this.proposalStorage.get(this.proposalKey(userId)) ?? [];
43742
44058
  const proposal = list.find((p) => p.id === proposalId);
43743
44059
  if (!proposal) return null;
43744
- const target = (0, import_node_path12.join)(this.skillsInstallDir, proposal.skillName);
43745
- if ((0, import_node_fs5.existsSync)(target)) {
44060
+ const validation = validateSkillDocument({
44061
+ skillName: proposal.skillName,
44062
+ description: proposal.description,
44063
+ skillMd: proposal.skillMd,
44064
+ baseDir: proposal.draftDir
44065
+ });
44066
+ if (!validation.ok) {
44067
+ throw new Error(`[skillForge] Skill \u8349\u7A3F\u6821\u9A8C\u5931\u8D25\uFF0C\u62D2\u7EDD\u843D\u5730\uFF1A
44068
+ ${formatSkillValidationIssues(validation)}`);
44069
+ }
44070
+ const target = assertSafeSkillTarget(this.skillsInstallDir, proposal.skillName);
44071
+ let installedTarget = target;
44072
+ if ((0, import_node_fs6.existsSync)(target)) {
43746
44073
  const alt = target + "-" + proposalId;
43747
- (0, import_node_fs5.mkdirSync)(alt, { recursive: true });
43748
- (0, import_node_fs5.cpSync)(proposal.draftDir, alt, { recursive: true });
44074
+ (0, import_node_fs6.mkdirSync)(alt, { recursive: true });
44075
+ (0, import_node_fs6.cpSync)(proposal.draftDir, alt, { recursive: true });
44076
+ installedTarget = alt;
43749
44077
  } else {
43750
- (0, import_node_fs5.mkdirSync)(target, { recursive: true });
43751
- (0, import_node_fs5.cpSync)(proposal.draftDir, target, { recursive: true });
44078
+ (0, import_node_fs6.mkdirSync)(target, { recursive: true });
44079
+ (0, import_node_fs6.cpSync)(proposal.draftDir, target, { recursive: true });
44080
+ }
44081
+ const smokeTest = smokeTestSkillDirectory(installedTarget, { expectedName: proposal.skillName });
44082
+ if (!smokeTest.ok) {
44083
+ try {
44084
+ (0, import_node_fs6.rmSync)(installedTarget, { recursive: true, force: true });
44085
+ } catch {
44086
+ }
44087
+ throw new Error(`[skillForge] Skill smoke test \u5931\u8D25\uFF0C\u5DF2\u56DE\u6EDA\u843D\u5730\u76EE\u5F55\uFF1A
44088
+ ${formatSkillValidationIssues(smokeTest)}`);
43752
44089
  }
43753
44090
  try {
43754
- (0, import_node_fs5.rmSync)(proposal.draftDir, { recursive: true, force: true });
44091
+ (0, import_node_fs6.rmSync)(proposal.draftDir, { recursive: true, force: true });
43755
44092
  } catch {
43756
44093
  }
43757
44094
  await this.removeProposal(userId, proposalId);
@@ -43763,7 +44100,7 @@ var SkillForgeEngine = class {
43763
44100
  const proposal = list.find((p) => p.id === proposalId);
43764
44101
  if (!proposal) return null;
43765
44102
  try {
43766
- (0, import_node_fs5.rmSync)(proposal.draftDir, { recursive: true, force: true });
44103
+ (0, import_node_fs6.rmSync)(proposal.draftDir, { recursive: true, force: true });
43767
44104
  } catch {
43768
44105
  }
43769
44106
  await this.removeProposal(userId, proposalId);
@@ -43912,9 +44249,13 @@ var skillForgeKeep = (engine) => ({
43912
44249
  return `\u672A\u80FD\u5B9A\u4F4D\u5230\u5177\u4F53\u7684\u8349\u7A3F\uFF0C\u8BF7\u8BA9\u7528\u6237\u8865\u5145\u8349\u7A3F\u540D\u79F0\u6216 id\u3002\u5F53\u524D pending \u5217\u8868\uFF1A
43913
44250
  ` + pending.map((p) => `- ${p.id} ${p.skillName}`).join("\n");
43914
44251
  }
43915
- const approved = await engine.approve(userId, target.id);
43916
- if (!approved) return `\u4FDD\u7559\u5931\u8D25\uFF1A\u8349\u7A3F ${target.id} \u5DF2\u88AB\u5904\u7406\u6216\u4E0D\u5B58\u5728\u3002`;
43917
- return `\u2705 \u5DF2\u4FDD\u7559\u6280\u80FD\u300C${approved.skillName}\u300D\u5230 ~/.agents/skills/\uFF0C\u4E0B\u6B21\u7C7B\u4F3C\u4EFB\u52A1\u5C06\u81EA\u52A8\u590D\u7528\u3002`;
44252
+ try {
44253
+ const approved = await engine.approve(userId, target.id);
44254
+ if (!approved) return `\u4FDD\u7559\u5931\u8D25\uFF1A\u8349\u7A3F ${target.id} \u5DF2\u88AB\u5904\u7406\u6216\u4E0D\u5B58\u5728\u3002`;
44255
+ return `\u2705 \u5DF2\u4FDD\u7559\u6280\u80FD\u300C${approved.skillName}\u300D\u5230 ~/.agents/skills/\uFF0C\u4E0B\u6B21\u7C7B\u4F3C\u4EFB\u52A1\u5C06\u81EA\u52A8\u590D\u7528\u3002`;
44256
+ } catch (err) {
44257
+ return `\u4FDD\u7559\u5931\u8D25\uFF1A${err.message}`;
44258
+ }
43918
44259
  }
43919
44260
  });
43920
44261
 
@@ -44803,7 +45144,7 @@ var llmRequestIdForTurn = (request, messages, system, tools) => {
44803
45144
  };
44804
45145
  var getDefaultAgentConfig = (tools, systemPrompt) => {
44805
45146
  loadEnv();
44806
- (0, import_node_fs6.mkdirSync)(DEFAULT_WORKSPACE_PATH, { recursive: true });
45147
+ (0, import_node_fs7.mkdirSync)(DEFAULT_WORKSPACE_PATH, { recursive: true });
44807
45148
  let system = ``;
44808
45149
  if (!systemPrompt) {
44809
45150
  system = `
@@ -44892,6 +45233,7 @@ The user will primarily request you perform software engineering tasks. This inc
44892
45233
  - \u5B58\u5728\u591A\u79CD\u65B9\u6848\u4E14\u5404\u6709\u5229\u5F0A\u65F6\uFF0C\u5217\u51FA\u9009\u9879\u8BA9\u7528\u6237\u9009\u62E9
44893
45234
  - \u4EFB\u52A1\u7406\u89E3\u6709\u6B67\u4E49\u65F6\uFF0C\u5148\u786E\u8BA4\u7528\u6237\u7684\u771F\u5B9E\u610F\u56FE
44894
45235
  - \u64CD\u4F5C\u7ED3\u679C\u4F1A\u5F71\u54CD\u5176\u4ED6\u4EBA\u6216\u5916\u90E8\u7CFB\u7EDF\u65F6
45236
+ - \u98DE\u4E66/Lark \u6388\u6743\u94FE\u63A5\u5FC5\u987B\u4E3B\u52A8\u8F6C\u53D1\uFF1A\u5F53\u5DE5\u5177\u8F93\u51FA\u3001\u90E8\u95E8\u6210\u5458\u56DE\u590D\u6216\u9519\u8BEF\u4FE1\u606F\u4E2D\u51FA\u73B0\u9700\u8981\u7528\u6237\u5728\u6D4F\u89C8\u5668\u5B8C\u6210\u7684\u98DE\u4E66/Lark \u6388\u6743\u3001\u5E94\u7528\u914D\u7F6E\u3001scope \u5F00\u901A\u3001console_url\u3001authorize_url\u3001auth login URL \u7B49\u94FE\u63A5\u65F6\uFF0C\u5FC5\u987B\u901A\u8FC7 send_message \u628A\u5B8C\u6574 URL \u76F4\u63A5\u53D1\u7ED9\u7528\u6237\uFF0C\u5E76\u660E\u786E\u8BF4\u660E\u9700\u8981\u7528\u6237\u6253\u5F00\u8BE5\u94FE\u63A5\u5B8C\u6210\u6388\u6743\u3002\u4E0D\u8981\u53EA\u8BF4\u201C\u8BF7\u5728\u6D4F\u89C8\u5668\u4E2D\u6253\u5F00\u6388\u6743\u94FE\u63A5\u201D\u800C\u4E0D\u63D0\u4F9B\u94FE\u63A5\u3002
44895
45237
  - \u4E0D\u8981\u64C5\u81EA\u505A\u91CD\u5927\u51B3\u5B9A\uFF0C\u5B81\u53EF\u591A\u95EE\u4E00\u53E5\u4E5F\u4E0D\u8981\u9ED8\u9ED8\u6267\u884C\u53EF\u80FD\u51FA\u9519\u7684\u64CD\u4F5C\u3002
44896
45238
  </Communication>
44897
45239
 
@@ -46108,15 +46450,7 @@ var wakeDepartmentAgent = async (mailboxId, msgIds) => {
46108
46450
  };
46109
46451
  const result = await agent(request);
46110
46452
  console.log(`[mailbox] department agent ${mailboxId} \u5904\u7406\u5B8C\u6210, alreadySent=${result.alreadySent}`);
46111
- for (const id of msgIds) {
46112
- const changed = updateMailboxMessageStatus(id, "pending", {
46113
- fromStatus: "processing",
46114
- reason: "department_agent_retry"
46115
- });
46116
- if (changed) {
46117
- console.log(`[mailbox] \u6D88\u606F ${id} \u672A\u88AB agent \u5904\u7406\uFF0C\u5DF2\u91CD\u7F6E\u4E3A pending`);
46118
- }
46119
- }
46453
+ finalizeDepartmentAgentUnrepliedMessages(mailboxId, msgIds, result);
46120
46454
  } catch (err) {
46121
46455
  console.error(`[mailbox] \u5524\u9192 department agent ${mailboxId} \u5931\u8D25:`, err);
46122
46456
  for (const id of msgIds) {
@@ -46127,6 +46461,63 @@ var wakeDepartmentAgent = async (mailboxId, msgIds) => {
46127
46461
  }
46128
46462
  }
46129
46463
  };
46464
+ var finalizeDepartmentAgentUnrepliedMessages = (mailboxId, msgIds, result) => {
46465
+ const fallbackContent = result.content?.trim();
46466
+ for (const id of msgIds) {
46467
+ const row = db2.prepare(
46468
+ `SELECT
46469
+ id,
46470
+ to_mailbox_id as toMailboxId,
46471
+ from_mailbox_id as fromMailboxId,
46472
+ status,
46473
+ origin_user_id as originUserId,
46474
+ origin_platform as originPlatform,
46475
+ thread_id as threadId
46476
+ FROM mailbox
46477
+ WHERE id = ?`
46478
+ ).get(id);
46479
+ if (!row || row.status !== "processing") continue;
46480
+ if (fallbackContent) {
46481
+ const changed2 = updateMailboxMessageStatus(id, "done", {
46482
+ fromStatus: "processing",
46483
+ actorMailboxId: mailboxId,
46484
+ counterpartMailboxId: row.fromMailboxId,
46485
+ reason: "department_agent_fallback_reply"
46486
+ });
46487
+ if (changed2) {
46488
+ sendMessage2(mailboxId, row.fromMailboxId, fallbackContent, {
46489
+ originUserId: row.originUserId,
46490
+ originPlatform: row.originPlatform,
46491
+ threadId: row.threadId || row.id,
46492
+ parentMessageId: row.id,
46493
+ auditDetail: {
46494
+ fallbackReason: "department_agent_returned_without_reply_mailbox"
46495
+ }
46496
+ });
46497
+ console.warn(`[mailbox] department agent ${mailboxId} \u672A\u8C03\u7528 reply_mailbox\uFF0C\u5DF2\u5C06\u6700\u7EC8\u6587\u672C\u515C\u5E95\u8F6C\u4E3A\u90AE\u4EF6 ${id} \u7684\u56DE\u4FE1`);
46498
+ }
46499
+ continue;
46500
+ }
46501
+ const changed = updateMailboxMessageStatus(id, "failed", {
46502
+ fromStatus: "processing",
46503
+ actorMailboxId: mailboxId,
46504
+ counterpartMailboxId: row.fromMailboxId,
46505
+ reason: "department_agent_no_reply"
46506
+ });
46507
+ if (changed) {
46508
+ sendMessage2(mailboxId, row.fromMailboxId, `[\u7CFB\u7EDF\u901A\u77E5] ${mailboxId} \u672C\u8F6E\u88AB\u5524\u9192\u540E\u6CA1\u6709\u4EA7\u51FA\u53EF\u8F6C\u4EA4\u7684\u56DE\u590D\uFF0C\u539F\u90AE\u4EF6\u5DF2\u6807\u8BB0\u4E3A failed\uFF0C\u907F\u514D\u7EE7\u7EED\u91CD\u590D\u6295\u9012\u3002`, {
46509
+ originUserId: row.originUserId,
46510
+ originPlatform: row.originPlatform,
46511
+ threadId: row.threadId || row.id,
46512
+ parentMessageId: row.id,
46513
+ auditDetail: {
46514
+ fallbackReason: "department_agent_returned_empty_without_reply_mailbox"
46515
+ }
46516
+ });
46517
+ console.warn(`[mailbox] department agent ${mailboxId} \u6CA1\u6709\u56DE\u590D\u5185\u5BB9\uFF0C\u90AE\u4EF6 ${id} \u5DF2\u6807\u8BB0 failed`);
46518
+ }
46519
+ }
46520
+ };
46130
46521
  var polling = false;
46131
46522
  var pollMailbox = async () => {
46132
46523
  if (polling) return;
@@ -46210,7 +46601,6 @@ var createDepartmentAgentTools = () => {
46210
46601
  registerTool(registry2, departmentSkillKeep);
46211
46602
  registerTool(registry2, departmentSkillDrop);
46212
46603
  registerTool(registry2, departmentProposalCreate);
46213
- registerTool(registry2, sendMessage);
46214
46604
  return { registry: registry2, executor };
46215
46605
  };
46216
46606
  var getDepartmentAgentConfig = (tools, memberFocusOn, workspacePath, departmentName) => {
@@ -46445,26 +46835,26 @@ var handleParsingNestedValues = (form, key, value) => {
46445
46835
  };
46446
46836
 
46447
46837
  // node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/utils/url.js
46448
- var splitPath = (path18) => {
46449
- const paths = path18.split("/");
46838
+ var splitPath = (path19) => {
46839
+ const paths = path19.split("/");
46450
46840
  if (paths[0] === "") {
46451
46841
  paths.shift();
46452
46842
  }
46453
46843
  return paths;
46454
46844
  };
46455
46845
  var splitRoutingPath = (routePath) => {
46456
- const { groups, path: path18 } = extractGroupsFromPath(routePath);
46457
- const paths = splitPath(path18);
46846
+ const { groups, path: path19 } = extractGroupsFromPath(routePath);
46847
+ const paths = splitPath(path19);
46458
46848
  return replaceGroupMarks(paths, groups);
46459
46849
  };
46460
- var extractGroupsFromPath = (path18) => {
46850
+ var extractGroupsFromPath = (path19) => {
46461
46851
  const groups = [];
46462
- path18 = path18.replace(/\{[^}]+\}/g, (match2, index) => {
46852
+ path19 = path19.replace(/\{[^}]+\}/g, (match2, index) => {
46463
46853
  const mark = `@${index}`;
46464
46854
  groups.push([mark, match2]);
46465
46855
  return mark;
46466
46856
  });
46467
- return { groups, path: path18 };
46857
+ return { groups, path: path19 };
46468
46858
  };
46469
46859
  var replaceGroupMarks = (paths, groups) => {
46470
46860
  for (let i = groups.length - 1; i >= 0; i--) {
@@ -46521,8 +46911,8 @@ var getPath = (request) => {
46521
46911
  const queryIndex = url.indexOf("?", i);
46522
46912
  const hashIndex = url.indexOf("#", i);
46523
46913
  const end = queryIndex === -1 ? hashIndex === -1 ? void 0 : hashIndex : hashIndex === -1 ? queryIndex : Math.min(queryIndex, hashIndex);
46524
- const path18 = url.slice(start, end);
46525
- return tryDecodeURI(path18.includes("%25") ? path18.replace(/%25/g, "%2525") : path18);
46914
+ const path19 = url.slice(start, end);
46915
+ return tryDecodeURI(path19.includes("%25") ? path19.replace(/%25/g, "%2525") : path19);
46526
46916
  } else if (charCode === 63 || charCode === 35) {
46527
46917
  break;
46528
46918
  }
@@ -46539,11 +46929,11 @@ var mergePath = (base, sub, ...rest) => {
46539
46929
  }
46540
46930
  return `${base?.[0] === "/" ? "" : "/"}${base}${sub === "/" ? "" : `${base?.at(-1) === "/" ? "" : "/"}${sub?.[0] === "/" ? sub.slice(1) : sub}`}`;
46541
46931
  };
46542
- var checkOptionalParameter = (path18) => {
46543
- if (path18.charCodeAt(path18.length - 1) !== 63 || !path18.includes(":")) {
46932
+ var checkOptionalParameter = (path19) => {
46933
+ if (path19.charCodeAt(path19.length - 1) !== 63 || !path19.includes(":")) {
46544
46934
  return null;
46545
46935
  }
46546
- const segments = path18.split("/");
46936
+ const segments = path19.split("/");
46547
46937
  const results = [];
46548
46938
  let basePath = "";
46549
46939
  segments.forEach((segment) => {
@@ -46684,9 +47074,9 @@ var HonoRequest = class {
46684
47074
  */
46685
47075
  path;
46686
47076
  bodyCache = {};
46687
- constructor(request, path18 = "/", matchResult = [[]]) {
47077
+ constructor(request, path19 = "/", matchResult = [[]]) {
46688
47078
  this.raw = request;
46689
- this.path = path18;
47079
+ this.path = path19;
46690
47080
  this.#matchResult = matchResult;
46691
47081
  this.#validatedData = {};
46692
47082
  }
@@ -47423,8 +47813,8 @@ var Hono = class _Hono {
47423
47813
  return this;
47424
47814
  };
47425
47815
  });
47426
- this.on = (method, path18, ...handlers) => {
47427
- for (const p of [path18].flat()) {
47816
+ this.on = (method, path19, ...handlers) => {
47817
+ for (const p of [path19].flat()) {
47428
47818
  this.#path = p;
47429
47819
  for (const m of [method].flat()) {
47430
47820
  handlers.map((handler) => {
@@ -47481,8 +47871,8 @@ var Hono = class _Hono {
47481
47871
  * app.route("/api", app2) // GET /api/user
47482
47872
  * ```
47483
47873
  */
47484
- route(path18, app) {
47485
- const subApp = this.basePath(path18);
47874
+ route(path19, app) {
47875
+ const subApp = this.basePath(path19);
47486
47876
  app.routes.map((r) => {
47487
47877
  let handler;
47488
47878
  if (app.errorHandler === errorHandler) {
@@ -47508,9 +47898,9 @@ var Hono = class _Hono {
47508
47898
  * const api = new Hono().basePath('/api')
47509
47899
  * ```
47510
47900
  */
47511
- basePath(path18) {
47901
+ basePath(path19) {
47512
47902
  const subApp = this.#clone();
47513
- subApp._basePath = mergePath(this._basePath, path18);
47903
+ subApp._basePath = mergePath(this._basePath, path19);
47514
47904
  return subApp;
47515
47905
  }
47516
47906
  /**
@@ -47584,7 +47974,7 @@ var Hono = class _Hono {
47584
47974
  * })
47585
47975
  * ```
47586
47976
  */
47587
- mount(path18, applicationHandler, options) {
47977
+ mount(path19, applicationHandler, options) {
47588
47978
  let replaceRequest;
47589
47979
  let optionHandler;
47590
47980
  if (options) {
@@ -47611,7 +48001,7 @@ var Hono = class _Hono {
47611
48001
  return [c.env, executionContext];
47612
48002
  };
47613
48003
  replaceRequest ||= (() => {
47614
- const mergedPath = mergePath(this._basePath, path18);
48004
+ const mergedPath = mergePath(this._basePath, path19);
47615
48005
  const pathPrefixLength = mergedPath === "/" ? 0 : mergedPath.length;
47616
48006
  return (request) => {
47617
48007
  const url = new URL(request.url);
@@ -47626,14 +48016,14 @@ var Hono = class _Hono {
47626
48016
  }
47627
48017
  await next();
47628
48018
  };
47629
- this.#addRoute(METHOD_NAME_ALL, mergePath(path18, "*"), handler);
48019
+ this.#addRoute(METHOD_NAME_ALL, mergePath(path19, "*"), handler);
47630
48020
  return this;
47631
48021
  }
47632
- #addRoute(method, path18, handler) {
48022
+ #addRoute(method, path19, handler) {
47633
48023
  method = method.toUpperCase();
47634
- path18 = mergePath(this._basePath, path18);
47635
- const r = { basePath: this._basePath, path: path18, method, handler };
47636
- this.router.add(method, path18, [handler, r]);
48024
+ path19 = mergePath(this._basePath, path19);
48025
+ const r = { basePath: this._basePath, path: path19, method, handler };
48026
+ this.router.add(method, path19, [handler, r]);
47637
48027
  this.routes.push(r);
47638
48028
  }
47639
48029
  #handleError(err, c) {
@@ -47646,10 +48036,10 @@ var Hono = class _Hono {
47646
48036
  if (method === "HEAD") {
47647
48037
  return (async () => new Response(null, await this.#dispatch(request, executionCtx, env, "GET")))();
47648
48038
  }
47649
- const path18 = this.getPath(request, { env });
47650
- const matchResult = this.router.match(method, path18);
48039
+ const path19 = this.getPath(request, { env });
48040
+ const matchResult = this.router.match(method, path19);
47651
48041
  const c = new Context(request, {
47652
- path: path18,
48042
+ path: path19,
47653
48043
  matchResult,
47654
48044
  env,
47655
48045
  executionCtx,
@@ -47749,7 +48139,7 @@ var Hono = class _Hono {
47749
48139
 
47750
48140
  // node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/matcher.js
47751
48141
  var emptyParam = [];
47752
- function match(method, path18) {
48142
+ function match(method, path19) {
47753
48143
  const matchers = this.buildAllMatchers();
47754
48144
  const match2 = ((method2, path22) => {
47755
48145
  const matcher = matchers[method2] || matchers[METHOD_NAME_ALL];
@@ -47765,7 +48155,7 @@ function match(method, path18) {
47765
48155
  return [matcher[1][index], match3];
47766
48156
  });
47767
48157
  this.match = match2;
47768
- return match2(method, path18);
48158
+ return match2(method, path19);
47769
48159
  }
47770
48160
 
47771
48161
  // node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/node.js
@@ -47880,12 +48270,12 @@ var Node = class _Node {
47880
48270
  var Trie = class {
47881
48271
  #context = { varIndex: 0 };
47882
48272
  #root = new Node();
47883
- insert(path18, index, pathErrorCheckOnly) {
48273
+ insert(path19, index, pathErrorCheckOnly) {
47884
48274
  const paramAssoc = [];
47885
48275
  const groups = [];
47886
48276
  for (let i = 0; ; ) {
47887
48277
  let replaced = false;
47888
- path18 = path18.replace(/\{[^}]+\}/g, (m) => {
48278
+ path19 = path19.replace(/\{[^}]+\}/g, (m) => {
47889
48279
  const mark = `@\\${i}`;
47890
48280
  groups[i] = [mark, m];
47891
48281
  i++;
@@ -47896,7 +48286,7 @@ var Trie = class {
47896
48286
  break;
47897
48287
  }
47898
48288
  }
47899
- const tokens = path18.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
48289
+ const tokens = path19.match(/(?::[^\/]+)|(?:\/\*$)|./g) || [];
47900
48290
  for (let i = groups.length - 1; i >= 0; i--) {
47901
48291
  const [mark] = groups[i];
47902
48292
  for (let j = tokens.length - 1; j >= 0; j--) {
@@ -47935,9 +48325,9 @@ var Trie = class {
47935
48325
  // node_modules/.pnpm/hono@4.12.9/node_modules/hono/dist/router/reg-exp-router/router.js
47936
48326
  var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
47937
48327
  var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
47938
- function buildWildcardRegExp(path18) {
47939
- return wildcardRegExpCache[path18] ??= new RegExp(
47940
- path18 === "*" ? "" : `^${path18.replace(
48328
+ function buildWildcardRegExp(path19) {
48329
+ return wildcardRegExpCache[path19] ??= new RegExp(
48330
+ path19 === "*" ? "" : `^${path19.replace(
47941
48331
  /\/\*$|([.\\+*[^\]$()])/g,
47942
48332
  (_, metaChar) => metaChar ? `\\${metaChar}` : "(?:|/.*)"
47943
48333
  )}$`
@@ -47959,17 +48349,17 @@ function buildMatcherFromPreprocessedRoutes(routes) {
47959
48349
  );
47960
48350
  const staticMap = /* @__PURE__ */ Object.create(null);
47961
48351
  for (let i = 0, j = -1, len = routesWithStaticPathFlag.length; i < len; i++) {
47962
- const [pathErrorCheckOnly, path18, handlers] = routesWithStaticPathFlag[i];
48352
+ const [pathErrorCheckOnly, path19, handlers] = routesWithStaticPathFlag[i];
47963
48353
  if (pathErrorCheckOnly) {
47964
- staticMap[path18] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
48354
+ staticMap[path19] = [handlers.map(([h]) => [h, /* @__PURE__ */ Object.create(null)]), emptyParam];
47965
48355
  } else {
47966
48356
  j++;
47967
48357
  }
47968
48358
  let paramAssoc;
47969
48359
  try {
47970
- paramAssoc = trie.insert(path18, j, pathErrorCheckOnly);
48360
+ paramAssoc = trie.insert(path19, j, pathErrorCheckOnly);
47971
48361
  } catch (e) {
47972
- throw e === PATH_ERROR ? new UnsupportedPathError(path18) : e;
48362
+ throw e === PATH_ERROR ? new UnsupportedPathError(path19) : e;
47973
48363
  }
47974
48364
  if (pathErrorCheckOnly) {
47975
48365
  continue;
@@ -48003,12 +48393,12 @@ function buildMatcherFromPreprocessedRoutes(routes) {
48003
48393
  }
48004
48394
  return [regexp, handlerMap, staticMap];
48005
48395
  }
48006
- function findMiddleware(middleware, path18) {
48396
+ function findMiddleware(middleware, path19) {
48007
48397
  if (!middleware) {
48008
48398
  return void 0;
48009
48399
  }
48010
48400
  for (const k of Object.keys(middleware).sort((a, b) => b.length - a.length)) {
48011
- if (buildWildcardRegExp(k).test(path18)) {
48401
+ if (buildWildcardRegExp(k).test(path19)) {
48012
48402
  return [...middleware[k]];
48013
48403
  }
48014
48404
  }
@@ -48022,7 +48412,7 @@ var RegExpRouter = class {
48022
48412
  this.#middleware = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
48023
48413
  this.#routes = { [METHOD_NAME_ALL]: /* @__PURE__ */ Object.create(null) };
48024
48414
  }
48025
- add(method, path18, handler) {
48415
+ add(method, path19, handler) {
48026
48416
  const middleware = this.#middleware;
48027
48417
  const routes = this.#routes;
48028
48418
  if (!middleware || !routes) {
@@ -48037,18 +48427,18 @@ var RegExpRouter = class {
48037
48427
  });
48038
48428
  });
48039
48429
  }
48040
- if (path18 === "/*") {
48041
- path18 = "*";
48430
+ if (path19 === "/*") {
48431
+ path19 = "*";
48042
48432
  }
48043
- const paramCount = (path18.match(/\/:/g) || []).length;
48044
- if (/\*$/.test(path18)) {
48045
- const re = buildWildcardRegExp(path18);
48433
+ const paramCount = (path19.match(/\/:/g) || []).length;
48434
+ if (/\*$/.test(path19)) {
48435
+ const re = buildWildcardRegExp(path19);
48046
48436
  if (method === METHOD_NAME_ALL) {
48047
48437
  Object.keys(middleware).forEach((m) => {
48048
- middleware[m][path18] ||= findMiddleware(middleware[m], path18) || findMiddleware(middleware[METHOD_NAME_ALL], path18) || [];
48438
+ middleware[m][path19] ||= findMiddleware(middleware[m], path19) || findMiddleware(middleware[METHOD_NAME_ALL], path19) || [];
48049
48439
  });
48050
48440
  } else {
48051
- middleware[method][path18] ||= findMiddleware(middleware[method], path18) || findMiddleware(middleware[METHOD_NAME_ALL], path18) || [];
48441
+ middleware[method][path19] ||= findMiddleware(middleware[method], path19) || findMiddleware(middleware[METHOD_NAME_ALL], path19) || [];
48052
48442
  }
48053
48443
  Object.keys(middleware).forEach((m) => {
48054
48444
  if (method === METHOD_NAME_ALL || method === m) {
@@ -48066,7 +48456,7 @@ var RegExpRouter = class {
48066
48456
  });
48067
48457
  return;
48068
48458
  }
48069
- const paths = checkOptionalParameter(path18) || [path18];
48459
+ const paths = checkOptionalParameter(path19) || [path19];
48070
48460
  for (let i = 0, len = paths.length; i < len; i++) {
48071
48461
  const path22 = paths[i];
48072
48462
  Object.keys(routes).forEach((m) => {
@@ -48093,13 +48483,13 @@ var RegExpRouter = class {
48093
48483
  const routes = [];
48094
48484
  let hasOwnRoute = method === METHOD_NAME_ALL;
48095
48485
  [this.#middleware, this.#routes].forEach((r) => {
48096
- const ownRoute = r[method] ? Object.keys(r[method]).map((path18) => [path18, r[method][path18]]) : [];
48486
+ const ownRoute = r[method] ? Object.keys(r[method]).map((path19) => [path19, r[method][path19]]) : [];
48097
48487
  if (ownRoute.length !== 0) {
48098
48488
  hasOwnRoute ||= true;
48099
48489
  routes.push(...ownRoute);
48100
48490
  } else if (method !== METHOD_NAME_ALL) {
48101
48491
  routes.push(
48102
- ...Object.keys(r[METHOD_NAME_ALL]).map((path18) => [path18, r[METHOD_NAME_ALL][path18]])
48492
+ ...Object.keys(r[METHOD_NAME_ALL]).map((path19) => [path19, r[METHOD_NAME_ALL][path19]])
48103
48493
  );
48104
48494
  }
48105
48495
  });
@@ -48119,13 +48509,13 @@ var SmartRouter = class {
48119
48509
  constructor(init) {
48120
48510
  this.#routers = init.routers;
48121
48511
  }
48122
- add(method, path18, handler) {
48512
+ add(method, path19, handler) {
48123
48513
  if (!this.#routes) {
48124
48514
  throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
48125
48515
  }
48126
- this.#routes.push([method, path18, handler]);
48516
+ this.#routes.push([method, path19, handler]);
48127
48517
  }
48128
- match(method, path18) {
48518
+ match(method, path19) {
48129
48519
  if (!this.#routes) {
48130
48520
  throw new Error("Fatal error");
48131
48521
  }
@@ -48140,7 +48530,7 @@ var SmartRouter = class {
48140
48530
  for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
48141
48531
  router.add(...routes[i2]);
48142
48532
  }
48143
- res = router.match(method, path18);
48533
+ res = router.match(method, path19);
48144
48534
  } catch (e) {
48145
48535
  if (e instanceof UnsupportedPathError) {
48146
48536
  continue;
@@ -48190,10 +48580,10 @@ var Node2 = class _Node2 {
48190
48580
  }
48191
48581
  this.#patterns = [];
48192
48582
  }
48193
- insert(method, path18, handler) {
48583
+ insert(method, path19, handler) {
48194
48584
  this.#order = ++this.#order;
48195
48585
  let curNode = this;
48196
- const parts = splitRoutingPath(path18);
48586
+ const parts = splitRoutingPath(path19);
48197
48587
  const possibleKeys = [];
48198
48588
  for (let i = 0, len = parts.length; i < len; i++) {
48199
48589
  const p = parts[i];
@@ -48242,12 +48632,12 @@ var Node2 = class _Node2 {
48242
48632
  }
48243
48633
  }
48244
48634
  }
48245
- search(method, path18) {
48635
+ search(method, path19) {
48246
48636
  const handlerSets = [];
48247
48637
  this.#params = emptyParams;
48248
48638
  const curNode = this;
48249
48639
  let curNodes = [curNode];
48250
- const parts = splitPath(path18);
48640
+ const parts = splitPath(path19);
48251
48641
  const curNodesQueue = [];
48252
48642
  const len = parts.length;
48253
48643
  let partOffsets = null;
@@ -48289,13 +48679,13 @@ var Node2 = class _Node2 {
48289
48679
  if (matcher instanceof RegExp) {
48290
48680
  if (partOffsets === null) {
48291
48681
  partOffsets = new Array(len);
48292
- let offset = path18[0] === "/" ? 1 : 0;
48682
+ let offset = path19[0] === "/" ? 1 : 0;
48293
48683
  for (let p = 0; p < len; p++) {
48294
48684
  partOffsets[p] = offset;
48295
48685
  offset += parts[p].length + 1;
48296
48686
  }
48297
48687
  }
48298
- const restPathString = path18.substring(partOffsets[i]);
48688
+ const restPathString = path19.substring(partOffsets[i]);
48299
48689
  const m = matcher.exec(restPathString);
48300
48690
  if (m) {
48301
48691
  params[name] = m[0];
@@ -48348,18 +48738,18 @@ var TrieRouter = class {
48348
48738
  constructor() {
48349
48739
  this.#node = new Node2();
48350
48740
  }
48351
- add(method, path18, handler) {
48352
- const results = checkOptionalParameter(path18);
48741
+ add(method, path19, handler) {
48742
+ const results = checkOptionalParameter(path19);
48353
48743
  if (results) {
48354
48744
  for (let i = 0, len = results.length; i < len; i++) {
48355
48745
  this.#node.insert(method, results[i], handler);
48356
48746
  }
48357
48747
  return;
48358
48748
  }
48359
- this.#node.insert(method, path18, handler);
48749
+ this.#node.insert(method, path19, handler);
48360
48750
  }
48361
- match(method, path18) {
48362
- return this.#node.search(method, path18);
48751
+ match(method, path19) {
48752
+ return this.#node.search(method, path19);
48363
48753
  }
48364
48754
  };
48365
48755
 
@@ -49061,10 +49451,10 @@ var createStreamBody = (stream) => {
49061
49451
  });
49062
49452
  return body;
49063
49453
  };
49064
- var getStats = (path18) => {
49454
+ var getStats = (path19) => {
49065
49455
  let stats;
49066
49456
  try {
49067
- stats = (0, import_fs15.statSync)(path18);
49457
+ stats = (0, import_fs15.statSync)(path19);
49068
49458
  } catch {
49069
49459
  }
49070
49460
  return stats;
@@ -49107,21 +49497,21 @@ var serveStatic = (options = { root: "" }) => {
49107
49497
  return next();
49108
49498
  }
49109
49499
  }
49110
- let path18 = (0, import_path20.join)(
49500
+ let path19 = (0, import_path20.join)(
49111
49501
  root,
49112
49502
  !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
49113
49503
  );
49114
- let stats = getStats(path18);
49504
+ let stats = getStats(path19);
49115
49505
  if (stats && stats.isDirectory()) {
49116
49506
  const indexFile = options.index ?? "index.html";
49117
- path18 = (0, import_path20.join)(path18, indexFile);
49118
- stats = getStats(path18);
49507
+ path19 = (0, import_path20.join)(path19, indexFile);
49508
+ stats = getStats(path19);
49119
49509
  }
49120
49510
  if (!stats) {
49121
- await options.onNotFound?.(path18, c);
49511
+ await options.onNotFound?.(path19, c);
49122
49512
  return next();
49123
49513
  }
49124
- const mimeType = getMimeType(path18);
49514
+ const mimeType = getMimeType(path19);
49125
49515
  c.header("Content-Type", mimeType || "application/octet-stream");
49126
49516
  if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
49127
49517
  const acceptEncodingSet = new Set(
@@ -49131,12 +49521,12 @@ var serveStatic = (options = { root: "" }) => {
49131
49521
  if (!acceptEncodingSet.has(encoding)) {
49132
49522
  continue;
49133
49523
  }
49134
- const precompressedStats = getStats(path18 + ENCODINGS[encoding]);
49524
+ const precompressedStats = getStats(path19 + ENCODINGS[encoding]);
49135
49525
  if (precompressedStats) {
49136
49526
  c.header("Content-Encoding", encoding);
49137
49527
  c.header("Vary", "Accept-Encoding", { append: true });
49138
49528
  stats = precompressedStats;
49139
- path18 = path18 + ENCODINGS[encoding];
49529
+ path19 = path19 + ENCODINGS[encoding];
49140
49530
  break;
49141
49531
  }
49142
49532
  }
@@ -49150,7 +49540,7 @@ var serveStatic = (options = { root: "" }) => {
49150
49540
  result = c.body(null);
49151
49541
  } else if (!range) {
49152
49542
  c.header("Content-Length", size.toString());
49153
- result = c.body(createStreamBody((0, import_fs15.createReadStream)(path18)), 200);
49543
+ result = c.body(createStreamBody((0, import_fs15.createReadStream)(path19)), 200);
49154
49544
  } else {
49155
49545
  c.header("Accept-Ranges", "bytes");
49156
49546
  c.header("Date", stats.birthtime.toUTCString());
@@ -49161,12 +49551,12 @@ var serveStatic = (options = { root: "" }) => {
49161
49551
  end = size - 1;
49162
49552
  }
49163
49553
  const chunksize = end - start + 1;
49164
- const stream = (0, import_fs15.createReadStream)(path18, { start, end });
49554
+ const stream = (0, import_fs15.createReadStream)(path19, { start, end });
49165
49555
  c.header("Content-Length", chunksize.toString());
49166
49556
  c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
49167
49557
  result = c.body(createStreamBody(stream), 206);
49168
49558
  }
49169
- await options.onFound?.(path18, c);
49559
+ await options.onFound?.(path19, c);
49170
49560
  return result;
49171
49561
  };
49172
49562
  };
@@ -49261,7 +49651,7 @@ var cors = (options) => {
49261
49651
 
49262
49652
  // src/server/index.ts
49263
49653
  var import_promises11 = require("node:fs/promises");
49264
- var import_node_path14 = __toESM(require("node:path"));
49654
+ var import_node_path15 = __toESM(require("node:path"));
49265
49655
 
49266
49656
  // src/git/worktree.ts
49267
49657
  var import_child_process2 = require("child_process");
@@ -50492,8 +50882,8 @@ mailboxRoutes.get("/mailbox/summary", (c) => {
50492
50882
 
50493
50883
  // src/server/routes/memory.ts
50494
50884
  var import_redis4 = __toESM(require_dist2());
50495
- var import_node_fs7 = require("node:fs");
50496
- var import_node_path13 = __toESM(require("node:path"));
50885
+ var import_node_fs8 = require("node:fs");
50886
+ var import_node_path14 = __toESM(require("node:path"));
50497
50887
  var memoryEngineSingleton = null;
50498
50888
  var dreamStorageSingleton = null;
50499
50889
  var dreamHistoryStorageSingleton = null;
@@ -50593,12 +50983,12 @@ var addPlausibleUserId = (set, userId) => {
50593
50983
  if (normalized && isPlausibleUserId(normalized)) set.add(normalized);
50594
50984
  };
50595
50985
  var readJsonFilesFromDir = (dir) => {
50596
- if (!(0, import_node_fs7.existsSync)(dir)) return [];
50986
+ if (!(0, import_node_fs8.existsSync)(dir)) return [];
50597
50987
  const result = [];
50598
- for (const file of (0, import_node_fs7.readdirSync)(dir)) {
50988
+ for (const file of (0, import_node_fs8.readdirSync)(dir)) {
50599
50989
  if (!file.endsWith(".json")) continue;
50600
50990
  try {
50601
- result.push(JSON.parse((0, import_node_fs7.readFileSync)(import_node_path13.default.join(dir, file), "utf-8")));
50991
+ result.push(JSON.parse((0, import_node_fs8.readFileSync)(import_node_path14.default.join(dir, file), "utf-8")));
50602
50992
  } catch (err) {
50603
50993
  console.warn(`[memoryRoutes] \u8DF3\u8FC7\u65E0\u6CD5\u89E3\u6790\u7684\u672C\u5730\u4E0A\u4E0B\u6587\u6587\u4EF6 ${file}: ${err.message}`);
50604
50994
  }
@@ -50606,13 +50996,13 @@ var readJsonFilesFromDir = (dir) => {
50606
50996
  return result;
50607
50997
  };
50608
50998
  var extractFileBackedStorageKeysForTest = (dataDir) => {
50609
- const kvRoot = import_node_path13.default.join(dataDir, "kv");
50610
- if (!(0, import_node_fs7.existsSync)(kvRoot)) return [];
50999
+ const kvRoot = import_node_path14.default.join(dataDir, "kv");
51000
+ if (!(0, import_node_fs8.existsSync)(kvRoot)) return [];
50611
51001
  const keys = [];
50612
- for (const prefixDir of (0, import_node_fs7.readdirSync)(kvRoot)) {
50613
- const absolutePrefixDir = import_node_path13.default.join(kvRoot, prefixDir);
50614
- if (!(0, import_node_fs7.existsSync)(absolutePrefixDir)) continue;
50615
- for (const file of (0, import_node_fs7.readdirSync)(absolutePrefixDir)) {
51002
+ for (const prefixDir of (0, import_node_fs8.readdirSync)(kvRoot)) {
51003
+ const absolutePrefixDir = import_node_path14.default.join(kvRoot, prefixDir);
51004
+ if (!(0, import_node_fs8.existsSync)(absolutePrefixDir)) continue;
51005
+ for (const file of (0, import_node_fs8.readdirSync)(absolutePrefixDir)) {
50616
51006
  if (!file.endsWith(".json")) continue;
50617
51007
  try {
50618
51008
  const logicalKey = Buffer.from(file.replace(/\.json$/, ""), "base64url").toString("utf8");
@@ -50630,12 +51020,12 @@ var collectLocalConversationUserIds = () => {
50630
51020
  };
50631
51021
  var extractLocalConversationUserIdsForTest = (homeDir) => {
50632
51022
  const userIds = /* @__PURE__ */ new Set();
50633
- for (const context of readJsonFilesFromDir(import_node_path13.default.join(homeDir, "goal-context"))) {
51023
+ for (const context of readJsonFilesFromDir(import_node_path14.default.join(homeDir, "goal-context"))) {
50634
51024
  addPlausibleUserId(userIds, context.threadId);
50635
51025
  addPlausibleUserId(userIds, context.originUserId);
50636
51026
  if (context.goalId) addPlausibleUserId(userIds, `kanban:goal:${context.goalId}`);
50637
51027
  }
50638
- for (const goal of readJsonFilesFromDir(import_node_path13.default.join(homeDir, "tasks"))) {
51028
+ for (const goal of readJsonFilesFromDir(import_node_path14.default.join(homeDir, "tasks"))) {
50639
51029
  if (goal.id) addPlausibleUserId(userIds, `kanban:goal:${goal.id}`);
50640
51030
  }
50641
51031
  return userIds;
@@ -51095,7 +51485,7 @@ var systemRoutes = new Hono2();
51095
51485
  var startTime = Date.now();
51096
51486
  systemRoutes.get("/system/info", (c) => {
51097
51487
  return c.json({
51098
- version: true ? "1.8.15" : "unknown",
51488
+ version: true ? "1.8.17" : "unknown",
51099
51489
  uptime: Math.floor((Date.now() - startTime) / 1e3),
51100
51490
  env: process.env.NODE_ENV || "development",
51101
51491
  nodeVersion: process.version
@@ -51119,7 +51509,7 @@ function createServer() {
51119
51509
  app.route("/api", systemRoutes);
51120
51510
  app.use("/*", serveStatic({ root: webDistRoot }));
51121
51511
  app.get("/*", async (c) => {
51122
- const indexHtml = await (0, import_promises11.readFile)(import_node_path14.default.join(webDistRoot, "index.html"), "utf8");
51512
+ const indexHtml = await (0, import_promises11.readFile)(import_node_path15.default.join(webDistRoot, "index.html"), "utf8");
51123
51513
  const tenantId = c.req.header("x-tenant-id");
51124
51514
  const assetBase = tenantId ? `/t/${tenantId}` : "";
51125
51515
  const html = indexHtml.replaceAll('"./', `"${assetBase}/`);
@@ -51146,10 +51536,10 @@ function shouldStartCoreChannelGateways(env = process.env) {
51146
51536
  }
51147
51537
 
51148
51538
  // src/runtime/saasAssets.ts
51149
- var import_node_fs8 = require("node:fs");
51539
+ var import_node_fs9 = require("node:fs");
51150
51540
  var import_promises12 = require("node:fs/promises");
51151
51541
  var import_node_os3 = require("node:os");
51152
- var import_node_path15 = __toESM(require("node:path"));
51542
+ var import_node_path16 = __toESM(require("node:path"));
51153
51543
  var MAX_CONTEXT_ASSETS = Number(process.env.DUCLAW_SAAS_ASSET_CONTEXT_LIMIT ?? 1e3);
51154
51544
  var MAX_SKILL_ASSETS = Number(process.env.DUCLAW_SAAS_ASSET_SKILL_LIMIT ?? 200);
51155
51545
  async function restoreSaasRuntimeAssets(reason) {
@@ -51179,8 +51569,8 @@ async function restoreSaasRuntimeAssets(reason) {
51179
51569
  async function restoreContextAsset(context, overwrite) {
51180
51570
  const target = contextPathForSourceKey(context.sourceKey);
51181
51571
  if (!target) return false;
51182
- if (!overwrite && (0, import_node_fs8.existsSync)(target)) return false;
51183
- await (0, import_promises12.mkdir)(import_node_path15.default.dirname(target), { recursive: true });
51572
+ if (!overwrite && (0, import_node_fs9.existsSync)(target)) return false;
51573
+ await (0, import_promises12.mkdir)(import_node_path16.default.dirname(target), { recursive: true });
51184
51574
  await (0, import_promises12.writeFile)(target, JSON.stringify(context.payload), "utf8");
51185
51575
  return true;
51186
51576
  }
@@ -51188,8 +51578,8 @@ async function restoreSkillAsset(skill, overwrite) {
51188
51578
  if (!skill.skillMd) return false;
51189
51579
  const target = safeSkillTargetPath(skill.sourcePath, skill.skillName);
51190
51580
  if (!target) return false;
51191
- if (!overwrite && (0, import_node_fs8.existsSync)(target)) return false;
51192
- await (0, import_promises12.mkdir)(import_node_path15.default.dirname(target), { recursive: true });
51581
+ if (!overwrite && (0, import_node_fs9.existsSync)(target)) return false;
51582
+ await (0, import_promises12.mkdir)(import_node_path16.default.dirname(target), { recursive: true });
51193
51583
  await (0, import_promises12.writeFile)(target, skill.skillMd, "utf8");
51194
51584
  return true;
51195
51585
  }
@@ -51222,30 +51612,30 @@ function runtimeAssetClient() {
51222
51612
  function contextPathForSourceKey(sourceKey) {
51223
51613
  if (sourceKey.startsWith("agent:")) {
51224
51614
  const logicalKey = sourceKey.slice("agent:".length);
51225
- return import_node_path15.default.join(getDuclawDataDir(), "kv", "agent", `${Buffer.from(logicalKey).toString("base64url")}.json`);
51615
+ return import_node_path16.default.join(getDuclawDataDir(), "kv", "agent", `${Buffer.from(logicalKey).toString("base64url")}.json`);
51226
51616
  }
51227
51617
  if (sourceKey.startsWith("goal-context:")) {
51228
- return import_node_path15.default.join(getDuclawHomeDir(), "goal-context", `${sourceKey.slice("goal-context:".length)}.json`);
51618
+ return import_node_path16.default.join(getDuclawHomeDir(), "goal-context", `${sourceKey.slice("goal-context:".length)}.json`);
51229
51619
  }
51230
51620
  if (sourceKey.startsWith("tasks:")) {
51231
- return import_node_path15.default.join(getDuclawHomeDir(), "tasks", `${sourceKey.slice("tasks:".length)}.json`);
51621
+ return import_node_path16.default.join(getDuclawHomeDir(), "tasks", `${sourceKey.slice("tasks:".length)}.json`);
51232
51622
  }
51233
51623
  return null;
51234
51624
  }
51235
51625
  function safeSkillTargetPath(sourcePath, skillName) {
51236
- const allowedRoots = skillRoots().map((root) => import_node_path15.default.resolve(root));
51237
- const normalized = import_node_path15.default.resolve(sourcePath);
51238
- if (allowedRoots.some((root) => normalized === import_node_path15.default.join(root, import_node_path15.default.basename(import_node_path15.default.dirname(normalized)), "SKILL.md"))) {
51626
+ const allowedRoots = skillRoots().map((root) => import_node_path16.default.resolve(root));
51627
+ const normalized = import_node_path16.default.resolve(sourcePath);
51628
+ if (allowedRoots.some((root) => normalized === import_node_path16.default.join(root, import_node_path16.default.basename(import_node_path16.default.dirname(normalized)), "SKILL.md"))) {
51239
51629
  return normalized;
51240
51630
  }
51241
51631
  const safeName = skillName.replace(/[^a-zA-Z0-9._-]/g, "-").slice(0, 120) || "imported-skill";
51242
- return import_node_path15.default.join("/home/user/app/skills", safeName, "SKILL.md");
51632
+ return import_node_path16.default.join("/home/user/app/skills", safeName, "SKILL.md");
51243
51633
  }
51244
51634
  function skillRoots() {
51245
51635
  return [
51246
51636
  "/home/user/app/skills",
51247
- import_node_path15.default.join(getDuclawHomeDir(), "skills"),
51248
- import_node_path15.default.join((0, import_node_os3.homedir)(), ".agents", "skills")
51637
+ import_node_path16.default.join(getDuclawHomeDir(), "skills"),
51638
+ import_node_path16.default.join((0, import_node_os3.homedir)(), ".agents", "skills")
51249
51639
  ];
51250
51640
  }
51251
51641