@threadbase-sh/streamer 1.36.1 → 1.36.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.
package/dist/cli.cjs CHANGED
@@ -26158,7 +26158,7 @@ var require_thread_stream = __commonJS({
26158
26158
  var { version: version2 } = require_package();
26159
26159
  var { EventEmitter: EventEmitter5 } = require("events");
26160
26160
  var { Worker } = require("worker_threads");
26161
- var { join: join28 } = require("path");
26161
+ var { join: join29 } = require("path");
26162
26162
  var { pathToFileURL } = require("url");
26163
26163
  var { wait } = require_wait();
26164
26164
  var {
@@ -26209,7 +26209,7 @@ var require_thread_stream = __commonJS({
26209
26209
  function createWorker(stream, opts) {
26210
26210
  const { filename, workerData } = opts;
26211
26211
  const bundlerOverrides = "__bundlerPathsOverrides" in globalThis ? globalThis.__bundlerPathsOverrides : {};
26212
- const toExecute = bundlerOverrides["thread-stream-worker"] || join28(__dirname, "lib", "worker.js");
26212
+ const toExecute = bundlerOverrides["thread-stream-worker"] || join29(__dirname, "lib", "worker.js");
26213
26213
  const worker = new Worker(toExecute, {
26214
26214
  ...opts.workerOpts,
26215
26215
  name: opts.workerOpts?.name || "thread-stream",
@@ -26677,7 +26677,7 @@ var require_transport = __commonJS({
26677
26677
  var { createRequire } = require("module");
26678
26678
  var { existsSync: existsSync15 } = require("fs");
26679
26679
  var getCallers = require_caller();
26680
- var { join: join28, isAbsolute: isAbsolute2, sep: sep3 } = require("path");
26680
+ var { join: join29, isAbsolute: isAbsolute2, sep: sep3 } = require("path");
26681
26681
  var { fileURLToPath: fileURLToPath3 } = require("url");
26682
26682
  var sleep = require_atomic_sleep();
26683
26683
  var onExit = require_on_exit_leak_free();
@@ -26830,7 +26830,7 @@ var require_transport = __commonJS({
26830
26830
  throw new Error("only one of target or targets can be specified");
26831
26831
  }
26832
26832
  if (targets) {
26833
- target = bundlerOverrides["pino-worker"] || join28(__dirname, "worker.js");
26833
+ target = bundlerOverrides["pino-worker"] || join29(__dirname, "worker.js");
26834
26834
  options.targets = targets.filter((dest) => dest.target).map((dest) => {
26835
26835
  return {
26836
26836
  ...dest,
@@ -26848,7 +26848,7 @@ var require_transport = __commonJS({
26848
26848
  });
26849
26849
  });
26850
26850
  } else if (pipeline2) {
26851
- target = bundlerOverrides["pino-worker"] || join28(__dirname, "worker.js");
26851
+ target = bundlerOverrides["pino-worker"] || join29(__dirname, "worker.js");
26852
26852
  options.pipelines = [pipeline2.map((dest) => {
26853
26853
  return {
26854
26854
  ...dest,
@@ -26871,7 +26871,7 @@ var require_transport = __commonJS({
26871
26871
  return origin;
26872
26872
  }
26873
26873
  if (origin === "pino/file") {
26874
- return join28(__dirname, "..", "file.js");
26874
+ return join29(__dirname, "..", "file.js");
26875
26875
  }
26876
26876
  let fixTarget2;
26877
26877
  for (const filePath of callers) {
@@ -27852,7 +27852,7 @@ var require_safe_stable_stringify = __commonJS({
27852
27852
  return circularValue;
27853
27853
  }
27854
27854
  let res = "";
27855
- let join28 = ",";
27855
+ let join29 = ",";
27856
27856
  const originalIndentation = indentation;
27857
27857
  if (Array.isArray(value)) {
27858
27858
  if (value.length === 0) {
@@ -27866,7 +27866,7 @@ var require_safe_stable_stringify = __commonJS({
27866
27866
  indentation += spacer;
27867
27867
  res += `
27868
27868
  ${indentation}`;
27869
- join28 = `,
27869
+ join29 = `,
27870
27870
  ${indentation}`;
27871
27871
  }
27872
27872
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -27874,13 +27874,13 @@ ${indentation}`;
27874
27874
  for (; i < maximumValuesToStringify - 1; i++) {
27875
27875
  const tmp2 = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
27876
27876
  res += tmp2 !== void 0 ? tmp2 : "null";
27877
- res += join28;
27877
+ res += join29;
27878
27878
  }
27879
27879
  const tmp = stringifyFnReplacer(String(i), value, stack, replacer, spacer, indentation);
27880
27880
  res += tmp !== void 0 ? tmp : "null";
27881
27881
  if (value.length - 1 > maximumBreadth) {
27882
27882
  const removedKeys = value.length - maximumBreadth - 1;
27883
- res += `${join28}"... ${getItemCount(removedKeys)} not stringified"`;
27883
+ res += `${join29}"... ${getItemCount(removedKeys)} not stringified"`;
27884
27884
  }
27885
27885
  if (spacer !== "") {
27886
27886
  res += `
@@ -27901,7 +27901,7 @@ ${originalIndentation}`;
27901
27901
  let separator = "";
27902
27902
  if (spacer !== "") {
27903
27903
  indentation += spacer;
27904
- join28 = `,
27904
+ join29 = `,
27905
27905
  ${indentation}`;
27906
27906
  whitespace = " ";
27907
27907
  }
@@ -27915,13 +27915,13 @@ ${indentation}`;
27915
27915
  const tmp = stringifyFnReplacer(key2, value, stack, replacer, spacer, indentation);
27916
27916
  if (tmp !== void 0) {
27917
27917
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
27918
- separator = join28;
27918
+ separator = join29;
27919
27919
  }
27920
27920
  }
27921
27921
  if (keyLength > maximumBreadth) {
27922
27922
  const removedKeys = keyLength - maximumBreadth;
27923
27923
  res += `${separator}"...":${whitespace}"${getItemCount(removedKeys)} not stringified"`;
27924
- separator = join28;
27924
+ separator = join29;
27925
27925
  }
27926
27926
  if (spacer !== "" && separator.length > 1) {
27927
27927
  res = `
@@ -27962,7 +27962,7 @@ ${originalIndentation}`;
27962
27962
  }
27963
27963
  const originalIndentation = indentation;
27964
27964
  let res = "";
27965
- let join28 = ",";
27965
+ let join29 = ",";
27966
27966
  if (Array.isArray(value)) {
27967
27967
  if (value.length === 0) {
27968
27968
  return "[]";
@@ -27975,7 +27975,7 @@ ${originalIndentation}`;
27975
27975
  indentation += spacer;
27976
27976
  res += `
27977
27977
  ${indentation}`;
27978
- join28 = `,
27978
+ join29 = `,
27979
27979
  ${indentation}`;
27980
27980
  }
27981
27981
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
@@ -27983,13 +27983,13 @@ ${indentation}`;
27983
27983
  for (; i < maximumValuesToStringify - 1; i++) {
27984
27984
  const tmp2 = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
27985
27985
  res += tmp2 !== void 0 ? tmp2 : "null";
27986
- res += join28;
27986
+ res += join29;
27987
27987
  }
27988
27988
  const tmp = stringifyArrayReplacer(String(i), value[i], stack, replacer, spacer, indentation);
27989
27989
  res += tmp !== void 0 ? tmp : "null";
27990
27990
  if (value.length - 1 > maximumBreadth) {
27991
27991
  const removedKeys = value.length - maximumBreadth - 1;
27992
- res += `${join28}"... ${getItemCount(removedKeys)} not stringified"`;
27992
+ res += `${join29}"... ${getItemCount(removedKeys)} not stringified"`;
27993
27993
  }
27994
27994
  if (spacer !== "") {
27995
27995
  res += `
@@ -28002,7 +28002,7 @@ ${originalIndentation}`;
28002
28002
  let whitespace = "";
28003
28003
  if (spacer !== "") {
28004
28004
  indentation += spacer;
28005
- join28 = `,
28005
+ join29 = `,
28006
28006
  ${indentation}`;
28007
28007
  whitespace = " ";
28008
28008
  }
@@ -28011,7 +28011,7 @@ ${indentation}`;
28011
28011
  const tmp = stringifyArrayReplacer(key2, value[key2], stack, replacer, spacer, indentation);
28012
28012
  if (tmp !== void 0) {
28013
28013
  res += `${separator}${strEscape(key2)}:${whitespace}${tmp}`;
28014
- separator = join28;
28014
+ separator = join29;
28015
28015
  }
28016
28016
  }
28017
28017
  if (spacer !== "" && separator.length > 1) {
@@ -28069,20 +28069,20 @@ ${originalIndentation}`;
28069
28069
  indentation += spacer;
28070
28070
  let res2 = `
28071
28071
  ${indentation}`;
28072
- const join29 = `,
28072
+ const join30 = `,
28073
28073
  ${indentation}`;
28074
28074
  const maximumValuesToStringify = Math.min(value.length, maximumBreadth);
28075
28075
  let i = 0;
28076
28076
  for (; i < maximumValuesToStringify - 1; i++) {
28077
28077
  const tmp2 = stringifyIndent(String(i), value[i], stack, spacer, indentation);
28078
28078
  res2 += tmp2 !== void 0 ? tmp2 : "null";
28079
- res2 += join29;
28079
+ res2 += join30;
28080
28080
  }
28081
28081
  const tmp = stringifyIndent(String(i), value[i], stack, spacer, indentation);
28082
28082
  res2 += tmp !== void 0 ? tmp : "null";
28083
28083
  if (value.length - 1 > maximumBreadth) {
28084
28084
  const removedKeys = value.length - maximumBreadth - 1;
28085
- res2 += `${join29}"... ${getItemCount(removedKeys)} not stringified"`;
28085
+ res2 += `${join30}"... ${getItemCount(removedKeys)} not stringified"`;
28086
28086
  }
28087
28087
  res2 += `
28088
28088
  ${originalIndentation}`;
@@ -28098,16 +28098,16 @@ ${originalIndentation}`;
28098
28098
  return '"[Object]"';
28099
28099
  }
28100
28100
  indentation += spacer;
28101
- const join28 = `,
28101
+ const join29 = `,
28102
28102
  ${indentation}`;
28103
28103
  let res = "";
28104
28104
  let separator = "";
28105
28105
  let maximumPropertiesToStringify = Math.min(keyLength, maximumBreadth);
28106
28106
  if (isTypedArrayWithEntries(value)) {
28107
- res += stringifyTypedArray(value, join28, maximumBreadth);
28107
+ res += stringifyTypedArray(value, join29, maximumBreadth);
28108
28108
  keys = keys.slice(value.length);
28109
28109
  maximumPropertiesToStringify -= value.length;
28110
- separator = join28;
28110
+ separator = join29;
28111
28111
  }
28112
28112
  if (deterministic) {
28113
28113
  keys = sort(keys, comparator);
@@ -28118,13 +28118,13 @@ ${indentation}`;
28118
28118
  const tmp = stringifyIndent(key2, value[key2], stack, spacer, indentation);
28119
28119
  if (tmp !== void 0) {
28120
28120
  res += `${separator}${strEscape(key2)}: ${tmp}`;
28121
- separator = join28;
28121
+ separator = join29;
28122
28122
  }
28123
28123
  }
28124
28124
  if (keyLength > maximumBreadth) {
28125
28125
  const removedKeys = keyLength - maximumBreadth;
28126
28126
  res += `${separator}"...": "${getItemCount(removedKeys)} not stringified"`;
28127
- separator = join28;
28127
+ separator = join29;
28128
28128
  }
28129
28129
  if (separator !== "") {
28130
28130
  res = `
@@ -100397,11 +100397,11 @@ var require_out = __commonJS({
100397
100397
  async.read(path2, getSettings(optionsOrSettingsOrCallback), callback);
100398
100398
  }
100399
100399
  exports2.stat = stat7;
100400
- function statSync13(path2, optionsOrSettings) {
100400
+ function statSync14(path2, optionsOrSettings) {
100401
100401
  const settings = getSettings(optionsOrSettings);
100402
100402
  return sync.read(path2, settings);
100403
100403
  }
100404
- exports2.statSync = statSync13;
100404
+ exports2.statSync = statSync14;
100405
100405
  function getSettings(settingsOrOptions = {}) {
100406
100406
  if (settingsOrOptions instanceof settings_1.default) {
100407
100407
  return settingsOrOptions;
@@ -135143,11 +135143,11 @@ async function search(query, options, scanner) {
135143
135143
 
135144
135144
  // src/server.ts
135145
135145
  var import_events2 = require("events");
135146
- var import_fs28 = require("fs");
135146
+ var import_fs29 = require("fs");
135147
135147
  var import_promises16 = require("fs/promises");
135148
135148
  var import_http = require("http");
135149
- var import_os11 = require("os");
135150
- var import_path28 = require("path");
135149
+ var import_os12 = require("os");
135150
+ var import_path29 = require("path");
135151
135151
  var import_readline4 = require("readline");
135152
135152
 
135153
135153
  // src/agent/agent-client.ts
@@ -142397,6 +142397,14 @@ function seal(plaintext, recipientPublicKeyBase64) {
142397
142397
  };
142398
142398
  }
142399
142399
 
142400
+ // src/services/cache/cacheMetadata.ts
142401
+ function getCacheMetadata(repo, key) {
142402
+ return repo.getCacheMetadata(key);
142403
+ }
142404
+ function setCacheMetadata(repo, key, value) {
142405
+ repo.setCacheMetadata(key, value);
142406
+ }
142407
+
142400
142408
  // src/services/cache-integrity/cacheIntegrityMonitor.ts
142401
142409
  var import_crypto10 = require("crypto");
142402
142410
  var import_fs24 = require("fs");
@@ -142936,6 +142944,360 @@ function pruneAgentConversations(cache) {
142936
142944
  return { scanned: rows.length, pruned, missing };
142937
142945
  }
142938
142946
 
142947
+ // node_modules/date-fns/constants.js
142948
+ var daysInYear = 365.2425;
142949
+ var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
142950
+ var minTime = -maxTime;
142951
+ var millisecondsInMinute = 6e4;
142952
+ var millisecondsInHour = 36e5;
142953
+ var secondsInHour = 3600;
142954
+ var secondsInDay = secondsInHour * 24;
142955
+ var secondsInWeek = secondsInDay * 7;
142956
+ var secondsInYear = secondsInDay * daysInYear;
142957
+ var secondsInMonth = secondsInYear / 12;
142958
+ var secondsInQuarter = secondsInMonth * 3;
142959
+ var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
142960
+
142961
+ // node_modules/date-fns/constructFrom.js
142962
+ function constructFrom(date5, value) {
142963
+ if (typeof date5 === "function") return date5(value);
142964
+ if (date5 && typeof date5 === "object" && constructFromSymbol in date5)
142965
+ return date5[constructFromSymbol](value);
142966
+ if (date5 instanceof Date) return new date5.constructor(value);
142967
+ return new Date(value);
142968
+ }
142969
+
142970
+ // node_modules/date-fns/toDate.js
142971
+ function toDate(argument, context) {
142972
+ return constructFrom(context || argument, argument);
142973
+ }
142974
+
142975
+ // node_modules/date-fns/compareDesc.js
142976
+ function compareDesc(dateLeft, dateRight) {
142977
+ const diff = +toDate(dateLeft) - +toDate(dateRight);
142978
+ if (diff > 0) return -1;
142979
+ else if (diff < 0) return 1;
142980
+ return diff;
142981
+ }
142982
+
142983
+ // node_modules/date-fns/isDate.js
142984
+ function isDate(value) {
142985
+ return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
142986
+ }
142987
+
142988
+ // node_modules/date-fns/isValid.js
142989
+ function isValid(date5) {
142990
+ return !(!isDate(date5) && typeof date5 !== "number" || isNaN(+toDate(date5)));
142991
+ }
142992
+
142993
+ // node_modules/date-fns/parseISO.js
142994
+ function parseISO(argument, options) {
142995
+ const invalidDate = () => constructFrom(options?.in, NaN);
142996
+ const additionalDigits = options?.additionalDigits ?? 2;
142997
+ const dateStrings = splitDateString(argument);
142998
+ let date5;
142999
+ if (dateStrings.date) {
143000
+ const parseYearResult = parseYear(dateStrings.date, additionalDigits);
143001
+ date5 = parseDate(parseYearResult.restDateString, parseYearResult.year);
143002
+ }
143003
+ if (!date5 || isNaN(+date5)) return invalidDate();
143004
+ const timestamp2 = +date5;
143005
+ let time3 = 0;
143006
+ let offset;
143007
+ if (dateStrings.time) {
143008
+ time3 = parseTime(dateStrings.time);
143009
+ if (isNaN(time3)) return invalidDate();
143010
+ }
143011
+ if (dateStrings.timezone) {
143012
+ offset = parseTimezone(dateStrings.timezone);
143013
+ if (isNaN(offset)) return invalidDate();
143014
+ } else {
143015
+ const tmpDate = new Date(timestamp2 + time3);
143016
+ const result = toDate(0, options?.in);
143017
+ result.setFullYear(
143018
+ tmpDate.getUTCFullYear(),
143019
+ tmpDate.getUTCMonth(),
143020
+ tmpDate.getUTCDate()
143021
+ );
143022
+ result.setHours(
143023
+ tmpDate.getUTCHours(),
143024
+ tmpDate.getUTCMinutes(),
143025
+ tmpDate.getUTCSeconds(),
143026
+ tmpDate.getUTCMilliseconds()
143027
+ );
143028
+ return result;
143029
+ }
143030
+ return toDate(timestamp2 + time3 + offset, options?.in);
143031
+ }
143032
+ var patterns = {
143033
+ dateTimeDelimiter: /[T ]/,
143034
+ timeZoneDelimiter: /[Z ]/i,
143035
+ timezone: /([Z+-].*)$/
143036
+ };
143037
+ var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
143038
+ var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
143039
+ var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
143040
+ function splitDateString(dateString) {
143041
+ const dateStrings = {};
143042
+ const array2 = dateString.split(patterns.dateTimeDelimiter);
143043
+ let timeString;
143044
+ if (array2.length > 2) {
143045
+ return dateStrings;
143046
+ }
143047
+ if (/:/.test(array2[0])) {
143048
+ timeString = array2[0];
143049
+ } else {
143050
+ dateStrings.date = array2[0];
143051
+ timeString = array2[1];
143052
+ if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
143053
+ dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
143054
+ timeString = dateString.substr(
143055
+ dateStrings.date.length,
143056
+ dateString.length
143057
+ );
143058
+ }
143059
+ }
143060
+ if (timeString) {
143061
+ const token = patterns.timezone.exec(timeString);
143062
+ if (token) {
143063
+ dateStrings.time = timeString.replace(token[1], "");
143064
+ dateStrings.timezone = token[1];
143065
+ } else {
143066
+ dateStrings.time = timeString;
143067
+ }
143068
+ }
143069
+ return dateStrings;
143070
+ }
143071
+ function parseYear(dateString, additionalDigits) {
143072
+ const regex = new RegExp(
143073
+ "^(?:(\\d{4}|[+-]\\d{" + (4 + additionalDigits) + "})|(\\d{2}|[+-]\\d{" + (2 + additionalDigits) + "})$)"
143074
+ );
143075
+ const captures = dateString.match(regex);
143076
+ if (!captures) return { year: NaN, restDateString: "" };
143077
+ const year = captures[1] ? parseInt(captures[1]) : null;
143078
+ const century = captures[2] ? parseInt(captures[2]) : null;
143079
+ return {
143080
+ year: century === null ? year : century * 100,
143081
+ restDateString: dateString.slice((captures[1] || captures[2]).length)
143082
+ };
143083
+ }
143084
+ function parseDate(dateString, year) {
143085
+ if (year === null) return /* @__PURE__ */ new Date(NaN);
143086
+ const captures = dateString.match(dateRegex);
143087
+ if (!captures) return /* @__PURE__ */ new Date(NaN);
143088
+ const isWeekDate = !!captures[4];
143089
+ const dayOfYear = parseDateUnit(captures[1]);
143090
+ const month = parseDateUnit(captures[2]) - 1;
143091
+ const day = parseDateUnit(captures[3]);
143092
+ const week = parseDateUnit(captures[4]);
143093
+ const dayOfWeek = parseDateUnit(captures[5]) - 1;
143094
+ if (isWeekDate) {
143095
+ if (!validateWeekDate(year, week, dayOfWeek)) {
143096
+ return /* @__PURE__ */ new Date(NaN);
143097
+ }
143098
+ return dayOfISOWeekYear(year, week, dayOfWeek);
143099
+ } else {
143100
+ const date5 = /* @__PURE__ */ new Date(0);
143101
+ if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {
143102
+ return /* @__PURE__ */ new Date(NaN);
143103
+ }
143104
+ date5.setUTCFullYear(year, month, Math.max(dayOfYear, day));
143105
+ return date5;
143106
+ }
143107
+ }
143108
+ function parseDateUnit(value) {
143109
+ return value ? parseInt(value) : 1;
143110
+ }
143111
+ function parseTime(timeString) {
143112
+ const captures = timeString.match(timeRegex);
143113
+ if (!captures) return NaN;
143114
+ const hours = parseTimeUnit(captures[1]);
143115
+ const minutes = parseTimeUnit(captures[2]);
143116
+ const seconds = parseTimeUnit(captures[3]);
143117
+ if (!validateTime(hours, minutes, seconds)) {
143118
+ return NaN;
143119
+ }
143120
+ return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1e3;
143121
+ }
143122
+ function parseTimeUnit(value) {
143123
+ return value && parseFloat(value.replace(",", ".")) || 0;
143124
+ }
143125
+ function parseTimezone(timezoneString) {
143126
+ if (timezoneString === "Z") return 0;
143127
+ const captures = timezoneString.match(timezoneRegex);
143128
+ if (!captures) return 0;
143129
+ const sign = captures[1] === "+" ? -1 : 1;
143130
+ const hours = parseInt(captures[2]);
143131
+ const minutes = captures[3] && parseInt(captures[3]) || 0;
143132
+ if (!validateTimezone(hours, minutes)) {
143133
+ return NaN;
143134
+ }
143135
+ return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
143136
+ }
143137
+ function dayOfISOWeekYear(isoWeekYear, week, day) {
143138
+ const date5 = /* @__PURE__ */ new Date(0);
143139
+ date5.setUTCFullYear(isoWeekYear, 0, 4);
143140
+ const fourthOfJanuaryDay = date5.getUTCDay() || 7;
143141
+ const diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;
143142
+ date5.setUTCDate(date5.getUTCDate() + diff);
143143
+ return date5;
143144
+ }
143145
+ var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
143146
+ function isLeapYearIndex(year) {
143147
+ return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
143148
+ }
143149
+ function validateDate(year, month, date5) {
143150
+ return month >= 0 && month <= 11 && date5 >= 1 && date5 <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));
143151
+ }
143152
+ function validateDayOfYearDate(year, dayOfYear) {
143153
+ return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);
143154
+ }
143155
+ function validateWeekDate(_year, week, day) {
143156
+ return week >= 1 && week <= 53 && day >= 0 && day <= 6;
143157
+ }
143158
+ function validateTime(hours, minutes, seconds) {
143159
+ if (hours === 24) {
143160
+ return minutes === 0 && seconds === 0;
143161
+ }
143162
+ return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;
143163
+ }
143164
+ function validateTimezone(_hours, minutes) {
143165
+ return minutes >= 0 && minutes <= 59;
143166
+ }
143167
+
143168
+ // src/utils/dates.ts
143169
+ function parseIsoDateOrNull(value) {
143170
+ if (!value) return null;
143171
+ const parsed = parseISO(value);
143172
+ return isValid(parsed) ? parsed : null;
143173
+ }
143174
+ function compareIsoDesc(a, b2) {
143175
+ const dateA = parseIsoDateOrNull(a);
143176
+ const dateB = parseIsoDateOrNull(b2);
143177
+ if (!dateA && !dateB) return 0;
143178
+ if (!dateA) return 1;
143179
+ if (!dateB) return -1;
143180
+ return compareDesc(dateA, dateB);
143181
+ }
143182
+
143183
+ // src/services/projects/ensureProjectsForConversations.ts
143184
+ function ensureProjectsForConversations(repo, conversations) {
143185
+ const conversationsByPath = /* @__PURE__ */ new Map();
143186
+ for (const conversation of conversations) {
143187
+ if (!conversation.projectPath) continue;
143188
+ const canonical = canonicalizeProjectPath(conversation.projectPath);
143189
+ if (!canonical) continue;
143190
+ const existing = conversationsByPath.get(canonical) ?? [];
143191
+ existing.push(conversation);
143192
+ conversationsByPath.set(canonical, existing);
143193
+ }
143194
+ const pathToProjectId = /* @__PURE__ */ new Map();
143195
+ for (const [path2, projectConversations] of conversationsByPath) {
143196
+ const latest = pickLatestConversation(projectConversations);
143197
+ const project = repo.upsertProjectByPath(path2, {
143198
+ lastConversationId: latest?.id ?? null,
143199
+ lastConversationCreatedAt: latest?.createdAt ?? null,
143200
+ latestMessageAt: latest?.latestMessageAt ?? null
143201
+ });
143202
+ pathToProjectId.set(path2, project.id);
143203
+ }
143204
+ return pathToProjectId;
143205
+ }
143206
+ function pickLatestConversation(conversations) {
143207
+ if (conversations.length === 0) return void 0;
143208
+ return [...conversations].sort((a, b2) => {
143209
+ const cmp = compareIsoDesc(a.latestMessageAt ?? null, b2.latestMessageAt ?? null);
143210
+ if (cmp !== 0) return cmp;
143211
+ return compareIsoDesc(a.createdAt ?? null, b2.createdAt ?? null);
143212
+ })[0];
143213
+ }
143214
+
143215
+ // src/services/conversations/refreshConversationCache.ts
143216
+ function refreshConversationCache(deps) {
143217
+ const { projectsRepo, conversationsRepo, cacheMetadataRepo } = deps;
143218
+ const conversations = conversationsRepo.listConversationsForProjectBackfill();
143219
+ const pathToProjectId = ensureProjectsForConversations(
143220
+ projectsRepo,
143221
+ conversations.map((c) => ({
143222
+ id: c.id,
143223
+ projectPath: c.projectPath,
143224
+ latestMessageAt: c.lastActivity ?? null,
143225
+ createdAt: c.lastActivity ?? null
143226
+ }))
143227
+ );
143228
+ let conversationsBackfilled = 0;
143229
+ for (const conversation of conversations) {
143230
+ if (!conversation.projectPath) continue;
143231
+ if (conversation.projectId) continue;
143232
+ const projectId = pathToProjectId.get(canonicalizeProjectPath(conversation.projectPath));
143233
+ if (!projectId) continue;
143234
+ conversationsRepo.updateConversationProjectId({
143235
+ conversationId: conversation.id,
143236
+ projectId
143237
+ });
143238
+ conversationsBackfilled += 1;
143239
+ }
143240
+ const latest = conversationsRepo.getLatestConversation();
143241
+ if (latest) {
143242
+ setCacheMetadata(cacheMetadataRepo, "last_conversation_id", latest.id);
143243
+ if (latest.lastActivity) {
143244
+ setCacheMetadata(cacheMetadataRepo, "last_conversation_created_at", latest.lastActivity);
143245
+ }
143246
+ }
143247
+ setCacheMetadata(cacheMetadataRepo, "conversations_last_indexed_at", (/* @__PURE__ */ new Date()).toISOString());
143248
+ return {
143249
+ projectsTouched: pathToProjectId.size,
143250
+ conversationsBackfilled,
143251
+ latestConversationId: latest?.id ?? null
143252
+ };
143253
+ }
143254
+
143255
+ // src/services/conversations/shouldRefreshProjectsFromHdd.ts
143256
+ var import_fs27 = require("fs");
143257
+ var import_os11 = require("os");
143258
+ var import_path27 = require("path");
143259
+ var DEFAULT_PROJECTS_DIR = (0, import_path27.join)((0, import_os11.homedir)(), ".claude", "projects");
143260
+ function maxProjectsTreeMtimeMs(projectsDir) {
143261
+ let maxMs;
143262
+ try {
143263
+ maxMs = (0, import_fs27.statSync)(projectsDir).mtimeMs;
143264
+ } catch {
143265
+ return null;
143266
+ }
143267
+ try {
143268
+ for (const ent of (0, import_fs27.readdirSync)(projectsDir, { withFileTypes: true })) {
143269
+ if (!ent.isDirectory()) continue;
143270
+ try {
143271
+ const childMs = (0, import_fs27.statSync)((0, import_path27.join)(projectsDir, ent.name)).mtimeMs;
143272
+ if (childMs > maxMs) maxMs = childMs;
143273
+ } catch {
143274
+ }
143275
+ }
143276
+ } catch {
143277
+ }
143278
+ return maxMs;
143279
+ }
143280
+ function shouldRefreshProjectsFromHdd(conversationsRepo, cacheMetadataRepo, opts = {}) {
143281
+ if (conversationsRepo.hasOrphanRows()) return true;
143282
+ const dirs = /* @__PURE__ */ new Set();
143283
+ if (opts.projectsDirs) {
143284
+ for (const d of opts.projectsDirs) dirs.add(d);
143285
+ }
143286
+ dirs.add(opts.projectsDir ?? DEFAULT_PROJECTS_DIR);
143287
+ let newestMs = null;
143288
+ for (const dir of dirs) {
143289
+ const ms2 = maxProjectsTreeMtimeMs(dir);
143290
+ if (ms2 === null) continue;
143291
+ if (newestMs === null || ms2 > newestMs) newestMs = ms2;
143292
+ }
143293
+ if (newestMs === null) return false;
143294
+ const lastIndexedIso = getCacheMetadata(cacheMetadataRepo, "conversations_last_indexed_at");
143295
+ if (!lastIndexedIso) return true;
143296
+ const lastIndexedMs = Date.parse(lastIndexedIso);
143297
+ if (Number.isNaN(lastIndexedMs)) return true;
143298
+ return newestMs > lastIndexedMs;
143299
+ }
143300
+
142939
143301
  // src/services/projectChats/deriveProjectChatTitle.ts
142940
143302
  function deriveProjectChatTitle(input) {
142941
143303
  const trimmed = input.title?.trim();
@@ -143097,7 +143459,7 @@ function resolveAnswer(pending, body) {
143097
143459
  }
143098
143460
 
143099
143461
  // src/services/sessions/conversationBusy.ts
143100
- var import_fs27 = require("fs");
143462
+ var import_fs28 = require("fs");
143101
143463
  var RESUME_BUSY_WINDOW_MS = 12e4;
143102
143464
  function resolveResumeBusyWindowMs(env = process.env) {
143103
143465
  const raw2 = env.THREADBASE_RESUME_BUSY_WINDOW_MS;
@@ -143114,7 +143476,7 @@ function conversationBusy(input) {
143114
143476
  let lastActivityMs = null;
143115
143477
  if (input.jsonlPath) {
143116
143478
  try {
143117
- const mtimeMs = (0, import_fs27.statSync)(input.jsonlPath).mtimeMs;
143479
+ const mtimeMs = (0, import_fs28.statSync)(input.jsonlPath).mtimeMs;
143118
143480
  const age = now - mtimeMs;
143119
143481
  lastActivityMs = Math.max(0, age);
143120
143482
  const isSelfEcho = input.selfPtyEndedAt != null && mtimeMs <= input.selfPtyEndedAt + SELF_ACTIVITY_SKEW_MS;
@@ -143368,7 +143730,7 @@ function discoveredToResponse(d, conversationId) {
143368
143730
  var import_crypto11 = require("crypto");
143369
143731
  var import_promises15 = require("fs/promises");
143370
143732
  var import_heic_convert = __toESM(require_heic_convert(), 1);
143371
- var import_path27 = require("path");
143733
+ var import_path28 = require("path");
143372
143734
  var UPLOAD_DIR_NAME = ".threadbase-uploads";
143373
143735
  var MAX_BYTES = 25 * 1024 * 1024;
143374
143736
  var HEIC_MIMES = /* @__PURE__ */ new Set(["image/heic", "image/heif"]);
@@ -143401,9 +143763,9 @@ async function saveUploadFile(input) {
143401
143763
  }
143402
143764
  const id = `up_${(0, import_crypto11.randomBytes)(8).toString("hex")}`;
143403
143765
  const safeName = sanitizeFilename(originalName) || `file${MIME_TO_EXT[mimeType] ?? ""}`;
143404
- const dir = (0, import_path27.join)(input.projectPath, UPLOAD_DIR_NAME, input.sessionId);
143766
+ const dir = (0, import_path28.join)(input.projectPath, UPLOAD_DIR_NAME, input.sessionId);
143405
143767
  await (0, import_promises15.mkdir)(dir, { recursive: true });
143406
- const filePath = (0, import_path27.join)(dir, `${Date.now()}-${id}-${safeName}`);
143768
+ const filePath = (0, import_path28.join)(dir, `${Date.now()}-${id}-${safeName}`);
143407
143769
  await (0, import_promises15.writeFile)(filePath, buffer);
143408
143770
  return {
143409
143771
  id,
@@ -143513,226 +143875,6 @@ function computeConversationEtag({
143513
143875
  return `"${digest}"`;
143514
143876
  }
143515
143877
 
143516
- // node_modules/date-fns/constants.js
143517
- var daysInYear = 365.2425;
143518
- var maxTime = Math.pow(10, 8) * 24 * 60 * 60 * 1e3;
143519
- var minTime = -maxTime;
143520
- var millisecondsInMinute = 6e4;
143521
- var millisecondsInHour = 36e5;
143522
- var secondsInHour = 3600;
143523
- var secondsInDay = secondsInHour * 24;
143524
- var secondsInWeek = secondsInDay * 7;
143525
- var secondsInYear = secondsInDay * daysInYear;
143526
- var secondsInMonth = secondsInYear / 12;
143527
- var secondsInQuarter = secondsInMonth * 3;
143528
- var constructFromSymbol = /* @__PURE__ */ Symbol.for("constructDateFrom");
143529
-
143530
- // node_modules/date-fns/constructFrom.js
143531
- function constructFrom(date5, value) {
143532
- if (typeof date5 === "function") return date5(value);
143533
- if (date5 && typeof date5 === "object" && constructFromSymbol in date5)
143534
- return date5[constructFromSymbol](value);
143535
- if (date5 instanceof Date) return new date5.constructor(value);
143536
- return new Date(value);
143537
- }
143538
-
143539
- // node_modules/date-fns/toDate.js
143540
- function toDate(argument, context) {
143541
- return constructFrom(context || argument, argument);
143542
- }
143543
-
143544
- // node_modules/date-fns/isDate.js
143545
- function isDate(value) {
143546
- return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
143547
- }
143548
-
143549
- // node_modules/date-fns/isValid.js
143550
- function isValid(date5) {
143551
- return !(!isDate(date5) && typeof date5 !== "number" || isNaN(+toDate(date5)));
143552
- }
143553
-
143554
- // node_modules/date-fns/parseISO.js
143555
- function parseISO(argument, options) {
143556
- const invalidDate = () => constructFrom(options?.in, NaN);
143557
- const additionalDigits = options?.additionalDigits ?? 2;
143558
- const dateStrings = splitDateString(argument);
143559
- let date5;
143560
- if (dateStrings.date) {
143561
- const parseYearResult = parseYear(dateStrings.date, additionalDigits);
143562
- date5 = parseDate(parseYearResult.restDateString, parseYearResult.year);
143563
- }
143564
- if (!date5 || isNaN(+date5)) return invalidDate();
143565
- const timestamp2 = +date5;
143566
- let time3 = 0;
143567
- let offset;
143568
- if (dateStrings.time) {
143569
- time3 = parseTime(dateStrings.time);
143570
- if (isNaN(time3)) return invalidDate();
143571
- }
143572
- if (dateStrings.timezone) {
143573
- offset = parseTimezone(dateStrings.timezone);
143574
- if (isNaN(offset)) return invalidDate();
143575
- } else {
143576
- const tmpDate = new Date(timestamp2 + time3);
143577
- const result = toDate(0, options?.in);
143578
- result.setFullYear(
143579
- tmpDate.getUTCFullYear(),
143580
- tmpDate.getUTCMonth(),
143581
- tmpDate.getUTCDate()
143582
- );
143583
- result.setHours(
143584
- tmpDate.getUTCHours(),
143585
- tmpDate.getUTCMinutes(),
143586
- tmpDate.getUTCSeconds(),
143587
- tmpDate.getUTCMilliseconds()
143588
- );
143589
- return result;
143590
- }
143591
- return toDate(timestamp2 + time3 + offset, options?.in);
143592
- }
143593
- var patterns = {
143594
- dateTimeDelimiter: /[T ]/,
143595
- timeZoneDelimiter: /[Z ]/i,
143596
- timezone: /([Z+-].*)$/
143597
- };
143598
- var dateRegex = /^-?(?:(\d{3})|(\d{2})(?:-?(\d{2}))?|W(\d{2})(?:-?(\d{1}))?|)$/;
143599
- var timeRegex = /^(\d{2}(?:[.,]\d*)?)(?::?(\d{2}(?:[.,]\d*)?))?(?::?(\d{2}(?:[.,]\d*)?))?$/;
143600
- var timezoneRegex = /^([+-])(\d{2})(?::?(\d{2}))?$/;
143601
- function splitDateString(dateString) {
143602
- const dateStrings = {};
143603
- const array2 = dateString.split(patterns.dateTimeDelimiter);
143604
- let timeString;
143605
- if (array2.length > 2) {
143606
- return dateStrings;
143607
- }
143608
- if (/:/.test(array2[0])) {
143609
- timeString = array2[0];
143610
- } else {
143611
- dateStrings.date = array2[0];
143612
- timeString = array2[1];
143613
- if (patterns.timeZoneDelimiter.test(dateStrings.date)) {
143614
- dateStrings.date = dateString.split(patterns.timeZoneDelimiter)[0];
143615
- timeString = dateString.substr(
143616
- dateStrings.date.length,
143617
- dateString.length
143618
- );
143619
- }
143620
- }
143621
- if (timeString) {
143622
- const token = patterns.timezone.exec(timeString);
143623
- if (token) {
143624
- dateStrings.time = timeString.replace(token[1], "");
143625
- dateStrings.timezone = token[1];
143626
- } else {
143627
- dateStrings.time = timeString;
143628
- }
143629
- }
143630
- return dateStrings;
143631
- }
143632
- function parseYear(dateString, additionalDigits) {
143633
- const regex = new RegExp(
143634
- "^(?:(\\d{4}|[+-]\\d{" + (4 + additionalDigits) + "})|(\\d{2}|[+-]\\d{" + (2 + additionalDigits) + "})$)"
143635
- );
143636
- const captures = dateString.match(regex);
143637
- if (!captures) return { year: NaN, restDateString: "" };
143638
- const year = captures[1] ? parseInt(captures[1]) : null;
143639
- const century = captures[2] ? parseInt(captures[2]) : null;
143640
- return {
143641
- year: century === null ? year : century * 100,
143642
- restDateString: dateString.slice((captures[1] || captures[2]).length)
143643
- };
143644
- }
143645
- function parseDate(dateString, year) {
143646
- if (year === null) return /* @__PURE__ */ new Date(NaN);
143647
- const captures = dateString.match(dateRegex);
143648
- if (!captures) return /* @__PURE__ */ new Date(NaN);
143649
- const isWeekDate = !!captures[4];
143650
- const dayOfYear = parseDateUnit(captures[1]);
143651
- const month = parseDateUnit(captures[2]) - 1;
143652
- const day = parseDateUnit(captures[3]);
143653
- const week = parseDateUnit(captures[4]);
143654
- const dayOfWeek = parseDateUnit(captures[5]) - 1;
143655
- if (isWeekDate) {
143656
- if (!validateWeekDate(year, week, dayOfWeek)) {
143657
- return /* @__PURE__ */ new Date(NaN);
143658
- }
143659
- return dayOfISOWeekYear(year, week, dayOfWeek);
143660
- } else {
143661
- const date5 = /* @__PURE__ */ new Date(0);
143662
- if (!validateDate(year, month, day) || !validateDayOfYearDate(year, dayOfYear)) {
143663
- return /* @__PURE__ */ new Date(NaN);
143664
- }
143665
- date5.setUTCFullYear(year, month, Math.max(dayOfYear, day));
143666
- return date5;
143667
- }
143668
- }
143669
- function parseDateUnit(value) {
143670
- return value ? parseInt(value) : 1;
143671
- }
143672
- function parseTime(timeString) {
143673
- const captures = timeString.match(timeRegex);
143674
- if (!captures) return NaN;
143675
- const hours = parseTimeUnit(captures[1]);
143676
- const minutes = parseTimeUnit(captures[2]);
143677
- const seconds = parseTimeUnit(captures[3]);
143678
- if (!validateTime(hours, minutes, seconds)) {
143679
- return NaN;
143680
- }
143681
- return hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * 1e3;
143682
- }
143683
- function parseTimeUnit(value) {
143684
- return value && parseFloat(value.replace(",", ".")) || 0;
143685
- }
143686
- function parseTimezone(timezoneString) {
143687
- if (timezoneString === "Z") return 0;
143688
- const captures = timezoneString.match(timezoneRegex);
143689
- if (!captures) return 0;
143690
- const sign = captures[1] === "+" ? -1 : 1;
143691
- const hours = parseInt(captures[2]);
143692
- const minutes = captures[3] && parseInt(captures[3]) || 0;
143693
- if (!validateTimezone(hours, minutes)) {
143694
- return NaN;
143695
- }
143696
- return sign * (hours * millisecondsInHour + minutes * millisecondsInMinute);
143697
- }
143698
- function dayOfISOWeekYear(isoWeekYear, week, day) {
143699
- const date5 = /* @__PURE__ */ new Date(0);
143700
- date5.setUTCFullYear(isoWeekYear, 0, 4);
143701
- const fourthOfJanuaryDay = date5.getUTCDay() || 7;
143702
- const diff = (week - 1) * 7 + day + 1 - fourthOfJanuaryDay;
143703
- date5.setUTCDate(date5.getUTCDate() + diff);
143704
- return date5;
143705
- }
143706
- var daysInMonths = [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
143707
- function isLeapYearIndex(year) {
143708
- return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
143709
- }
143710
- function validateDate(year, month, date5) {
143711
- return month >= 0 && month <= 11 && date5 >= 1 && date5 <= (daysInMonths[month] || (isLeapYearIndex(year) ? 29 : 28));
143712
- }
143713
- function validateDayOfYearDate(year, dayOfYear) {
143714
- return dayOfYear >= 1 && dayOfYear <= (isLeapYearIndex(year) ? 366 : 365);
143715
- }
143716
- function validateWeekDate(_year, week, day) {
143717
- return week >= 1 && week <= 53 && day >= 0 && day <= 6;
143718
- }
143719
- function validateTime(hours, minutes, seconds) {
143720
- if (hours === 24) {
143721
- return minutes === 0 && seconds === 0;
143722
- }
143723
- return seconds >= 0 && seconds < 60 && minutes >= 0 && minutes < 60 && hours >= 0 && hours < 25;
143724
- }
143725
- function validateTimezone(_hours, minutes) {
143726
- return minutes >= 0 && minutes <= 59;
143727
- }
143728
-
143729
- // src/utils/dates.ts
143730
- function parseIsoDateOrNull(value) {
143731
- if (!value) return null;
143732
- const parsed = parseISO(value);
143733
- return isValid(parsed) ? parsed : null;
143734
- }
143735
-
143736
143878
  // src/utils/isScannedSnapshotStale.ts
143737
143879
  var STALENESS_TOLERANCE_MS = 1e3;
143738
143880
  function isScannedSnapshotStale(snapshotTimestamp, fileMtimeMs) {
@@ -143943,6 +144085,10 @@ var StreamerServer = class {
143943
144085
  // Set by onConversationChanged while a scan is in-flight; getScanner() does
143944
144086
  // a single rescan after the current one completes instead of restarting it.
143945
144087
  scannerStale = false;
144088
+ // Single-flight guard for the background disk reconcile: a burst of list
144089
+ // polls during active session writes shares one rescan instead of queueing
144090
+ // a full rescan per request.
144091
+ conversationReconcileInFlight = null;
143946
144092
  // Single-flight + TTL guard around scanner.refreshFile (see refreshFileGuarded).
143947
144093
  // A live file's mtime is always newer than the snapshot, so an unguarded
143948
144094
  // refresh fires on every request and re-parses the whole file from byte 0.
@@ -144033,13 +144179,13 @@ var StreamerServer = class {
144033
144179
  this.disableDb = config2.disableDb ?? false;
144034
144180
  this.scannerPersistenceDisabled = config2.scannerPersistent === false;
144035
144181
  this.scanProfiles = config2.scanProfiles;
144036
- this.codexRoots = config2.codexRoots ?? [(0, import_path28.join)((0, import_os11.homedir)(), ".codex", "sessions")];
144182
+ this.codexRoots = config2.codexRoots ?? [(0, import_path29.join)((0, import_os12.homedir)(), ".codex", "sessions")];
144037
144183
  this.ptyGracePeriodMs = config2.ptyGracePeriodMs ?? DEFAULT_PTY_GRACE_PERIOD_MS;
144038
144184
  this.defaultSystemPrompt = config2.defaultSystemPrompt ?? DEFAULT_SYSTEM_PROMPT;
144039
144185
  this.defaultPermissionMode = config2.defaultPermissionMode ?? loadDefaultPermissionMode() ?? "acceptEdits";
144040
144186
  this.defaultModel = config2.defaultModel ?? "sonnet";
144041
144187
  this.defaultEffort = config2.defaultEffort ?? "low";
144042
- this.cacheDir = config2.cacheDir ?? loadCacheDir() ?? (0, import_path28.join)((0, import_os11.homedir)(), ".threadbase", "cache");
144188
+ this.cacheDir = config2.cacheDir ?? loadCacheDir() ?? (0, import_path29.join)((0, import_os12.homedir)(), ".threadbase", "cache");
144043
144189
  this.tailSize = config2.tailSize ?? loadTailSize() ?? 10;
144044
144190
  this.directoryDebounceMs = parseDirScanDebounceEnv(process.env.THREADBASE_DIR_SCAN_DEBOUNCE_MS) ?? config2.directoryScanDebounceMs ?? 1e3;
144045
144191
  this.markScannerStaleDebounced = debounce(() => {
@@ -144080,7 +144226,7 @@ var StreamerServer = class {
144080
144226
  const seqs = cache.extendMessageIndex(
144081
144227
  filePath,
144082
144228
  spans,
144083
- (0, import_fs28.statSync)(filePath),
144229
+ (0, import_fs29.statSync)(filePath),
144084
144230
  readFrom,
144085
144231
  endOffset
144086
144232
  );
@@ -144246,7 +144392,7 @@ var StreamerServer = class {
144246
144392
  temporalClient,
144247
144393
  taskQueue: agentConfig.temporal.taskQueue
144248
144394
  });
144249
- const conversationsBaseDir = agentConfig.conversationsDir || (0, import_path28.join)((0, import_path28.dirname)(this.cacheDir), "conversations");
144395
+ const conversationsBaseDir = agentConfig.conversationsDir || (0, import_path29.join)((0, import_path29.dirname)(this.cacheDir), "conversations");
144250
144396
  conversationWriter = createConversationWriter({
144251
144397
  baseDir: conversationsBaseDir
144252
144398
  });
@@ -144569,7 +144715,7 @@ var StreamerServer = class {
144569
144715
  });
144570
144716
  try {
144571
144717
  this.cache = ConversationCache.open(
144572
- (0, import_path28.join)(this.cacheDir, "cache.db"),
144718
+ (0, import_path29.join)(this.cacheDir, "cache.db"),
144573
144719
  this.tailSize,
144574
144720
  void 0,
144575
144721
  {
@@ -144614,7 +144760,7 @@ var StreamerServer = class {
144614
144760
  this.fileWatcher.watchDirectory(dir);
144615
144761
  }
144616
144762
  for (const dir of this.codexRoots) {
144617
- if (!(0, import_fs28.existsSync)(dir)) continue;
144763
+ if (!(0, import_fs29.existsSync)(dir)) continue;
144618
144764
  this.fileWatcher.watchDirectory(dir);
144619
144765
  }
144620
144766
  } catch (err) {
@@ -144695,6 +144841,20 @@ var StreamerServer = class {
144695
144841
  count: pruned.length,
144696
144842
  event: "cache.prune_ghosts"
144697
144843
  });
144844
+ if (this.projectsRepo && this.conversationsRepo && this.cacheMetadataRepo) {
144845
+ refreshConversationCache({
144846
+ cache: this.cache,
144847
+ projectsRepo: this.projectsRepo,
144848
+ conversationsRepo: this.conversationsRepo,
144849
+ cacheMetadataRepo: this.cacheMetadataRepo
144850
+ });
144851
+ } else if (this.cacheMetadataRepo) {
144852
+ setCacheMetadata(
144853
+ this.cacheMetadataRepo,
144854
+ "conversations_last_indexed_at",
144855
+ (/* @__PURE__ */ new Date()).toISOString()
144856
+ );
144857
+ }
144698
144858
  }
144699
144859
  }).catch((err) => {
144700
144860
  const message = err instanceof Error ? err.message : String(err);
@@ -144934,6 +145094,68 @@ var StreamerServer = class {
144934
145094
  checkSessionInputRateLimit(sessionId) {
144935
145095
  return this.checkRateLimit(this.sessionInputAttempts, sessionId, 500, 6e4);
144936
145096
  }
145097
+ /** Project roots watched for conversation JSONLs (profiles or ~/.claude/projects). */
145098
+ projectsDirsForFreshnessCheck() {
145099
+ if (this.scanProfiles && this.scanProfiles.length > 0) {
145100
+ return this.scanProfiles.filter((p2) => p2.enabled).map((p2) => (0, import_path29.join)(p2.configDir, "projects"));
145101
+ }
145102
+ return [(0, import_path29.join)((0, import_os12.homedir)(), ".claude", "projects")];
145103
+ }
145104
+ /**
145105
+ * Full-glob scan + cache upsert/delete reconcile. Used by ?refresh=1 and by
145106
+ * the automatic freshness path when the directory watcher marked the scanner
145107
+ * stale or shouldRefreshProjectsFromHdd detected disk drift.
145108
+ */
145109
+ async reconcileConversationsCacheFromDisk(onProgress) {
145110
+ if (!this.cache) return;
145111
+ const scanner = await this.rescanForRefresh(onProgress);
145112
+ const metas = [...scanner.getMetadataCache().values()];
145113
+ try {
145114
+ this.cache.upsertFromScannerMeta(metas);
145115
+ if (!this.cacheMonitor?.pending) {
145116
+ this.cache.reconcileDeletions(canonicalLivePathSet(metas));
145117
+ }
145118
+ if (this.projectsRepo && this.conversationsRepo && this.cacheMetadataRepo) {
145119
+ refreshConversationCache({
145120
+ cache: this.cache,
145121
+ projectsRepo: this.projectsRepo,
145122
+ conversationsRepo: this.conversationsRepo,
145123
+ cacheMetadataRepo: this.cacheMetadataRepo
145124
+ });
145125
+ } else if (this.cacheMetadataRepo) {
145126
+ setCacheMetadata(
145127
+ this.cacheMetadataRepo,
145128
+ "conversations_last_indexed_at",
145129
+ (/* @__PURE__ */ new Date()).toISOString()
145130
+ );
145131
+ }
145132
+ } catch (err) {
145133
+ this.log.warn(
145134
+ `refresh reconcile failed: ${err instanceof Error ? err.message : String(err)}`,
145135
+ { event: "conversations.reconcile_failed" }
145136
+ );
145137
+ }
145138
+ }
145139
+ // Reconcile the cache from disk without blocking the caller. Single-flighted
145140
+ // so a burst of list polls during active session writes shares one rescan
145141
+ // rather than queueing a full rescan each; tracked so close() awaits the
145142
+ // in-flight cache write before shutting the DB.
145143
+ startBackgroundConversationReconcile() {
145144
+ if (this.conversationReconcileInFlight) return;
145145
+ const task = this.reconcileConversationsCacheFromDisk().finally(() => {
145146
+ this.conversationReconcileInFlight = null;
145147
+ });
145148
+ this.conversationReconcileInFlight = task;
145149
+ this.trackCacheWrite(task);
145150
+ }
145151
+ shouldAutoReconcileConversationList() {
145152
+ if (!this.cache) return false;
145153
+ if (this.scannerStale) return true;
145154
+ if (!this.conversationsRepo || !this.cacheMetadataRepo) return false;
145155
+ return shouldRefreshProjectsFromHdd(this.conversationsRepo, this.cacheMetadataRepo, {
145156
+ projectsDirs: this.projectsDirsForFreshnessCheck()
145157
+ });
145158
+ }
144937
145159
  async handleListConversations(url2, res) {
144938
145160
  if (this.rejectIfWarmingUp(res)) return;
144939
145161
  const limit = intParam(url2, "limit", 50);
@@ -144942,18 +145164,19 @@ var StreamerServer = class {
144942
145164
  const project = url2.searchParams.get("project") ?? void 0;
144943
145165
  const providerFilter = url2.searchParams.get("provider") ?? void 0;
144944
145166
  const bustCache = url2.searchParams.get("refresh") === "1";
144945
- if (bustCache && this.cache) {
144946
- const scanner2 = await this.withWarmup("conversation_refresh", () => this.rescanForRefresh());
144947
- const metas2 = [...scanner2.getMetadataCache().values()];
144948
- try {
144949
- this.cache.upsertFromScannerMeta(metas2);
144950
- if (!this.cacheMonitor?.pending) {
144951
- this.cache.reconcileDeletions(canonicalLivePathSet(metas2));
144952
- }
144953
- } catch (err) {
144954
- this.log.warn(
144955
- `refresh reconcile failed: ${err instanceof Error ? err.message : String(err)}`,
144956
- { event: "conversations.reconcile_failed" }
145167
+ if (this.cache && (bustCache || this.shouldAutoReconcileConversationList())) {
145168
+ const canServeStale = !bustCache && this.cache.listConversations({ limit: 0, offset: 0 }).total > 0;
145169
+ if (canServeStale) {
145170
+ this.startBackgroundConversationReconcile();
145171
+ } else {
145172
+ const shouldEmitProgress = createScanProgressThrottle();
145173
+ await this.withWarmup(
145174
+ "conversation_refresh",
145175
+ () => this.reconcileConversationsCacheFromDisk((scanned, total2) => {
145176
+ if (shouldEmitProgress(scanned, total2)) {
145177
+ this.wsHub.broadcast({ type: "scan_progress", scanned, total: total2 });
145178
+ }
145179
+ })
144957
145180
  );
144958
145181
  }
144959
145182
  }
@@ -145190,7 +145413,7 @@ var StreamerServer = class {
145190
145413
  // getFreshScanner() this does NOT discard the warm scanner. scannerReady is
145191
145414
  // only ever reassigned to a live scan promise (never nulled mid-scan), so the
145192
145415
  // getScanner() anti-infinite-loop guard is preserved.
145193
- async rescanForRefresh() {
145416
+ async rescanForRefresh(onProgress) {
145194
145417
  if (this.scannerReady) await this.scannerReady;
145195
145418
  this.scannerStale = false;
145196
145419
  if (!this.scanner) {
@@ -145201,7 +145424,8 @@ var StreamerServer = class {
145201
145424
  this.scannerReady = scanner.scan({
145202
145425
  ...this.scanProfiles ? { profiles: this.scanProfiles } : {},
145203
145426
  ...this.codexScanOpts(),
145204
- fullRescan: true
145427
+ fullRescan: true,
145428
+ ...onProgress ? { onProgress } : {}
145205
145429
  });
145206
145430
  await this.scannerReady;
145207
145431
  return scanner;
@@ -145216,22 +145440,22 @@ var StreamerServer = class {
145216
145440
  */
145217
145441
  projectsDirs() {
145218
145442
  if (this.scanProfiles && this.scanProfiles.length > 0) {
145219
- return this.scanProfiles.filter((p2) => p2.enabled).map((p2) => (0, import_path28.join)(p2.configDir, "projects"));
145443
+ return this.scanProfiles.filter((p2) => p2.enabled).map((p2) => (0, import_path29.join)(p2.configDir, "projects"));
145220
145444
  }
145221
- return [(0, import_path28.join)((0, import_os11.homedir)(), ".claude", "projects")];
145445
+ return [(0, import_path29.join)((0, import_os12.homedir)(), ".claude", "projects")];
145222
145446
  }
145223
145447
  findJsonlPath(uuid3) {
145224
145448
  const filename = `${uuid3}.jsonl`;
145225
145449
  for (const projectsDir of this.projectsDirs()) {
145226
- if (!(0, import_fs28.existsSync)(projectsDir)) continue;
145227
- for (const dir of (0, import_fs28.readdirSync)(projectsDir)) {
145228
- const fp = (0, import_path28.join)(projectsDir, dir, filename);
145229
- if ((0, import_fs28.existsSync)(fp)) return fp;
145230
- const projectDir = (0, import_path28.join)(projectsDir, dir);
145450
+ if (!(0, import_fs29.existsSync)(projectsDir)) continue;
145451
+ for (const dir of (0, import_fs29.readdirSync)(projectsDir)) {
145452
+ const fp = (0, import_path29.join)(projectsDir, dir, filename);
145453
+ if ((0, import_fs29.existsSync)(fp)) return fp;
145454
+ const projectDir = (0, import_path29.join)(projectsDir, dir);
145231
145455
  try {
145232
- for (const sub of (0, import_fs28.readdirSync)(projectDir)) {
145233
- const subagentPath = (0, import_path28.join)(projectDir, sub, "subagents", filename);
145234
- if ((0, import_fs28.existsSync)(subagentPath)) return subagentPath;
145456
+ for (const sub of (0, import_fs29.readdirSync)(projectDir)) {
145457
+ const subagentPath = (0, import_path29.join)(projectDir, sub, "subagents", filename);
145458
+ if ((0, import_fs29.existsSync)(subagentPath)) return subagentPath;
145235
145459
  }
145236
145460
  } catch {
145237
145461
  }
@@ -145241,7 +145465,7 @@ var StreamerServer = class {
145241
145465
  }
145242
145466
  async readCwdFromJsonl(filePath) {
145243
145467
  return new Promise((resolve4) => {
145244
- const rl = (0, import_readline4.createInterface)({ input: (0, import_fs28.createReadStream)(filePath), crlfDelay: Infinity });
145468
+ const rl = (0, import_readline4.createInterface)({ input: (0, import_fs29.createReadStream)(filePath), crlfDelay: Infinity });
145245
145469
  let found = false;
145246
145470
  rl.on("line", (line) => {
145247
145471
  if (found) return;
@@ -145331,7 +145555,7 @@ var StreamerServer = class {
145331
145555
  if (this.isManagedTailPath(key)) return;
145332
145556
  let mtimeMs;
145333
145557
  try {
145334
- mtimeMs = (0, import_fs28.statSync)(filePath).mtimeMs;
145558
+ mtimeMs = (0, import_fs29.statSync)(filePath).mtimeMs;
145335
145559
  } catch {
145336
145560
  return;
145337
145561
  }
@@ -145513,7 +145737,7 @@ var StreamerServer = class {
145513
145737
  if (!conv.filePath) return false;
145514
145738
  let mtimeMs = null;
145515
145739
  try {
145516
- mtimeMs = (0, import_fs28.statSync)(conv.filePath).mtimeMs;
145740
+ mtimeMs = (0, import_fs29.statSync)(conv.filePath).mtimeMs;
145517
145741
  } catch {
145518
145742
  return false;
145519
145743
  }
@@ -145886,7 +146110,7 @@ var StreamerServer = class {
145886
146110
  if (this.rejectIfWarmingUp(res)) return;
145887
146111
  const session = this.sessionStore.get(sessionId, this.ptyAttachedIds());
145888
146112
  if (session) {
145889
- if (!(0, import_fs28.existsSync)(session.projectPath)) {
146113
+ if (!(0, import_fs29.existsSync)(session.projectPath)) {
145890
146114
  session.failureReason = `Project directory not found: ${session.projectPath}`;
145891
146115
  }
145892
146116
  if (this.ptyManager.hasSession(sessionId)) {
@@ -146357,7 +146581,7 @@ var StreamerServer = class {
146357
146581
  const jsonlCwd = jsonlPath ? await this.readCwdFromJsonl(jsonlPath) : null;
146358
146582
  if (jsonlCwd) {
146359
146583
  projectPath = jsonlCwd;
146360
- projectName = projectName || (0, import_path28.basename)(jsonlCwd);
146584
+ projectName = projectName || (0, import_path29.basename)(jsonlCwd);
146361
146585
  }
146362
146586
  }
146363
146587
  if (!projectPath) {
@@ -146433,7 +146657,7 @@ var StreamerServer = class {
146433
146657
  sessionStore: this.sessionStore,
146434
146658
  // biome-ignore lint/style/noNonNullAssertion: agentClient is set when agentConfig.enabled is true
146435
146659
  agentClient: this.agentClient,
146436
- conversationsDir: this.cacheDir ? (0, import_path28.join)((0, import_path28.dirname)(this.cacheDir), "conversations") : "",
146660
+ conversationsDir: this.cacheDir ? (0, import_path29.join)((0, import_path29.dirname)(this.cacheDir), "conversations") : "",
146437
146661
  agentConfig: this.agentConfig
146438
146662
  });
146439
146663
  json2(res, result.status, result.body);
@@ -146577,7 +146801,7 @@ var StreamerServer = class {
146577
146801
  // file isn't slurped in full.
146578
146802
  readFirstLineSessionId(filePath) {
146579
146803
  try {
146580
- const content = (0, import_fs28.readFileSync)(filePath, "utf8");
146804
+ const content = (0, import_fs29.readFileSync)(filePath, "utf8");
146581
146805
  const nl = content.indexOf("\n");
146582
146806
  const firstLine = nl === -1 ? content : content.slice(0, nl);
146583
146807
  if (!firstLine.trim()) return null;
@@ -146592,9 +146816,9 @@ var StreamerServer = class {
146592
146816
  // was passed to Claude via --session-id so the filename matches from the start.
146593
146817
  watchForJsonl(sessionId, projectPath) {
146594
146818
  const encoded = projectPath.replace(/[/\\:.]/g, "-");
146595
- const projectsDir = (0, import_path28.join)((0, import_os11.homedir)(), ".claude", "projects", encoded);
146819
+ const projectsDir = (0, import_path29.join)((0, import_os12.homedir)(), ".claude", "projects", encoded);
146596
146820
  const expectedFile = `${sessionId}.jsonl`;
146597
- const filePath = (0, import_path28.join)(projectsDir, expectedFile);
146821
+ const filePath = (0, import_path29.join)(projectsDir, expectedFile);
146598
146822
  const deadline = Date.now() + 12e4;
146599
146823
  let watcher = null;
146600
146824
  const cleanup = () => {
@@ -146612,14 +146836,14 @@ var StreamerServer = class {
146612
146836
  cleanup();
146613
146837
  return;
146614
146838
  }
146615
- let resolvedFilePath = (0, import_fs28.existsSync)(filePath) ? filePath : null;
146616
- if (!resolvedFilePath && (0, import_fs28.existsSync)(projectsDir)) {
146839
+ let resolvedFilePath = (0, import_fs29.existsSync)(filePath) ? filePath : null;
146840
+ if (!resolvedFilePath && (0, import_fs29.existsSync)(projectsDir)) {
146617
146841
  try {
146618
146842
  const now = Date.now();
146619
- const match2 = (0, import_fs28.readdirSync)(projectsDir).filter((f2) => f2.endsWith(".jsonl")).map((f2) => ({ f: f2, mtime: (0, import_fs28.statSync)((0, import_path28.join)(projectsDir, f2)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).filter(
146620
- ({ f: f2 }) => (0, import_path28.basename)(f2, ".jsonl") === sessionId || this.readFirstLineSessionId((0, import_path28.join)(projectsDir, f2)) === sessionId
146843
+ const match2 = (0, import_fs29.readdirSync)(projectsDir).filter((f2) => f2.endsWith(".jsonl")).map((f2) => ({ f: f2, mtime: (0, import_fs29.statSync)((0, import_path29.join)(projectsDir, f2)).mtimeMs })).filter(({ mtime }) => now - mtime < 5e3).filter(
146844
+ ({ f: f2 }) => (0, import_path29.basename)(f2, ".jsonl") === sessionId || this.readFirstLineSessionId((0, import_path29.join)(projectsDir, f2)) === sessionId
146621
146845
  ).sort((a, b2) => b2.mtime - a.mtime)[0];
146622
- if (match2) resolvedFilePath = (0, import_path28.join)(projectsDir, match2.f);
146846
+ if (match2) resolvedFilePath = (0, import_path29.join)(projectsDir, match2.f);
146623
146847
  } catch {
146624
146848
  }
146625
146849
  }
@@ -146627,7 +146851,7 @@ var StreamerServer = class {
146627
146851
  cleanup();
146628
146852
  this.sessionFileMap.set(sessionId, resolvedFilePath);
146629
146853
  try {
146630
- const existing = (0, import_fs28.readFileSync)(resolvedFilePath, "utf8").split("\n").filter(Boolean);
146854
+ const existing = (0, import_fs29.readFileSync)(resolvedFilePath, "utf8").split("\n").filter(Boolean);
146631
146855
  if (existing.length > 0) {
146632
146856
  this.broadcastConversationLines(sessionId, existing);
146633
146857
  }
@@ -146651,7 +146875,7 @@ var StreamerServer = class {
146651
146875
  if (this.sessionFileMap.has(sessionId)) return;
146652
146876
  try {
146653
146877
  require("fs").mkdirSync(projectsDir, { recursive: true });
146654
- watcher = (0, import_fs28.watch)(projectsDir, tryWire);
146878
+ watcher = (0, import_fs29.watch)(projectsDir, tryWire);
146655
146879
  watcher.on("error", cleanup);
146656
146880
  } catch {
146657
146881
  }
@@ -146667,7 +146891,7 @@ var StreamerServer = class {
146667
146891
  watchForCodexRollout(sessionId, projectPath) {
146668
146892
  const deadline = Date.now() + 12e4;
146669
146893
  const now = /* @__PURE__ */ new Date();
146670
- const dateDir = (0, import_path28.join)(
146894
+ const dateDir = (0, import_path29.join)(
146671
146895
  String(now.getFullYear()),
146672
146896
  String(now.getMonth() + 1).padStart(2, "0"),
146673
146897
  String(now.getDate()).padStart(2, "0")
@@ -146680,7 +146904,7 @@ var StreamerServer = class {
146680
146904
  };
146681
146905
  const matchesProjectPath = (candidatePath) => {
146682
146906
  try {
146683
- const firstLine = (0, import_fs28.readFileSync)(candidatePath, "utf8").split("\n", 1)[0];
146907
+ const firstLine = (0, import_fs29.readFileSync)(candidatePath, "utf8").split("\n", 1)[0];
146684
146908
  if (!firstLine) return null;
146685
146909
  const parsed = JSON.parse(firstLine);
146686
146910
  if (parsed?.type !== "session_meta") return null;
@@ -146708,18 +146932,18 @@ var StreamerServer = class {
146708
146932
  this.sessionStore.listManaged().filter((s3) => s3.id !== sessionId && s3.boundConversationId != null).map((s3) => s3.boundConversationId)
146709
146933
  );
146710
146934
  for (const root of this.codexRoots) {
146711
- const sessionsDir = (0, import_path28.join)(root, dateDir);
146712
- if (!(0, import_fs28.existsSync)(sessionsDir)) continue;
146935
+ const sessionsDir = (0, import_path29.join)(root, dateDir);
146936
+ if (!(0, import_fs29.existsSync)(sessionsDir)) continue;
146713
146937
  let candidateFiles;
146714
146938
  try {
146715
- candidateFiles = (0, import_fs28.readdirSync)(sessionsDir).filter((f2) => f2.endsWith(".jsonl"));
146939
+ candidateFiles = (0, import_fs29.readdirSync)(sessionsDir).filter((f2) => f2.endsWith(".jsonl"));
146716
146940
  } catch {
146717
146941
  continue;
146718
146942
  }
146719
146943
  const nowMs = Date.now();
146720
- const recentCandidates = candidateFiles.map((f2) => ({ f: f2, mtime: (0, import_fs28.statSync)((0, import_path28.join)(sessionsDir, f2)).mtimeMs })).filter(({ mtime }) => nowMs - mtime < 1e4).sort((a, b2) => b2.mtime - a.mtime);
146944
+ const recentCandidates = candidateFiles.map((f2) => ({ f: f2, mtime: (0, import_fs29.statSync)((0, import_path29.join)(sessionsDir, f2)).mtimeMs })).filter(({ mtime }) => nowMs - mtime < 1e4).sort((a, b2) => b2.mtime - a.mtime);
146721
146945
  for (const { f: f2 } of recentCandidates) {
146722
- const candidatePath = (0, import_path28.join)(sessionsDir, f2);
146946
+ const candidatePath = (0, import_path29.join)(sessionsDir, f2);
146723
146947
  const match2 = matchesProjectPath(candidatePath);
146724
146948
  if (!match2) continue;
146725
146949
  if (boundElsewhere.has(match2.id)) continue;
@@ -146729,7 +146953,7 @@ var StreamerServer = class {
146729
146953
  this.sessionFileMap.set(sessionId, candidatePath);
146730
146954
  this.fileWatcher.watch(candidatePath);
146731
146955
  try {
146732
- const existing = (0, import_fs28.readFileSync)(candidatePath, "utf8").split("\n").filter(Boolean);
146956
+ const existing = (0, import_fs29.readFileSync)(candidatePath, "utf8").split("\n").filter(Boolean);
146733
146957
  if (existing.length > 0) {
146734
146958
  this.broadcastConversationLines(sessionId, existing);
146735
146959
  }
@@ -146863,7 +147087,7 @@ async function waitForProcessExit(pid, timeoutMs, pollMs = ADOPT_KILL_POLL_MS) {
146863
147087
  }
146864
147088
  function classifyResumability(cwd) {
146865
147089
  if (!cwd) return { resumable: true };
146866
- if ((0, import_fs28.existsSync)(cwd)) return { resumable: true };
147090
+ if ((0, import_fs29.existsSync)(cwd)) return { resumable: true };
146867
147091
  const ranInWorktree = /\/\.worktrees\//.test(cwd) || /\/\.claude\/worktrees\//.test(cwd);
146868
147092
  return {
146869
147093
  resumable: false,
@@ -147533,13 +147757,13 @@ var import_node_fs18 = require("fs");
147533
147757
 
147534
147758
  // node_modules/tar/dist/esm/index.min.js
147535
147759
  var import_events3 = __toESM(require("events"), 1);
147536
- var import_fs29 = __toESM(require("fs"), 1);
147760
+ var import_fs30 = __toESM(require("fs"), 1);
147537
147761
  var import_node_events3 = require("events");
147538
147762
  var import_node_stream2 = __toESM(require("stream"), 1);
147539
147763
  var import_node_string_decoder = require("string_decoder");
147540
147764
  var import_node_path14 = __toESM(require("path"), 1);
147541
147765
  var import_node_fs12 = __toESM(require("fs"), 1);
147542
- var import_path29 = require("path");
147766
+ var import_path30 = require("path");
147543
147767
  var import_events4 = require("events");
147544
147768
  var import_assert = __toESM(require("assert"), 1);
147545
147769
  var import_buffer2 = require("buffer");
@@ -147547,17 +147771,17 @@ var Ps = __toESM(require("zlib"), 1);
147547
147771
  var import_zlib = __toESM(require("zlib"), 1);
147548
147772
  var import_node_path15 = require("path");
147549
147773
  var import_node_path16 = require("path");
147550
- var import_fs30 = __toESM(require("fs"), 1);
147551
147774
  var import_fs31 = __toESM(require("fs"), 1);
147552
- var import_path30 = __toESM(require("path"), 1);
147553
- var import_node_path17 = require("path");
147775
+ var import_fs32 = __toESM(require("fs"), 1);
147554
147776
  var import_path31 = __toESM(require("path"), 1);
147777
+ var import_node_path17 = require("path");
147778
+ var import_path32 = __toESM(require("path"), 1);
147555
147779
  var import_node_fs13 = __toESM(require("fs"), 1);
147556
147780
  var import_node_assert = __toESM(require("assert"), 1);
147557
147781
  var import_node_crypto5 = require("crypto");
147558
147782
  var import_node_fs14 = __toESM(require("fs"), 1);
147559
147783
  var import_node_path18 = __toESM(require("path"), 1);
147560
- var import_fs32 = __toESM(require("fs"), 1);
147784
+ var import_fs33 = __toESM(require("fs"), 1);
147561
147785
  var import_node_fs15 = __toESM(require("fs"), 1);
147562
147786
  var import_node_path19 = __toESM(require("path"), 1);
147563
147787
  var import_node_fs16 = __toESM(require("fs"), 1);
@@ -147909,7 +148133,7 @@ var A = class extends import_node_events3.EventEmitter {
147909
148133
  return Wr;
147910
148134
  }
147911
148135
  };
147912
- var Jr = import_fs29.default.writev;
148136
+ var Jr = import_fs30.default.writev;
147913
148137
  var ht = /* @__PURE__ */ Symbol("_autoClose");
147914
148138
  var H2 = /* @__PURE__ */ Symbol("_close");
147915
148139
  var te = /* @__PURE__ */ Symbol("_ended");
@@ -147964,7 +148188,7 @@ var _t = class extends A {
147964
148188
  throw new TypeError("this is a readable stream");
147965
148189
  }
147966
148190
  [at]() {
147967
- import_fs29.default.open(this[U], "r", (t, e) => this[Ht](t, e));
148191
+ import_fs30.default.open(this[U], "r", (t, e) => this[Ht](t, e));
147968
148192
  }
147969
148193
  [Ht](t, e) {
147970
148194
  t ? this[Ut](t) : (this[u] = e, this.emit("open", e), this[zt]());
@@ -147977,7 +148201,7 @@ var _t = class extends A {
147977
148201
  this[j] = true;
147978
148202
  let t = this[vi]();
147979
148203
  if (t.length === 0) return process.nextTick(() => this[Ii](null, 0, t));
147980
- import_fs29.default.read(this[u], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
148204
+ import_fs30.default.read(this[u], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
147981
148205
  }
147982
148206
  }
147983
148207
  [Ii](t, e, i) {
@@ -147986,7 +148210,7 @@ var _t = class extends A {
147986
148210
  [H2]() {
147987
148211
  if (this[ht] && typeof this[u] == "number") {
147988
148212
  let t = this[u];
147989
- this[u] = void 0, import_fs29.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
148213
+ this[u] = void 0, import_fs30.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
147990
148214
  }
147991
148215
  }
147992
148216
  [Ut](t) {
@@ -148014,7 +148238,7 @@ var Be = class extends _t {
148014
148238
  [at]() {
148015
148239
  let t = true;
148016
148240
  try {
148017
- this[Ht](null, import_fs29.default.openSync(this[U], "r")), t = false;
148241
+ this[Ht](null, import_fs30.default.openSync(this[U], "r")), t = false;
148018
148242
  } finally {
148019
148243
  t && this[H2]();
148020
148244
  }
@@ -148025,7 +148249,7 @@ var Be = class extends _t {
148025
148249
  if (!this[j]) {
148026
148250
  this[j] = true;
148027
148251
  do {
148028
- let e = this[vi](), i = e.length === 0 ? 0 : import_fs29.default.readSync(this[u], e, 0, e.length, null);
148252
+ let e = this[vi](), i = e.length === 0 ? 0 : import_fs30.default.readSync(this[u], e, 0, e.length, null);
148029
148253
  if (!this[ki](i, e)) break;
148030
148254
  } while (true);
148031
148255
  this[j] = false;
@@ -148038,7 +148262,7 @@ var Be = class extends _t {
148038
148262
  [H2]() {
148039
148263
  if (this[ht] && typeof this[u] == "number") {
148040
148264
  let t = this[u];
148041
- this[u] = void 0, import_fs29.default.closeSync(t), this.emit("close");
148265
+ this[u] = void 0, import_fs30.default.closeSync(t), this.emit("close");
148042
148266
  }
148043
148267
  }
148044
148268
  };
@@ -148080,7 +148304,7 @@ var et = class extends import_events3.default {
148080
148304
  this[H2](), this[gt] = true, this.emit("error", t);
148081
148305
  }
148082
148306
  [at]() {
148083
- import_fs29.default.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
148307
+ import_fs30.default.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
148084
148308
  }
148085
148309
  [Ht](t, e) {
148086
148310
  this[Me] && this[tt] === "r+" && t && t.code === "ENOENT" ? (this[tt] = "w", this[at]()) : t ? this[Ut](t) : (this[u] = e, this.emit("open", e), this[gt] || this[Ai]());
@@ -148092,7 +148316,7 @@ var et = class extends import_events3.default {
148092
148316
  return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", new Error("write() after end()")), false) : this[u] === void 0 || this[gt] || this[Y2].length ? (this[Y2].push(t), this[ke] = true, false) : (this[gt] = true, this[ve](t), true);
148093
148317
  }
148094
148318
  [ve](t) {
148095
- import_fs29.default.write(this[u], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
148319
+ import_fs30.default.write(this[u], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
148096
148320
  }
148097
148321
  [Pt](t, e) {
148098
148322
  t ? this[Ut](t) : (this[ot] !== void 0 && typeof e == "number" && (this[ot] += e), this[Y2].length ? this[Ai]() : (this[gt] = false, this[te] && !this[Ni] ? (this[Ni] = true, this[H2](), this.emit("finish")) : this[ke] && (this[ke] = false, this.emit("drain"))));
@@ -148108,7 +148332,7 @@ var et = class extends import_events3.default {
148108
148332
  [H2]() {
148109
148333
  if (this[ht] && typeof this[u] == "number") {
148110
148334
  let t = this[u];
148111
- this[u] = void 0, import_fs29.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
148335
+ this[u] = void 0, import_fs30.default.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
148112
148336
  }
148113
148337
  }
148114
148338
  };
@@ -148116,24 +148340,24 @@ var Wt = class extends et {
148116
148340
  [at]() {
148117
148341
  let t;
148118
148342
  if (this[Me] && this[tt] === "r+") try {
148119
- t = import_fs29.default.openSync(this[U], this[tt], this[ie]);
148343
+ t = import_fs30.default.openSync(this[U], this[tt], this[ie]);
148120
148344
  } catch (e) {
148121
148345
  if (e?.code === "ENOENT") return this[tt] = "w", this[at]();
148122
148346
  throw e;
148123
148347
  }
148124
- else t = import_fs29.default.openSync(this[U], this[tt], this[ie]);
148348
+ else t = import_fs30.default.openSync(this[U], this[tt], this[ie]);
148125
148349
  this[Ht](null, t);
148126
148350
  }
148127
148351
  [H2]() {
148128
148352
  if (this[ht] && typeof this[u] == "number") {
148129
148353
  let t = this[u];
148130
- this[u] = void 0, import_fs29.default.closeSync(t), this.emit("close");
148354
+ this[u] = void 0, import_fs30.default.closeSync(t), this.emit("close");
148131
148355
  }
148132
148356
  }
148133
148357
  [ve](t) {
148134
148358
  let e = true;
148135
148359
  try {
148136
- this[Pt](null, import_fs29.default.writeSync(this[u], t, 0, t.length, this[ot])), e = false;
148360
+ this[Pt](null, import_fs30.default.writeSync(this[u], t, 0, t.length, this[ot])), e = false;
148137
148361
  } finally {
148138
148362
  if (e) try {
148139
148363
  this[H2]();
@@ -148916,11 +149140,11 @@ var vn = (s3) => {
148916
149140
  };
148917
149141
  var Qi = (s3, t) => {
148918
149142
  let e = new Map(t.map((n) => [ut(n), true])), i = s3.filter, r = (n, o = "") => {
148919
- let h = o || (0, import_path29.parse)(n).root || ".", a;
149143
+ let h = o || (0, import_path30.parse)(n).root || ".", a;
148920
149144
  if (n === h) a = false;
148921
149145
  else {
148922
149146
  let l = e.get(n);
148923
- a = l !== void 0 ? l : r((0, import_path29.dirname)(n), h);
149147
+ a = l !== void 0 ? l : r((0, import_path30.dirname)(n), h);
148924
149148
  }
148925
149149
  return e.set(n, a), a;
148926
149150
  };
@@ -149040,7 +149264,7 @@ var de = class extends A {
149040
149264
  let [o, h] = ce(this.path);
149041
149265
  o && typeof h == "string" && (this.path = h, r = o);
149042
149266
  }
149043
- this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || import_path30.default.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
149267
+ this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || import_path31.default.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
149044
149268
  let n = this.statCache.get(this.absolute);
149045
149269
  n ? this[si](n) : this[ss]();
149046
149270
  }
@@ -149051,7 +149275,7 @@ var de = class extends A {
149051
149275
  return t === "error" && (this.#t = true), super.emit(t, ...e);
149052
149276
  }
149053
149277
  [ss]() {
149054
- import_fs31.default.lstat(this.absolute, (t, e) => {
149278
+ import_fs32.default.lstat(this.absolute, (t, e) => {
149055
149279
  if (t) return this.emit("error", t);
149056
149280
  this[si](e);
149057
149281
  });
@@ -149089,7 +149313,7 @@ var de = class extends A {
149089
149313
  this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[fe](), this.end();
149090
149314
  }
149091
149315
  [is]() {
149092
- import_fs31.default.readlink(this.absolute, (t, e) => {
149316
+ import_fs32.default.readlink(this.absolute, (t, e) => {
149093
149317
  if (t) return this.emit("error", t);
149094
149318
  this[ns](e);
149095
149319
  });
@@ -149099,7 +149323,7 @@ var de = class extends A {
149099
149323
  }
149100
149324
  [sr](t) {
149101
149325
  if (!this.stat) throw new Error("cannot create link entry without stat");
149102
- this.type = "Link", this.linkpath = f(import_path30.default.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
149326
+ this.type = "Link", this.linkpath = f(import_path31.default.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
149103
149327
  }
149104
149328
  [er]() {
149105
149329
  if (!this.stat) throw new Error("cannot create file entry without stat");
@@ -149112,7 +149336,7 @@ var de = class extends A {
149112
149336
  this[os]();
149113
149337
  }
149114
149338
  [os]() {
149115
- import_fs31.default.open(this.absolute, "r", (t, e) => {
149339
+ import_fs32.default.open(this.absolute, "r", (t, e) => {
149116
149340
  if (t) return this.emit("error", t);
149117
149341
  this[hs](e);
149118
149342
  });
@@ -149127,14 +149351,14 @@ var de = class extends A {
149127
149351
  [ii]() {
149128
149352
  let { fd: t, buf: e, offset: i, length: r, pos: n } = this;
149129
149353
  if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening");
149130
- import_fs31.default.read(t, e, i, r, n, (o, h) => {
149354
+ import_fs32.default.read(t, e, i, r, n, (o, h) => {
149131
149355
  if (o) return this[pt](() => this.emit("error", o));
149132
149356
  this[rs](h);
149133
149357
  });
149134
149358
  }
149135
149359
  [pt](t = () => {
149136
149360
  }) {
149137
- this.fd !== void 0 && import_fs31.default.close(this.fd, t);
149361
+ this.fd !== void 0 && import_fs32.default.close(this.fd, t);
149138
149362
  }
149139
149363
  [rs](t) {
149140
149364
  if (t <= 0 && this.remain > 0) {
@@ -149169,20 +149393,20 @@ var de = class extends A {
149169
149393
  var ni = class extends de {
149170
149394
  sync = true;
149171
149395
  [ss]() {
149172
- this[si](import_fs31.default.lstatSync(this.absolute));
149396
+ this[si](import_fs32.default.lstatSync(this.absolute));
149173
149397
  }
149174
149398
  [is]() {
149175
- this[ns](import_fs31.default.readlinkSync(this.absolute));
149399
+ this[ns](import_fs32.default.readlinkSync(this.absolute));
149176
149400
  }
149177
149401
  [os]() {
149178
- this[hs](import_fs31.default.openSync(this.absolute, "r"));
149402
+ this[hs](import_fs32.default.openSync(this.absolute, "r"));
149179
149403
  }
149180
149404
  [ii]() {
149181
149405
  let t = true;
149182
149406
  try {
149183
149407
  let { fd: e, buf: i, offset: r, length: n, pos: o } = this;
149184
149408
  if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method");
149185
- let h = import_fs31.default.readSync(e, i, r, n, o);
149409
+ let h = import_fs32.default.readSync(e, i, r, n, o);
149186
149410
  this[rs](h), t = false;
149187
149411
  } finally {
149188
149412
  if (t) try {
@@ -149197,7 +149421,7 @@ var ni = class extends de {
149197
149421
  }
149198
149422
  [pt](t = () => {
149199
149423
  }) {
149200
- this.fd !== void 0 && import_fs31.default.closeSync(this.fd), t();
149424
+ this.fd !== void 0 && import_fs32.default.closeSync(this.fd), t();
149201
149425
  }
149202
149426
  };
149203
149427
  var oi = class extends A {
@@ -149513,7 +149737,7 @@ var wt = class extends A {
149513
149737
  return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing;
149514
149738
  }
149515
149739
  [or](t) {
149516
- let e = f(import_path31.default.resolve(this.cwd, t.path));
149740
+ let e = f(import_path32.default.resolve(this.cwd, t.path));
149517
149741
  if (!this.filter(t.path, t)) t.resume();
149518
149742
  else {
149519
149743
  let i = new pi(t.path, e);
@@ -149522,13 +149746,13 @@ var wt = class extends A {
149522
149746
  this[Ft]();
149523
149747
  }
149524
149748
  [ci](t) {
149525
- let e = f(import_path31.default.resolve(this.cwd, t));
149749
+ let e = f(import_path32.default.resolve(this.cwd, t));
149526
149750
  this[W2].push(new pi(t, e)), this[Ft]();
149527
149751
  }
149528
149752
  [ds](t) {
149529
149753
  t.pending = true, this[G] += 1;
149530
149754
  let e = this.follow ? "stat" : "lstat";
149531
- import_fs30.default[e](t.absolute, (i, r) => {
149755
+ import_fs31.default[e](t.absolute, (i, r) => {
149532
149756
  t.pending = false, this[G] -= 1, i ? this.emit("error", i) : this[li](t, r);
149533
149757
  });
149534
149758
  }
@@ -149542,7 +149766,7 @@ var wt = class extends A {
149542
149766
  this[Ft]();
149543
149767
  }
149544
149768
  [ms](t) {
149545
- t.pending = true, this[G] += 1, import_fs30.default.readdir(t.absolute, (e, i) => {
149769
+ t.pending = true, this[G] += 1, import_fs31.default.readdir(t.absolute, (e, i) => {
149546
149770
  if (t.pending = false, this[G] -= 1, e) return this.emit("error", e);
149547
149771
  this[fi](t, i);
149548
149772
  });
@@ -149643,10 +149867,10 @@ var kt = class extends wt {
149643
149867
  }
149644
149868
  [ds](t) {
149645
149869
  let e = this.follow ? "statSync" : "lstatSync";
149646
- this[li](t, import_fs30.default[e](t.absolute));
149870
+ this[li](t, import_fs31.default[e](t.absolute));
149647
149871
  }
149648
149872
  [ms](t) {
149649
- this[fi](t, import_fs30.default.readdirSync(t.absolute));
149873
+ this[fi](t, import_fs31.default.readdirSync(t.absolute));
149650
149874
  }
149651
149875
  [di](t) {
149652
149876
  let e = t.entry, i = this.zip;
@@ -149697,8 +149921,8 @@ var Qn = K(Vn, $n, Xn, qn, (s3, t) => {
149697
149921
  });
149698
149922
  var Jn = process.env.__FAKE_PLATFORM__ || process.platform;
149699
149923
  var Er = Jn === "win32";
149700
- var { O_CREAT: wr, O_NOFOLLOW: mr, O_TRUNC: Sr, O_WRONLY: yr } = import_fs32.default.constants;
149701
- var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || import_fs32.default.constants.UV_FS_O_FILEMAP || 0;
149924
+ var { O_CREAT: wr, O_NOFOLLOW: mr, O_TRUNC: Sr, O_WRONLY: yr } = import_fs33.default.constants;
149925
+ var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || import_fs33.default.constants.UV_FS_O_FILEMAP || 0;
149702
149926
  var jn = Er && !!Rr;
149703
149927
  var to = 512 * 1024;
149704
149928
  var eo = Rr | Sr | wr | yr;
@@ -151038,8 +151262,8 @@ program2.command("cache").description("Manage the local SQLite conversation cach
151038
151262
  `${process.env.HOME}/.threadbase/cache`
151039
151263
  ).action((opts) => {
151040
151264
  const { rmSync: rmSync6, existsSync: existsSync15 } = require("fs");
151041
- const { join: join28 } = require("path");
151042
- const dbPath = join28(opts.cacheDir, "cache.db");
151265
+ const { join: join29 } = require("path");
151266
+ const dbPath = join29(opts.cacheDir, "cache.db");
151043
151267
  for (const suffix of ["", "-shm", "-wal"]) {
151044
151268
  const f2 = dbPath + suffix;
151045
151269
  if (existsSync15(f2)) {