workspacecord 1.1.2 → 1.1.3

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.
@@ -319,8 +319,8 @@ var require_legacy_streams = __commonJS({
319
319
  options = options || {};
320
320
  var keys = Object.keys(options);
321
321
  for (var index = 0, length = keys.length; index < length; index++) {
322
- var key = keys[index];
323
- this[key] = options[key];
322
+ var key2 = keys[index];
323
+ this[key2] = options[key2];
324
324
  }
325
325
  if (this.encoding) this.setEncoding(this.encoding);
326
326
  if (this.start !== void 0) {
@@ -367,8 +367,8 @@ var require_legacy_streams = __commonJS({
367
367
  options = options || {};
368
368
  var keys = Object.keys(options);
369
369
  for (var index = 0, length = keys.length; index < length; index++) {
370
- var key = keys[index];
371
- this[key] = options[key];
370
+ var key2 = keys[index];
371
+ this[key2] = options[key2];
372
372
  }
373
373
  if (this.start !== void 0) {
374
374
  if ("number" !== typeof this.start) {
@@ -406,8 +406,8 @@ var require_clone = __commonJS({
406
406
  var copy = { __proto__: getPrototypeOf(obj) };
407
407
  else
408
408
  var copy = /* @__PURE__ */ Object.create(null);
409
- Object.getOwnPropertyNames(obj).forEach(function(key) {
410
- Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
409
+ Object.getOwnPropertyNames(obj).forEach(function(key2) {
410
+ Object.defineProperty(copy, key2, Object.getOwnPropertyDescriptor(obj, key2));
411
411
  });
412
412
  return copy;
413
413
  }
@@ -914,15 +914,15 @@ var require_err = __commonJS({
914
914
  if (Array.isArray(err.errors)) {
915
915
  _err.aggregateErrors = err.errors.map((err2) => errSerializer(err2));
916
916
  }
917
- for (const key in err) {
918
- if (_err[key] === void 0) {
919
- const val = err[key];
917
+ for (const key2 in err) {
918
+ if (_err[key2] === void 0) {
919
+ const val = err[key2];
920
920
  if (isErrorLike(val)) {
921
- if (key !== "cause" && !Object.prototype.hasOwnProperty.call(val, seen)) {
922
- _err[key] = errSerializer(val);
921
+ if (key2 !== "cause" && !Object.prototype.hasOwnProperty.call(val, seen)) {
922
+ _err[key2] = errSerializer(val);
923
923
  }
924
924
  } else {
925
- _err[key] = val;
925
+ _err[key2] = val;
926
926
  }
927
927
  }
928
928
  }
@@ -957,15 +957,15 @@ var require_err_with_cause = __commonJS({
957
957
  if (isErrorLike(err.cause) && !Object.prototype.hasOwnProperty.call(err.cause, seen)) {
958
958
  _err.cause = errWithCauseSerializer(err.cause);
959
959
  }
960
- for (const key in err) {
961
- if (_err[key] === void 0) {
962
- const val = err[key];
960
+ for (const key2 in err) {
961
+ if (_err[key2] === void 0) {
962
+ const val = err[key2];
963
963
  if (isErrorLike(val)) {
964
964
  if (!Object.prototype.hasOwnProperty.call(val, seen)) {
965
- _err[key] = errWithCauseSerializer(val);
965
+ _err[key2] = errWithCauseSerializer(val);
966
966
  }
967
967
  } else {
968
- _err[key] = val;
968
+ _err[key2] = val;
969
969
  }
970
970
  }
971
971
  }
@@ -1205,9 +1205,9 @@ var require_redact = __commonJS({
1205
1205
  }
1206
1206
  if (typeof obj === "object") {
1207
1207
  const cloned = Object.create(Object.getPrototypeOf(obj));
1208
- for (const key in obj) {
1209
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
1210
- cloned[key] = deepClone(obj[key]);
1208
+ for (const key2 in obj) {
1209
+ if (Object.prototype.hasOwnProperty.call(obj, key2)) {
1210
+ cloned[key2] = deepClone(obj[key2]);
1211
1211
  }
1212
1212
  }
1213
1213
  return cloned;
@@ -1260,14 +1260,14 @@ var require_redact = __commonJS({
1260
1260
  function setValue(obj, parts, value) {
1261
1261
  let current = obj;
1262
1262
  for (let i = 0; i < parts.length - 1; i++) {
1263
- const key = parts[i];
1264
- if (typeof current !== "object" || current === null || !(key in current)) {
1263
+ const key2 = parts[i];
1264
+ if (typeof current !== "object" || current === null || !(key2 in current)) {
1265
1265
  return false;
1266
1266
  }
1267
- if (typeof current[key] !== "object" || current[key] === null) {
1267
+ if (typeof current[key2] !== "object" || current[key2] === null) {
1268
1268
  return false;
1269
1269
  }
1270
- current = current[key];
1270
+ current = current[key2];
1271
1271
  }
1272
1272
  const lastKey = parts[parts.length - 1];
1273
1273
  if (lastKey === "*") {
@@ -1276,9 +1276,9 @@ var require_redact = __commonJS({
1276
1276
  current[i] = value;
1277
1277
  }
1278
1278
  } else if (typeof current === "object" && current !== null) {
1279
- for (const key in current) {
1280
- if (Object.prototype.hasOwnProperty.call(current, key)) {
1281
- current[key] = value;
1279
+ for (const key2 in current) {
1280
+ if (Object.prototype.hasOwnProperty.call(current, key2)) {
1281
+ current[key2] = value;
1282
1282
  }
1283
1283
  }
1284
1284
  }
@@ -1292,14 +1292,14 @@ var require_redact = __commonJS({
1292
1292
  function removeKey(obj, parts) {
1293
1293
  let current = obj;
1294
1294
  for (let i = 0; i < parts.length - 1; i++) {
1295
- const key = parts[i];
1296
- if (typeof current !== "object" || current === null || !(key in current)) {
1295
+ const key2 = parts[i];
1296
+ if (typeof current !== "object" || current === null || !(key2 in current)) {
1297
1297
  return false;
1298
1298
  }
1299
- if (typeof current[key] !== "object" || current[key] === null) {
1299
+ if (typeof current[key2] !== "object" || current[key2] === null) {
1300
1300
  return false;
1301
1301
  }
1302
- current = current[key];
1302
+ current = current[key2];
1303
1303
  }
1304
1304
  const lastKey = parts[parts.length - 1];
1305
1305
  if (lastKey === "*") {
@@ -1308,9 +1308,9 @@ var require_redact = __commonJS({
1308
1308
  current[i] = void 0;
1309
1309
  }
1310
1310
  } else if (typeof current === "object" && current !== null) {
1311
- for (const key in current) {
1312
- if (Object.prototype.hasOwnProperty.call(current, key)) {
1313
- delete current[key];
1311
+ for (const key2 in current) {
1312
+ if (Object.prototype.hasOwnProperty.call(current, key2)) {
1313
+ delete current[key2];
1314
1314
  }
1315
1315
  }
1316
1316
  }
@@ -1395,19 +1395,19 @@ var require_redact = __commonJS({
1395
1395
  } else if (typeof current === "object" && current !== null) {
1396
1396
  if (remove) {
1397
1397
  const keysToDelete = [];
1398
- for (const key in current) {
1399
- if (Object.prototype.hasOwnProperty.call(current, key)) {
1400
- keysToDelete.push(key);
1398
+ for (const key2 in current) {
1399
+ if (Object.prototype.hasOwnProperty.call(current, key2)) {
1400
+ keysToDelete.push(key2);
1401
1401
  }
1402
1402
  }
1403
- for (const key of keysToDelete) {
1404
- delete current[key];
1403
+ for (const key2 of keysToDelete) {
1404
+ delete current[key2];
1405
1405
  }
1406
1406
  } else {
1407
- for (const key in current) {
1408
- const keyPath = [...parentParts, key];
1409
- const actualCensor = typeof censor === "function" ? censor(current[key], keyPath) : censor;
1410
- current[key] = actualCensor;
1407
+ for (const key2 in current) {
1408
+ const keyPath = [...parentParts, key2];
1409
+ const actualCensor = typeof censor === "function" ? censor(current[key2], keyPath) : censor;
1410
+ current[key2] = actualCensor;
1411
1411
  }
1412
1412
  }
1413
1413
  }
@@ -1427,9 +1427,9 @@ var require_redact = __commonJS({
1427
1427
  traverse(current[i], pathLength + 1);
1428
1428
  }
1429
1429
  } else if (typeof current === "object" && current !== null) {
1430
- for (const key in current) {
1431
- pathArray[pathLength] = key;
1432
- traverse(current[key], pathLength + 1);
1430
+ for (const key2 in current) {
1431
+ pathArray[pathLength] = key2;
1432
+ traverse(current[key2], pathLength + 1);
1433
1433
  }
1434
1434
  }
1435
1435
  } else if (pathLength < beforeWildcard.length) {
@@ -1516,12 +1516,12 @@ var require_redact = __commonJS({
1516
1516
  return cloned2;
1517
1517
  }
1518
1518
  const cloned = Object.create(Object.getPrototypeOf(source));
1519
- for (const key in source) {
1520
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1521
- if (pathMap.has(key) || pathMap.has("*")) {
1522
- cloned[key] = cloneSelectively(source[key], pathMap.get(key) || pathMap.get("*"));
1519
+ for (const key2 in source) {
1520
+ if (Object.prototype.hasOwnProperty.call(source, key2)) {
1521
+ if (pathMap.has(key2) || pathMap.has("*")) {
1522
+ cloned[key2] = cloneSelectively(source[key2], pathMap.get(key2) || pathMap.get("*"));
1523
1523
  } else {
1524
- cloned[key] = source[key];
1524
+ cloned[key2] = source[key2];
1525
1525
  }
1526
1526
  }
1527
1527
  }
@@ -2768,7 +2768,7 @@ var require_thread_stream = __commonJS({
2768
2768
  var { version } = require_package();
2769
2769
  var { EventEmitter: EventEmitter2 } = __require("events");
2770
2770
  var { Worker } = __require("worker_threads");
2771
- var { join: join4 } = __require("path");
2771
+ var { join: join5 } = __require("path");
2772
2772
  var { pathToFileURL } = __require("url");
2773
2773
  var { wait } = require_wait();
2774
2774
  var {
@@ -2804,7 +2804,7 @@ var require_thread_stream = __commonJS({
2804
2804
  function createWorker(stream, opts) {
2805
2805
  const { filename, workerData } = opts;
2806
2806
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
2807
- const toExecute = bundlerOverrides["thread-stream-worker"] || join4(__dirname, "lib", "worker.js");
2807
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join5(__dirname, "lib", "worker.js");
2808
2808
  const worker = new Worker(toExecute, {
2809
2809
  ...opts.workerOpts,
2810
2810
  trackUnmanagedFds: false,
@@ -3193,9 +3193,9 @@ var require_transport = __commonJS({
3193
3193
  "../../node_modules/.pnpm/pino@10.3.1/node_modules/pino/lib/transport.js"(exports, module) {
3194
3194
  "use strict";
3195
3195
  var { createRequire } = __require("module");
3196
- var { existsSync: existsSync3 } = __require("fs");
3196
+ var { existsSync: existsSync4 } = __require("fs");
3197
3197
  var getCallers = require_caller();
3198
- var { join: join4, isAbsolute: isAbsolute2, sep } = __require("path");
3198
+ var { join: join5, isAbsolute: isAbsolute2, sep } = __require("path");
3199
3199
  var { fileURLToPath } = __require("url");
3200
3200
  var sleep = require_atomic_sleep();
3201
3201
  var onExit = require_on_exit_leak_free();
@@ -3267,7 +3267,7 @@ var require_transport = __commonJS({
3267
3267
  return false;
3268
3268
  }
3269
3269
  }
3270
- return isAbsolute2(path5) && !existsSync3(path5);
3270
+ return isAbsolute2(path5) && !existsSync4(path5);
3271
3271
  }
3272
3272
  function stripQuotes(value) {
3273
3273
  const first = value[0];
@@ -3348,7 +3348,7 @@ var require_transport = __commonJS({
3348
3348
  throw new Error("only one of target or targets can be specified");
3349
3349
  }
3350
3350
  if (targets) {
3351
- target = bundlerOverrides["pino-worker"] || join4(__dirname, "worker.js");
3351
+ target = bundlerOverrides["pino-worker"] || join5(__dirname, "worker.js");
3352
3352
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
3353
3353
  return {
3354
3354
  ...dest,
@@ -3366,7 +3366,7 @@ var require_transport = __commonJS({
3366
3366
  });
3367
3367
  });
3368
3368
  } else if (pipeline) {
3369
- target = bundlerOverrides["pino-worker"] || join4(__dirname, "worker.js");
3369
+ target = bundlerOverrides["pino-worker"] || join5(__dirname, "worker.js");
3370
3370
  options.pipelines = [pipeline.map((dest) => {
3371
3371
  return {
3372
3372
  ...dest,
@@ -3389,7 +3389,7 @@ var require_transport = __commonJS({
3389
3389
  return origin;
3390
3390
  }
3391
3391
  if (origin === "pino/file") {
3392
- return join4(__dirname, "..", "file.js");
3392
+ return join5(__dirname, "..", "file.js");
3393
3393
  }
3394
3394
  let fixTarget2;
3395
3395
  for (const filePath of callers) {
@@ -3529,15 +3529,15 @@ var require_tools = __commonJS({
3529
3529
  }
3530
3530
  const wildcardStringifier = stringifiers[wildcardFirstSym];
3531
3531
  let propStr = "";
3532
- for (const key in obj) {
3533
- value = obj[key];
3534
- if (Object.prototype.hasOwnProperty.call(obj, key) && value !== void 0) {
3535
- if (serializers[key]) {
3536
- value = serializers[key](value);
3537
- } else if (key === errorKey && serializers.err) {
3532
+ for (const key2 in obj) {
3533
+ value = obj[key2];
3534
+ if (Object.prototype.hasOwnProperty.call(obj, key2) && value !== void 0) {
3535
+ if (serializers[key2]) {
3536
+ value = serializers[key2](value);
3537
+ } else if (key2 === errorKey && serializers.err) {
3538
3538
  value = serializers.err(value);
3539
3539
  }
3540
- const stringifier = stringifiers[key] || wildcardStringifier;
3540
+ const stringifier = stringifiers[key2] || wildcardStringifier;
3541
3541
  switch (typeof value) {
3542
3542
  case "undefined":
3543
3543
  case "function":
@@ -3557,7 +3557,7 @@ var require_tools = __commonJS({
3557
3557
  value = (stringifier || stringify2)(value, stringifySafe);
3558
3558
  }
3559
3559
  if (value === void 0) continue;
3560
- const strKey = asString(key);
3560
+ const strKey = asString(key2);
3561
3561
  propStr += "," + strKey + ":" + value;
3562
3562
  }
3563
3563
  }
@@ -3602,14 +3602,14 @@ var require_tools = __commonJS({
3602
3602
  const serializers = instance[serializersSym];
3603
3603
  const formatter = instance[formattersSym].bindings;
3604
3604
  bindings = formatter(bindings);
3605
- for (const key in bindings) {
3606
- value = bindings[key];
3607
- const valid = (key.length < 5 || key !== "level" && key !== "serializers" && key !== "formatters" && key !== "customLevels") && bindings.hasOwnProperty(key) && value !== void 0;
3605
+ for (const key2 in bindings) {
3606
+ value = bindings[key2];
3607
+ const valid = (key2.length < 5 || key2 !== "level" && key2 !== "serializers" && key2 !== "formatters" && key2 !== "customLevels") && bindings.hasOwnProperty(key2) && value !== void 0;
3608
3608
  if (valid === true) {
3609
- value = serializers[key] ? serializers[key](value) : value;
3610
- value = (stringifiers[key] || wildcardStringifier || stringify2)(value, stringifySafe);
3609
+ value = serializers[key2] ? serializers[key2](value) : value;
3610
+ value = (stringifiers[key2] || wildcardStringifier || stringify2)(value, stringifySafe);
3611
3611
  if (value === void 0) continue;
3612
- data += ',"' + key + '":' + value;
3612
+ data += ',"' + key2 + '":' + value;
3613
3613
  }
3614
3614
  }
3615
3615
  return data;
@@ -3845,12 +3845,12 @@ var require_levels = __commonJS({
3845
3845
  const useOnlyCustomLevelsVal = this[useOnlyCustomLevelsSym];
3846
3846
  const levelComparison = this[levelCompSym];
3847
3847
  const hook = this[hooksSym].logMethod;
3848
- for (const key in values) {
3849
- if (levelComparison(values[key], levelVal) === false) {
3850
- this[key] = noop;
3848
+ for (const key2 in values) {
3849
+ if (levelComparison(values[key2], levelVal) === false) {
3850
+ this[key2] = noop;
3851
3851
  continue;
3852
3852
  }
3853
- this[key] = isStandardLevel(key, useOnlyCustomLevelsVal) ? levelMethods[key](hook) : genLog(values[key], hook);
3853
+ this[key2] = isStandardLevel(key2, useOnlyCustomLevelsVal) ? levelMethods[key2](hook) : genLog(values[key2], hook);
3854
3854
  }
3855
3855
  this.emit(
3856
3856
  "level-change",
@@ -3902,7 +3902,7 @@ var require_levels = __commonJS({
3902
3902
  function assertDefaultLevelFound(defaultLevel, customLevels, useOnlyCustomLevels) {
3903
3903
  if (typeof defaultLevel === "number") {
3904
3904
  const values = [].concat(
3905
- Object.keys(customLevels || {}).map((key) => customLevels[key]),
3905
+ Object.keys(customLevels || {}).map((key2) => customLevels[key2]),
3906
3906
  useOnlyCustomLevels ? [] : Object.keys(nums).map((level) => +level),
3907
3907
  Infinity
3908
3908
  );
@@ -4171,7 +4171,7 @@ var require_proto = __commonJS({
4171
4171
  if (mixin) {
4172
4172
  obj = mixinMergeStrategy(obj, mixin(obj, num, this));
4173
4173
  }
4174
- const s = this[asJsonSym](obj, msg, num, t);
4174
+ const s2 = this[asJsonSym](obj, msg, num, t);
4175
4175
  const stream = this[streamSym];
4176
4176
  if (stream[needsMetadataGsym] === true) {
4177
4177
  stream.lastLevel = num;
@@ -4180,7 +4180,7 @@ var require_proto = __commonJS({
4180
4180
  stream.lastTime = t.slice(this[timeSliceIndexSym]);
4181
4181
  stream.lastLogger = this;
4182
4182
  }
4183
- stream.write(streamWriteHook ? streamWriteHook(s) : s);
4183
+ stream.write(streamWriteHook ? streamWriteHook(s2) : s2);
4184
4184
  }
4185
4185
  function flush(cb) {
4186
4186
  if (cb != null && typeof cb !== "function") {
@@ -4280,28 +4280,28 @@ var require_safe_stable_stringify = __commonJS({
4280
4280
  }
4281
4281
  return value === void 0 ? true : value;
4282
4282
  }
4283
- function getBooleanOption(options, key) {
4283
+ function getBooleanOption(options, key2) {
4284
4284
  let value;
4285
- if (hasOwnProperty.call(options, key)) {
4286
- value = options[key];
4285
+ if (hasOwnProperty.call(options, key2)) {
4286
+ value = options[key2];
4287
4287
  if (typeof value !== "boolean") {
4288
- throw new TypeError(`The "${key}" argument must be of type boolean`);
4288
+ throw new TypeError(`The "${key2}" argument must be of type boolean`);
4289
4289
  }
4290
4290
  }
4291
4291
  return value === void 0 ? true : value;
4292
4292
  }
4293
- function getPositiveIntegerOption(options, key) {
4293
+ function getPositiveIntegerOption(options, key2) {
4294
4294
  let value;
4295
- if (hasOwnProperty.call(options, key)) {
4296
- value = options[key];
4295
+ if (hasOwnProperty.call(options, key2)) {
4296
+ value = options[key2];
4297
4297
  if (typeof value !== "number") {
4298
- throw new TypeError(`The "${key}" argument must be of type number`);
4298
+ throw new TypeError(`The "${key2}" argument must be of type number`);
4299
4299
  }
4300
4300
  if (!Number.isInteger(value)) {
4301
- throw new TypeError(`The "${key}" argument must be an integer`);
4301
+ throw new TypeError(`The "${key2}" argument must be an integer`);
4302
4302
  }
4303
4303
  if (value < 1) {
4304
- throw new RangeError(`The "${key}" argument must be >= 1`);
4304
+ throw new RangeError(`The "${key2}" argument must be >= 1`);
4305
4305
  }
4306
4306
  }
4307
4307
  return value === void 0 ? Infinity : value;
@@ -4353,12 +4353,12 @@ var require_safe_stable_stringify = __commonJS({
4353
4353
  const comparator = typeof deterministic === "function" ? deterministic : void 0;
4354
4354
  const maximumDepth = getPositiveIntegerOption(options, "maximumDepth");
4355
4355
  const maximumBreadth = getPositiveIntegerOption(options, "maximumBreadth");
4356
- function stringifyFnReplacer(key, parent, stack, replacer, spacer, indentation) {
4357
- let value = parent[key];
4356
+ function stringifyFnReplacer(key2, parent, stack, replacer, spacer, indentation) {
4357
+ let value = parent[key2];
4358
4358
  if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
4359
- value = value.toJSON(key);
4359
+ value = value.toJSON(key2);
4360
4360
  }
4361
- value = replacer.call(parent, key, value);
4361
+ value = replacer.call(parent, key2, value);
4362
4362
  switch (typeof value) {
4363
4363
  case "string":
4364
4364
  return strEscape(value);
@@ -4370,7 +4370,7 @@ var require_safe_stable_stringify = __commonJS({
4370
4370
  return circularValue;
4371
4371
  }
4372
4372
  let res = "";
4373
- let join4 = ",";
4373
+ let join5 = ",";
4374
4374
  const originalIndentation = indentation;
4375
4375
  if (Array.isArray(value)) {
4376
4376
  if (value.length === 0) {
@@ -4384,7 +4384,7 @@ var require_safe_stable_stringify = __commonJS({
4384
4384
  indentation += spacer;
4385
4385
  res += `
4386
4386
  ${indentation}`;
4387
- join4 = `,
4387
+ join5 = `,
4388
4388
  ${indentation}`;
4389
4389
  }
4390
4390
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -4392,13 +4392,13 @@ ${indentation}`;
4392
4392
  for (; i < maximumValuesToStringify - 1; i++) {
4393
4393
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
4394
4394
  res += tmp2 !== void 0 ? tmp2 : "null";
4395
- res += join4;
4395
+ res += join5;
4396
4396
  }
4397
4397
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
4398
4398
  res += tmp !== void 0 ? tmp : "null";
4399
4399
  if (value.length - 1 > maximumBreadth) {
4400
4400
  const removedKeys = value.length - maximumBreadth - 1;
4401
- res += `${join4}"... ${getItemCount(removedKeys)} not stringified"`;
4401
+ res += `${join5}"... ${getItemCount(removedKeys)} not stringified"`;
4402
4402
  }
4403
4403
  if (spacer !== "") {
4404
4404
  res += `
@@ -4419,7 +4419,7 @@ ${originalIndentation}`;
4419
4419
  let separator = "";
4420
4420
  if (spacer !== "") {
4421
4421
  indentation += spacer;
4422
- join4 = `,
4422
+ join5 = `,
4423
4423
  ${indentation}`;
4424
4424
  whitespace = " ";
4425
4425
  }
@@ -4429,17 +4429,17 @@ ${indentation}`;
4429
4429
  }
4430
4430
  stack.push(value);
4431
4431
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
4432
- const key2 = keys[i];
4433
- const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
4432
+ const key3 = keys[i];
4433
+ const tmp = stringifyFnReplacer(key3, value, stack, replacer, spacer, indentation);
4434
4434
  if (tmp !== void 0) {
4435
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
4436
- separator = join4;
4435
+ res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
4436
+ separator = join5;
4437
4437
  }
4438
4438
  }
4439
4439
  if (keyLength > maximumBreadth) {
4440
4440
  const removedKeys = keyLength - maximumBreadth;
4441
4441
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
4442
- separator = join4;
4442
+ separator = join5;
4443
4443
  }
4444
4444
  if (spacer !== "" && separator.length > 1) {
4445
4445
  res = `
@@ -4464,9 +4464,9 @@ ${originalIndentation}`;
4464
4464
  return fail ? fail(value) : void 0;
4465
4465
  }
4466
4466
  }
4467
- function stringifyArrayReplacer(key, value, stack, replacer, spacer, indentation) {
4467
+ function stringifyArrayReplacer(key2, value, stack, replacer, spacer, indentation) {
4468
4468
  if (typeof value === "object" && value !== null && typeof value.toJSON === "function") {
4469
- value = value.toJSON(key);
4469
+ value = value.toJSON(key2);
4470
4470
  }
4471
4471
  switch (typeof value) {
4472
4472
  case "string":
@@ -4480,7 +4480,7 @@ ${originalIndentation}`;
4480
4480
  }
4481
4481
  const originalIndentation = indentation;
4482
4482
  let res = "";
4483
- let join4 = ",";
4483
+ let join5 = ",";
4484
4484
  if (Array.isArray(value)) {
4485
4485
  if (value.length === 0) {
4486
4486
  return "[]";
@@ -4493,7 +4493,7 @@ ${originalIndentation}`;
4493
4493
  indentation += spacer;
4494
4494
  res += `
4495
4495
  ${indentation}`;
4496
- join4 = `,
4496
+ join5 = `,
4497
4497
  ${indentation}`;
4498
4498
  }
4499
4499
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -4501,13 +4501,13 @@ ${indentation}`;
4501
4501
  for (; i < maximumValuesToStringify - 1; i++) {
4502
4502
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
4503
4503
  res += tmp2 !== void 0 ? tmp2 : "null";
4504
- res += join4;
4504
+ res += join5;
4505
4505
  }
4506
4506
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
4507
4507
  res += tmp !== void 0 ? tmp : "null";
4508
4508
  if (value.length - 1 > maximumBreadth) {
4509
4509
  const removedKeys = value.length - maximumBreadth - 1;
4510
- res += `${join4}"... ${getItemCount(removedKeys)} not stringified"`;
4510
+ res += `${join5}"... ${getItemCount(removedKeys)} not stringified"`;
4511
4511
  }
4512
4512
  if (spacer !== "") {
4513
4513
  res += `
@@ -4520,16 +4520,16 @@ ${originalIndentation}`;
4520
4520
  let whitespace = "";
4521
4521
  if (spacer !== "") {
4522
4522
  indentation += spacer;
4523
- join4 = `,
4523
+ join5 = `,
4524
4524
  ${indentation}`;
4525
4525
  whitespace = " ";
4526
4526
  }
4527
4527
  let separator = "";
4528
- for (const key2 of replacer) {
4529
- const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
4528
+ for (const key3 of replacer) {
4529
+ const tmp = stringifyArrayReplacer(key3, value[key3], stack, replacer, spacer, indentation);
4530
4530
  if (tmp !== void 0) {
4531
- res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
4532
- separator = join4;
4531
+ res += `${separator}${strEscape(key3)}:${whitespace}${tmp}`;
4532
+ separator = join5;
4533
4533
  }
4534
4534
  }
4535
4535
  if (spacer !== "" && separator.length > 1) {
@@ -4555,7 +4555,7 @@ ${originalIndentation}`;
4555
4555
  return fail ? fail(value) : void 0;
4556
4556
  }
4557
4557
  }
4558
- function stringifyIndent(key, value, stack, spacer, indentation) {
4558
+ function stringifyIndent(key2, value, stack, spacer, indentation) {
4559
4559
  switch (typeof value) {
4560
4560
  case "string":
4561
4561
  return strEscape(value);
@@ -4564,9 +4564,9 @@ ${originalIndentation}`;
4564
4564
  return "null";
4565
4565
  }
4566
4566
  if (typeof value.toJSON === "function") {
4567
- value = value.toJSON(key);
4567
+ value = value.toJSON(key2);
4568
4568
  if (typeof value !== "object") {
4569
- return stringifyIndent(key, value, stack, spacer, indentation);
4569
+ return stringifyIndent(key2, value, stack, spacer, indentation);
4570
4570
  }
4571
4571
  if (value === null) {
4572
4572
  return "null";
@@ -4587,20 +4587,20 @@ ${originalIndentation}`;
4587
4587
  indentation += spacer;
4588
4588
  let res2 = `
4589
4589
  ${indentation}`;
4590
- const join5 = `,
4590
+ const join6 = `,
4591
4591
  ${indentation}`;
4592
4592
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
4593
4593
  let i = 0;
4594
4594
  for (; i < maximumValuesToStringify - 1; i++) {
4595
4595
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
4596
4596
  res2 += tmp2 !== void 0 ? tmp2 : "null";
4597
- res2 += join5;
4597
+ res2 += join6;
4598
4598
  }
4599
4599
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
4600
4600
  res2 += tmp !== void 0 ? tmp : "null";
4601
4601
  if (value.length - 1 > maximumBreadth) {
4602
4602
  const removedKeys = value.length - maximumBreadth - 1;
4603
- res2 += `${join5}"... ${getItemCount(removedKeys)} not stringified"`;
4603
+ res2 += `${join6}"... ${getItemCount(removedKeys)} not stringified"`;
4604
4604
  }
4605
4605
  res2 += `
4606
4606
  ${originalIndentation}`;
@@ -4616,33 +4616,33 @@ ${originalIndentation}`;
4616
4616
  return '"[Object]"';
4617
4617
  }
4618
4618
  indentation += spacer;
4619
- const join4 = `,
4619
+ const join5 = `,
4620
4620
  ${indentation}`;
4621
4621
  let res = "";
4622
4622
  let separator = "";
4623
4623
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
4624
4624
  if (isTypedArrayWithEntries(value)) {
4625
- res += stringifyTypedArray(value, join4, maximumBreadth);
4625
+ res += stringifyTypedArray(value, join5, maximumBreadth);
4626
4626
  keys = keys.slice(value.length);
4627
4627
  maximumPropertiesToStringify -= value.length;
4628
- separator = join4;
4628
+ separator = join5;
4629
4629
  }
4630
4630
  if (deterministic) {
4631
4631
  keys = sort(keys, comparator);
4632
4632
  }
4633
4633
  stack.push(value);
4634
4634
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
4635
- const key2 = keys[i];
4636
- const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
4635
+ const key3 = keys[i];
4636
+ const tmp = stringifyIndent(key3, value[key3], stack, spacer, indentation);
4637
4637
  if (tmp !== void 0) {
4638
- res += `${separator}${strEscape(key2)}: ${tmp}`;
4639
- separator = join4;
4638
+ res += `${separator}${strEscape(key3)}: ${tmp}`;
4639
+ separator = join5;
4640
4640
  }
4641
4641
  }
4642
4642
  if (keyLength > maximumBreadth) {
4643
4643
  const removedKeys = keyLength - maximumBreadth;
4644
4644
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
4645
- separator = join4;
4645
+ separator = join5;
4646
4646
  }
4647
4647
  if (separator !== "") {
4648
4648
  res = `
@@ -4667,7 +4667,7 @@ ${originalIndentation}`;
4667
4667
  return fail ? fail(value) : void 0;
4668
4668
  }
4669
4669
  }
4670
- function stringifySimple(key, value, stack) {
4670
+ function stringifySimple(key2, value, stack) {
4671
4671
  switch (typeof value) {
4672
4672
  case "string":
4673
4673
  return strEscape(value);
@@ -4676,9 +4676,9 @@ ${originalIndentation}`;
4676
4676
  return "null";
4677
4677
  }
4678
4678
  if (typeof value.toJSON === "function") {
4679
- value = value.toJSON(key);
4679
+ value = value.toJSON(key2);
4680
4680
  if (typeof value !== "object") {
4681
- return stringifySimple(key, value, stack);
4681
+ return stringifySimple(key2, value, stack);
4682
4682
  }
4683
4683
  if (value === null) {
4684
4684
  return "null";
@@ -4734,10 +4734,10 @@ ${originalIndentation}`;
4734
4734
  }
4735
4735
  stack.push(value);
4736
4736
  for (let i = 0; i < maximumPropertiesToStringify; i++) {
4737
- const key2 = keys[i];
4738
- const tmp = stringifySimple(key2, value[key2], stack);
4737
+ const key3 = keys[i];
4738
+ const tmp = stringifySimple(key3, value[key3], stack);
4739
4739
  if (tmp !== void 0) {
4740
- res += `${separator}${strEscape(key2)}:${tmp}`;
4740
+ res += `${separator}${strEscape(key3)}:${tmp}`;
4741
4741
  separator = ",";
4742
4742
  }
4743
4743
  }
@@ -4905,7 +4905,7 @@ var require_multistream = __commonJS({
4905
4905
  }
4906
4906
  function remove(id) {
4907
4907
  const { streams } = this;
4908
- const index = streams.findIndex((s) => s.id === id);
4908
+ const index = streams.findIndex((s2) => s2.id === id);
4909
4909
  if (index >= 0) {
4910
4910
  streams.splice(index, 1);
4911
4911
  streams.sort(compareByLevel);
@@ -5779,8 +5779,8 @@ function getProperty(object, path5, value) {
5779
5779
  return value;
5780
5780
  }
5781
5781
  for (let index = 0; index < pathArray.length; index++) {
5782
- const key = pathArray[index];
5783
- object = object[key];
5782
+ const key2 = pathArray[index];
5783
+ object = object[key2];
5784
5784
  if (object === void 0 || object === null) {
5785
5785
  if (index !== pathArray.length - 1) {
5786
5786
  return value;
@@ -5800,15 +5800,15 @@ function setProperty(object, path5, value) {
5800
5800
  return object;
5801
5801
  }
5802
5802
  for (let index = 0; index < pathArray.length; index++) {
5803
- const key = pathArray[index];
5803
+ const key2 = pathArray[index];
5804
5804
  if (index === pathArray.length - 1) {
5805
- object[key] = value;
5806
- } else if (!isObject(object[key])) {
5805
+ object[key2] = value;
5806
+ } else if (!isObject(object[key2])) {
5807
5807
  const nextKey = pathArray[index + 1];
5808
5808
  const shouldCreateArray = typeof nextKey === "number";
5809
- object[key] = shouldCreateArray ? [] : {};
5809
+ object[key2] = shouldCreateArray ? [] : {};
5810
5810
  }
5811
- object = object[key];
5811
+ object = object[key2];
5812
5812
  }
5813
5813
  return root;
5814
5814
  }
@@ -5821,16 +5821,16 @@ function deleteProperty(object, path5) {
5821
5821
  return false;
5822
5822
  }
5823
5823
  for (let index = 0; index < pathArray.length; index++) {
5824
- const key = pathArray[index];
5824
+ const key2 = pathArray[index];
5825
5825
  if (index === pathArray.length - 1) {
5826
- const existed = Object.hasOwn(object, key);
5826
+ const existed = Object.hasOwn(object, key2);
5827
5827
  if (!existed) {
5828
5828
  return false;
5829
5829
  }
5830
- delete object[key];
5830
+ delete object[key2];
5831
5831
  return true;
5832
5832
  }
5833
- object = object[key];
5833
+ object = object[key2];
5834
5834
  if (!isObject(object)) {
5835
5835
  return false;
5836
5836
  }
@@ -5844,11 +5844,11 @@ function hasProperty(object, path5) {
5844
5844
  if (pathArray.length === 0) {
5845
5845
  return false;
5846
5846
  }
5847
- for (const key of pathArray) {
5848
- if (!isObject(object) || !(key in object)) {
5847
+ for (const key2 of pathArray) {
5848
+ if (!isObject(object) || !(key2 in object)) {
5849
5849
  return false;
5850
5850
  }
5851
- object = object[key];
5851
+ object = object[key2];
5852
5852
  }
5853
5853
  return true;
5854
5854
  }
@@ -5938,26 +5938,26 @@ var Configstore = class {
5938
5938
  get size() {
5939
5939
  return Object.keys(this.all).length;
5940
5940
  }
5941
- get(key) {
5942
- return getProperty(this.all, key);
5941
+ get(key2) {
5942
+ return getProperty(this.all, key2);
5943
5943
  }
5944
- set(key, value) {
5944
+ set(key2, value) {
5945
5945
  const config2 = this.all;
5946
- if (typeof key === "object" && arguments.length === 1) {
5947
- for (const k of Object.keys(key)) {
5948
- setProperty(config2, k, key[k]);
5946
+ if (typeof key2 === "object" && arguments.length === 1) {
5947
+ for (const k of Object.keys(key2)) {
5948
+ setProperty(config2, k, key2[k]);
5949
5949
  }
5950
5950
  } else {
5951
- setProperty(config2, key, value);
5951
+ setProperty(config2, key2, value);
5952
5952
  }
5953
5953
  this.all = config2;
5954
5954
  }
5955
- has(key) {
5956
- return hasProperty(this.all, key);
5955
+ has(key2) {
5956
+ return hasProperty(this.all, key2);
5957
5957
  }
5958
- delete(key) {
5958
+ delete(key2) {
5959
5959
  const config2 = this.all;
5960
- deleteProperty(config2, key);
5960
+ deleteProperty(config2, key2);
5961
5961
  this.all = config2;
5962
5962
  }
5963
5963
  clear() {
@@ -5969,9 +5969,35 @@ var Configstore = class {
5969
5969
  };
5970
5970
 
5971
5971
  // ../core/src/global-config.ts
5972
- import { existsSync, readFileSync } from "fs";
5972
+ import { existsSync, readFileSync, statSync } from "fs";
5973
5973
  import { join } from "path";
5974
5974
  import { homedir } from "os";
5975
+ var EXTERNAL_CONFIG_MAX_BYTES = 1 * 1024 * 1024;
5976
+ var EXTERNAL_CONFIG_TTL_MS = 5e3;
5977
+ var externalConfigCache = /* @__PURE__ */ new Map();
5978
+ function readExternalJson(path5) {
5979
+ const now = Date.now();
5980
+ const cached = externalConfigCache.get(path5);
5981
+ if (cached && now - cached.at < EXTERNAL_CONFIG_TTL_MS) {
5982
+ return cached.value;
5983
+ }
5984
+ let value = null;
5985
+ try {
5986
+ if (existsSync(path5)) {
5987
+ const { size } = statSync(path5);
5988
+ if (size <= EXTERNAL_CONFIG_MAX_BYTES) {
5989
+ const parsed = JSON.parse(readFileSync(path5, "utf-8"));
5990
+ if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
5991
+ value = parsed;
5992
+ }
5993
+ }
5994
+ }
5995
+ } catch {
5996
+ value = null;
5997
+ }
5998
+ externalConfigCache.set(path5, { at: now, value });
5999
+ return value;
6000
+ }
5975
6001
  var SENSITIVE_KEYS = /* @__PURE__ */ new Set(["DISCORD_TOKEN", "ANTHROPIC_API_KEY", "CODEX_API_KEY"]);
5976
6002
  var VALID_KEYS = /* @__PURE__ */ new Set([
5977
6003
  "DISCORD_TOKEN",
@@ -6047,11 +6073,11 @@ function getStore() {
6047
6073
  }
6048
6074
  return store;
6049
6075
  }
6050
- function validateConfigValue(key, value) {
6051
- if (!VALID_KEYS.has(key)) {
6052
- return `Unknown config key: ${key}. Valid keys: ${Array.from(VALID_KEYS).join(", ")}`;
6076
+ function validateConfigValue(key2, value) {
6077
+ if (!VALID_KEYS.has(key2)) {
6078
+ return `Unknown config key: ${key2}. Valid keys: ${Array.from(VALID_KEYS).join(", ")}`;
6053
6079
  }
6054
- switch (key) {
6080
+ switch (key2) {
6055
6081
  case "CODEX_SANDBOX_MODE":
6056
6082
  if (!CODEX_SANDBOX_MODES.has(value)) {
6057
6083
  return `Invalid value for CODEX_SANDBOX_MODE. Expected one of: ${Array.from(CODEX_SANDBOX_MODES).join(", ")}`;
@@ -6075,7 +6101,7 @@ function validateConfigValue(key, value) {
6075
6101
  case "TEXT_CHUNK_LIMIT": {
6076
6102
  const n = Number(value);
6077
6103
  if (!Number.isInteger(n) || n < 1 || n > 2e3) {
6078
- return `Invalid value for ${key}. Expected an integer between 1 and 2000`;
6104
+ return `Invalid value for ${key2}. Expected an integer between 1 and 2000`;
6079
6105
  }
6080
6106
  break;
6081
6107
  }
@@ -6109,7 +6135,7 @@ function validateConfigValue(key, value) {
6109
6135
  case "HEALTH_CHECK_IDLE_THRESHOLD_MS": {
6110
6136
  const n = Number(value);
6111
6137
  if (!Number.isInteger(n) || n < 0) {
6112
- return `Invalid value for ${key}. Expected a non-negative integer`;
6138
+ return `Invalid value for ${key2}. Expected a non-negative integer`;
6113
6139
  }
6114
6140
  break;
6115
6141
  }
@@ -6122,7 +6148,7 @@ function validateConfigValue(key, value) {
6122
6148
  case "MAX_ACTIVE_SESSIONS": {
6123
6149
  const n = Number(value);
6124
6150
  if (!Number.isInteger(n) || n <= 0) {
6125
- return `Invalid value for ${key}. Expected a positive integer`;
6151
+ return `Invalid value for ${key2}. Expected a positive integer`;
6126
6152
  }
6127
6153
  break;
6128
6154
  }
@@ -6168,68 +6194,59 @@ function validateConfigValue(key, value) {
6168
6194
  }
6169
6195
  return null;
6170
6196
  }
6171
- function maskSensitive(key, value) {
6172
- if (!SENSITIVE_KEYS.has(key)) return value;
6197
+ function maskSensitive(key2, value) {
6198
+ if (!SENSITIVE_KEYS.has(key2)) return value;
6173
6199
  if (value.length <= 8) return "********";
6174
6200
  return `${value.slice(0, 4)}********${value.slice(-4)}`;
6175
6201
  }
6176
- function readAnthropicConfig(key) {
6202
+ function readAnthropicConfig(key2) {
6177
6203
  const path5 = join(homedir(), ".claude", "settings.json");
6178
- try {
6179
- if (existsSync(path5)) {
6180
- const content = readFileSync(path5, "utf-8");
6181
- const config2 = JSON.parse(content);
6182
- const env2 = config2.env || {};
6183
- if (key === "ANTHROPIC_API_KEY") {
6184
- return env2.ANTHROPIC_AUTH_TOKEN || env2.ANTHROPIC_API_KEY;
6185
- }
6186
- if (key === "ANTHROPIC_BASE_URL") {
6187
- return env2.ANTHROPIC_BASE_URL;
6188
- }
6189
- }
6190
- } catch {
6204
+ const config2 = readExternalJson(path5);
6205
+ if (!config2) return void 0;
6206
+ const env2 = config2.env && typeof config2.env === "object" ? config2.env : {};
6207
+ if (key2 === "ANTHROPIC_API_KEY") {
6208
+ const token = env2.ANTHROPIC_AUTH_TOKEN ?? env2.ANTHROPIC_API_KEY;
6209
+ return typeof token === "string" ? token : void 0;
6210
+ }
6211
+ if (key2 === "ANTHROPIC_BASE_URL") {
6212
+ return typeof env2.ANTHROPIC_BASE_URL === "string" ? env2.ANTHROPIC_BASE_URL : void 0;
6191
6213
  }
6192
6214
  return void 0;
6193
6215
  }
6194
- function readCodexConfig(key) {
6216
+ function readCodexConfig(key2) {
6195
6217
  const path5 = join(homedir(), ".codex", "config.json");
6196
- try {
6197
- if (existsSync(path5)) {
6198
- const content = readFileSync(path5, "utf-8");
6199
- const config2 = JSON.parse(content);
6200
- if (key === "CODEX_API_KEY" && config2.api_key) {
6201
- return config2.api_key;
6202
- }
6203
- if (key === "CODEX_BASE_URL" && config2.base_url) {
6204
- return config2.base_url;
6205
- }
6206
- }
6207
- } catch {
6218
+ const config2 = readExternalJson(path5);
6219
+ if (!config2) return void 0;
6220
+ if (key2 === "CODEX_API_KEY" && typeof config2.api_key === "string") {
6221
+ return config2.api_key;
6222
+ }
6223
+ if (key2 === "CODEX_BASE_URL" && typeof config2.base_url === "string") {
6224
+ return config2.base_url;
6208
6225
  }
6209
6226
  return void 0;
6210
6227
  }
6211
- function getConfigValue(key) {
6212
- const storeValue = getStore().get(key);
6228
+ function getConfigValue(key2) {
6229
+ const storeValue = getStore().get(key2);
6213
6230
  if (storeValue !== void 0) {
6214
6231
  return storeValue;
6215
6232
  }
6216
- const envValue = process.env[key];
6233
+ const envValue = process.env[key2];
6217
6234
  if (envValue !== void 0) {
6218
6235
  return envValue;
6219
6236
  }
6220
- if (key === "ANTHROPIC_API_KEY" || key === "ANTHROPIC_BASE_URL") {
6221
- return readAnthropicConfig(key);
6237
+ if (key2 === "ANTHROPIC_API_KEY" || key2 === "ANTHROPIC_BASE_URL") {
6238
+ return readAnthropicConfig(key2);
6222
6239
  }
6223
- if (key === "CODEX_API_KEY" || key === "CODEX_BASE_URL") {
6224
- return readCodexConfig(key);
6240
+ if (key2 === "CODEX_API_KEY" || key2 === "CODEX_BASE_URL") {
6241
+ return readCodexConfig(key2);
6225
6242
  }
6226
6243
  return void 0;
6227
6244
  }
6228
- function setConfigValue(key, value) {
6229
- getStore().set(key, value);
6245
+ function setConfigValue(key2, value) {
6246
+ getStore().set(key2, value);
6230
6247
  }
6231
- function deleteConfigValue(key) {
6232
- getStore().delete(key);
6248
+ function deleteConfigValue(key2) {
6249
+ getStore().delete(key2);
6233
6250
  }
6234
6251
  function getAllConfig() {
6235
6252
  return getStore().all ?? {};
@@ -6241,39 +6258,39 @@ function getConfigPath() {
6241
6258
  // ../core/src/config.ts
6242
6259
  import { homedir as homedir2 } from "os";
6243
6260
  import { join as join2 } from "path";
6244
- function required(key) {
6245
- const value = getConfigValue(key);
6261
+ function required(key2) {
6262
+ const value = getConfigValue(key2);
6246
6263
  if (!value) {
6247
6264
  if (process.env.NODE_ENV === "test" || process.env.VITEST === "true") {
6248
- return `test-${key.toLowerCase()}`;
6265
+ return `test-${key2.toLowerCase()}`;
6249
6266
  }
6250
- console.error(`ERROR: ${key} is not configured.`);
6267
+ console.error(`ERROR: ${key2} is not configured.`);
6251
6268
  console.error("Run \x1B[36mworkspacecord config setup\x1B[0m to configure.");
6252
6269
  process.exit(1);
6253
6270
  }
6254
6271
  return value;
6255
6272
  }
6256
- function optional(key, fallback) {
6257
- return getConfigValue(key) ?? fallback;
6273
+ function optional(key2, fallback) {
6274
+ return getConfigValue(key2) ?? fallback;
6258
6275
  }
6259
- function optionalList(key, fallback = []) {
6260
- const value = getConfigValue(key);
6276
+ function optionalList(key2, fallback = []) {
6277
+ const value = getConfigValue(key2);
6261
6278
  if (!value) return fallback;
6262
6279
  return value.split(",").map((item) => item.trim()).filter(Boolean);
6263
6280
  }
6264
- function optionalInt(key, fallback) {
6265
- const value = getConfigValue(key);
6281
+ function optionalInt(key2, fallback) {
6282
+ const value = getConfigValue(key2);
6266
6283
  if (!value) return fallback;
6267
6284
  const n = parseInt(value, 10);
6268
6285
  return Number.isNaN(n) ? fallback : n;
6269
6286
  }
6270
- function optionalBool(key, fallback) {
6271
- const value = getConfigValue(key);
6287
+ function optionalBool(key2, fallback) {
6288
+ const value = getConfigValue(key2);
6272
6289
  if (!value) return fallback;
6273
6290
  return value === "true" || value === "1";
6274
6291
  }
6275
- function optionalEnum(key, fallback, allowed) {
6276
- const value = getConfigValue(key);
6292
+ function optionalEnum(key2, fallback, allowed) {
6293
+ const value = getConfigValue(key2);
6277
6294
  if (!value) return fallback;
6278
6295
  return allowed.includes(value) ? value : fallback;
6279
6296
  }
@@ -6315,7 +6332,26 @@ var config = {
6315
6332
  healthReportEnabled: optionalBool("HEALTH_REPORT_ENABLED", true),
6316
6333
  healthCheckStuckThresholdMs: optionalInt("HEALTH_CHECK_STUCK_THRESHOLD_MS", 18e5),
6317
6334
  healthCheckIdleThresholdMs: optionalInt("HEALTH_CHECK_IDLE_THRESHOLD_MS", 72e5),
6318
- hookSecret: optional("HOOK_SECRET", "")
6335
+ hookSecret: optional("HOOK_SECRET", ""),
6336
+ /**
6337
+ * 重启后 Monitor run 自动续跑策略:
6338
+ * - `abandon-only`(默认):只把 running 的 run 标记为 abandoned,不自动续跑
6339
+ * - `resume-with-goal`:session 仍在 monitor 模式且保存了 goal → 重新拉起 monitor 循环
6340
+ */
6341
+ monitorAutoResumePolicy: optionalEnum(
6342
+ "MONITOR_AUTO_RESUME_POLICY",
6343
+ "abandon-only",
6344
+ ["abandon-only", "resume-with-goal"]
6345
+ ),
6346
+ /**
6347
+ * 重启后 pending 人工门控的处理策略:
6348
+ * - `invalidate-all`(默认):全部标记为 invalidated,Discord 消息置灰
6349
+ * - `resume-pending`:保留 pending,按剩余时间重建 5 分钟超时,用户可继续审批
6350
+ */
6351
+ gateRestartPolicy: optionalEnum("GATE_RESTART_POLICY", "invalidate-all", [
6352
+ "invalidate-all",
6353
+ "resume-pending"
6354
+ ])
6319
6355
  };
6320
6356
  if (config.anthropicApiKey) process.env.ANTHROPIC_API_KEY = config.anthropicApiKey;
6321
6357
  if (config.anthropicBaseUrl) process.env.ANTHROPIC_BASE_URL = config.anthropicBaseUrl;
@@ -6339,10 +6375,10 @@ function resolvePath(p) {
6339
6375
  return isAbsolute(p) ? p : resolve(process.cwd(), p);
6340
6376
  }
6341
6377
  function formatDuration(ms) {
6342
- const s = Math.floor(ms / 1e3);
6343
- if (s < 60) return `${s}s`;
6344
- const m = Math.floor(s / 60);
6345
- if (m < 60) return `${m}m ${s % 60}s`;
6378
+ const s2 = Math.floor(ms / 1e3);
6379
+ if (s2 < 60) return `${s2}s`;
6380
+ const m = Math.floor(s2 / 60);
6381
+ if (m < 60) return `${m}m ${s2 % 60}s`;
6346
6382
  const h = Math.floor(m / 60);
6347
6383
  return `${h}h ${m % 60}m`;
6348
6384
  }
@@ -6353,9 +6389,9 @@ function formatRelative(ts) {
6353
6389
  if (diff < 864e5) return `${Math.floor(diff / 36e5)}h ago`;
6354
6390
  return `${Math.floor(diff / 864e5)}d ago`;
6355
6391
  }
6356
- function truncate(s, max) {
6357
- if (s.length <= max) return s;
6358
- return s.slice(0, max - 1) + "\u2026";
6392
+ function truncate(s2, max) {
6393
+ if (s2.length <= max) return s2;
6394
+ return s2.slice(0, max - 1) + "\u2026";
6359
6395
  }
6360
6396
  function isUserAllowed(userId, allowedUsers, allowAll) {
6361
6397
  if (allowAll) return true;
@@ -6430,8 +6466,628 @@ var Store = class {
6430
6466
  }
6431
6467
  };
6432
6468
 
6469
+ // ../core/src/schema.ts
6470
+ function pushIssue(issues, path5, message) {
6471
+ issues.push({ path: path5, message });
6472
+ }
6473
+ var s = {
6474
+ string(options = {}) {
6475
+ return {
6476
+ parse(input, path5, issues) {
6477
+ if (input === void 0 || input === null) {
6478
+ if (options.optional) return options.default;
6479
+ pushIssue(issues, path5, "expected string, got " + describe(input));
6480
+ return options.default;
6481
+ }
6482
+ if (typeof input !== "string") {
6483
+ pushIssue(issues, path5, "expected string, got " + describe(input));
6484
+ return options.default;
6485
+ }
6486
+ return input;
6487
+ }
6488
+ };
6489
+ },
6490
+ number(options = {}) {
6491
+ return {
6492
+ parse(input, path5, issues) {
6493
+ if (input === void 0 || input === null) {
6494
+ if (options.optional) return options.default;
6495
+ pushIssue(issues, path5, "expected number, got " + describe(input));
6496
+ return options.default;
6497
+ }
6498
+ if (typeof input !== "number" || !Number.isFinite(input)) {
6499
+ pushIssue(issues, path5, "expected finite number, got " + describe(input));
6500
+ return options.default;
6501
+ }
6502
+ if (options.integer && !Number.isInteger(input)) {
6503
+ pushIssue(issues, path5, "expected integer, got " + input);
6504
+ return options.default;
6505
+ }
6506
+ return input;
6507
+ }
6508
+ };
6509
+ },
6510
+ boolean(options = {}) {
6511
+ return {
6512
+ parse(input, path5, issues) {
6513
+ if (input === void 0 || input === null) {
6514
+ if (options.optional) return options.default;
6515
+ pushIssue(issues, path5, "expected boolean, got " + describe(input));
6516
+ return options.default;
6517
+ }
6518
+ if (typeof input !== "boolean") {
6519
+ pushIssue(issues, path5, "expected boolean, got " + describe(input));
6520
+ return options.default;
6521
+ }
6522
+ return input;
6523
+ }
6524
+ };
6525
+ },
6526
+ literal(values, options = {}) {
6527
+ return {
6528
+ parse(input, path5, issues) {
6529
+ if (input === void 0 || input === null) {
6530
+ if (options.optional) return options.default;
6531
+ pushIssue(issues, path5, "expected one of [" + values.join(", ") + "], got " + describe(input));
6532
+ return options.default;
6533
+ }
6534
+ if (typeof input !== "string" || !values.includes(input)) {
6535
+ pushIssue(issues, path5, "expected one of [" + values.join(", ") + "], got " + describe(input));
6536
+ return options.default;
6537
+ }
6538
+ return input;
6539
+ }
6540
+ };
6541
+ },
6542
+ array(item, options = {}) {
6543
+ return {
6544
+ parse(input, path5, issues) {
6545
+ if (input === void 0 || input === null) {
6546
+ if (options.optional) return options.default;
6547
+ pushIssue(issues, path5, "expected array, got " + describe(input));
6548
+ return options.default ?? [];
6549
+ }
6550
+ if (!Array.isArray(input)) {
6551
+ pushIssue(issues, path5, "expected array, got " + describe(input));
6552
+ return options.default ?? [];
6553
+ }
6554
+ const out = [];
6555
+ for (let i = 0; i < input.length; i++) {
6556
+ const parsed = item.parse(input[i], `${path5}[${i}]`, issues);
6557
+ if (parsed !== void 0) out.push(parsed);
6558
+ }
6559
+ return out;
6560
+ }
6561
+ };
6562
+ },
6563
+ unknown() {
6564
+ return {
6565
+ parse(input) {
6566
+ return input;
6567
+ }
6568
+ };
6569
+ },
6570
+ record(value, options = {}) {
6571
+ return {
6572
+ parse(input, path5, issues) {
6573
+ if (input === void 0 || input === null) {
6574
+ if (options.optional) return void 0;
6575
+ pushIssue(issues, path5, "expected object, got " + describe(input));
6576
+ return void 0;
6577
+ }
6578
+ if (typeof input !== "object" || Array.isArray(input)) {
6579
+ pushIssue(issues, path5, "expected object, got " + describe(input));
6580
+ return void 0;
6581
+ }
6582
+ const out = {};
6583
+ for (const [key2, raw] of Object.entries(input)) {
6584
+ const parsed = value.parse(raw, `${path5}.${key2}`, issues);
6585
+ if (parsed !== void 0) out[key2] = parsed;
6586
+ }
6587
+ return out;
6588
+ }
6589
+ };
6590
+ }
6591
+ };
6592
+ function describe(v) {
6593
+ if (v === null) return "null";
6594
+ if (v === void 0) return "undefined";
6595
+ if (Array.isArray(v)) return "array";
6596
+ return typeof v;
6597
+ }
6598
+ function formatIssues(issues, limit = 5) {
6599
+ if (issues.length === 0) return "";
6600
+ const shown = issues.slice(0, limit).map((i) => ` - ${i.path}: ${i.message}`);
6601
+ const suffix = issues.length > limit ? `
6602
+ ...and ${issues.length - limit} more` : "";
6603
+ return shown.join("\n") + suffix;
6604
+ }
6605
+
6606
+ // ../core/src/persistence-schema.ts
6607
+ var PROVIDER_NAMES = ["claude", "codex"];
6608
+ var SESSION_MODES = ["auto", "plan", "normal", "monitor"];
6609
+ var SESSION_TYPES = ["persistent", "subagent"];
6610
+ var CLAUDE_PERM = ["bypass", "normal"];
6611
+ var CODEX_SANDBOX = ["read-only", "workspace-write", "danger-full-access"];
6612
+ var CODEX_APPROVAL = ["never", "on-request", "on-failure", "untrusted"];
6613
+ var CODEX_WEB_SEARCH = ["disabled", "cached", "live"];
6614
+ var DISCOVERY_SOURCES = ["discord", "claude-hook", "codex-log", "sync"];
6615
+ var WORKFLOW_STATUSES = [
6616
+ "idle",
6617
+ "worker_running",
6618
+ "retrying",
6619
+ "monitor_review",
6620
+ "awaiting_human",
6621
+ "completed",
6622
+ "blocked",
6623
+ "error"
6624
+ ];
6625
+ function isObject2(v) {
6626
+ return typeof v === "object" && v !== null && !Array.isArray(v);
6627
+ }
6628
+ function parseWorkflowState(raw, path5, issues) {
6629
+ const defaults = {
6630
+ status: "idle",
6631
+ iteration: 0,
6632
+ updatedAt: Date.now()
6633
+ };
6634
+ if (!isObject2(raw)) {
6635
+ return defaults;
6636
+ }
6637
+ const status = s.literal(WORKFLOW_STATUSES, { default: "idle" }).parse(
6638
+ raw.status,
6639
+ `${path5}.status`,
6640
+ issues
6641
+ );
6642
+ const iteration = s.number({ integer: true, default: 0 }).parse(
6643
+ raw.iteration,
6644
+ `${path5}.iteration`,
6645
+ issues
6646
+ );
6647
+ const updatedAt = s.number({ default: Date.now() }).parse(
6648
+ raw.updatedAt,
6649
+ `${path5}.updatedAt`,
6650
+ issues
6651
+ );
6652
+ const workflow = { status, iteration, updatedAt };
6653
+ if (typeof raw.lastHook === "string") workflow.lastHook = raw.lastHook;
6654
+ if (typeof raw.lastWorkerSummary === "string") workflow.lastWorkerSummary = raw.lastWorkerSummary;
6655
+ if (typeof raw.lastMonitorRationale === "string") workflow.lastMonitorRationale = raw.lastMonitorRationale;
6656
+ if (typeof raw.awaitingHumanReason === "string") workflow.awaitingHumanReason = raw.awaitingHumanReason;
6657
+ if (isObject2(raw.lastWorkerReport)) {
6658
+ workflow.lastWorkerReport = raw.lastWorkerReport;
6659
+ }
6660
+ if (isObject2(raw.lastMonitorDecision)) {
6661
+ workflow.lastMonitorDecision = raw.lastMonitorDecision;
6662
+ }
6663
+ if (isObject2(raw.nextProofContract)) {
6664
+ workflow.nextProofContract = raw.nextProofContract;
6665
+ }
6666
+ return workflow;
6667
+ }
6668
+ function parseSessionPersistData(raw, index, issues) {
6669
+ if (!isObject2(raw)) {
6670
+ issues.push({ path: `sessions[${index}]`, message: "expected object, got " + typeof raw });
6671
+ return void 0;
6672
+ }
6673
+ const path5 = `sessions[${index}]`;
6674
+ const id = s.string().parse(raw.id, `${path5}.id`, issues);
6675
+ const channelId = s.string().parse(raw.channelId, `${path5}.channelId`, issues);
6676
+ const categoryId = s.string().parse(raw.categoryId, `${path5}.categoryId`, issues);
6677
+ const projectName = s.string().parse(raw.projectName, `${path5}.projectName`, issues);
6678
+ const agentLabel = s.string().parse(raw.agentLabel, `${path5}.agentLabel`, issues);
6679
+ const directory = s.string().parse(raw.directory, `${path5}.directory`, issues);
6680
+ if (!id || !channelId || !categoryId || !projectName || !agentLabel || !directory) {
6681
+ return void 0;
6682
+ }
6683
+ const provider = s.literal(PROVIDER_NAMES, { default: "claude" }).parse(
6684
+ raw.provider,
6685
+ `${path5}.provider`,
6686
+ issues
6687
+ );
6688
+ const mode = s.literal(SESSION_MODES, { default: "auto" }).parse(
6689
+ raw.mode,
6690
+ `${path5}.mode`,
6691
+ issues
6692
+ );
6693
+ const type = s.literal(SESSION_TYPES, { default: "persistent" }).parse(
6694
+ raw.type,
6695
+ `${path5}.type`,
6696
+ issues
6697
+ );
6698
+ const now = Date.now();
6699
+ const session = {
6700
+ id,
6701
+ channelId,
6702
+ categoryId,
6703
+ projectName,
6704
+ agentLabel,
6705
+ provider,
6706
+ type,
6707
+ mode,
6708
+ directory,
6709
+ subagentDepth: s.number({ integer: true, default: 0 }).parse(raw.subagentDepth, `${path5}.subagentDepth`, issues),
6710
+ verbose: s.boolean({ default: false }).parse(raw.verbose, `${path5}.verbose`, issues),
6711
+ workflowState: parseWorkflowState(raw.workflowState, `${path5}.workflowState`, issues),
6712
+ createdAt: s.number({ default: now }).parse(raw.createdAt, `${path5}.createdAt`, issues),
6713
+ lastActivity: s.number({ default: now }).parse(raw.lastActivity, `${path5}.lastActivity`, issues),
6714
+ messageCount: s.number({ integer: true, default: 0 }).parse(raw.messageCount, `${path5}.messageCount`, issues),
6715
+ totalCost: s.number({ default: 0 }).parse(raw.totalCost, `${path5}.totalCost`, issues),
6716
+ currentTurn: s.number({ integer: true, default: 0 }).parse(raw.currentTurn, `${path5}.currentTurn`, issues),
6717
+ humanResolved: s.boolean({ default: false }).parse(raw.humanResolved, `${path5}.humanResolved`, issues)
6718
+ };
6719
+ if (typeof raw.providerSessionId === "string") session.providerSessionId = raw.providerSessionId;
6720
+ if (typeof raw.model === "string") session.model = raw.model;
6721
+ if (typeof raw.parentChannelId === "string") session.parentChannelId = raw.parentChannelId;
6722
+ if (typeof raw.agentPersona === "string") session.agentPersona = raw.agentPersona;
6723
+ if (typeof raw.monitorGoal === "string") session.monitorGoal = raw.monitorGoal;
6724
+ if (typeof raw.monitorProviderSessionId === "string") session.monitorProviderSessionId = raw.monitorProviderSessionId;
6725
+ if (typeof raw.currentInteractionMessageId === "string") session.currentInteractionMessageId = raw.currentInteractionMessageId;
6726
+ if (typeof raw.statusCardMessageId === "string") session.statusCardMessageId = raw.statusCardMessageId;
6727
+ if (typeof raw.lastInboundMessageId === "string") session.lastInboundMessageId = raw.lastInboundMessageId;
6728
+ if (typeof raw.lastObservedState === "string") session.lastObservedState = raw.lastObservedState;
6729
+ if (typeof raw.lastObservedEventKey === "string") session.lastObservedEventKey = raw.lastObservedEventKey;
6730
+ if (typeof raw.lastObservedAt === "number") session.lastObservedAt = raw.lastObservedAt;
6731
+ if (typeof raw.lastObservedCwd === "string") session.lastObservedCwd = raw.lastObservedCwd;
6732
+ if (typeof raw.activeHumanGateId === "string") session.activeHumanGateId = raw.activeHumanGateId;
6733
+ if (typeof raw.remoteHumanControl === "boolean") session.remoteHumanControl = raw.remoteHumanControl;
6734
+ if (typeof raw.claudePermissionMode === "string" && CLAUDE_PERM.includes(raw.claudePermissionMode)) {
6735
+ session.claudePermissionMode = raw.claudePermissionMode;
6736
+ }
6737
+ if (typeof raw.codexSandboxMode === "string" && CODEX_SANDBOX.includes(raw.codexSandboxMode)) {
6738
+ session.codexSandboxMode = raw.codexSandboxMode;
6739
+ }
6740
+ if (typeof raw.codexApprovalPolicy === "string" && CODEX_APPROVAL.includes(raw.codexApprovalPolicy)) {
6741
+ session.codexApprovalPolicy = raw.codexApprovalPolicy;
6742
+ }
6743
+ if (typeof raw.codexBypass === "boolean") session.codexBypass = raw.codexBypass;
6744
+ if (typeof raw.codexNetworkAccessEnabled === "boolean") session.codexNetworkAccessEnabled = raw.codexNetworkAccessEnabled;
6745
+ if (typeof raw.codexWebSearchMode === "string" && CODEX_WEB_SEARCH.includes(raw.codexWebSearchMode)) {
6746
+ session.codexWebSearchMode = raw.codexWebSearchMode;
6747
+ }
6748
+ if (typeof raw.discoverySource === "string" && DISCOVERY_SOURCES.includes(raw.discoverySource)) {
6749
+ session.discoverySource = raw.discoverySource;
6750
+ }
6751
+ return session;
6752
+ }
6753
+ function parseMcpServer(raw) {
6754
+ if (!isObject2(raw)) return void 0;
6755
+ if (typeof raw.name !== "string" || typeof raw.command !== "string") return void 0;
6756
+ const server = { name: raw.name, command: raw.command };
6757
+ if (Array.isArray(raw.args)) {
6758
+ server.args = raw.args.filter((a) => typeof a === "string");
6759
+ }
6760
+ return server;
6761
+ }
6762
+ function parseRegisteredProject(raw, index, issues) {
6763
+ if (!isObject2(raw)) {
6764
+ issues.push({ path: `projects[${index}]`, message: "expected object, got " + typeof raw });
6765
+ return void 0;
6766
+ }
6767
+ const path5 = `projects[${index}]`;
6768
+ const id = s.string().parse(raw.id, `${path5}.id`, issues);
6769
+ const name = s.string().parse(raw.name, `${path5}.name`, issues);
6770
+ const projectPath = s.string().parse(raw.path, `${path5}.path`, issues);
6771
+ if (!id || !name || !projectPath) return void 0;
6772
+ const now = Date.now();
6773
+ const project = {
6774
+ id,
6775
+ name,
6776
+ path: projectPath,
6777
+ skills: {},
6778
+ mcpServers: [],
6779
+ createdAt: s.number({ default: now }).parse(raw.createdAt, `${path5}.createdAt`, issues),
6780
+ updatedAt: s.number({ default: now }).parse(raw.updatedAt, `${path5}.updatedAt`, issues)
6781
+ };
6782
+ if (isObject2(raw.skills)) {
6783
+ for (const [key2, value] of Object.entries(raw.skills)) {
6784
+ if (typeof value === "string") project.skills[key2] = value;
6785
+ }
6786
+ }
6787
+ if (Array.isArray(raw.mcpServers)) {
6788
+ for (const item of raw.mcpServers) {
6789
+ const parsed = parseMcpServer(item);
6790
+ if (parsed) project.mcpServers.push(parsed);
6791
+ }
6792
+ }
6793
+ if (typeof raw.discordCategoryId === "string") project.discordCategoryId = raw.discordCategoryId;
6794
+ if (typeof raw.discordCategoryName === "string") project.discordCategoryName = raw.discordCategoryName;
6795
+ if (typeof raw.historyChannelId === "string") project.historyChannelId = raw.historyChannelId;
6796
+ if (typeof raw.controlChannelId === "string") project.controlChannelId = raw.controlChannelId;
6797
+ if (typeof raw.personality === "string") project.personality = raw.personality;
6798
+ return project;
6799
+ }
6800
+
6801
+ // ../core/src/repository/json-repo.ts
6802
+ var DEFAULT_DEBOUNCE_MS = 1e3;
6803
+ var NULL_INDEX_KEY = "__json_repo_null__";
6804
+ function indexKey(value) {
6805
+ if (value === void 0 || value === null) return NULL_INDEX_KEY;
6806
+ if (typeof value === "string") return `s:${value}`;
6807
+ if (typeof value === "number") return `n:${value}`;
6808
+ if (typeof value === "boolean") return `b:${value ? 1 : 0}`;
6809
+ return `o:${String(value)}`;
6810
+ }
6811
+ var JsonFileRepository = class {
6812
+ store;
6813
+ idField;
6814
+ indexes;
6815
+ parse;
6816
+ serialize;
6817
+ debounceMs;
6818
+ entries = /* @__PURE__ */ new Map();
6819
+ /** 索引字段 → 索引值 key → 持有该值的主键集合 */
6820
+ indexMaps = /* @__PURE__ */ new Map();
6821
+ saveTimer = null;
6822
+ writeChain = Promise.resolve();
6823
+ dirty = false;
6824
+ constructor(options) {
6825
+ this.store = new Store(options.filename);
6826
+ this.idField = options.idField;
6827
+ this.indexes = options.indexes ?? [];
6828
+ this.parse = options.parse;
6829
+ this.serialize = options.serialize;
6830
+ this.debounceMs = options.debounceMs ?? DEFAULT_DEBOUNCE_MS;
6831
+ for (const idx of this.indexes) this.indexMaps.set(idx.field, /* @__PURE__ */ new Map());
6832
+ }
6833
+ async init() {
6834
+ const raw = await this.store.read();
6835
+ if (!Array.isArray(raw)) return;
6836
+ for (let i = 0; i < raw.length; i++) {
6837
+ const parsed = this.parse ? this.parse(raw[i], i) : raw[i];
6838
+ if (!parsed) continue;
6839
+ const id = parsed[this.idField];
6840
+ if (typeof id !== "string") continue;
6841
+ this.entries.set(id, parsed);
6842
+ this.addToIndexes(id, parsed);
6843
+ }
6844
+ }
6845
+ get(id) {
6846
+ return this.entries.get(id);
6847
+ }
6848
+ find(options = {}) {
6849
+ let candidates;
6850
+ if (options.where) {
6851
+ const whereEntries = Object.entries(options.where);
6852
+ const indexedEntry = whereEntries.find(
6853
+ ([field]) => this.indexMaps.has(field)
6854
+ );
6855
+ if (indexedEntry) {
6856
+ const [field, value] = indexedEntry;
6857
+ const idSet = this.indexMaps.get(field)?.get(indexKey(value));
6858
+ if (!idSet || idSet.size === 0) return [];
6859
+ const seed = [];
6860
+ for (const id of idSet) {
6861
+ const entity = this.entries.get(id);
6862
+ if (entity) seed.push(entity);
6863
+ }
6864
+ candidates = seed;
6865
+ } else {
6866
+ candidates = this.entries.values();
6867
+ }
6868
+ let result2 = Array.from(candidates).filter(
6869
+ (item) => whereEntries.every(([key2, value]) => item[key2] === value)
6870
+ );
6871
+ if (options.sort) result2.sort(options.sort);
6872
+ if (options.limit !== void 0) result2 = result2.slice(0, options.limit);
6873
+ return result2;
6874
+ }
6875
+ let result = Array.from(this.entries.values());
6876
+ if (options.sort) result.sort(options.sort);
6877
+ if (options.limit !== void 0) result = result.slice(0, options.limit);
6878
+ return result;
6879
+ }
6880
+ getAll() {
6881
+ return Array.from(this.entries.values());
6882
+ }
6883
+ size() {
6884
+ return this.entries.size;
6885
+ }
6886
+ async save(entity) {
6887
+ const id = entity[this.idField];
6888
+ if (typeof id !== "string") {
6889
+ throw new Error(`Repository.save: id field "${this.idField}" missing or non-string`);
6890
+ }
6891
+ const existing = this.entries.get(id);
6892
+ if (existing && existing !== entity) {
6893
+ this.removeFromIndexes(id, existing);
6894
+ } else if (existing) {
6895
+ this.removeFromIndexes(id, existing);
6896
+ }
6897
+ this.entries.set(id, entity);
6898
+ this.addToIndexes(id, entity);
6899
+ this.scheduleWrite();
6900
+ }
6901
+ async saveMany(entities) {
6902
+ for (const entity of entities) {
6903
+ const id = entity[this.idField];
6904
+ if (typeof id !== "string") continue;
6905
+ const existing = this.entries.get(id);
6906
+ if (existing) this.removeFromIndexes(id, existing);
6907
+ this.entries.set(id, entity);
6908
+ this.addToIndexes(id, entity);
6909
+ }
6910
+ this.scheduleWrite();
6911
+ }
6912
+ async update(id, patch) {
6913
+ const current = this.entries.get(id);
6914
+ if (!current) return void 0;
6915
+ this.removeFromIndexes(id, current);
6916
+ const next = { ...current, ...patch };
6917
+ this.entries.set(id, next);
6918
+ this.addToIndexes(id, next);
6919
+ this.scheduleWrite();
6920
+ return next;
6921
+ }
6922
+ async delete(id) {
6923
+ const existing = this.entries.get(id);
6924
+ if (!existing) return false;
6925
+ this.removeFromIndexes(id, existing);
6926
+ this.entries.delete(id);
6927
+ this.scheduleWrite();
6928
+ return true;
6929
+ }
6930
+ async clear() {
6931
+ this.entries.clear();
6932
+ for (const map of this.indexMaps.values()) map.clear();
6933
+ this.scheduleWrite();
6934
+ }
6935
+ async flush() {
6936
+ if (this.saveTimer) {
6937
+ clearTimeout(this.saveTimer);
6938
+ this.saveTimer = null;
6939
+ }
6940
+ if (this.dirty) {
6941
+ this.writeChain = this.writeChain.catch(() => {
6942
+ }).then(() => this.writeNow());
6943
+ }
6944
+ await this.writeChain;
6945
+ }
6946
+ /**
6947
+ * 调用方在直接 mutate entity 字段后,显式触发一次索引重建 + 持久化调度。
6948
+ * 典型场景:session 对象被多处代码引用,就地改 providerSessionId 后需要重建二级索引。
6949
+ */
6950
+ reindex(id) {
6951
+ const entity = this.entries.get(id);
6952
+ if (!entity) return;
6953
+ this.removeFromIndexes(id, entity);
6954
+ this.addToIndexes(id, entity);
6955
+ this.scheduleWrite();
6956
+ }
6957
+ // ─── Index maintenance ────────────────────────────────────────────────────
6958
+ addToIndexes(id, entity) {
6959
+ for (const idx of this.indexes) {
6960
+ const raw = idx.extract ? idx.extract(entity) : entity[idx.field];
6961
+ const key2 = indexKey(raw);
6962
+ const map = this.indexMaps.get(idx.field);
6963
+ if (!map) continue;
6964
+ let set = map.get(key2);
6965
+ if (!set) {
6966
+ set = /* @__PURE__ */ new Set();
6967
+ map.set(key2, set);
6968
+ }
6969
+ set.add(id);
6970
+ }
6971
+ }
6972
+ removeFromIndexes(id, entity) {
6973
+ for (const idx of this.indexes) {
6974
+ const raw = idx.extract ? idx.extract(entity) : entity[idx.field];
6975
+ const key2 = indexKey(raw);
6976
+ const map = this.indexMaps.get(idx.field);
6977
+ if (!map) continue;
6978
+ const set = map.get(key2);
6979
+ if (!set) continue;
6980
+ set.delete(id);
6981
+ if (set.size === 0) map.delete(key2);
6982
+ }
6983
+ }
6984
+ // ─── Internals ────────────────────────────────────────────────────────────
6985
+ scheduleWrite() {
6986
+ this.dirty = true;
6987
+ if (this.debounceMs === 0) {
6988
+ this.writeChain = this.writeChain.catch(() => {
6989
+ }).then(() => this.writeNow());
6990
+ return;
6991
+ }
6992
+ if (this.saveTimer) return;
6993
+ this.saveTimer = setTimeout(() => {
6994
+ this.saveTimer = null;
6995
+ if (!this.dirty) return;
6996
+ this.writeChain = this.writeChain.catch(() => {
6997
+ }).then(() => this.writeNow());
6998
+ }, this.debounceMs);
6999
+ this.saveTimer.unref?.();
7000
+ }
7001
+ async writeNow() {
7002
+ this.dirty = false;
7003
+ const snapshot = [];
7004
+ for (const entity of this.entries.values()) {
7005
+ snapshot.push(this.serialize ? this.serialize(entity) : entity);
7006
+ }
7007
+ try {
7008
+ await this.store.write(snapshot);
7009
+ } catch (err) {
7010
+ console.error(`[JsonFileRepository] write failed: ${err.message}`);
7011
+ }
7012
+ }
7013
+ };
7014
+
7015
+ // ../core/src/repository/sqlite-repo.ts
7016
+ import { existsSync as existsSync3 } from "fs";
7017
+ import { mkdirSync } from "fs";
7018
+ import { dirname as dirname2, join as join4 } from "path";
7019
+
6433
7020
  // ../core/src/event-bus.ts
6434
7021
  import { EventEmitter } from "events";
7022
+ function key(eventType) {
7023
+ return eventType;
7024
+ }
7025
+ var EventBus = class extends EventEmitter {
7026
+ #middleware = [];
7027
+ constructor() {
7028
+ super({ captureRejections: false });
7029
+ this.setMaxListeners(Infinity);
7030
+ }
7031
+ /**
7032
+ * Emit an event. Automatically generates traceId, timestamp, and source.
7033
+ * Middleware runs before any handlers. Middleware errors are logged but
7034
+ * do not stop propagation.
7035
+ */
7036
+ emit(eventType, payload, source = "unknown") {
7037
+ const event = {
7038
+ type: key(eventType),
7039
+ payload,
7040
+ traceId: crypto.randomUUID(),
7041
+ timestamp: Date.now(),
7042
+ source
7043
+ };
7044
+ const middlewarePromises = this.#middleware.map(async (fn) => {
7045
+ try {
7046
+ await fn(event);
7047
+ } catch (err) {
7048
+ console.error("[EventBus] middleware error:", err);
7049
+ }
7050
+ });
7051
+ void Promise.allSettled(middlewarePromises);
7052
+ return super.emit(key(eventType), event);
7053
+ }
7054
+ /** Register a handler for the given event type. */
7055
+ on(eventType, handler) {
7056
+ return super.on(key(eventType), handler);
7057
+ }
7058
+ /** Register a one-shot handler for the given event type. */
7059
+ once(eventType, handler) {
7060
+ return super.once(key(eventType), handler);
7061
+ }
7062
+ /** Remove a previously registered handler. */
7063
+ off(eventType, handler) {
7064
+ return super.off(key(eventType), handler);
7065
+ }
7066
+ /**
7067
+ * Register middleware that runs before every handler.
7068
+ * Middleware receives the raw AppEvent and can mutate it.
7069
+ * Errors are caught and logged — they do not stop propagation.
7070
+ */
7071
+ middleware(fn) {
7072
+ this.#middleware.push(fn);
7073
+ }
7074
+ };
7075
+
7076
+ // ../core/src/domain-events.ts
7077
+ var SessionErrored = "session.errored";
7078
+ var SessionAwaitingHuman = "session.awaiting_human";
7079
+ var SessionCreated = "session.created";
7080
+ var SessionEnded = "session.ended";
7081
+ var SessionModeChanged = "session.mode_changed";
7082
+ var MonitorRunStarted = "monitor.run.started";
7083
+ var MonitorRunEnded = "monitor.run.ended";
7084
+ var GateCreated = "gate.created";
7085
+ var GateResolved = "gate.resolved";
7086
+ var _domainBus = null;
7087
+ function getDomainBus() {
7088
+ if (!_domainBus) _domainBus = new EventBus();
7089
+ return _domainBus;
7090
+ }
6435
7091
 
6436
7092
  // ../core/src/logger.ts
6437
7093
  var import_pino = __toESM(require_pino(), 1);
@@ -6444,7 +7100,7 @@ var ServiceBus = class {
6444
7100
  #services = [];
6445
7101
  #started = /* @__PURE__ */ new Set();
6446
7102
  register(service) {
6447
- if (this.#services.some((s) => s.name === service.name)) {
7103
+ if (this.#services.some((s2) => s2.name === service.name)) {
6448
7104
  throw new Error(`Service "${service.name}" is already registered`);
6449
7105
  }
6450
7106
  this.#services.push(service);
@@ -6523,6 +7179,20 @@ export {
6523
7179
  formatUptime,
6524
7180
  getDataDir,
6525
7181
  Store,
7182
+ formatIssues,
7183
+ parseSessionPersistData,
7184
+ parseRegisteredProject,
7185
+ JsonFileRepository,
7186
+ SessionErrored,
7187
+ SessionAwaitingHuman,
7188
+ SessionCreated,
7189
+ SessionEnded,
7190
+ SessionModeChanged,
7191
+ MonitorRunStarted,
7192
+ MonitorRunEnded,
7193
+ GateCreated,
7194
+ GateResolved,
7195
+ getDomainBus,
6526
7196
  ServiceBus,
6527
7197
  intervalService
6528
7198
  };