@essentialai/cogent-bridge-bundled 3.23.5 → 3.23.6

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.
Files changed (2) hide show
  1. package/cogent-bridge.mjs +442 -275
  2. package/package.json +1 -1
package/cogent-bridge.mjs CHANGED
@@ -1259,8 +1259,8 @@ var init_parseUtil = __esm({
1259
1259
  init_errors();
1260
1260
  init_en();
1261
1261
  makeIssue = (params) => {
1262
- const { data, path: path24, errorMaps, issueData } = params;
1263
- const fullPath = [...path24, ...issueData.path || []];
1262
+ const { data, path: path25, errorMaps, issueData } = params;
1263
+ const fullPath = [...path25, ...issueData.path || []];
1264
1264
  const fullIssue = {
1265
1265
  ...issueData,
1266
1266
  path: fullPath
@@ -1540,11 +1540,11 @@ var init_types = __esm({
1540
1540
  init_parseUtil();
1541
1541
  init_util();
1542
1542
  ParseInputLazyPath = class {
1543
- constructor(parent, value, path24, key) {
1543
+ constructor(parent, value, path25, key) {
1544
1544
  this._cachedPath = [];
1545
1545
  this.parent = parent;
1546
1546
  this.data = value;
1547
- this._path = path24;
1547
+ this._path = path25;
1548
1548
  this._key = key;
1549
1549
  }
1550
1550
  get path() {
@@ -4996,10 +4996,10 @@ function assignProp(target, prop, value) {
4996
4996
  configurable: true
4997
4997
  });
4998
4998
  }
4999
- function getElementAtPath(obj, path24) {
5000
- if (!path24)
4999
+ function getElementAtPath(obj, path25) {
5000
+ if (!path25)
5001
5001
  return obj;
5002
- return path24.reduce((acc, key) => acc?.[key], obj);
5002
+ return path25.reduce((acc, key) => acc?.[key], obj);
5003
5003
  }
5004
5004
  function promiseAllObject(promisesObj) {
5005
5005
  const keys = Object.keys(promisesObj);
@@ -5248,11 +5248,11 @@ function aborted(x, startIndex = 0) {
5248
5248
  }
5249
5249
  return false;
5250
5250
  }
5251
- function prefixIssues(path24, issues) {
5251
+ function prefixIssues(path25, issues) {
5252
5252
  return issues.map((iss) => {
5253
5253
  var _a;
5254
5254
  (_a = iss).path ?? (_a.path = []);
5255
- iss.path.unshift(path24);
5255
+ iss.path.unshift(path25);
5256
5256
  return iss;
5257
5257
  });
5258
5258
  }
@@ -17058,8 +17058,8 @@ var require_utils = __commonJS({
17058
17058
  }
17059
17059
  return ind;
17060
17060
  }
17061
- function removeDotSegments(path24) {
17062
- let input = path24;
17061
+ function removeDotSegments(path25) {
17062
+ let input = path25;
17063
17063
  const output = [];
17064
17064
  let nextSlash = -1;
17065
17065
  let len = 0;
@@ -17258,8 +17258,8 @@ var require_schemes = __commonJS({
17258
17258
  wsComponent.secure = void 0;
17259
17259
  }
17260
17260
  if (wsComponent.resourceName) {
17261
- const [path24, query] = wsComponent.resourceName.split("?");
17262
- wsComponent.path = path24 && path24 !== "/" ? path24 : void 0;
17261
+ const [path25, query] = wsComponent.resourceName.split("?");
17262
+ wsComponent.path = path25 && path25 !== "/" ? path25 : void 0;
17263
17263
  wsComponent.query = query;
17264
17264
  wsComponent.resourceName = void 0;
17265
17265
  }
@@ -20612,12 +20612,12 @@ var require_dist = __commonJS({
20612
20612
  throw new Error(`Unknown format "${name}"`);
20613
20613
  return f;
20614
20614
  };
20615
- function addFormats(ajv, list, fs22, exportName) {
20615
+ function addFormats(ajv, list, fs23, exportName) {
20616
20616
  var _a;
20617
20617
  var _b;
20618
20618
  (_a = (_b = ajv.opts.code).formats) !== null && _a !== void 0 ? _a : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
20619
20619
  for (const f of list)
20620
- ajv.addFormat(f, fs22[f]);
20620
+ ajv.addFormat(f, fs23[f]);
20621
20621
  }
20622
20622
  module.exports = exports = formatsPlugin;
20623
20623
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -21729,8 +21729,8 @@ var require_parseUtil = __commonJS({
21729
21729
  var errors_js_1 = require_errors2();
21730
21730
  var en_js_1 = __importDefault(require_en());
21731
21731
  var makeIssue2 = (params) => {
21732
- const { data, path: path24, errorMaps, issueData } = params;
21733
- const fullPath = [...path24, ...issueData.path || []];
21732
+ const { data, path: path25, errorMaps, issueData } = params;
21733
+ const fullPath = [...path25, ...issueData.path || []];
21734
21734
  const fullIssue = {
21735
21735
  ...issueData,
21736
21736
  path: fullPath
@@ -21884,11 +21884,11 @@ var require_types2 = __commonJS({
21884
21884
  var parseUtil_js_1 = require_parseUtil();
21885
21885
  var util_js_1 = require_util2();
21886
21886
  var ParseInputLazyPath2 = class {
21887
- constructor(parent, value, path24, key) {
21887
+ constructor(parent, value, path25, key) {
21888
21888
  this._cachedPath = [];
21889
21889
  this.parent = parent;
21890
21890
  this.data = value;
21891
- this._path = path24;
21891
+ this._path = path25;
21892
21892
  this._key = key;
21893
21893
  }
21894
21894
  get path() {
@@ -26389,8 +26389,8 @@ var init_stdio2 = __esm({
26389
26389
  // src/constants.ts
26390
26390
  import { createRequire } from "node:module";
26391
26391
  function resolveVersion() {
26392
- if ("3.23.5") {
26393
- return "3.23.5";
26392
+ if ("3.23.6") {
26393
+ return "3.23.6";
26394
26394
  }
26395
26395
  try {
26396
26396
  const require2 = createRequire(import.meta.url);
@@ -27826,7 +27826,7 @@ var init_http_backend = __esm({
27826
27826
  * in cloud mode we ignore it and use this.sessionId (the cloud session).
27827
27827
  */
27828
27828
  async registerPeer(peerId, _sessionId, cwd, label, clientVersion, mode, _channelSessionId, capabilities, workspaceId, threadId, peerSecret) {
27829
- const path24 = PATHS.peers.replace(":sessionId", this.sessionId);
27829
+ const path25 = PATHS.peers.replace(":sessionId", this.sessionId);
27830
27830
  const body = {
27831
27831
  peerId,
27832
27832
  cwd,
@@ -27857,7 +27857,7 @@ var init_http_backend = __esm({
27857
27857
  if (peerSecret !== void 0 && await relaySupports(this.http, "peer-ownership")) {
27858
27858
  body.peerSecret = peerSecret;
27859
27859
  }
27860
- return this.http.post(path24, body);
27860
+ return this.http.post(path25, body);
27861
27861
  }
27862
27862
  /**
27863
27863
  * Deregister a peer from the cloud session.
@@ -27869,9 +27869,9 @@ var init_http_backend = __esm({
27869
27869
  * local mail creds. A 404 (peer not found) resolves to `{ removed: false, ... }`, not a throw.
27870
27870
  */
27871
27871
  async deregisterPeer(peerId) {
27872
- const path24 = PATHS.peer.replace(":sessionId", this.sessionId).replace(":peerId", peerId);
27872
+ const path25 = PATHS.peer.replace(":sessionId", this.sessionId).replace(":peerId", peerId);
27873
27873
  try {
27874
- const headers = await this.http.delete(path24, {});
27874
+ const headers = await this.http.delete(path25, {});
27875
27875
  const mailboxDeprovisioned = headers.get(MAILBOX_DEPROVISIONED_HEADER) === "true";
27876
27876
  return { removed: true, mailboxDeprovisioned };
27877
27877
  } catch (err) {
@@ -27895,8 +27895,8 @@ var init_http_backend = __esm({
27895
27895
  * GET /api/sessions/:sessionId/peers
27896
27896
  */
27897
27897
  async listPeers() {
27898
- const path24 = PATHS.peers.replace(":sessionId", this.sessionId);
27899
- const result = await this.http.get(path24);
27898
+ const path25 = PATHS.peers.replace(":sessionId", this.sessionId);
27899
+ const result = await this.http.get(path25);
27900
27900
  return result.peers;
27901
27901
  }
27902
27902
  /**
@@ -27904,8 +27904,8 @@ var init_http_backend = __esm({
27904
27904
  * Calls the lightweight heartbeat endpoint on the cloud relay server.
27905
27905
  */
27906
27906
  async updateLastSeen(peerId) {
27907
- const path24 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
27908
- await this.http.post(path24, { peerId });
27907
+ const path25 = PATHS.heartbeat.replace(":sessionId", this.sessionId);
27908
+ await this.http.post(path25, { peerId });
27909
27909
  }
27910
27910
  /**
27911
27911
  * Record a message in the cloud session.
@@ -27916,7 +27916,7 @@ var init_http_backend = __esm({
27916
27916
  * the input record to construct a full MessageRecord.
27917
27917
  */
27918
27918
  async recordMessage(record2) {
27919
- const path24 = PATHS.messages.replace(":sessionId", this.sessionId);
27919
+ const path25 = PATHS.messages.replace(":sessionId", this.sessionId);
27920
27920
  const body = {
27921
27921
  fromPeerId: record2.fromPeerId,
27922
27922
  toPeerId: record2.toPeerId,
@@ -27939,7 +27939,7 @@ var init_http_backend = __esm({
27939
27939
  if (record2.attachments && record2.attachments.length > 0) {
27940
27940
  body.attachments = record2.attachments;
27941
27941
  }
27942
- const resp = await this.http.post(path24, body);
27942
+ const resp = await this.http.post(path25, body);
27943
27943
  return {
27944
27944
  ...record2,
27945
27945
  id: resp.id,
@@ -27953,7 +27953,7 @@ var init_http_backend = __esm({
27953
27953
  * Supports optional peerId filter and limit (default 300).
27954
27954
  */
27955
27955
  async getHistory(peerId, limit, includeRelayEchoes, metadataOnly, dedupInferredEchoes) {
27956
- const path24 = PATHS.messages.replace(":sessionId", this.sessionId);
27956
+ const path25 = PATHS.messages.replace(":sessionId", this.sessionId);
27957
27957
  const query = {};
27958
27958
  if (peerId) {
27959
27959
  query.peerId = peerId;
@@ -27968,7 +27968,7 @@ var init_http_backend = __esm({
27968
27968
  if (dedupInferredEchoes) {
27969
27969
  query.dedupInferredEchoes = "true";
27970
27970
  }
27971
- const result = await this.http.get(path24, query);
27971
+ const result = await this.http.get(path25, query);
27972
27972
  return result.messages;
27973
27973
  }
27974
27974
  /**
@@ -27979,12 +27979,12 @@ var init_http_backend = __esm({
27979
27979
  * so that get-history shows the actual response (not null).
27980
27980
  */
27981
27981
  async updateMessageResponse(messageId, response, durationMs, pending) {
27982
- const path24 = PATHS.message.replace(":sessionId", this.sessionId).replace(":messageId", messageId);
27982
+ const path25 = PATHS.message.replace(":sessionId", this.sessionId).replace(":messageId", messageId);
27983
27983
  const body = { response, durationMs };
27984
27984
  if (pending === true) {
27985
27985
  body.pending = true;
27986
27986
  }
27987
- await this.http.patch(path24, body);
27987
+ await this.http.patch(path25, body);
27988
27988
  }
27989
27989
  /**
27990
27990
  * Validate a session.
@@ -28126,8 +28126,8 @@ var init_http_client = __esm({
28126
28126
  * Perform an authenticated GET request.
28127
28127
  * Appends query parameters to the URL if provided.
28128
28128
  */
28129
- async get(path24, query) {
28130
- const url = new URL(path24, this.baseUrl);
28129
+ async get(path25, query) {
28130
+ const url = new URL(path25, this.baseUrl);
28131
28131
  if (query) {
28132
28132
  for (const [k, v] of Object.entries(query)) {
28133
28133
  url.searchParams.set(k, v);
@@ -28142,8 +28142,8 @@ var init_http_client = __esm({
28142
28142
  /**
28143
28143
  * Perform an authenticated POST request with a JSON body.
28144
28144
  */
28145
- async post(path24, body) {
28146
- const url = new URL(path24, this.baseUrl);
28145
+ async post(path25, body) {
28146
+ const url = new URL(path25, this.baseUrl);
28147
28147
  const resp = await this.fetchWithTimeout(url, {
28148
28148
  method: "POST",
28149
28149
  headers: this.headers(),
@@ -28161,8 +28161,8 @@ var init_http_client = __esm({
28161
28161
  * Perform an authenticated PATCH request with a JSON body.
28162
28162
  * Used to update existing resources (e.g., message response fields).
28163
28163
  */
28164
- async patch(path24, body) {
28165
- const url = new URL(path24, this.baseUrl);
28164
+ async patch(path25, body) {
28165
+ const url = new URL(path25, this.baseUrl);
28166
28166
  const resp = await this.fetchWithTimeout(url, {
28167
28167
  method: "PATCH",
28168
28168
  headers: this.headers(),
@@ -28187,8 +28187,8 @@ var init_http_client = __esm({
28187
28187
  * "Malformed JSON in request body" 400 from cogent-server <=3.1.2 when
28188
28188
  * any client (including third-party tools) DELETEd a peer without a body.
28189
28189
  */
28190
- async delete(path24, body) {
28191
- const url = new URL(path24, this.baseUrl);
28190
+ async delete(path25, body) {
28191
+ const url = new URL(path25, this.baseUrl);
28192
28192
  const headers = {
28193
28193
  "Authorization": `Bearer ${this.token}`
28194
28194
  };
@@ -32393,14 +32393,14 @@ var init_ws_client = __esm({
32393
32393
  if (this.pollTimer) return;
32394
32394
  const poll = async () => {
32395
32395
  try {
32396
- const path24 = `/api/sessions/${this.opts.sessionId}/poll`;
32396
+ const path25 = `/api/sessions/${this.opts.sessionId}/poll`;
32397
32397
  const query = {
32398
32398
  peerId: this.opts.peerId
32399
32399
  };
32400
32400
  if (this.lastMessageId) {
32401
32401
  query.lastMessageId = this.lastMessageId;
32402
32402
  }
32403
- const result = await this.opts.http.get(path24, query);
32403
+ const result = await this.opts.http.get(path25, query);
32404
32404
  if (result.messages && result.messages.length > 0) {
32405
32405
  this.opts.onMessages(result.messages);
32406
32406
  this.lastMessageId = result.messages[result.messages.length - 1].id;
@@ -33741,6 +33741,162 @@ var init_wake_ownership = __esm({
33741
33741
  }
33742
33742
  });
33743
33743
 
33744
+ // src/services/stale-bridge-reaper.ts
33745
+ import { execFileSync as execFileSync2 } from "node:child_process";
33746
+ import fs18 from "node:fs";
33747
+ import path19 from "node:path";
33748
+ function isBridgeCommand(argv) {
33749
+ if (!argv) return false;
33750
+ if (/\.test\.|-test\.mjs|scripts\//.test(argv)) return false;
33751
+ return /\/bridge\/cogent-bridge\.mjs(\s|$)/.test(argv) || // plugin bundle (Claude + codex)
33752
+ /\/cogent-bridge(\s|$)/.test(argv) || // npx / global bin shim
33753
+ /@essentialai\/cogent-bridge(-bundled)?\/dist\/(cli|index)\.js(\s|$)/.test(argv);
33754
+ }
33755
+ function versionFromArgv(argv) {
33756
+ const m = argv.match(/\/cogent\/(\d+\.\d+\.\d+)\//);
33757
+ return m ? m[1] : null;
33758
+ }
33759
+ function listProcesses() {
33760
+ let out;
33761
+ try {
33762
+ out = execFileSync2("ps", ["-eo", "pid=,ppid=,lstart=,args="], {
33763
+ encoding: "utf-8",
33764
+ maxBuffer: 8 * 1024 * 1024,
33765
+ timeout: 1e4
33766
+ });
33767
+ } catch (err) {
33768
+ logger.debug(`stale-bridge-reaper: ps failed (${err.message})`);
33769
+ return [];
33770
+ }
33771
+ const procs = [];
33772
+ for (const line of out.split("\n")) {
33773
+ const m = line.match(/^\s*(\d+)\s+(\d+)\s+(\S+\s+\S+\s+\S+\s+\S+\s+\S+)\s+(.*)$/);
33774
+ if (!m) continue;
33775
+ const started = Date.parse(m[3]);
33776
+ procs.push({
33777
+ pid: Number(m[1]),
33778
+ ppid: Number(m[2]),
33779
+ startedAt: Number.isFinite(started) ? started : NaN,
33780
+ argv: m[4]
33781
+ });
33782
+ }
33783
+ return procs;
33784
+ }
33785
+ function processCwd(pid) {
33786
+ try {
33787
+ if (process.platform === "linux") {
33788
+ return path19.resolve(fs18.readlinkSync(`/proc/${pid}/cwd`));
33789
+ }
33790
+ if (process.platform === "darwin") {
33791
+ const out = execFileSync2("lsof", ["-a", "-d", "cwd", "-p", String(pid), "-Fn"], {
33792
+ encoding: "utf-8",
33793
+ timeout: 1e4,
33794
+ stdio: ["ignore", "pipe", "ignore"]
33795
+ });
33796
+ const line = out.split("\n").find((l) => l.startsWith("n"));
33797
+ return line ? path19.resolve(line.slice(1)) : null;
33798
+ }
33799
+ } catch {
33800
+ }
33801
+ return null;
33802
+ }
33803
+ function canonicalPath(p) {
33804
+ try {
33805
+ return fs18.realpathSync(path19.resolve(p));
33806
+ } catch {
33807
+ return path19.resolve(p);
33808
+ }
33809
+ }
33810
+ function ancestorsOf(pid, procs) {
33811
+ const byPid = new Map(procs.map((p) => [p.pid, p]));
33812
+ const seen = /* @__PURE__ */ new Set();
33813
+ let cur = byPid.get(pid)?.ppid;
33814
+ while (cur && cur > 1 && !seen.has(cur)) {
33815
+ seen.add(cur);
33816
+ cur = byPid.get(cur)?.ppid;
33817
+ }
33818
+ return seen;
33819
+ }
33820
+ function announcedPidsFor(cwd) {
33821
+ const pids = /* @__PURE__ */ new Set();
33822
+ try {
33823
+ const base = path19.dirname(bridgeDirFor(cwd, "x"));
33824
+ const prefix = path19.basename(bridgeDirFor(cwd, "x")).split(".")[0];
33825
+ for (const dir of fs18.readdirSync(base)) {
33826
+ if (!dir.startsWith(`${prefix}.`)) continue;
33827
+ const peerId = dir.slice(prefix.length + 1);
33828
+ for (const e of listLiveBridges(cwd, peerId)) pids.add(e.pid);
33829
+ }
33830
+ } catch {
33831
+ }
33832
+ return pids;
33833
+ }
33834
+ function findStaleBridges(cwd, procs = listProcesses(), opts = {}) {
33835
+ const selfPid = opts.selfPid ?? process.pid;
33836
+ const selfStartedAt = opts.selfStartedAt ?? Date.now() - Math.floor(process.uptime() * 1e3);
33837
+ const cwdOf = opts.cwdOf ?? processCwd;
33838
+ const announced = opts.announced ?? announcedPidsFor(cwd);
33839
+ const target = canonicalPath(cwd);
33840
+ const ancestors = ancestorsOf(selfPid, procs);
33841
+ const out = [];
33842
+ for (const p of procs) {
33843
+ if (p.pid === selfPid) continue;
33844
+ if (ancestors.has(p.pid)) continue;
33845
+ if (!isBridgeCommand(p.argv)) continue;
33846
+ if (announced.has(p.pid)) continue;
33847
+ if (!Number.isFinite(p.startedAt) || p.startedAt >= selfStartedAt) continue;
33848
+ const theirCwd = cwdOf(p.pid);
33849
+ if (!theirCwd || canonicalPath(theirCwd) !== target) continue;
33850
+ const ver = versionFromArgv(p.argv);
33851
+ out.push({
33852
+ proc: p,
33853
+ reason: `pid ${p.pid}${ver ? ` (plugin ${ver})` : ""} is a cogent bridge in this exact checkout, started ${new Date(p.startedAt).toISOString()} \u2014 before this process \u2014 and has not announced itself, so it predates self-supersession and would keep waking this session forever`
33854
+ });
33855
+ }
33856
+ return out;
33857
+ }
33858
+ function reaperEnabled(env = process.env) {
33859
+ const v = env.COGENT_REAP_STALE_BRIDGES;
33860
+ if (v === void 0 || v === "") return true;
33861
+ return !/^(0|false|no|off)$/i.test(v.trim());
33862
+ }
33863
+ function reapStaleBridges(cwd, opts = {}) {
33864
+ if (!reaperEnabled()) {
33865
+ logger.debug("stale-bridge-reaper: disabled by COGENT_REAP_STALE_BRIDGES");
33866
+ return [];
33867
+ }
33868
+ let candidates;
33869
+ try {
33870
+ candidates = findStaleBridges(cwd, listProcesses(), opts);
33871
+ } catch (err) {
33872
+ logger.warn(`stale-bridge-reaper: scan failed (${err.message}) \u2014 reaping nothing`);
33873
+ return [];
33874
+ }
33875
+ const reaped = [];
33876
+ for (const c2 of candidates) {
33877
+ logger.warn(`Cogent: terminating a stale bridge \u2014 ${c2.reason}`);
33878
+ try {
33879
+ process.kill(c2.proc.pid, "SIGTERM");
33880
+ reaped.push(c2);
33881
+ } catch (err) {
33882
+ logger.warn(`stale-bridge-reaper: could not signal pid ${c2.proc.pid}: ${err.message}`);
33883
+ }
33884
+ }
33885
+ if (reaped.length) {
33886
+ logger.warn(
33887
+ `Cogent: reaped ${reaped.length} stale bridge process(es) left behind by an earlier plugin version. They could not stand down on their own because they predate 3.23.4.`
33888
+ );
33889
+ }
33890
+ return reaped;
33891
+ }
33892
+ var init_stale_bridge_reaper = __esm({
33893
+ "src/services/stale-bridge-reaper.ts"() {
33894
+ "use strict";
33895
+ init_logger();
33896
+ init_wake_ownership();
33897
+ }
33898
+ });
33899
+
33744
33900
  // src/services/auto-relay.ts
33745
33901
  import { randomUUID as randomUUID2 } from "node:crypto";
33746
33902
  function buildStatusNotice(status, peerId, traceId) {
@@ -33883,6 +34039,7 @@ var init_auto_relay = __esm({
33883
34039
  init_wake_claim();
33884
34040
  init_wake_lock();
33885
34041
  init_wake_ownership();
34042
+ init_stale_bridge_reaper();
33886
34043
  init_constants();
33887
34044
  init_logger();
33888
34045
  init_npm_update_check();
@@ -33932,6 +34089,8 @@ var init_auto_relay = __esm({
33932
34089
  processing = false;
33933
34090
  /** Senders already told this bridge is superseded — one notice each, not one per message. */
33934
34091
  supersededNotified = /* @__PURE__ */ new Set();
34092
+ /** Reaping leftovers is a one-shot per process, not a per-registration action. */
34093
+ reapedStaleBridges = false;
33935
34094
  queue = [];
33936
34095
  // Message ids to be handled inject-only (full-group-chat awareness) rather than
33937
34096
  // full-wake+reply. Shares the `processing` lock + `queue` so an awareness inject
@@ -33980,6 +34139,14 @@ var init_auto_relay = __esm({
33980
34139
  );
33981
34140
  announceBridge(cwd, peerId, CLIENT_VERSION, getConfig().COGENT_ENDPOINT ?? "local");
33982
34141
  this.supersededNotified.clear();
34142
+ if (!this.reapedStaleBridges) {
34143
+ this.reapedStaleBridges = true;
34144
+ try {
34145
+ reapStaleBridges(cwd);
34146
+ } catch (err) {
34147
+ logger.debug(`stale-bridge reap skipped: ${err.message}`);
34148
+ }
34149
+ }
33983
34150
  }
33984
34151
  /**
33985
34152
  * Emit one content-free wake-trace line (ids/decisions/timings only — NEVER
@@ -35101,8 +35268,8 @@ __export(startup_exports, {
35101
35268
  triggerReRegistration: () => triggerReRegistration
35102
35269
  });
35103
35270
  import os14 from "node:os";
35104
- import path19 from "node:path";
35105
- import fs18 from "node:fs/promises";
35271
+ import path20 from "node:path";
35272
+ import fs19 from "node:fs/promises";
35106
35273
  import readline2 from "node:readline";
35107
35274
  import { execFile as execFile5 } from "node:child_process";
35108
35275
  import { promisify as promisify4 } from "node:util";
@@ -35120,7 +35287,7 @@ function bindInboxNotifier() {
35120
35287
  }
35121
35288
  async function loadPersistedConfig() {
35122
35289
  try {
35123
- const raw = await fs18.readFile(PERSIST_PATH, "utf-8");
35290
+ const raw = await fs19.readFile(PERSIST_PATH, "utf-8");
35124
35291
  return JSON.parse(raw);
35125
35292
  } catch {
35126
35293
  return {};
@@ -35128,7 +35295,7 @@ async function loadPersistedConfig() {
35128
35295
  }
35129
35296
  async function savePersistedConfig(config2) {
35130
35297
  try {
35131
- await fs18.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
35298
+ await fs19.writeFile(PERSIST_PATH, JSON.stringify(config2, null, 2) + "\n", "utf-8");
35132
35299
  } catch (err) {
35133
35300
  const msg = err instanceof Error ? err.message : String(err);
35134
35301
  logger.warn(`Could not save config to ${PERSIST_PATH}: ${msg}`);
@@ -35163,11 +35330,11 @@ First run detected. Where should cogent-bridge store its data?
35163
35330
  });
35164
35331
  }
35165
35332
  async function validateStateDir(statePath) {
35166
- await fs18.mkdir(statePath, { recursive: true });
35167
- const testFile = path19.join(statePath, ".write-test");
35333
+ await fs19.mkdir(statePath, { recursive: true });
35334
+ const testFile = path20.join(statePath, ".write-test");
35168
35335
  try {
35169
- await fs18.writeFile(testFile, "test", "utf-8");
35170
- await fs18.unlink(testFile);
35336
+ await fs19.writeFile(testFile, "test", "utf-8");
35337
+ await fs19.unlink(testFile);
35171
35338
  } catch {
35172
35339
  throw new BridgeError(
35173
35340
  "STARTUP_FAILED" /* STARTUP_FAILED */,
@@ -35355,10 +35522,10 @@ async function runStartup() {
35355
35522
  if (envStatePath) {
35356
35523
  statePath = envStatePath;
35357
35524
  } else {
35358
- const defaultPath = path19.join(os14.homedir(), ".cogent");
35525
+ const defaultPath = path20.join(os14.homedir(), ".cogent");
35359
35526
  statePath = await firstRunPrompt(defaultPath);
35360
35527
  }
35361
- if (!envStatePath && statePath !== path19.join(os14.homedir(), ".cogent")) {
35528
+ if (!envStatePath && statePath !== path20.join(os14.homedir(), ".cogent")) {
35362
35529
  process.env.COGENT_STATE_PATH = statePath;
35363
35530
  } else if (!envStatePath) {
35364
35531
  process.env.COGENT_STATE_PATH = statePath;
@@ -35422,7 +35589,7 @@ async function runStartup() {
35422
35589
  }
35423
35590
  initLogger(
35424
35591
  config2.COGENT_LOG_LEVEL,
35425
- path19.join(config2.COGENT_STATE_PATH, "logs")
35592
+ path20.join(config2.COGENT_STATE_PATH, "logs")
35426
35593
  );
35427
35594
  if (isCloud && effectiveSessionId && effectiveToken) {
35428
35595
  cloudInbox = new MessageInbox();
@@ -35484,7 +35651,7 @@ var init_startup = __esm({
35484
35651
  init_auto_relay();
35485
35652
  UUID_V4_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
35486
35653
  execFileAsync3 = promisify4(execFile5);
35487
- PERSIST_PATH = path19.join(os14.homedir(), ".cogent-config.json");
35654
+ PERSIST_PATH = path20.join(os14.homedir(), ".cogent-config.json");
35488
35655
  legacyWarnEmitted = false;
35489
35656
  cloudWsClient = null;
35490
35657
  cloudInbox = null;
@@ -35499,12 +35666,12 @@ var init_startup = __esm({
35499
35666
 
35500
35667
  // src/cloud/mail-credential-store.ts
35501
35668
  import crypto9 from "node:crypto";
35502
- import fs19 from "node:fs/promises";
35503
- import path20 from "node:path";
35669
+ import fs20 from "node:fs/promises";
35670
+ import path21 from "node:path";
35504
35671
  import os15 from "node:os";
35505
35672
  function defaultMailCredentialPath(cwd = process.cwd()) {
35506
- const hash = crypto9.createHash("sha256").update(path20.resolve(cwd)).digest("hex").slice(0, 16);
35507
- return path20.join(os15.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
35673
+ const hash = crypto9.createHash("sha256").update(path21.resolve(cwd)).digest("hex").slice(0, 16);
35674
+ return path21.join(os15.homedir(), ".cogent", "mail-credentials", `${hash}.json`);
35508
35675
  }
35509
35676
  function resolveMailCredentialPath(credentialPath) {
35510
35677
  if (credentialPath) return credentialPath;
@@ -35515,16 +35682,16 @@ function resolveMailCredentialPath(credentialPath) {
35515
35682
  async function loadMailCredentials(credentialPath) {
35516
35683
  const filePath = resolveMailCredentialPath(credentialPath);
35517
35684
  try {
35518
- return JSON.parse(await fs19.readFile(filePath, "utf-8"));
35685
+ return JSON.parse(await fs20.readFile(filePath, "utf-8"));
35519
35686
  } catch {
35520
35687
  return null;
35521
35688
  }
35522
35689
  }
35523
35690
  async function saveMailCredentials(creds, credentialPath) {
35524
35691
  const filePath = resolveMailCredentialPath(credentialPath);
35525
- await fs19.mkdir(path20.dirname(filePath), { recursive: true, mode: 448 });
35526
- await fs19.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
35527
- await fs19.chmod(filePath, 384);
35692
+ await fs20.mkdir(path21.dirname(filePath), { recursive: true, mode: 448 });
35693
+ await fs20.writeFile(filePath, JSON.stringify(creds, null, 2) + "\n", { encoding: "utf-8", mode: 384 });
35694
+ await fs20.chmod(filePath, 384);
35528
35695
  }
35529
35696
  async function persistProvisionedMailbox(mailbox, credentialPath) {
35530
35697
  if (!mailbox?.address || !mailbox.password) return false;
@@ -35545,7 +35712,7 @@ async function persistProvisionedMailbox(mailbox, credentialPath) {
35545
35712
  async function clearMailCredentials(credentialPath) {
35546
35713
  const filePath = resolveMailCredentialPath(credentialPath);
35547
35714
  try {
35548
- await fs19.unlink(filePath);
35715
+ await fs20.unlink(filePath);
35549
35716
  } catch (err) {
35550
35717
  if (err.code !== "ENOENT") throw err;
35551
35718
  }
@@ -37510,8 +37677,8 @@ var require_cookies = __commonJS({
37510
37677
  if (urlparts.hostname !== cookie.domain && (cookie.domain.charAt(0) !== "." || ("." + urlparts.hostname).substr(-cookie.domain.length) !== cookie.domain)) {
37511
37678
  return false;
37512
37679
  }
37513
- let path24 = this.getPath(urlparts.pathname);
37514
- if (path24.substr(0, cookie.path.length) !== cookie.path) {
37680
+ let path25 = this.getPath(urlparts.pathname);
37681
+ if (path25.substr(0, cookie.path.length) !== cookie.path) {
37515
37682
  return false;
37516
37683
  }
37517
37684
  if (cookie.secure && urlparts.protocol !== "https:") {
@@ -37571,16 +37738,16 @@ var require_cookies = __commonJS({
37571
37738
  * @returns {String} Normalized path
37572
37739
  */
37573
37740
  getPath(pathname) {
37574
- let path24 = (pathname || "/").split("/");
37575
- path24.pop();
37576
- path24 = path24.join("/").trim();
37577
- if (path24.charAt(0) !== "/") {
37578
- path24 = "/" + path24;
37741
+ let path25 = (pathname || "/").split("/");
37742
+ path25.pop();
37743
+ path25 = path25.join("/").trim();
37744
+ if (path25.charAt(0) !== "/") {
37745
+ path25 = "/" + path25;
37579
37746
  }
37580
- if (path24.substr(-1) !== "/") {
37581
- path24 += "/";
37747
+ if (path25.substr(-1) !== "/") {
37748
+ path25 += "/";
37582
37749
  }
37583
- return path24;
37750
+ return path25;
37584
37751
  }
37585
37752
  };
37586
37753
  module.exports = Cookies;
@@ -37881,7 +38048,7 @@ var require_shared = __commonJS({
37881
38048
  "use strict";
37882
38049
  var urllib = __require("url");
37883
38050
  var util2 = __require("util");
37884
- var fs22 = __require("fs");
38051
+ var fs23 = __require("fs");
37885
38052
  var nmfetch = require_fetch();
37886
38053
  var dns = __require("dns");
37887
38054
  var net = __require("net");
@@ -38267,7 +38434,7 @@ var require_shared = __commonJS({
38267
38434
  }
38268
38435
  return callback(null, parsedDataUri.data);
38269
38436
  } else if (content.path) {
38270
- return resolveStream(fs22.createReadStream(content.path), callback);
38437
+ return resolveStream(fs23.createReadStream(content.path), callback);
38271
38438
  }
38272
38439
  }
38273
38440
  if (typeof data[key].content === "string" && !["utf8", "usascii", "ascii"].includes(encoding)) {
@@ -38391,7 +38558,7 @@ var require_shared = __commonJS({
38391
38558
  var require_mime_types = __commonJS({
38392
38559
  "node_modules/nodemailer/lib/mime-funcs/mime-types.js"(exports, module) {
38393
38560
  "use strict";
38394
- var path24 = __require("path");
38561
+ var path25 = __require("path");
38395
38562
  var defaultMimeType = "application/octet-stream";
38396
38563
  var defaultExtension = "bin";
38397
38564
  var mimeTypes = /* @__PURE__ */ new Map([
@@ -40449,7 +40616,7 @@ var require_mime_types = __commonJS({
40449
40616
  if (!filename) {
40450
40617
  return defaultMimeType;
40451
40618
  }
40452
- let parsed = path24.parse(filename);
40619
+ let parsed = path25.parse(filename);
40453
40620
  let extension = (parsed.ext.substr(1) || parsed.name || "").split("?").shift().trim().toLowerCase();
40454
40621
  let value = defaultMimeType;
40455
40622
  if (extensions.has(extension)) {
@@ -41851,7 +42018,7 @@ var require_mime_node = __commonJS({
41851
42018
  "node_modules/nodemailer/lib/mime-node/index.js"(exports, module) {
41852
42019
  "use strict";
41853
42020
  var crypto12 = __require("crypto");
41854
- var fs22 = __require("fs");
42021
+ var fs23 = __require("fs");
41855
42022
  var punycode = require_punycode();
41856
42023
  var PassThrough = __require("stream").PassThrough;
41857
42024
  var shared = require_shared();
@@ -42566,7 +42733,7 @@ var require_mime_node = __commonJS({
42566
42733
  setImmediate(() => contentStream.emit("error", new Error("File access rejected for " + content.path)));
42567
42734
  return contentStream;
42568
42735
  }
42569
- return fs22.createReadStream(content.path);
42736
+ return fs23.createReadStream(content.path);
42570
42737
  } else if (content && typeof content.href === "string") {
42571
42738
  if (this.disableUrlAccess) {
42572
42739
  contentStream = new PassThrough();
@@ -43587,8 +43754,8 @@ var require_dkim = __commonJS({
43587
43754
  var RelaxedBody = require_relaxed_body();
43588
43755
  var sign = require_sign();
43589
43756
  var PassThrough = __require("stream").PassThrough;
43590
- var fs22 = __require("fs");
43591
- var path24 = __require("path");
43757
+ var fs23 = __require("fs");
43758
+ var path25 = __require("path");
43592
43759
  var crypto12 = __require("crypto");
43593
43760
  var DKIM_ALGO = "sha256";
43594
43761
  var MAX_MESSAGE_SIZE = 128 * 1024;
@@ -43602,7 +43769,7 @@ var require_dkim = __commonJS({
43602
43769
  this.chunks = [];
43603
43770
  this.chunklen = 0;
43604
43771
  this.readPos = 0;
43605
- this.cachePath = this.cacheDir ? path24.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
43772
+ this.cachePath = this.cacheDir ? path25.join(this.cacheDir, "message." + Date.now() + "-" + crypto12.randomBytes(14).toString("hex")) : false;
43606
43773
  this.cache = false;
43607
43774
  this.headers = false;
43608
43775
  this.bodyHash = false;
@@ -43622,10 +43789,10 @@ var require_dkim = __commonJS({
43622
43789
  if (!this.cache || !this.cachePath) {
43623
43790
  return;
43624
43791
  }
43625
- fs22.unlink(this.cachePath, () => false);
43792
+ fs23.unlink(this.cachePath, () => false);
43626
43793
  }
43627
43794
  createReadCache() {
43628
- this.cache = fs22.createReadStream(this.cachePath);
43795
+ this.cache = fs23.createReadStream(this.cachePath);
43629
43796
  this.cache.once("error", (err) => {
43630
43797
  this.cleanup();
43631
43798
  this.output.emit("error", err);
@@ -43681,7 +43848,7 @@ var require_dkim = __commonJS({
43681
43848
  }
43682
43849
  createWriteCache() {
43683
43850
  this.output.usingCache = true;
43684
- this.cache = fs22.createWriteStream(this.cachePath);
43851
+ this.cache = fs23.createWriteStream(this.cachePath);
43685
43852
  this.cache.once("error", (err) => {
43686
43853
  this.cleanup();
43687
43854
  this.relaxedBody.unpipe(this.cache);
@@ -48570,13 +48737,13 @@ var require_nodemailer = __commonJS({
48570
48737
  });
48571
48738
 
48572
48739
  // src/mail/mail-sender.ts
48573
- import fs20 from "node:fs/promises";
48574
- import path21 from "node:path";
48740
+ import fs21 from "node:fs/promises";
48741
+ import path22 from "node:path";
48575
48742
  async function buildAndSendMail(sender, creds, params) {
48576
48743
  const attachments = [];
48577
48744
  for (const p of params.attachmentPaths ?? []) {
48578
- const content = await fs20.readFile(p);
48579
- attachments.push({ filename: path21.basename(p), content });
48745
+ const content = await fs21.readFile(p);
48746
+ attachments.push({ filename: path22.basename(p), content });
48580
48747
  }
48581
48748
  const { messageId } = await sender.send({
48582
48749
  from: creds.address,
@@ -48965,8 +49132,8 @@ var require_req = __commonJS({
48965
49132
  if (req.originalUrl) {
48966
49133
  _req.url = req.originalUrl;
48967
49134
  } else {
48968
- const path24 = req.path;
48969
- _req.url = typeof path24 === "string" ? path24 : req.url ? req.url.path || req.url : void 0;
49135
+ const path25 = req.path;
49136
+ _req.url = typeof path25 === "string" ? path25 : req.url ? req.url.path || req.url : void 0;
48970
49137
  }
48971
49138
  if (req.query) {
48972
49139
  _req.query = req.query;
@@ -49131,14 +49298,14 @@ var require_redact = __commonJS({
49131
49298
  }
49132
49299
  return obj;
49133
49300
  }
49134
- function parsePath(path24) {
49301
+ function parsePath(path25) {
49135
49302
  const parts = [];
49136
49303
  let current = "";
49137
49304
  let inBrackets = false;
49138
49305
  let inQuotes = false;
49139
49306
  let quoteChar = "";
49140
- for (let i = 0; i < path24.length; i++) {
49141
- const char = path24[i];
49307
+ for (let i = 0; i < path25.length; i++) {
49308
+ const char = path25[i];
49142
49309
  if (!inBrackets && char === ".") {
49143
49310
  if (current) {
49144
49311
  parts.push(current);
@@ -49269,10 +49436,10 @@ var require_redact = __commonJS({
49269
49436
  return current;
49270
49437
  }
49271
49438
  function redactPaths(obj, paths, censor, remove = false) {
49272
- for (const path24 of paths) {
49273
- const parts = parsePath(path24);
49439
+ for (const path25 of paths) {
49440
+ const parts = parsePath(path25);
49274
49441
  if (parts.includes("*")) {
49275
- redactWildcardPath(obj, parts, censor, path24, remove);
49442
+ redactWildcardPath(obj, parts, censor, path25, remove);
49276
49443
  } else {
49277
49444
  if (remove) {
49278
49445
  removeKey(obj, parts);
@@ -49357,8 +49524,8 @@ var require_redact = __commonJS({
49357
49524
  }
49358
49525
  } else {
49359
49526
  if (afterWildcard.includes("*")) {
49360
- const wrappedCensor = typeof censor === "function" ? (value, path24) => {
49361
- const fullPath = [...pathArray.slice(0, pathLength), ...path24];
49527
+ const wrappedCensor = typeof censor === "function" ? (value, path25) => {
49528
+ const fullPath = [...pathArray.slice(0, pathLength), ...path25];
49362
49529
  return censor(value, fullPath);
49363
49530
  } : censor;
49364
49531
  redactWildcardPath(current, afterWildcard, wrappedCensor, originalPath, remove);
@@ -49393,8 +49560,8 @@ var require_redact = __commonJS({
49393
49560
  return null;
49394
49561
  }
49395
49562
  const pathStructure = /* @__PURE__ */ new Map();
49396
- for (const path24 of pathsToClone) {
49397
- const parts = parsePath(path24);
49563
+ for (const path25 of pathsToClone) {
49564
+ const parts = parsePath(path25);
49398
49565
  let current = pathStructure;
49399
49566
  for (let i = 0; i < parts.length; i++) {
49400
49567
  const part = parts[i];
@@ -49446,24 +49613,24 @@ var require_redact = __commonJS({
49446
49613
  }
49447
49614
  return cloneSelectively(obj, pathStructure);
49448
49615
  }
49449
- function validatePath(path24) {
49450
- if (typeof path24 !== "string") {
49616
+ function validatePath(path25) {
49617
+ if (typeof path25 !== "string") {
49451
49618
  throw new Error("Paths must be (non-empty) strings");
49452
49619
  }
49453
- if (path24 === "") {
49620
+ if (path25 === "") {
49454
49621
  throw new Error("Invalid redaction path ()");
49455
49622
  }
49456
- if (path24.includes("..")) {
49457
- throw new Error(`Invalid redaction path (${path24})`);
49623
+ if (path25.includes("..")) {
49624
+ throw new Error(`Invalid redaction path (${path25})`);
49458
49625
  }
49459
- if (path24.includes(",")) {
49460
- throw new Error(`Invalid redaction path (${path24})`);
49626
+ if (path25.includes(",")) {
49627
+ throw new Error(`Invalid redaction path (${path25})`);
49461
49628
  }
49462
49629
  let bracketCount = 0;
49463
49630
  let inQuotes = false;
49464
49631
  let quoteChar = "";
49465
- for (let i = 0; i < path24.length; i++) {
49466
- const char = path24[i];
49632
+ for (let i = 0; i < path25.length; i++) {
49633
+ const char = path25[i];
49467
49634
  if ((char === '"' || char === "'") && bracketCount > 0) {
49468
49635
  if (!inQuotes) {
49469
49636
  inQuotes = true;
@@ -49477,20 +49644,20 @@ var require_redact = __commonJS({
49477
49644
  } else if (char === "]" && !inQuotes) {
49478
49645
  bracketCount--;
49479
49646
  if (bracketCount < 0) {
49480
- throw new Error(`Invalid redaction path (${path24})`);
49647
+ throw new Error(`Invalid redaction path (${path25})`);
49481
49648
  }
49482
49649
  }
49483
49650
  }
49484
49651
  if (bracketCount !== 0) {
49485
- throw new Error(`Invalid redaction path (${path24})`);
49652
+ throw new Error(`Invalid redaction path (${path25})`);
49486
49653
  }
49487
49654
  }
49488
49655
  function validatePaths(paths) {
49489
49656
  if (!Array.isArray(paths)) {
49490
49657
  throw new TypeError("paths must be an array");
49491
49658
  }
49492
- for (const path24 of paths) {
49493
- validatePath(path24);
49659
+ for (const path25 of paths) {
49660
+ validatePath(path25);
49494
49661
  }
49495
49662
  }
49496
49663
  function slowRedact(options = {}) {
@@ -49658,8 +49825,8 @@ var require_redaction = __commonJS({
49658
49825
  if (shape[k] === null) {
49659
49826
  o[k] = (value) => topCensor(value, [k]);
49660
49827
  } else {
49661
- const wrappedCensor = typeof censor === "function" ? (value, path24) => {
49662
- return censor(value, [k, ...path24]);
49828
+ const wrappedCensor = typeof censor === "function" ? (value, path25) => {
49829
+ return censor(value, [k, ...path25]);
49663
49830
  } : censor;
49664
49831
  o[k] = Redact({
49665
49832
  paths: shape[k],
@@ -49877,10 +50044,10 @@ var require_atomic_sleep = __commonJS({
49877
50044
  var require_sonic_boom = __commonJS({
49878
50045
  "node_modules/sonic-boom/index.js"(exports, module) {
49879
50046
  "use strict";
49880
- var fs22 = __require("fs");
50047
+ var fs23 = __require("fs");
49881
50048
  var EventEmitter = __require("events");
49882
50049
  var inherits = __require("util").inherits;
49883
- var path24 = __require("path");
50050
+ var path25 = __require("path");
49884
50051
  var sleep4 = require_atomic_sleep();
49885
50052
  var assert2 = __require("assert");
49886
50053
  var BUSY_WRITE_TIMEOUT = 100;
@@ -49934,20 +50101,20 @@ var require_sonic_boom = __commonJS({
49934
50101
  const mode = sonic.mode;
49935
50102
  if (sonic.sync) {
49936
50103
  try {
49937
- if (sonic.mkdir) fs22.mkdirSync(path24.dirname(file), { recursive: true });
49938
- const fd = fs22.openSync(file, flags, mode);
50104
+ if (sonic.mkdir) fs23.mkdirSync(path25.dirname(file), { recursive: true });
50105
+ const fd = fs23.openSync(file, flags, mode);
49939
50106
  fileOpened(null, fd);
49940
50107
  } catch (err) {
49941
50108
  fileOpened(err);
49942
50109
  throw err;
49943
50110
  }
49944
50111
  } else if (sonic.mkdir) {
49945
- fs22.mkdir(path24.dirname(file), { recursive: true }, (err) => {
50112
+ fs23.mkdir(path25.dirname(file), { recursive: true }, (err) => {
49946
50113
  if (err) return fileOpened(err);
49947
- fs22.open(file, flags, mode, fileOpened);
50114
+ fs23.open(file, flags, mode, fileOpened);
49948
50115
  });
49949
50116
  } else {
49950
- fs22.open(file, flags, mode, fileOpened);
50117
+ fs23.open(file, flags, mode, fileOpened);
49951
50118
  }
49952
50119
  }
49953
50120
  function SonicBoom(opts) {
@@ -49988,8 +50155,8 @@ var require_sonic_boom = __commonJS({
49988
50155
  this.flush = flushBuffer;
49989
50156
  this.flushSync = flushBufferSync;
49990
50157
  this._actualWrite = actualWriteBuffer;
49991
- fsWriteSync = () => fs22.writeSync(this.fd, this._writingBuf);
49992
- fsWrite = () => fs22.write(this.fd, this._writingBuf, this.release);
50158
+ fsWriteSync = () => fs23.writeSync(this.fd, this._writingBuf);
50159
+ fsWrite = () => fs23.write(this.fd, this._writingBuf, this.release);
49993
50160
  } else if (contentMode === void 0 || contentMode === kContentModeUtf8) {
49994
50161
  this._writingBuf = "";
49995
50162
  this.write = write;
@@ -49998,15 +50165,15 @@ var require_sonic_boom = __commonJS({
49998
50165
  this._actualWrite = actualWrite;
49999
50166
  fsWriteSync = () => {
50000
50167
  if (Buffer.isBuffer(this._writingBuf)) {
50001
- return fs22.writeSync(this.fd, this._writingBuf);
50168
+ return fs23.writeSync(this.fd, this._writingBuf);
50002
50169
  }
50003
- return fs22.writeSync(this.fd, this._writingBuf, "utf8");
50170
+ return fs23.writeSync(this.fd, this._writingBuf, "utf8");
50004
50171
  };
50005
50172
  fsWrite = () => {
50006
50173
  if (Buffer.isBuffer(this._writingBuf)) {
50007
- return fs22.write(this.fd, this._writingBuf, this.release);
50174
+ return fs23.write(this.fd, this._writingBuf, this.release);
50008
50175
  }
50009
- return fs22.write(this.fd, this._writingBuf, "utf8", this.release);
50176
+ return fs23.write(this.fd, this._writingBuf, "utf8", this.release);
50010
50177
  };
50011
50178
  } else {
50012
50179
  throw new Error(`SonicBoom supports "${kContentModeUtf8}" and "${kContentModeBuffer}", but passed ${contentMode}`);
@@ -50063,7 +50230,7 @@ var require_sonic_boom = __commonJS({
50063
50230
  }
50064
50231
  }
50065
50232
  if (this._fsync) {
50066
- fs22.fsyncSync(this.fd);
50233
+ fs23.fsyncSync(this.fd);
50067
50234
  }
50068
50235
  const len = this._len;
50069
50236
  if (this._reopening) {
@@ -50177,7 +50344,7 @@ var require_sonic_boom = __commonJS({
50177
50344
  const onDrain = () => {
50178
50345
  if (!this._fsync) {
50179
50346
  try {
50180
- fs22.fsync(this.fd, (err) => {
50347
+ fs23.fsync(this.fd, (err) => {
50181
50348
  this._flushPending = false;
50182
50349
  cb(err);
50183
50350
  });
@@ -50279,7 +50446,7 @@ var require_sonic_boom = __commonJS({
50279
50446
  const fd = this.fd;
50280
50447
  this.once("ready", () => {
50281
50448
  if (fd !== this.fd) {
50282
- fs22.close(fd, (err) => {
50449
+ fs23.close(fd, (err) => {
50283
50450
  if (err) {
50284
50451
  return this.emit("error", err);
50285
50452
  }
@@ -50328,7 +50495,7 @@ var require_sonic_boom = __commonJS({
50328
50495
  buf = this._bufs[0];
50329
50496
  }
50330
50497
  try {
50331
- const n = Buffer.isBuffer(buf) ? fs22.writeSync(this.fd, buf) : fs22.writeSync(this.fd, buf, "utf8");
50498
+ const n = Buffer.isBuffer(buf) ? fs23.writeSync(this.fd, buf) : fs23.writeSync(this.fd, buf, "utf8");
50332
50499
  const releasedBufObj = releaseWritingBuf(buf, this._len, n);
50333
50500
  buf = releasedBufObj.writingBuf;
50334
50501
  this._len = releasedBufObj.len;
@@ -50344,7 +50511,7 @@ var require_sonic_boom = __commonJS({
50344
50511
  }
50345
50512
  }
50346
50513
  try {
50347
- fs22.fsyncSync(this.fd);
50514
+ fs23.fsyncSync(this.fd);
50348
50515
  } catch {
50349
50516
  }
50350
50517
  }
@@ -50365,7 +50532,7 @@ var require_sonic_boom = __commonJS({
50365
50532
  buf = mergeBuf(this._bufs[0], this._lens[0]);
50366
50533
  }
50367
50534
  try {
50368
- const n = fs22.writeSync(this.fd, buf);
50535
+ const n = fs23.writeSync(this.fd, buf);
50369
50536
  buf = buf.subarray(n);
50370
50537
  this._len = Math.max(this._len - n, 0);
50371
50538
  if (buf.length <= 0) {
@@ -50393,13 +50560,13 @@ var require_sonic_boom = __commonJS({
50393
50560
  this._writingBuf = this._writingBuf.length ? this._writingBuf : this._bufs.shift() || "";
50394
50561
  if (this.sync) {
50395
50562
  try {
50396
- const written = Buffer.isBuffer(this._writingBuf) ? fs22.writeSync(this.fd, this._writingBuf) : fs22.writeSync(this.fd, this._writingBuf, "utf8");
50563
+ const written = Buffer.isBuffer(this._writingBuf) ? fs23.writeSync(this.fd, this._writingBuf) : fs23.writeSync(this.fd, this._writingBuf, "utf8");
50397
50564
  release(null, written);
50398
50565
  } catch (err) {
50399
50566
  release(err);
50400
50567
  }
50401
50568
  } else {
50402
- fs22.write(this.fd, this._writingBuf, release);
50569
+ fs23.write(this.fd, this._writingBuf, release);
50403
50570
  }
50404
50571
  }
50405
50572
  function actualWriteBuffer() {
@@ -50408,7 +50575,7 @@ var require_sonic_boom = __commonJS({
50408
50575
  this._writingBuf = this._writingBuf.length ? this._writingBuf : mergeBuf(this._bufs.shift(), this._lens.shift());
50409
50576
  if (this.sync) {
50410
50577
  try {
50411
- const written = fs22.writeSync(this.fd, this._writingBuf);
50578
+ const written = fs23.writeSync(this.fd, this._writingBuf);
50412
50579
  release(null, written);
50413
50580
  } catch (err) {
50414
50581
  release(err);
@@ -50417,7 +50584,7 @@ var require_sonic_boom = __commonJS({
50417
50584
  if (kCopyBuffer) {
50418
50585
  this._writingBuf = Buffer.from(this._writingBuf);
50419
50586
  }
50420
- fs22.write(this.fd, this._writingBuf, release);
50587
+ fs23.write(this.fd, this._writingBuf, release);
50421
50588
  }
50422
50589
  }
50423
50590
  function actualClose(sonic) {
@@ -50433,12 +50600,12 @@ var require_sonic_boom = __commonJS({
50433
50600
  sonic._lens = [];
50434
50601
  assert2(typeof sonic.fd === "number", `sonic.fd must be a number, got ${typeof sonic.fd}`);
50435
50602
  try {
50436
- fs22.fsync(sonic.fd, closeWrapped);
50603
+ fs23.fsync(sonic.fd, closeWrapped);
50437
50604
  } catch {
50438
50605
  }
50439
50606
  function closeWrapped() {
50440
50607
  if (sonic.fd !== 1 && sonic.fd !== 2) {
50441
- fs22.close(sonic.fd, done);
50608
+ fs23.close(sonic.fd, done);
50442
50609
  } else {
50443
50610
  done();
50444
50611
  }
@@ -51274,15 +51441,15 @@ var require_transport = __commonJS({
51274
51441
  if (!unquoted) {
51275
51442
  return false;
51276
51443
  }
51277
- let path24 = unquoted;
51278
- if (path24.startsWith("file://")) {
51444
+ let path25 = unquoted;
51445
+ if (path25.startsWith("file://")) {
51279
51446
  try {
51280
- path24 = fileURLToPath(path24);
51447
+ path25 = fileURLToPath(path25);
51281
51448
  } catch {
51282
51449
  return false;
51283
51450
  }
51284
51451
  }
51285
- return isAbsolute(path24) && !existsSync(path24);
51452
+ return isAbsolute(path25) && !existsSync(path25);
51286
51453
  }
51287
51454
  function stripQuotes(value) {
51288
51455
  const first = value[0];
@@ -85349,15 +85516,15 @@ var require_tools2 = __commonJS({
85349
85516
  * @param {String} path - Mailbox path to encode
85350
85517
  * @returns {String} Encoded mailbox path
85351
85518
  */
85352
- encodePath(connection, path24) {
85353
- path24 = (path24 || "").toString();
85354
- if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path24)) {
85519
+ encodePath(connection, path25) {
85520
+ path25 = (path25 || "").toString();
85521
+ if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&\x00-\x08\x0b-\x0c\x0e-\x1f\u0080-\uffff]/.test(path25)) {
85355
85522
  try {
85356
- path24 = iconv.encode(path24, "utf-7-imap").toString();
85523
+ path25 = iconv.encode(path25, "utf-7-imap").toString();
85357
85524
  } catch {
85358
85525
  }
85359
85526
  }
85360
- return path24;
85527
+ return path25;
85361
85528
  },
85362
85529
  /**
85363
85530
  * Decodes a mailbox path from modified UTF-7 if the server does not support UTF8=ACCEPT.
@@ -85366,15 +85533,15 @@ var require_tools2 = __commonJS({
85366
85533
  * @param {String} path - Mailbox path to decode
85367
85534
  * @returns {String} Decoded mailbox path
85368
85535
  */
85369
- decodePath(connection, path24) {
85370
- path24 = (path24 || "").toString();
85371
- if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path24)) {
85536
+ decodePath(connection, path25) {
85537
+ path25 = (path25 || "").toString();
85538
+ if (!connection.enabled.has("UTF8=ACCEPT") && !tools.isRev2Active(connection) && /[&]/.test(path25)) {
85372
85539
  try {
85373
- path24 = iconv.decode(Buffer.from(path24), "utf-7-imap").toString();
85540
+ path25 = iconv.decode(Buffer.from(path25), "utf-7-imap").toString();
85374
85541
  } catch {
85375
85542
  }
85376
85543
  }
85377
- return path24;
85544
+ return path25;
85378
85545
  },
85379
85546
  /**
85380
85547
  * Normalizes a mailbox path by joining array segments with the namespace delimiter,
@@ -85385,17 +85552,17 @@ var require_tools2 = __commonJS({
85385
85552
  * @param {Boolean} [skipNamespace] - If true, skips prepending the namespace prefix
85386
85553
  * @returns {String} Normalized mailbox path
85387
85554
  */
85388
- normalizePath(connection, path24, skipNamespace) {
85389
- if (Array.isArray(path24)) {
85390
- path24 = path24.join(connection.namespace && connection.namespace.delimiter || "");
85555
+ normalizePath(connection, path25, skipNamespace) {
85556
+ if (Array.isArray(path25)) {
85557
+ path25 = path25.join(connection.namespace && connection.namespace.delimiter || "");
85391
85558
  }
85392
- if (path24.toUpperCase() === "INBOX") {
85559
+ if (path25.toUpperCase() === "INBOX") {
85393
85560
  return "INBOX";
85394
85561
  }
85395
- if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path24.startsWith(connection.namespace.prefix)) {
85396
- path24 = connection.namespace.prefix + path24;
85562
+ if (!skipNamespace && connection.namespace && connection.namespace.prefix && !path25.startsWith(connection.namespace.prefix)) {
85563
+ path25 = connection.namespace.prefix + path25;
85397
85564
  }
85398
- return path24;
85565
+ return path25;
85399
85566
  },
85400
85567
  /**
85401
85568
  * Compares two mailbox paths for equality after normalization.
@@ -85726,14 +85893,14 @@ var require_tools2 = __commonJS({
85726
85893
  }
85727
85894
  }
85728
85895
  if (map.emailId || map.uid) {
85729
- let path24 = mailbox.path;
85730
- if (/[\u0080-\uffff]/.test(path24)) {
85896
+ let path25 = mailbox.path;
85897
+ if (/[\u0080-\uffff]/.test(path25)) {
85731
85898
  try {
85732
- path24 = iconv.encode(path24, "utf-7-imap").toString();
85899
+ path25 = iconv.encode(path25, "utf-7-imap").toString();
85733
85900
  } catch {
85734
85901
  }
85735
85902
  }
85736
- map.id = map.emailId || createHash2("md5").update([path24, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
85903
+ map.id = map.emailId || createHash2("md5").update([path25, mailbox.uidValidity?.toString() || "", map.uid.toString()].join(":")).digest("hex");
85737
85904
  }
85738
85905
  if (map.flags) {
85739
85906
  let flagColor = tools.getFlagColor(map.flags);
@@ -85908,16 +86075,16 @@ var require_tools2 = __commonJS({
85908
86075
  * @returns {Object} Parsed body structure tree with part numbers, types, parameters, and child nodes
85909
86076
  */
85910
86077
  parseBodystructure(entry) {
85911
- let walk = (node, path24) => {
85912
- path24 = path24 || [];
86078
+ let walk = (node, path25) => {
86079
+ path25 = path25 || [];
85913
86080
  let curNode = {}, i = 0, part = 0;
85914
- if (path24.length) {
85915
- curNode.part = path24.join(".");
86081
+ if (path25.length) {
86082
+ curNode.part = path25.join(".");
85916
86083
  }
85917
86084
  if (Array.isArray(node[0])) {
85918
86085
  curNode.childNodes = [];
85919
86086
  while (Array.isArray(node[i])) {
85920
- curNode.childNodes.push(walk(node[i], path24.concat(++part)));
86087
+ curNode.childNodes.push(walk(node[i], path25.concat(++part)));
85921
86088
  i++;
85922
86089
  }
85923
86090
  curNode.type = "multipart/" + ((node[i++] || {}).value || "").toString().toLowerCase();
@@ -85960,7 +86127,7 @@ var require_tools2 = __commonJS({
85960
86127
  // the encapsulated message shares the part number with its wrapper.
85961
86128
  // Distinction is via suffixes: path.MIME = wrapper headers,
85962
86129
  // path.HEADER = encapsulated message headers.
85963
- walk(node[i], path24)
86130
+ walk(node[i], path25)
85964
86131
  ];
85965
86132
  }
85966
86133
  i++;
@@ -87922,14 +88089,14 @@ var require_select = __commonJS({
87922
88089
  // update into a silent no-op for the rest of the session.
87923
88090
  permanentflags: { key: "permanentFlags", parse: (value) => Array.isArray(value) && new Set(value) }
87924
88091
  });
87925
- module.exports = async (connection, path24, options) => {
88092
+ module.exports = async (connection, path25, options) => {
87926
88093
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
87927
88094
  return;
87928
88095
  }
87929
88096
  options = options || {};
87930
- path24 = normalizePath(connection, path24);
87931
- if (!connection.folders.has(path24)) {
87932
- let folders = await connection.run("LIST", "", path24);
88097
+ path25 = normalizePath(connection, path25);
88098
+ if (!connection.folders.has(path25)) {
88099
+ let folders = await connection.run("LIST", "", path25);
87933
88100
  if (!folders) {
87934
88101
  throw new Error("Failed to fetch folders");
87935
88102
  }
@@ -87937,10 +88104,10 @@ var require_select = __commonJS({
87937
88104
  connection.folders.set(folder.path, folder);
87938
88105
  });
87939
88106
  }
87940
- let folderListData = connection.folders.has(path24) ? connection.folders.get(path24) : false;
88107
+ let folderListData = connection.folders.has(path25) ? connection.folders.get(path25) : false;
87941
88108
  let response;
87942
88109
  try {
87943
- let map = { path: path24 };
88110
+ let map = { path: path25 };
87944
88111
  if (folderListData) {
87945
88112
  ["delimiter", "specialUse", "subscribed", "listed"].forEach((key) => {
87946
88113
  if (folderListData[key]) {
@@ -87959,7 +88126,7 @@ var require_select = __commonJS({
87959
88126
  ]);
87960
88127
  map.qresync = true;
87961
88128
  }
87962
- let encodedPath = encodePath(connection, path24);
88129
+ let encodedPath = encodePath(connection, path25);
87963
88130
  let selectCommand = {
87964
88131
  command: !options.readOnly ? "SELECT" : "EXAMINE",
87965
88132
  /* c8 ignore next */
@@ -88019,12 +88186,12 @@ var require_select = __commonJS({
88019
88186
  // since the client's last known state. Only received when QRESYNC was requested.
88020
88187
  // A dummy mailbox object is passed because the mailbox isn't officially open yet.
88021
88188
  VANISHED: async (untagged) => {
88022
- await connection.untaggedVanished(untagged, { path: path24, uidNext: false, uidValidity: false });
88189
+ await connection.untaggedVanished(untagged, { path: path25, uidNext: false, uidValidity: false });
88023
88190
  },
88024
88191
  // Untagged FETCH during SELECT/EXAMINE: only occurs with QRESYNC, delivering
88025
88192
  // updated flags for messages that changed since the client's last modseq.
88026
88193
  FETCH: async (untagged) => {
88027
- await connection.untaggedFetch(untagged, { path: path24, uidNext: false, uidValidity: false });
88194
+ await connection.untaggedFetch(untagged, { path: path25, uidNext: false, uidValidity: false });
88028
88195
  }
88029
88196
  }
88030
88197
  });
@@ -88038,13 +88205,13 @@ var require_select = __commonJS({
88038
88205
  }
88039
88206
  let currentMailbox = connection.mailbox;
88040
88207
  connection.mailbox = false;
88041
- if (currentMailbox && currentMailbox.path !== path24) {
88208
+ if (currentMailbox && currentMailbox.path !== path25) {
88042
88209
  connection.emit("mailboxClose", currentMailbox);
88043
88210
  }
88044
88211
  connection.mailbox = map;
88045
88212
  connection.currentSelectCommand = selectCommand;
88046
88213
  connection.state = connection.states.SELECTED;
88047
- if (!currentMailbox || currentMailbox.path !== path24) {
88214
+ if (!currentMailbox || currentMailbox.path !== path25) {
88048
88215
  connection.emit("mailboxOpen", connection.mailbox);
88049
88216
  }
88050
88217
  response.next();
@@ -88259,17 +88426,17 @@ var require_create = __commonJS({
88259
88426
  "node_modules/imapflow/lib/commands/create.js"(exports, module) {
88260
88427
  "use strict";
88261
88428
  var { encodePath, normalizePath, getStatusCode, enhanceCommandError } = require_tools2();
88262
- module.exports = async (connection, path24) => {
88429
+ module.exports = async (connection, path25) => {
88263
88430
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
88264
88431
  return;
88265
88432
  }
88266
- path24 = normalizePath(connection, path24);
88433
+ path25 = normalizePath(connection, path25);
88267
88434
  let response;
88268
88435
  try {
88269
88436
  let map = {
88270
- path: path24
88437
+ path: path25
88271
88438
  };
88272
- response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
88439
+ response = await connection.exec("CREATE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
88273
88440
  let section = response.response.attributes && response.response.attributes[0] && response.response.attributes[0].section && response.response.attributes[0].section.length ? response.response.attributes[0].section : false;
88274
88441
  if (section) {
88275
88442
  let key;
@@ -88295,13 +88462,13 @@ var require_create = __commonJS({
88295
88462
  }
88296
88463
  map.created = true;
88297
88464
  response.next();
88298
- await connection.run("SUBSCRIBE", path24);
88465
+ await connection.run("SUBSCRIBE", path25);
88299
88466
  return map;
88300
88467
  } catch (err) {
88301
88468
  let errorCode = getStatusCode(err.response);
88302
88469
  if (errorCode === "ALREADYEXISTS") {
88303
88470
  return {
88304
- path: path24,
88471
+ path: path25,
88305
88472
  created: false
88306
88473
  };
88307
88474
  }
@@ -88318,20 +88485,20 @@ var require_delete = __commonJS({
88318
88485
  "node_modules/imapflow/lib/commands/delete.js"(exports, module) {
88319
88486
  "use strict";
88320
88487
  var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
88321
- module.exports = async (connection, path24) => {
88488
+ module.exports = async (connection, path25) => {
88322
88489
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
88323
88490
  return;
88324
88491
  }
88325
- path24 = normalizePath(connection, path24);
88326
- if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
88492
+ path25 = normalizePath(connection, path25);
88493
+ if (connection.state === connection.states.SELECTED && connection.mailbox.path === path25) {
88327
88494
  await connection.run("CLOSE");
88328
88495
  }
88329
88496
  let response;
88330
88497
  try {
88331
88498
  let map = {
88332
- path: path24
88499
+ path: path25
88333
88500
  };
88334
- response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
88501
+ response = await connection.exec("DELETE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
88335
88502
  response.next();
88336
88503
  return map;
88337
88504
  } catch (err) {
@@ -88348,23 +88515,23 @@ var require_rename = __commonJS({
88348
88515
  "node_modules/imapflow/lib/commands/rename.js"(exports, module) {
88349
88516
  "use strict";
88350
88517
  var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
88351
- module.exports = async (connection, path24, newPath) => {
88518
+ module.exports = async (connection, path25, newPath) => {
88352
88519
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
88353
88520
  return;
88354
88521
  }
88355
- path24 = normalizePath(connection, path24);
88522
+ path25 = normalizePath(connection, path25);
88356
88523
  newPath = normalizePath(connection, newPath);
88357
- if (connection.state === connection.states.SELECTED && connection.mailbox.path === path24) {
88524
+ if (connection.state === connection.states.SELECTED && connection.mailbox.path === path25) {
88358
88525
  await connection.run("CLOSE");
88359
88526
  }
88360
88527
  let response;
88361
88528
  try {
88362
88529
  let map = {
88363
- path: path24,
88530
+ path: path25,
88364
88531
  newPath
88365
88532
  };
88366
88533
  response = await connection.exec("RENAME", [
88367
- { type: "ATOM", value: encodePath(connection, path24) },
88534
+ { type: "ATOM", value: encodePath(connection, path25) },
88368
88535
  { type: "ATOM", value: encodePath(connection, newPath) }
88369
88536
  ]);
88370
88537
  response.next();
@@ -88411,14 +88578,14 @@ var require_subscribe = __commonJS({
88411
88578
  "node_modules/imapflow/lib/commands/subscribe.js"(exports, module) {
88412
88579
  "use strict";
88413
88580
  var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
88414
- module.exports = async (connection, path24) => {
88581
+ module.exports = async (connection, path25) => {
88415
88582
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
88416
88583
  return;
88417
88584
  }
88418
- path24 = normalizePath(connection, path24);
88585
+ path25 = normalizePath(connection, path25);
88419
88586
  let response;
88420
88587
  try {
88421
- response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
88588
+ response = await connection.exec("SUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
88422
88589
  response.next();
88423
88590
  return true;
88424
88591
  } catch (err) {
@@ -88435,14 +88602,14 @@ var require_unsubscribe = __commonJS({
88435
88602
  "node_modules/imapflow/lib/commands/unsubscribe.js"(exports, module) {
88436
88603
  "use strict";
88437
88604
  var { encodePath, normalizePath, enhanceCommandError } = require_tools2();
88438
- module.exports = async (connection, path24) => {
88605
+ module.exports = async (connection, path25) => {
88439
88606
  if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state)) {
88440
88607
  return;
88441
88608
  }
88442
- path24 = normalizePath(connection, path24);
88609
+ path25 = normalizePath(connection, path25);
88443
88610
  let response;
88444
88611
  try {
88445
- response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path24) }]);
88612
+ response = await connection.exec("UNSUBSCRIBE", [{ type: "ATOM", value: encodePath(connection, path25) }]);
88446
88613
  response.next();
88447
88614
  return true;
88448
88615
  } catch (err) {
@@ -89248,11 +89415,11 @@ var require_status = __commonJS({
89248
89415
  var { encodePath, normalizePath, buildStatusQueryAttributes, isRev2Active } = require_tools2();
89249
89416
  var { parseStatusList } = require_status_fields();
89250
89417
  var MAILBOX_UPDATERS = {
89251
- messages: (value, connection, path24) => {
89418
+ messages: (value, connection, path25) => {
89252
89419
  let prevCount = connection.mailbox.exists;
89253
89420
  if (prevCount !== value) {
89254
89421
  connection.mailbox.exists = value;
89255
- connection.emit("exists", { path: path24, count: value, prevCount });
89422
+ connection.emit("exists", { path: path25, count: value, prevCount });
89256
89423
  }
89257
89424
  },
89258
89425
  uidNext: (value, connection) => {
@@ -89262,28 +89429,28 @@ var require_status = __commonJS({
89262
89429
  connection.mailbox.highestModseq = value;
89263
89430
  }
89264
89431
  };
89265
- module.exports = async (connection, path24, query) => {
89266
- if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
89432
+ module.exports = async (connection, path25, query) => {
89433
+ if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path25) {
89267
89434
  return false;
89268
89435
  }
89269
- path24 = normalizePath(connection, path24);
89270
- let encodedPath = encodePath(connection, path24);
89436
+ path25 = normalizePath(connection, path25);
89437
+ let encodedPath = encodePath(connection, path25);
89271
89438
  let attributes = [{ type: encodedPath.indexOf("&") >= 0 ? "STRING" : "ATOM", value: encodedPath }];
89272
89439
  let queryAttributes = buildStatusQueryAttributes(connection, query);
89273
89440
  let syntheticRecent = query && query.recent && isRev2Active(connection);
89274
89441
  if (!queryAttributes.length) {
89275
- return syntheticRecent ? { path: path24, recent: 0 } : false;
89442
+ return syntheticRecent ? { path: path25, recent: 0 } : false;
89276
89443
  }
89277
89444
  attributes.push(queryAttributes);
89278
89445
  let response;
89279
89446
  try {
89280
- let map = { path: path24 };
89447
+ let map = { path: path25 };
89281
89448
  response = await connection.exec("STATUS", attributes, {
89282
89449
  untagged: {
89283
89450
  // STATUS response: * STATUS <mailbox> (<key> <value> <key> <value> ...)
89284
89451
  // Parsed as alternating key-value pairs (i % 2 pattern).
89285
89452
  STATUS: async (untagged) => {
89286
- let updateCurrent = connection.state === connection.states.SELECTED && path24 === connection.mailbox.path;
89453
+ let updateCurrent = connection.state === connection.states.SELECTED && path25 === connection.mailbox.path;
89287
89454
  let list = untagged.attributes && Array.isArray(untagged.attributes[1]) ? untagged.attributes[1] : false;
89288
89455
  if (!list) {
89289
89456
  return;
@@ -89291,7 +89458,7 @@ var require_status = __commonJS({
89291
89458
  parseStatusList(list, (key, value) => {
89292
89459
  map[key] = value;
89293
89460
  if (updateCurrent && MAILBOX_UPDATERS[key]) {
89294
- MAILBOX_UPDATERS[key](value, connection, path24);
89461
+ MAILBOX_UPDATERS[key](value, connection, path25);
89295
89462
  }
89296
89463
  });
89297
89464
  }
@@ -89304,9 +89471,9 @@ var require_status = __commonJS({
89304
89471
  return map;
89305
89472
  } catch (err) {
89306
89473
  if (err.responseStatus === "NO") {
89307
- let folders = await connection.run("LIST", "", path24, { listOnly: true });
89474
+ let folders = await connection.run("LIST", "", path25, { listOnly: true });
89308
89475
  if (folders && !folders.length) {
89309
- let error2 = new Error(`Mailbox doesn't exist: ${path24}`);
89476
+ let error2 = new Error(`Mailbox doesn't exist: ${path25}`);
89310
89477
  error2.code = "NotFound";
89311
89478
  error2.response = err;
89312
89479
  throw error2;
@@ -89453,15 +89620,15 @@ var require_quota = __commonJS({
89453
89620
  "node_modules/imapflow/lib/commands/quota.js"(exports, module) {
89454
89621
  "use strict";
89455
89622
  var { encodePath, normalizePath, enhanceCommandError, parseUintValue, isUnsafeKey } = require_tools2();
89456
- module.exports = async (connection, path24) => {
89457
- if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path24) {
89623
+ module.exports = async (connection, path25) => {
89624
+ if (![connection.states.AUTHENTICATED, connection.states.SELECTED].includes(connection.state) || !path25) {
89458
89625
  return;
89459
89626
  }
89460
89627
  if (!connection.capabilities.has("QUOTA")) {
89461
89628
  return false;
89462
89629
  }
89463
- path24 = normalizePath(connection, path24);
89464
- let map = { path: path24 };
89630
+ path25 = normalizePath(connection, path25);
89631
+ let map = { path: path25 };
89465
89632
  let processQuotaResponse = (untagged) => {
89466
89633
  let attributes = untagged.attributes && untagged.attributes[1];
89467
89634
  if (!attributes || !attributes.length) {
@@ -89501,7 +89668,7 @@ var require_quota = __commonJS({
89501
89668
  let quotaFound = false;
89502
89669
  let response;
89503
89670
  try {
89504
- response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path24) }], {
89671
+ response = await connection.exec("GETQUOTAROOT", [{ type: "ATOM", value: encodePath(connection, path25) }], {
89505
89672
  untagged: {
89506
89673
  // QUOTAROOT response tells us which quota root applies to this mailbox.
89507
89674
  // A mailbox may have zero or one quota root.
@@ -89644,15 +89811,15 @@ var require_idle = __commonJS({
89644
89811
  }
89645
89812
  }
89646
89813
  async function pollOnce2(connection, session) {
89647
- let path24 = connection.mailbox && connection.mailbox.path;
89814
+ let path25 = connection.mailbox && connection.mailbox.path;
89648
89815
  switch (connection.missingIdleCommand) {
89649
89816
  case "SELECT":
89650
89817
  connection.log.debug({ src: "c", msg: `Running SELECT to detect changes in folder`, cid: connection.id });
89651
- await connection.runInternal("SELECT", path24, { readOnly: session.selectCommand.command === "EXAMINE" });
89818
+ await connection.runInternal("SELECT", path25, { readOnly: session.selectCommand.command === "EXAMINE" });
89652
89819
  break;
89653
89820
  case "STATUS": {
89654
89821
  connection.log.debug({ src: "c", msg: `Running STATUS to detect changes in folder`, cid: connection.id });
89655
- let status = await connection.runInternal("STATUS", path24, {
89822
+ let status = await connection.runInternal("STATUS", path25, {
89656
89823
  messages: true,
89657
89824
  uidNext: true,
89658
89825
  uidValidity: true,
@@ -91339,12 +91506,12 @@ var require_imap_flow = __commonJS({
91339
91506
  this.emit("flags", updateEvent);
91340
91507
  }
91341
91508
  }
91342
- async ensureSelectedMailbox(path24) {
91343
- if (!path24) {
91509
+ async ensureSelectedMailbox(path25) {
91510
+ if (!path25) {
91344
91511
  return false;
91345
91512
  }
91346
- if (!this.mailbox || !comparePaths(this, this.mailbox.path, path24)) {
91347
- return await this.mailboxOpen(path24);
91513
+ if (!this.mailbox || !comparePaths(this, this.mailbox.path, path25)) {
91514
+ return await this.mailboxOpen(path25);
91348
91515
  }
91349
91516
  return true;
91350
91517
  }
@@ -91759,9 +91926,9 @@ var require_imap_flow = __commonJS({
91759
91926
  * let quota = await client.getQuota();
91760
91927
  * console.log(quota.storage.used, quota.storage.limit)
91761
91928
  */
91762
- async getQuota(path24) {
91763
- path24 = path24 || "INBOX";
91764
- return await this.run("QUOTA", path24);
91929
+ async getQuota(path25) {
91930
+ path25 = path25 || "INBOX";
91931
+ return await this.run("QUOTA", path25);
91765
91932
  }
91766
91933
  /**
91767
91934
  * @typedef {Object} ListResponse
@@ -91871,8 +92038,8 @@ var require_imap_flow = __commonJS({
91871
92038
  * console.log(info.path);
91872
92039
  * // "INBOX.parent.child" // assumes "INBOX." as namespace prefix and "." as delimiter
91873
92040
  */
91874
- async mailboxCreate(path24) {
91875
- return await this.run("CREATE", path24);
92041
+ async mailboxCreate(path25) {
92042
+ return await this.run("CREATE", path25);
91876
92043
  }
91877
92044
  /**
91878
92045
  * @typedef {Object} MailboxRenameResponse
@@ -91893,8 +92060,8 @@ var require_imap_flow = __commonJS({
91893
92060
  * console.log(info.newPath);
91894
92061
  * // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
91895
92062
  */
91896
- async mailboxRename(path24, newPath) {
91897
- return await this.run("RENAME", path24, newPath);
92063
+ async mailboxRename(path25, newPath) {
92064
+ return await this.run("RENAME", path25, newPath);
91898
92065
  }
91899
92066
  /**
91900
92067
  * @typedef {Object} MailboxDeleteResponse
@@ -91913,8 +92080,8 @@ var require_imap_flow = __commonJS({
91913
92080
  * console.log(info.path);
91914
92081
  * // "INBOX.Important stuff ❗️" // assumes "INBOX." as namespace prefix
91915
92082
  */
91916
- async mailboxDelete(path24) {
91917
- return await this.run("DELETE", path24);
92083
+ async mailboxDelete(path25) {
92084
+ return await this.run("DELETE", path25);
91918
92085
  }
91919
92086
  /**
91920
92087
  * Subscribes to a mailbox
@@ -91925,8 +92092,8 @@ var require_imap_flow = __commonJS({
91925
92092
  * @example
91926
92093
  * await client.mailboxSubscribe('Important stuff ❗️');
91927
92094
  */
91928
- async mailboxSubscribe(path24) {
91929
- return await this.run("SUBSCRIBE", path24);
92095
+ async mailboxSubscribe(path25) {
92096
+ return await this.run("SUBSCRIBE", path25);
91930
92097
  }
91931
92098
  /**
91932
92099
  * Unsubscribes from a mailbox
@@ -91937,8 +92104,8 @@ var require_imap_flow = __commonJS({
91937
92104
  * @example
91938
92105
  * await client.mailboxUnsubscribe('Important stuff ❗️');
91939
92106
  */
91940
- async mailboxUnsubscribe(path24) {
91941
- return await this.run("UNSUBSCRIBE", path24);
92107
+ async mailboxUnsubscribe(path25) {
92108
+ return await this.run("UNSUBSCRIBE", path25);
91942
92109
  }
91943
92110
  /**
91944
92111
  * Opens a mailbox to access messages. You can perform message operations only against an opened mailbox.
@@ -91956,8 +92123,8 @@ var require_imap_flow = __commonJS({
91956
92123
  * console.log(mailbox.exists);
91957
92124
  * // 125
91958
92125
  */
91959
- async mailboxOpen(path24, options) {
91960
- return await this.run("SELECT", path24, options);
92126
+ async mailboxOpen(path25, options) {
92127
+ return await this.run("SELECT", path25, options);
91961
92128
  }
91962
92129
  /**
91963
92130
  * Closes a previously opened mailbox
@@ -92004,8 +92171,8 @@ var require_imap_flow = __commonJS({
92004
92171
  * console.log(status.unseen);
92005
92172
  * // 123
92006
92173
  */
92007
- async status(path24, query) {
92008
- return await this.run("STATUS", path24, query);
92174
+ async status(path25, query) {
92175
+ return await this.run("STATUS", path25, query);
92009
92176
  }
92010
92177
  /**
92011
92178
  * Starts listening for new or deleted messages from the currently opened mailbox. Only required if {@link ImapFlow#disableAutoIdle} is set to `true`
@@ -92259,8 +92426,8 @@ var require_imap_flow = __commonJS({
92259
92426
  * @example
92260
92427
  * await client.append('INBOX', rawMessageBuffer, ['\\Seen'], new Date(2000, 1, 1));
92261
92428
  */
92262
- async append(path24, content, flags, idate) {
92263
- return await this.run("APPEND", path24, content, flags, idate) || false;
92429
+ async append(path25, content, flags, idate) {
92430
+ return await this.run("APPEND", path25, content, flags, idate) || false;
92264
92431
  }
92265
92432
  /**
92266
92433
  * @typedef {Object} CopyResponseObject
@@ -93104,7 +93271,7 @@ var require_imap_flow = __commonJS({
93104
93271
  await new Promise((resolve2) => setImmediate(resolve2));
93105
93272
  }
93106
93273
  const lock = this.locks.shift();
93107
- const { resolve, reject, path: path24, options, lockId } = lock;
93274
+ const { resolve, reject, path: path25, options, lockId } = lock;
93108
93275
  if (lock.acquireTimer) {
93109
93276
  clearTimeout(lock.acquireTimer);
93110
93277
  lock.acquireTimer = null;
@@ -93120,7 +93287,7 @@ var require_imap_flow = __commonJS({
93120
93287
  this.log.warn({
93121
93288
  msg: "Mailbox lock held for a long time",
93122
93289
  lockId: lock.lockId,
93123
- path: path24,
93290
+ path: path25,
93124
93291
  heldFor: Date.now() - lock.heldAt,
93125
93292
  /* c8 ignore next */
93126
93293
  // the held-lock-warning diagnostic with a description set is a timing-dependent log detail
@@ -93156,52 +93323,52 @@ var require_imap_flow = __commonJS({
93156
93323
  }
93157
93324
  };
93158
93325
  if (!this.usable || !this.socket || this.socket.destroyed) {
93159
- this.log.trace({ msg: "Failed to acquire mailbox lock", path: path24, lockId, idling: this.idling });
93326
+ this.log.trace({ msg: "Failed to acquire mailbox lock", path: path25, lockId, idling: this.idling });
93160
93327
  let error2 = new Error("Connection not available");
93161
93328
  error2.code = "NoConnection";
93162
93329
  reject(error2);
93163
93330
  continue;
93164
93331
  }
93165
- if (this.mailbox && this.mailbox.path === path24 && !!this.mailbox.readOnly === !!options.readOnly) {
93332
+ if (this.mailbox && this.mailbox.path === path25 && !!this.mailbox.readOnly === !!options.readOnly) {
93166
93333
  this.log.trace({
93167
93334
  msg: "Mailbox lock acquired [existing]",
93168
- path: path24,
93335
+ path: path25,
93169
93336
  lockId,
93170
93337
  idling: this.idling,
93171
93338
  ...options.description && { description: options.description }
93172
93339
  });
93173
93340
  this.currentLock = lock;
93174
93341
  armHeldTimer();
93175
- resolve({ path: path24, release });
93342
+ resolve({ path: path25, release });
93176
93343
  break;
93177
93344
  }
93178
93345
  try {
93179
- await this.mailboxOpen(path24, options);
93346
+ await this.mailboxOpen(path25, options);
93180
93347
  this.log.trace({
93181
93348
  msg: "Mailbox lock acquired [selected]",
93182
- path: path24,
93349
+ path: path25,
93183
93350
  lockId,
93184
93351
  idling: this.idling,
93185
93352
  ...options.description && { description: options.description }
93186
93353
  });
93187
93354
  this.currentLock = lock;
93188
93355
  armHeldTimer();
93189
- resolve({ path: path24, release });
93356
+ resolve({ path: path25, release });
93190
93357
  break;
93191
93358
  } catch (err) {
93192
93359
  if (err.responseStatus === "NO") {
93193
93360
  try {
93194
- let folders = await this.run("LIST", "", path24, { listOnly: true });
93361
+ let folders = await this.run("LIST", "", path25, { listOnly: true });
93195
93362
  if (!folders || !folders.length) {
93196
93363
  err.mailboxMissing = true;
93197
93364
  }
93198
93365
  } catch (E) {
93199
- this.log.trace({ msg: "Failed to verify failed mailbox", path: path24, err: E });
93366
+ this.log.trace({ msg: "Failed to verify failed mailbox", path: path25, err: E });
93200
93367
  }
93201
93368
  }
93202
93369
  this.log.trace({
93203
93370
  msg: "Failed to acquire mailbox lock",
93204
- path: path24,
93371
+ path: path25,
93205
93372
  lockId,
93206
93373
  idling: this.idling,
93207
93374
  ...options.description && { description: options.description },
@@ -93240,13 +93407,13 @@ var require_imap_flow = __commonJS({
93240
93407
  * lock.release();
93241
93408
  * }
93242
93409
  */
93243
- getMailboxLock(path24, options) {
93410
+ getMailboxLock(path25, options) {
93244
93411
  options = options || {};
93245
- path24 = normalizePath(this, path24);
93412
+ path25 = normalizePath(this, path25);
93246
93413
  let lockId = ++this.lockCounter;
93247
93414
  this.log.trace({
93248
93415
  msg: "Requesting lock",
93249
- path: path24,
93416
+ path: path25,
93250
93417
  lockId,
93251
93418
  ...options.description && { description: options.description },
93252
93419
  activeLock: this.currentLock ? {
@@ -93255,7 +93422,7 @@ var require_imap_flow = __commonJS({
93255
93422
  } : null
93256
93423
  });
93257
93424
  let lockPromise = new Promise((resolve, reject) => {
93258
- let lockEntry = { resolve, reject, path: path24, options, lockId };
93425
+ let lockEntry = { resolve, reject, path: path25, options, lockId };
93259
93426
  this.locks.push(lockEntry);
93260
93427
  if (Number(options.acquireTimeout) > 0) {
93261
93428
  lockEntry.acquireTimer = setTimeout(() => {
@@ -93344,16 +93511,16 @@ var require_imap_flow = __commonJS({
93344
93511
  });
93345
93512
 
93346
93513
  // src/mail/mail-fetcher.ts
93347
- import fs21 from "node:fs/promises";
93348
- import path22 from "node:path";
93514
+ import fs22 from "node:fs/promises";
93515
+ import path23 from "node:path";
93349
93516
  async function saveAttachments(attachments, downloadDir) {
93350
93517
  if (attachments.length === 0) return [];
93351
- await fs21.mkdir(downloadDir, { recursive: true });
93518
+ await fs22.mkdir(downloadDir, { recursive: true });
93352
93519
  const saved = [];
93353
93520
  for (const a of attachments) {
93354
- const name = path22.basename(a.filename) || "attachment";
93355
- const savedPath = path22.join(downloadDir, name);
93356
- await fs21.writeFile(savedPath, a.content);
93521
+ const name = path23.basename(a.filename) || "attachment";
93522
+ const savedPath = path23.join(downloadDir, name);
93523
+ await fs22.writeFile(savedPath, a.content);
93357
93524
  saved.push({ filename: name, savedPath, size: a.content.length });
93358
93525
  }
93359
93526
  return saved;
@@ -93484,7 +93651,7 @@ var init_mail_fetcher = __esm({
93484
93651
 
93485
93652
  // src/tools/fetch-mail.ts
93486
93653
  import os16 from "node:os";
93487
- import path23 from "node:path";
93654
+ import path24 from "node:path";
93488
93655
  function registerFetchMailTool(server, deps = {}) {
93489
93656
  const makeFetcher = deps.fetcherFactory ?? ((creds) => new ImapflowMailFetcher(creds));
93490
93657
  server.registerTool(
@@ -93546,7 +93713,7 @@ var init_fetch_mail = __esm({
93546
93713
  init_mail_fetcher();
93547
93714
  init_auth_error();
93548
93715
  init_validate();
93549
- DEFAULT_DOWNLOAD_DIR = path23.join(os16.homedir(), ".cogent", "mail-downloads");
93716
+ DEFAULT_DOWNLOAD_DIR = path24.join(os16.homedir(), ".cogent", "mail-downloads");
93550
93717
  }
93551
93718
  });
93552
93719