mcp-agents-memory 0.9.15 → 0.9.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.js CHANGED
@@ -1655,11 +1655,11 @@ var require_pg_connection_string = __commonJS({
1655
1655
  config2.client_encoding = result.searchParams.get("encoding");
1656
1656
  return config2;
1657
1657
  }
1658
- const hostname12 = dummyHost ? "" : result.hostname;
1658
+ const hostname13 = dummyHost ? "" : result.hostname;
1659
1659
  if (!config2.host) {
1660
- config2.host = decodeURIComponent(hostname12);
1661
- } else if (hostname12 && /^%2f/i.test(hostname12)) {
1662
- result.pathname = hostname12 + result.pathname;
1660
+ config2.host = decodeURIComponent(hostname13);
1661
+ } else if (hostname13 && /^%2f/i.test(hostname13)) {
1662
+ result.pathname = hostname13 + result.pathname;
1663
1663
  }
1664
1664
  if (!config2.port) {
1665
1665
  config2.port = result.port;
@@ -1675,15 +1675,15 @@ var require_pg_connection_string = __commonJS({
1675
1675
  if (config2.sslcert || config2.sslkey || config2.sslrootcert || config2.sslmode) {
1676
1676
  config2.ssl = {};
1677
1677
  }
1678
- const fs12 = config2.sslcert || config2.sslkey || config2.sslrootcert ? __require("fs") : null;
1678
+ const fs13 = config2.sslcert || config2.sslkey || config2.sslrootcert ? __require("fs") : null;
1679
1679
  if (config2.sslcert) {
1680
- config2.ssl.cert = fs12.readFileSync(config2.sslcert).toString();
1680
+ config2.ssl.cert = fs13.readFileSync(config2.sslcert).toString();
1681
1681
  }
1682
1682
  if (config2.sslkey) {
1683
- config2.ssl.key = fs12.readFileSync(config2.sslkey).toString();
1683
+ config2.ssl.key = fs13.readFileSync(config2.sslkey).toString();
1684
1684
  }
1685
1685
  if (config2.sslrootcert) {
1686
- config2.ssl.ca = fs12.readFileSync(config2.sslrootcert).toString();
1686
+ config2.ssl.ca = fs13.readFileSync(config2.sslrootcert).toString();
1687
1687
  }
1688
1688
  if (options.useLibpqCompat && config2.uselibpqcompat) {
1689
1689
  throw new Error("Both useLibpqCompat and uselibpqcompat are set. Please use only one of them.");
@@ -3378,7 +3378,7 @@ var require_split2 = __commonJS({
3378
3378
  }
3379
3379
  cb();
3380
3380
  }
3381
- function flush2(cb) {
3381
+ function flush3(cb) {
3382
3382
  this[kLast] += this[kDecoder].end();
3383
3383
  if (this[kLast]) {
3384
3384
  try {
@@ -3424,7 +3424,7 @@ var require_split2 = __commonJS({
3424
3424
  options = Object.assign({}, options);
3425
3425
  options.autoDestroy = true;
3426
3426
  options.transform = transform2;
3427
- options.flush = flush2;
3427
+ options.flush = flush3;
3428
3428
  options.readableObjectMode = true;
3429
3429
  const stream = new Transform(options);
3430
3430
  stream[kLast] = "";
@@ -3448,7 +3448,7 @@ var require_split2 = __commonJS({
3448
3448
  var require_helper = __commonJS({
3449
3449
  "node_modules/pgpass/lib/helper.js"(exports, module) {
3450
3450
  "use strict";
3451
- var path12 = __require("path");
3451
+ var path13 = __require("path");
3452
3452
  var Stream2 = __require("stream").Stream;
3453
3453
  var split = require_split2();
3454
3454
  var util2 = __require("util");
@@ -3487,7 +3487,7 @@ var require_helper = __commonJS({
3487
3487
  };
3488
3488
  module.exports.getFileName = function(rawEnv) {
3489
3489
  var env = rawEnv || process.env;
3490
- var file = env.PGPASSFILE || (isWin ? path12.join(env.APPDATA || "./", "postgresql", "pgpass.conf") : path12.join(env.HOME || "./", ".pgpass"));
3490
+ var file = env.PGPASSFILE || (isWin ? path13.join(env.APPDATA || "./", "postgresql", "pgpass.conf") : path13.join(env.HOME || "./", ".pgpass"));
3491
3491
  return file;
3492
3492
  };
3493
3493
  module.exports.usePgPass = function(stats, fname) {
@@ -3619,16 +3619,16 @@ var require_helper = __commonJS({
3619
3619
  var require_lib = __commonJS({
3620
3620
  "node_modules/pgpass/lib/index.js"(exports, module) {
3621
3621
  "use strict";
3622
- var path12 = __require("path");
3623
- var fs12 = __require("fs");
3622
+ var path13 = __require("path");
3623
+ var fs13 = __require("fs");
3624
3624
  var helper = require_helper();
3625
3625
  module.exports = function(connInfo, cb) {
3626
3626
  var file = helper.getFileName();
3627
- fs12.stat(file, function(err3, stat) {
3627
+ fs13.stat(file, function(err3, stat) {
3628
3628
  if (err3 || !helper.usePgPass(stat, file)) {
3629
3629
  return cb(void 0);
3630
3630
  }
3631
- var st = fs12.createReadStream(file);
3631
+ var st = fs13.createReadStream(file);
3632
3632
  helper.getPassword(connInfo, st, cb);
3633
3633
  });
3634
3634
  };
@@ -13224,11 +13224,11 @@ var require_agent = __commonJS({
13224
13224
  };
13225
13225
  })();
13226
13226
  var WINDOWS_PIPE_REGEX = /^[/\\][/\\]\.[/\\]pipe[/\\].+/;
13227
- function createAgent(path12) {
13228
- if (process.platform === "win32" && !WINDOWS_PIPE_REGEX.test(path12)) {
13229
- return path12 === "pageant" ? new PageantAgent() : new CygwinAgent(path12);
13227
+ function createAgent(path13) {
13228
+ if (process.platform === "win32" && !WINDOWS_PIPE_REGEX.test(path13)) {
13229
+ return path13 === "pageant" ? new PageantAgent() : new CygwinAgent(path13);
13230
13230
  }
13231
- return new OpenSSHAgent(path12);
13231
+ return new OpenSSHAgent(path13);
13232
13232
  }
13233
13233
  var AgentProtocol = (() => {
13234
13234
  const SSH_AGENTC_REQUEST_IDENTITIES = 11;
@@ -17103,7 +17103,7 @@ var require_Protocol = __commonJS({
17103
17103
  sendPacket(this, this._packetRW.write.finalize(packet));
17104
17104
  });
17105
17105
  }
17106
- authHostbased(username, pubKey, hostname12, userlocal, keyAlgo, cbSign) {
17106
+ authHostbased(username, pubKey, hostname13, userlocal, keyAlgo, cbSign) {
17107
17107
  if (this._server)
17108
17108
  throw new Error("Client-only method called in server mode");
17109
17109
  pubKey = parseKey(pubKey);
@@ -17122,7 +17122,7 @@ var require_Protocol = __commonJS({
17122
17122
  const pubKeyLen = pubKey.length;
17123
17123
  const sessionID = this._kex.sessionID;
17124
17124
  const sesLen = sessionID.length;
17125
- const hostnameLen = Buffer.byteLength(hostname12);
17125
+ const hostnameLen = Buffer.byteLength(hostname13);
17126
17126
  const userlocalLen = Buffer.byteLength(userlocal);
17127
17127
  const data = Buffer.allocUnsafe(
17128
17128
  4 + sesLen + 1 + 4 + userLen + 4 + 14 + 4 + 9 + 4 + algoLen + 4 + pubKeyLen + 4 + hostnameLen + 4 + userlocalLen
@@ -17142,7 +17142,7 @@ var require_Protocol = __commonJS({
17142
17142
  writeUInt32BE(data, pubKeyLen, p += algoLen);
17143
17143
  data.set(pubKey, p += 4);
17144
17144
  writeUInt32BE(data, hostnameLen, p += pubKeyLen);
17145
- data.utf8Write(hostname12, p += 4, hostnameLen);
17145
+ data.utf8Write(hostname13, p += 4, hostnameLen);
17146
17146
  writeUInt32BE(data, userlocalLen, p += hostnameLen);
17147
17147
  data.utf8Write(userlocal, p += 4, userlocalLen);
17148
17148
  cbSign(data, (signature) => {
@@ -18203,8 +18203,8 @@ var require_SFTP = __commonJS({
18203
18203
  "node_modules/ssh2/lib/protocol/SFTP.js"(exports, module) {
18204
18204
  "use strict";
18205
18205
  var EventEmitter = __require("events");
18206
- var fs12 = __require("fs");
18207
- var { constants } = fs12;
18206
+ var fs13 = __require("fs");
18207
+ var { constants } = fs13;
18208
18208
  var {
18209
18209
  Readable: ReadableStream2,
18210
18210
  Writable: WritableStream
@@ -18472,17 +18472,17 @@ var require_SFTP = __commonJS({
18472
18472
  // ===========================================================================
18473
18473
  // Client-specific ===========================================================
18474
18474
  // ===========================================================================
18475
- createReadStream(path12, options) {
18475
+ createReadStream(path13, options) {
18476
18476
  if (this.server)
18477
18477
  throw new Error("Client-only method called in server mode");
18478
- return new ReadStream(this, path12, options);
18478
+ return new ReadStream(this, path13, options);
18479
18479
  }
18480
- createWriteStream(path12, options) {
18480
+ createWriteStream(path13, options) {
18481
18481
  if (this.server)
18482
18482
  throw new Error("Client-only method called in server mode");
18483
- return new WriteStream(this, path12, options);
18483
+ return new WriteStream(this, path13, options);
18484
18484
  }
18485
- open(path12, flags_, attrs, cb) {
18485
+ open(path13, flags_, attrs, cb) {
18486
18486
  if (this.server)
18487
18487
  throw new Error("Client-only method called in server mode");
18488
18488
  if (typeof attrs === "function") {
@@ -18501,7 +18501,7 @@ var require_SFTP = __commonJS({
18501
18501
  attrsFlags = attrs.flags;
18502
18502
  attrsLen = attrs.nb;
18503
18503
  }
18504
- const pathLen = Buffer.byteLength(path12);
18504
+ const pathLen = Buffer.byteLength(path13);
18505
18505
  let p = 9;
18506
18506
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + 4 + attrsLen);
18507
18507
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -18509,7 +18509,7 @@ var require_SFTP = __commonJS({
18509
18509
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
18510
18510
  writeUInt32BE(buf, reqid, 5);
18511
18511
  writeUInt32BE(buf, pathLen, p);
18512
- buf.utf8Write(path12, p += 4, pathLen);
18512
+ buf.utf8Write(path13, p += 4, pathLen);
18513
18513
  writeUInt32BE(buf, flags, p += pathLen);
18514
18514
  writeUInt32BE(buf, attrsFlags, p += 4);
18515
18515
  if (attrsLen) {
@@ -18633,14 +18633,14 @@ var require_SFTP = __commonJS({
18633
18633
  fastGet(remotePath, localPath, opts, cb) {
18634
18634
  if (this.server)
18635
18635
  throw new Error("Client-only method called in server mode");
18636
- fastXfer(this, fs12, remotePath, localPath, opts, cb);
18636
+ fastXfer(this, fs13, remotePath, localPath, opts, cb);
18637
18637
  }
18638
18638
  fastPut(localPath, remotePath, opts, cb) {
18639
18639
  if (this.server)
18640
18640
  throw new Error("Client-only method called in server mode");
18641
- fastXfer(fs12, this, localPath, remotePath, opts, cb);
18641
+ fastXfer(fs13, this, localPath, remotePath, opts, cb);
18642
18642
  }
18643
- readFile(path12, options, callback_) {
18643
+ readFile(path13, options, callback_) {
18644
18644
  if (this.server)
18645
18645
  throw new Error("Client-only method called in server mode");
18646
18646
  let callback;
@@ -18713,13 +18713,13 @@ var require_SFTP = __commonJS({
18713
18713
  return callback && callback(er, buffer);
18714
18714
  });
18715
18715
  };
18716
- this.open(path12, flag, 438, (er, handle_) => {
18716
+ this.open(path13, flag, 438, (er, handle_) => {
18717
18717
  if (er)
18718
18718
  return callback && callback(er);
18719
18719
  handle = handle_;
18720
18720
  const tryStat = (er2, st) => {
18721
18721
  if (er2) {
18722
- this.stat(path12, (er_, st_) => {
18722
+ this.stat(path13, (er_, st_) => {
18723
18723
  if (er_) {
18724
18724
  return this.close(handle, () => {
18725
18725
  callback && callback(er2);
@@ -18740,7 +18740,7 @@ var require_SFTP = __commonJS({
18740
18740
  this.fstat(handle, tryStat);
18741
18741
  });
18742
18742
  }
18743
- writeFile(path12, data, options, callback_) {
18743
+ writeFile(path13, data, options, callback_) {
18744
18744
  if (this.server)
18745
18745
  throw new Error("Client-only method called in server mode");
18746
18746
  let callback;
@@ -18759,7 +18759,7 @@ var require_SFTP = __commonJS({
18759
18759
  if (options.encoding && !Buffer.isEncoding(options.encoding))
18760
18760
  throw new Error(`Unknown encoding: ${options.encoding}`);
18761
18761
  const flag = options.flag || "w";
18762
- this.open(path12, flag, options.mode, (openErr, handle) => {
18762
+ this.open(path13, flag, options.mode, (openErr, handle) => {
18763
18763
  if (openErr) {
18764
18764
  callback && callback(openErr);
18765
18765
  } else {
@@ -18768,7 +18768,7 @@ var require_SFTP = __commonJS({
18768
18768
  if (position === null) {
18769
18769
  const tryStat = (er, st) => {
18770
18770
  if (er) {
18771
- this.stat(path12, (er_, st_) => {
18771
+ this.stat(path13, (er_, st_) => {
18772
18772
  if (er_) {
18773
18773
  return this.close(handle, () => {
18774
18774
  callback && callback(er);
@@ -18787,7 +18787,7 @@ var require_SFTP = __commonJS({
18787
18787
  }
18788
18788
  });
18789
18789
  }
18790
- appendFile(path12, data, options, callback_) {
18790
+ appendFile(path13, data, options, callback_) {
18791
18791
  if (this.server)
18792
18792
  throw new Error("Client-only method called in server mode");
18793
18793
  let callback;
@@ -18805,12 +18805,12 @@ var require_SFTP = __commonJS({
18805
18805
  throw new TypeError("Bad arguments");
18806
18806
  if (!options.flag)
18807
18807
  options = Object.assign({ flag: "a" }, options);
18808
- this.writeFile(path12, data, options, callback);
18808
+ this.writeFile(path13, data, options, callback);
18809
18809
  }
18810
- exists(path12, cb) {
18810
+ exists(path13, cb) {
18811
18811
  if (this.server)
18812
18812
  throw new Error("Client-only method called in server mode");
18813
- this.stat(path12, (err3) => {
18813
+ this.stat(path13, (err3) => {
18814
18814
  cb && cb(err3 ? false : true);
18815
18815
  });
18816
18816
  }
@@ -18853,7 +18853,7 @@ var require_SFTP = __commonJS({
18853
18853
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} RENAME`
18854
18854
  );
18855
18855
  }
18856
- mkdir(path12, attrs, cb) {
18856
+ mkdir(path13, attrs, cb) {
18857
18857
  if (this.server)
18858
18858
  throw new Error("Client-only method called in server mode");
18859
18859
  let flags = 0;
@@ -18867,7 +18867,7 @@ var require_SFTP = __commonJS({
18867
18867
  flags = attrs.flags;
18868
18868
  attrsLen = attrs.nb;
18869
18869
  }
18870
- const pathLen = Buffer.byteLength(path12);
18870
+ const pathLen = Buffer.byteLength(path13);
18871
18871
  let p = 9;
18872
18872
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + attrsLen);
18873
18873
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -18875,7 +18875,7 @@ var require_SFTP = __commonJS({
18875
18875
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
18876
18876
  writeUInt32BE(buf, reqid, 5);
18877
18877
  writeUInt32BE(buf, pathLen, p);
18878
- buf.utf8Write(path12, p += 4, pathLen);
18878
+ buf.utf8Write(path13, p += 4, pathLen);
18879
18879
  writeUInt32BE(buf, flags, p += pathLen);
18880
18880
  if (attrsLen) {
18881
18881
  p += 4;
@@ -18891,10 +18891,10 @@ var require_SFTP = __commonJS({
18891
18891
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} MKDIR`
18892
18892
  );
18893
18893
  }
18894
- rmdir(path12, cb) {
18894
+ rmdir(path13, cb) {
18895
18895
  if (this.server)
18896
18896
  throw new Error("Client-only method called in server mode");
18897
- const pathLen = Buffer.byteLength(path12);
18897
+ const pathLen = Buffer.byteLength(path13);
18898
18898
  let p = 9;
18899
18899
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
18900
18900
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -18902,7 +18902,7 @@ var require_SFTP = __commonJS({
18902
18902
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
18903
18903
  writeUInt32BE(buf, reqid, 5);
18904
18904
  writeUInt32BE(buf, pathLen, p);
18905
- buf.utf8Write(path12, p += 4, pathLen);
18905
+ buf.utf8Write(path13, p += 4, pathLen);
18906
18906
  this._requests[reqid] = { cb };
18907
18907
  const isBuffered = sendOrBuffer(this, buf);
18908
18908
  this._debug && this._debug(
@@ -18992,10 +18992,10 @@ var require_SFTP = __commonJS({
18992
18992
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} FSTAT`
18993
18993
  );
18994
18994
  }
18995
- stat(path12, cb) {
18995
+ stat(path13, cb) {
18996
18996
  if (this.server)
18997
18997
  throw new Error("Client-only method called in server mode");
18998
- const pathLen = Buffer.byteLength(path12);
18998
+ const pathLen = Buffer.byteLength(path13);
18999
18999
  let p = 9;
19000
19000
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
19001
19001
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19003,17 +19003,17 @@ var require_SFTP = __commonJS({
19003
19003
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19004
19004
  writeUInt32BE(buf, reqid, 5);
19005
19005
  writeUInt32BE(buf, pathLen, p);
19006
- buf.utf8Write(path12, p += 4, pathLen);
19006
+ buf.utf8Write(path13, p += 4, pathLen);
19007
19007
  this._requests[reqid] = { cb };
19008
19008
  const isBuffered = sendOrBuffer(this, buf);
19009
19009
  this._debug && this._debug(
19010
19010
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} STAT`
19011
19011
  );
19012
19012
  }
19013
- lstat(path12, cb) {
19013
+ lstat(path13, cb) {
19014
19014
  if (this.server)
19015
19015
  throw new Error("Client-only method called in server mode");
19016
- const pathLen = Buffer.byteLength(path12);
19016
+ const pathLen = Buffer.byteLength(path13);
19017
19017
  let p = 9;
19018
19018
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
19019
19019
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19021,17 +19021,17 @@ var require_SFTP = __commonJS({
19021
19021
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19022
19022
  writeUInt32BE(buf, reqid, 5);
19023
19023
  writeUInt32BE(buf, pathLen, p);
19024
- buf.utf8Write(path12, p += 4, pathLen);
19024
+ buf.utf8Write(path13, p += 4, pathLen);
19025
19025
  this._requests[reqid] = { cb };
19026
19026
  const isBuffered = sendOrBuffer(this, buf);
19027
19027
  this._debug && this._debug(
19028
19028
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} LSTAT`
19029
19029
  );
19030
19030
  }
19031
- opendir(path12, cb) {
19031
+ opendir(path13, cb) {
19032
19032
  if (this.server)
19033
19033
  throw new Error("Client-only method called in server mode");
19034
- const pathLen = Buffer.byteLength(path12);
19034
+ const pathLen = Buffer.byteLength(path13);
19035
19035
  let p = 9;
19036
19036
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
19037
19037
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19039,14 +19039,14 @@ var require_SFTP = __commonJS({
19039
19039
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19040
19040
  writeUInt32BE(buf, reqid, 5);
19041
19041
  writeUInt32BE(buf, pathLen, p);
19042
- buf.utf8Write(path12, p += 4, pathLen);
19042
+ buf.utf8Write(path13, p += 4, pathLen);
19043
19043
  this._requests[reqid] = { cb };
19044
19044
  const isBuffered = sendOrBuffer(this, buf);
19045
19045
  this._debug && this._debug(
19046
19046
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} OPENDIR`
19047
19047
  );
19048
19048
  }
19049
- setstat(path12, attrs, cb) {
19049
+ setstat(path13, attrs, cb) {
19050
19050
  if (this.server)
19051
19051
  throw new Error("Client-only method called in server mode");
19052
19052
  let flags = 0;
@@ -19058,7 +19058,7 @@ var require_SFTP = __commonJS({
19058
19058
  } else if (typeof attrs === "function") {
19059
19059
  cb = attrs;
19060
19060
  }
19061
- const pathLen = Buffer.byteLength(path12);
19061
+ const pathLen = Buffer.byteLength(path13);
19062
19062
  let p = 9;
19063
19063
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen + 4 + attrsLen);
19064
19064
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19066,7 +19066,7 @@ var require_SFTP = __commonJS({
19066
19066
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19067
19067
  writeUInt32BE(buf, reqid, 5);
19068
19068
  writeUInt32BE(buf, pathLen, p);
19069
- buf.utf8Write(path12, p += 4, pathLen);
19069
+ buf.utf8Write(path13, p += 4, pathLen);
19070
19070
  writeUInt32BE(buf, flags, p += pathLen);
19071
19071
  if (attrsLen) {
19072
19072
  p += 4;
@@ -19126,8 +19126,8 @@ var require_SFTP = __commonJS({
19126
19126
  mtime: toUnixTimestamp(mtime)
19127
19127
  }, cb);
19128
19128
  }
19129
- utimes(path12, atime, mtime, cb) {
19130
- return this.setstat(path12, {
19129
+ utimes(path13, atime, mtime, cb) {
19130
+ return this.setstat(path13, {
19131
19131
  atime: toUnixTimestamp(atime),
19132
19132
  mtime: toUnixTimestamp(mtime)
19133
19133
  }, cb);
@@ -19138,8 +19138,8 @@ var require_SFTP = __commonJS({
19138
19138
  gid
19139
19139
  }, cb);
19140
19140
  }
19141
- chown(path12, uid, gid, cb) {
19142
- return this.setstat(path12, {
19141
+ chown(path13, uid, gid, cb) {
19142
+ return this.setstat(path13, {
19143
19143
  uid,
19144
19144
  gid
19145
19145
  }, cb);
@@ -19149,15 +19149,15 @@ var require_SFTP = __commonJS({
19149
19149
  mode
19150
19150
  }, cb);
19151
19151
  }
19152
- chmod(path12, mode, cb) {
19153
- return this.setstat(path12, {
19152
+ chmod(path13, mode, cb) {
19153
+ return this.setstat(path13, {
19154
19154
  mode
19155
19155
  }, cb);
19156
19156
  }
19157
- readlink(path12, cb) {
19157
+ readlink(path13, cb) {
19158
19158
  if (this.server)
19159
19159
  throw new Error("Client-only method called in server mode");
19160
- const pathLen = Buffer.byteLength(path12);
19160
+ const pathLen = Buffer.byteLength(path13);
19161
19161
  let p = 9;
19162
19162
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
19163
19163
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19165,7 +19165,7 @@ var require_SFTP = __commonJS({
19165
19165
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19166
19166
  writeUInt32BE(buf, reqid, 5);
19167
19167
  writeUInt32BE(buf, pathLen, p);
19168
- buf.utf8Write(path12, p += 4, pathLen);
19168
+ buf.utf8Write(path13, p += 4, pathLen);
19169
19169
  this._requests[reqid] = {
19170
19170
  cb: (err3, names) => {
19171
19171
  if (typeof cb !== "function")
@@ -19210,10 +19210,10 @@ var require_SFTP = __commonJS({
19210
19210
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} SYMLINK`
19211
19211
  );
19212
19212
  }
19213
- realpath(path12, cb) {
19213
+ realpath(path13, cb) {
19214
19214
  if (this.server)
19215
19215
  throw new Error("Client-only method called in server mode");
19216
- const pathLen = Buffer.byteLength(path12);
19216
+ const pathLen = Buffer.byteLength(path13);
19217
19217
  let p = 9;
19218
19218
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + pathLen);
19219
19219
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19221,7 +19221,7 @@ var require_SFTP = __commonJS({
19221
19221
  const reqid = this._writeReqid = this._writeReqid + 1 & MAX_REQID;
19222
19222
  writeUInt32BE(buf, reqid, 5);
19223
19223
  writeUInt32BE(buf, pathLen, p);
19224
- buf.utf8Write(path12, p += 4, pathLen);
19224
+ buf.utf8Write(path13, p += 4, pathLen);
19225
19225
  this._requests[reqid] = {
19226
19226
  cb: (err3, names) => {
19227
19227
  if (typeof cb !== "function")
@@ -19266,13 +19266,13 @@ var require_SFTP = __commonJS({
19266
19266
  this._debug(`SFTP: Outbound: ${which} posix-rename@openssh.com`);
19267
19267
  }
19268
19268
  }
19269
- ext_openssh_statvfs(path12, cb) {
19269
+ ext_openssh_statvfs(path13, cb) {
19270
19270
  if (this.server)
19271
19271
  throw new Error("Client-only method called in server mode");
19272
19272
  const ext = this._extensions["statvfs@openssh.com"];
19273
19273
  if (!ext || ext !== "2")
19274
19274
  throw new Error("Server does not support this extended request");
19275
- const pathLen = Buffer.byteLength(path12);
19275
+ const pathLen = Buffer.byteLength(path13);
19276
19276
  let p = 9;
19277
19277
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + 19 + 4 + pathLen);
19278
19278
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19282,7 +19282,7 @@ var require_SFTP = __commonJS({
19282
19282
  writeUInt32BE(buf, 19, p);
19283
19283
  buf.utf8Write("statvfs@openssh.com", p += 4, 19);
19284
19284
  writeUInt32BE(buf, pathLen, p += 19);
19285
- buf.utf8Write(path12, p += 4, pathLen);
19285
+ buf.utf8Write(path13, p += 4, pathLen);
19286
19286
  this._requests[reqid] = { extended: "statvfs@openssh.com", cb };
19287
19287
  const isBuffered = sendOrBuffer(this, buf);
19288
19288
  if (this._debug) {
@@ -19368,7 +19368,7 @@ var require_SFTP = __commonJS({
19368
19368
  `SFTP: Outbound: ${isBuffered ? "Buffered" : "Sending"} fsync@openssh.com`
19369
19369
  );
19370
19370
  }
19371
- ext_openssh_lsetstat(path12, attrs, cb) {
19371
+ ext_openssh_lsetstat(path13, attrs, cb) {
19372
19372
  if (this.server)
19373
19373
  throw new Error("Client-only method called in server mode");
19374
19374
  const ext = this._extensions["lsetstat@openssh.com"];
@@ -19383,7 +19383,7 @@ var require_SFTP = __commonJS({
19383
19383
  } else if (typeof attrs === "function") {
19384
19384
  cb = attrs;
19385
19385
  }
19386
- const pathLen = Buffer.byteLength(path12);
19386
+ const pathLen = Buffer.byteLength(path13);
19387
19387
  let p = 9;
19388
19388
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + 20 + 4 + pathLen + 4 + attrsLen);
19389
19389
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19393,7 +19393,7 @@ var require_SFTP = __commonJS({
19393
19393
  writeUInt32BE(buf, 20, p);
19394
19394
  buf.utf8Write("lsetstat@openssh.com", p += 4, 20);
19395
19395
  writeUInt32BE(buf, pathLen, p += 20);
19396
- buf.utf8Write(path12, p += 4, pathLen);
19396
+ buf.utf8Write(path13, p += 4, pathLen);
19397
19397
  writeUInt32BE(buf, flags, p += pathLen);
19398
19398
  if (attrsLen) {
19399
19399
  p += 4;
@@ -19410,13 +19410,13 @@ var require_SFTP = __commonJS({
19410
19410
  this._debug(`SFTP: Outbound: ${status} lsetstat@openssh.com`);
19411
19411
  }
19412
19412
  }
19413
- ext_openssh_expandPath(path12, cb) {
19413
+ ext_openssh_expandPath(path13, cb) {
19414
19414
  if (this.server)
19415
19415
  throw new Error("Client-only method called in server mode");
19416
19416
  const ext = this._extensions["expand-path@openssh.com"];
19417
19417
  if (ext !== "1")
19418
19418
  throw new Error("Server does not support this extended request");
19419
- const pathLen = Buffer.byteLength(path12);
19419
+ const pathLen = Buffer.byteLength(path13);
19420
19420
  let p = 9;
19421
19421
  const buf = Buffer.allocUnsafe(4 + 1 + 4 + 4 + 23 + 4 + pathLen);
19422
19422
  writeUInt32BE(buf, buf.length - 4, 0);
@@ -19426,7 +19426,7 @@ var require_SFTP = __commonJS({
19426
19426
  writeUInt32BE(buf, 23, p);
19427
19427
  buf.utf8Write("expand-path@openssh.com", p += 4, 23);
19428
19428
  writeUInt32BE(buf, pathLen, p += 20);
19429
- buf.utf8Write(path12, p += 4, pathLen);
19429
+ buf.utf8Write(path13, p += 4, pathLen);
19430
19430
  this._requests[reqid] = {
19431
19431
  cb: (err3, names) => {
19432
19432
  if (typeof cb !== "function")
@@ -19899,13 +19899,13 @@ var require_SFTP = __commonJS({
19899
19899
  if (--left === 0)
19900
19900
  cb(err3);
19901
19901
  };
19902
- if (srcHandle && (src === fs12 || src.outgoing.state === "open"))
19902
+ if (srcHandle && (src === fs13 || src.outgoing.state === "open"))
19903
19903
  ++left;
19904
- if (dstHandle && (dst === fs12 || dst.outgoing.state === "open"))
19904
+ if (dstHandle && (dst === fs13 || dst.outgoing.state === "open"))
19905
19905
  ++left;
19906
- if (srcHandle && (src === fs12 || src.outgoing.state === "open"))
19906
+ if (srcHandle && (src === fs13 || src.outgoing.state === "open"))
19907
19907
  src.close(srcHandle, cbfinal);
19908
- if (dstHandle && (dst === fs12 || dst.outgoing.state === "open"))
19908
+ if (dstHandle && (dst === fs13 || dst.outgoing.state === "open"))
19909
19909
  dst.close(dstHandle, cbfinal);
19910
19910
  } else {
19911
19911
  cb(err3);
@@ -19921,7 +19921,7 @@ var require_SFTP = __commonJS({
19921
19921
  tryStat(null, { size: fileSize });
19922
19922
  function tryStat(err4, attrs) {
19923
19923
  if (err4) {
19924
- if (src !== fs12) {
19924
+ if (src !== fs13) {
19925
19925
  src.stat(srcPath, (err_, attrs_) => {
19926
19926
  if (err_)
19927
19927
  return onerror(err4);
@@ -20704,12 +20704,12 @@ var require_SFTP = __commonJS({
20704
20704
  [REQUEST.LSTAT]: (sftp, payload) => {
20705
20705
  bufferParser.init(payload, 1);
20706
20706
  const reqID = bufferParser.readUInt32BE();
20707
- const path12 = bufferParser.readString(true);
20707
+ const path13 = bufferParser.readString(true);
20708
20708
  bufferParser.clear();
20709
- if (path12 === void 0)
20709
+ if (path13 === void 0)
20710
20710
  return doFatalSFTPError(sftp, "Malformed LSTAT packet");
20711
20711
  sftp._debug && sftp._debug(`SFTP: Inbound: Received LSTAT (id:${reqID})`);
20712
- if (!sftp.emit("LSTAT", reqID, path12)) {
20712
+ if (!sftp.emit("LSTAT", reqID, path13)) {
20713
20713
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20714
20714
  }
20715
20715
  },
@@ -20728,13 +20728,13 @@ var require_SFTP = __commonJS({
20728
20728
  [REQUEST.SETSTAT]: (sftp, payload) => {
20729
20729
  bufferParser.init(payload, 1);
20730
20730
  const reqID = bufferParser.readUInt32BE();
20731
- const path12 = bufferParser.readString(true);
20731
+ const path13 = bufferParser.readString(true);
20732
20732
  const attrs = readAttrs(sftp._biOpt);
20733
20733
  bufferParser.clear();
20734
20734
  if (attrs === void 0)
20735
20735
  return doFatalSFTPError(sftp, "Malformed SETSTAT packet");
20736
20736
  sftp._debug && sftp._debug(`SFTP: Inbound: Received SETSTAT (id:${reqID})`);
20737
- if (!sftp.emit("SETSTAT", reqID, path12, attrs)) {
20737
+ if (!sftp.emit("SETSTAT", reqID, path13, attrs)) {
20738
20738
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20739
20739
  }
20740
20740
  },
@@ -20756,12 +20756,12 @@ var require_SFTP = __commonJS({
20756
20756
  [REQUEST.OPENDIR]: (sftp, payload) => {
20757
20757
  bufferParser.init(payload, 1);
20758
20758
  const reqID = bufferParser.readUInt32BE();
20759
- const path12 = bufferParser.readString(true);
20759
+ const path13 = bufferParser.readString(true);
20760
20760
  bufferParser.clear();
20761
- if (path12 === void 0)
20761
+ if (path13 === void 0)
20762
20762
  return doFatalSFTPError(sftp, "Malformed OPENDIR packet");
20763
20763
  sftp._debug && sftp._debug(`SFTP: Inbound: Received OPENDIR (id:${reqID})`);
20764
- if (!sftp.emit("OPENDIR", reqID, path12)) {
20764
+ if (!sftp.emit("OPENDIR", reqID, path13)) {
20765
20765
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20766
20766
  }
20767
20767
  },
@@ -20780,63 +20780,63 @@ var require_SFTP = __commonJS({
20780
20780
  [REQUEST.REMOVE]: (sftp, payload) => {
20781
20781
  bufferParser.init(payload, 1);
20782
20782
  const reqID = bufferParser.readUInt32BE();
20783
- const path12 = bufferParser.readString(true);
20783
+ const path13 = bufferParser.readString(true);
20784
20784
  bufferParser.clear();
20785
- if (path12 === void 0)
20785
+ if (path13 === void 0)
20786
20786
  return doFatalSFTPError(sftp, "Malformed REMOVE packet");
20787
20787
  sftp._debug && sftp._debug(`SFTP: Inbound: Received REMOVE (id:${reqID})`);
20788
- if (!sftp.emit("REMOVE", reqID, path12)) {
20788
+ if (!sftp.emit("REMOVE", reqID, path13)) {
20789
20789
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20790
20790
  }
20791
20791
  },
20792
20792
  [REQUEST.MKDIR]: (sftp, payload) => {
20793
20793
  bufferParser.init(payload, 1);
20794
20794
  const reqID = bufferParser.readUInt32BE();
20795
- const path12 = bufferParser.readString(true);
20795
+ const path13 = bufferParser.readString(true);
20796
20796
  const attrs = readAttrs(sftp._biOpt);
20797
20797
  bufferParser.clear();
20798
20798
  if (attrs === void 0)
20799
20799
  return doFatalSFTPError(sftp, "Malformed MKDIR packet");
20800
20800
  sftp._debug && sftp._debug(`SFTP: Inbound: Received MKDIR (id:${reqID})`);
20801
- if (!sftp.emit("MKDIR", reqID, path12, attrs)) {
20801
+ if (!sftp.emit("MKDIR", reqID, path13, attrs)) {
20802
20802
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20803
20803
  }
20804
20804
  },
20805
20805
  [REQUEST.RMDIR]: (sftp, payload) => {
20806
20806
  bufferParser.init(payload, 1);
20807
20807
  const reqID = bufferParser.readUInt32BE();
20808
- const path12 = bufferParser.readString(true);
20808
+ const path13 = bufferParser.readString(true);
20809
20809
  bufferParser.clear();
20810
- if (path12 === void 0)
20810
+ if (path13 === void 0)
20811
20811
  return doFatalSFTPError(sftp, "Malformed RMDIR packet");
20812
20812
  sftp._debug && sftp._debug(`SFTP: Inbound: Received RMDIR (id:${reqID})`);
20813
- if (!sftp.emit("RMDIR", reqID, path12)) {
20813
+ if (!sftp.emit("RMDIR", reqID, path13)) {
20814
20814
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20815
20815
  }
20816
20816
  },
20817
20817
  [REQUEST.REALPATH]: (sftp, payload) => {
20818
20818
  bufferParser.init(payload, 1);
20819
20819
  const reqID = bufferParser.readUInt32BE();
20820
- const path12 = bufferParser.readString(true);
20820
+ const path13 = bufferParser.readString(true);
20821
20821
  bufferParser.clear();
20822
- if (path12 === void 0)
20822
+ if (path13 === void 0)
20823
20823
  return doFatalSFTPError(sftp, "Malformed REALPATH packet");
20824
20824
  sftp._debug && sftp._debug(
20825
20825
  `SFTP: Inbound: Received REALPATH (id:${reqID})`
20826
20826
  );
20827
- if (!sftp.emit("REALPATH", reqID, path12)) {
20827
+ if (!sftp.emit("REALPATH", reqID, path13)) {
20828
20828
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20829
20829
  }
20830
20830
  },
20831
20831
  [REQUEST.STAT]: (sftp, payload) => {
20832
20832
  bufferParser.init(payload, 1);
20833
20833
  const reqID = bufferParser.readUInt32BE();
20834
- const path12 = bufferParser.readString(true);
20834
+ const path13 = bufferParser.readString(true);
20835
20835
  bufferParser.clear();
20836
- if (path12 === void 0)
20836
+ if (path13 === void 0)
20837
20837
  return doFatalSFTPError(sftp, "Malformed STAT packet");
20838
20838
  sftp._debug && sftp._debug(`SFTP: Inbound: Received STAT (id:${reqID})`);
20839
- if (!sftp.emit("STAT", reqID, path12)) {
20839
+ if (!sftp.emit("STAT", reqID, path13)) {
20840
20840
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20841
20841
  }
20842
20842
  },
@@ -20856,14 +20856,14 @@ var require_SFTP = __commonJS({
20856
20856
  [REQUEST.READLINK]: (sftp, payload) => {
20857
20857
  bufferParser.init(payload, 1);
20858
20858
  const reqID = bufferParser.readUInt32BE();
20859
- const path12 = bufferParser.readString(true);
20859
+ const path13 = bufferParser.readString(true);
20860
20860
  bufferParser.clear();
20861
- if (path12 === void 0)
20861
+ if (path13 === void 0)
20862
20862
  return doFatalSFTPError(sftp, "Malformed READLINK packet");
20863
20863
  sftp._debug && sftp._debug(
20864
20864
  `SFTP: Inbound: Received READLINK (id:${reqID})`
20865
20865
  );
20866
- if (!sftp.emit("READLINK", reqID, path12)) {
20866
+ if (!sftp.emit("READLINK", reqID, path13)) {
20867
20867
  sftp.status(reqID, STATUS_CODE.OP_UNSUPPORTED);
20868
20868
  }
20869
20869
  },
@@ -20934,7 +20934,7 @@ var require_SFTP = __commonJS({
20934
20934
  function roundUpToMultipleOf8(n) {
20935
20935
  return n + 7 & ~7;
20936
20936
  }
20937
- function ReadStream(sftp, path12, options) {
20937
+ function ReadStream(sftp, path13, options) {
20938
20938
  if (options === void 0)
20939
20939
  options = {};
20940
20940
  else if (typeof options === "string")
@@ -20948,7 +20948,7 @@ var require_SFTP = __commonJS({
20948
20948
  options.emitClose = false;
20949
20949
  options.autoDestroy = false;
20950
20950
  ReadableStream2.call(this, options);
20951
- this.path = path12;
20951
+ this.path = path13;
20952
20952
  this.flags = options.flags === void 0 ? "r" : options.flags;
20953
20953
  this.mode = options.mode === void 0 ? 438 : options.mode;
20954
20954
  this.start = options.start;
@@ -21079,7 +21079,7 @@ var require_SFTP = __commonJS({
21079
21079
  },
21080
21080
  configurable: true
21081
21081
  });
21082
- function WriteStream(sftp, path12, options) {
21082
+ function WriteStream(sftp, path13, options) {
21083
21083
  if (options === void 0)
21084
21084
  options = {};
21085
21085
  else if (typeof options === "string")
@@ -21091,7 +21091,7 @@ var require_SFTP = __commonJS({
21091
21091
  options.emitClose = false;
21092
21092
  options.autoDestroy = false;
21093
21093
  WritableStream.call(this, options);
21094
- this.path = path12;
21094
+ this.path = path13;
21095
21095
  this.flags = options.flags === void 0 ? "w" : options.flags;
21096
21096
  this.mode = options.mode === void 0 ? 438 : options.mode;
21097
21097
  this.start = options.start;
@@ -25300,7 +25300,7 @@ var require_tunnel_ssh = __commonJS({
25300
25300
  "node_modules/tunnel-ssh/index.js"(exports) {
25301
25301
  var net = __require("net");
25302
25302
  var { Client: Client2 } = require_lib4();
25303
- var os13 = __require("os");
25303
+ var os14 = __require("os");
25304
25304
  function autoClose(server, connection) {
25305
25305
  connection.on("close", () => {
25306
25306
  server.getConnections((error2, count) => {
@@ -25485,9 +25485,9 @@ var require_package2 = __commonJS({
25485
25485
  // node_modules/dotenv/lib/main.js
25486
25486
  var require_main = __commonJS({
25487
25487
  "node_modules/dotenv/lib/main.js"(exports, module) {
25488
- var fs12 = __require("fs");
25489
- var path12 = __require("path");
25490
- var os13 = __require("os");
25488
+ var fs13 = __require("fs");
25489
+ var path13 = __require("path");
25490
+ var os14 = __require("os");
25491
25491
  var crypto3 = __require("crypto");
25492
25492
  var packageJson2 = require_package2();
25493
25493
  var version2 = packageJson2.version;
@@ -25594,7 +25594,7 @@ var require_main = __commonJS({
25594
25594
  if (options && options.path && options.path.length > 0) {
25595
25595
  if (Array.isArray(options.path)) {
25596
25596
  for (const filepath of options.path) {
25597
- if (fs12.existsSync(filepath)) {
25597
+ if (fs13.existsSync(filepath)) {
25598
25598
  possibleVaultPath = filepath.endsWith(".vault") ? filepath : `${filepath}.vault`;
25599
25599
  }
25600
25600
  }
@@ -25602,15 +25602,15 @@ var require_main = __commonJS({
25602
25602
  possibleVaultPath = options.path.endsWith(".vault") ? options.path : `${options.path}.vault`;
25603
25603
  }
25604
25604
  } else {
25605
- possibleVaultPath = path12.resolve(process.cwd(), ".env.vault");
25605
+ possibleVaultPath = path13.resolve(process.cwd(), ".env.vault");
25606
25606
  }
25607
- if (fs12.existsSync(possibleVaultPath)) {
25607
+ if (fs13.existsSync(possibleVaultPath)) {
25608
25608
  return possibleVaultPath;
25609
25609
  }
25610
25610
  return null;
25611
25611
  }
25612
25612
  function _resolveHome(envPath) {
25613
- return envPath[0] === "~" ? path12.join(os13.homedir(), envPath.slice(1)) : envPath;
25613
+ return envPath[0] === "~" ? path13.join(os14.homedir(), envPath.slice(1)) : envPath;
25614
25614
  }
25615
25615
  function _configVault(options) {
25616
25616
  const debug = Boolean(options && options.debug);
@@ -25627,7 +25627,7 @@ var require_main = __commonJS({
25627
25627
  return { parsed };
25628
25628
  }
25629
25629
  function configDotenv(options) {
25630
- const dotenvPath = path12.resolve(process.cwd(), ".env");
25630
+ const dotenvPath = path13.resolve(process.cwd(), ".env");
25631
25631
  let encoding = "utf8";
25632
25632
  const debug = Boolean(options && options.debug);
25633
25633
  const quiet = options && "quiet" in options ? options.quiet : true;
@@ -25651,13 +25651,13 @@ var require_main = __commonJS({
25651
25651
  }
25652
25652
  let lastError;
25653
25653
  const parsedAll = {};
25654
- for (const path13 of optionPaths) {
25654
+ for (const path14 of optionPaths) {
25655
25655
  try {
25656
- const parsed = DotenvModule.parse(fs12.readFileSync(path13, { encoding }));
25656
+ const parsed = DotenvModule.parse(fs13.readFileSync(path14, { encoding }));
25657
25657
  DotenvModule.populate(parsedAll, parsed, options);
25658
25658
  } catch (e) {
25659
25659
  if (debug) {
25660
- _debug(`Failed to load ${path13} ${e.message}`);
25660
+ _debug(`Failed to load ${path14} ${e.message}`);
25661
25661
  }
25662
25662
  lastError = e;
25663
25663
  }
@@ -25672,7 +25672,7 @@ var require_main = __commonJS({
25672
25672
  const shortPaths = [];
25673
25673
  for (const filePath of optionPaths) {
25674
25674
  try {
25675
- const relative = path12.relative(process.cwd(), filePath);
25675
+ const relative = path13.relative(process.cwd(), filePath);
25676
25676
  shortPaths.push(relative);
25677
25677
  } catch (e) {
25678
25678
  if (debug) {
@@ -29163,8 +29163,8 @@ var require_utils5 = __commonJS({
29163
29163
  }
29164
29164
  return ind;
29165
29165
  }
29166
- function removeDotSegments(path12) {
29167
- let input = path12;
29166
+ function removeDotSegments(path13) {
29167
+ let input = path13;
29168
29168
  const output = [];
29169
29169
  let nextSlash = -1;
29170
29170
  let len = 0;
@@ -29363,8 +29363,8 @@ var require_schemes = __commonJS({
29363
29363
  wsComponent.secure = void 0;
29364
29364
  }
29365
29365
  if (wsComponent.resourceName) {
29366
- const [path12, query] = wsComponent.resourceName.split("?");
29367
- wsComponent.path = path12 && path12 !== "/" ? path12 : void 0;
29366
+ const [path13, query] = wsComponent.resourceName.split("?");
29367
+ wsComponent.path = path13 && path13 !== "/" ? path13 : void 0;
29368
29368
  wsComponent.query = query;
29369
29369
  wsComponent.resourceName = void 0;
29370
29370
  }
@@ -32726,12 +32726,12 @@ var require_dist2 = __commonJS({
32726
32726
  throw new Error(`Unknown format "${name}"`);
32727
32727
  return f;
32728
32728
  };
32729
- function addFormats(ajv, list, fs12, exportName) {
32729
+ function addFormats(ajv, list, fs13, exportName) {
32730
32730
  var _a3;
32731
32731
  var _b;
32732
32732
  (_a3 = (_b = ajv.opts.code).formats) !== null && _a3 !== void 0 ? _a3 : _b.formats = (0, codegen_1._)`require("ajv-formats/dist/formats").${exportName}`;
32733
32733
  for (const f of list)
32734
- ajv.addFormat(f, fs12[f]);
32734
+ ajv.addFormat(f, fs13[f]);
32735
32735
  }
32736
32736
  module.exports = exports = formatsPlugin;
32737
32737
  Object.defineProperty(exports, "__esModule", { value: true });
@@ -32770,12 +32770,12 @@ __export(runner_exports, {
32770
32770
  runAllMigrations: () => runAllMigrations
32771
32771
  });
32772
32772
  import { spawn } from "child_process";
32773
- import fs10 from "fs";
32774
- import path11 from "path";
32773
+ import fs11 from "fs";
32774
+ import path12 from "path";
32775
32775
  import { fileURLToPath as fileURLToPath4 } from "url";
32776
32776
  function listMigrationFiles() {
32777
- if (!fs10.existsSync(migrationsDir)) return [];
32778
- return fs10.readdirSync(migrationsDir).filter((f) => MIGRATION_FILE_RE.test(f)).sort();
32777
+ if (!fs11.existsSync(migrationsDir)) return [];
32778
+ return fs11.readdirSync(migrationsDir).filter((f) => MIGRATION_FILE_RE.test(f)).sort();
32779
32779
  }
32780
32780
  function runOne(file) {
32781
32781
  return new Promise((resolve, reject) => {
@@ -32785,7 +32785,7 @@ function runOne(file) {
32785
32785
  });
32786
32786
  child.on("exit", (code) => {
32787
32787
  if (code === 0) return resolve();
32788
- reject(new Error(`Migration ${path11.basename(file)} exited with code ${code}`));
32788
+ reject(new Error(`Migration ${path12.basename(file)} exited with code ${code}`));
32789
32789
  });
32790
32790
  child.on("error", reject);
32791
32791
  });
@@ -32798,7 +32798,7 @@ async function runAllMigrations() {
32798
32798
  }
32799
32799
  console.log(`\u{1F4E6} Running ${files.length} migration(s) from ${migrationsDir}`);
32800
32800
  for (const f of files) {
32801
- await runOne(path11.join(migrationsDir, f));
32801
+ await runOne(path12.join(migrationsDir, f));
32802
32802
  }
32803
32803
  console.log(`\u2705 Migration runner complete \u2014 ${files.length} file(s) processed.`);
32804
32804
  return { ran: files.length, files };
@@ -32807,8 +32807,8 @@ var __dirname4, migrationsDir, MIGRATION_FILE_RE;
32807
32807
  var init_runner = __esm({
32808
32808
  "src/migrations/runner.ts"() {
32809
32809
  "use strict";
32810
- __dirname4 = path11.dirname(fileURLToPath4(import.meta.url));
32811
- migrationsDir = fs10.existsSync(path11.join(__dirname4, "migrations")) ? path11.join(__dirname4, "migrations") : __dirname4;
32810
+ __dirname4 = path12.dirname(fileURLToPath4(import.meta.url));
32811
+ migrationsDir = fs11.existsSync(path12.join(__dirname4, "migrations")) ? path12.join(__dirname4, "migrations") : __dirname4;
32812
32812
  MIGRATION_FILE_RE = /^\d{3}_.+\.js$/;
32813
32813
  }
32814
32814
  });
@@ -33294,8 +33294,8 @@ function getErrorMap() {
33294
33294
 
33295
33295
  // node_modules/zod/v3/helpers/parseUtil.js
33296
33296
  var makeIssue = (params) => {
33297
- const { data, path: path12, errorMaps, issueData } = params;
33298
- const fullPath = [...path12, ...issueData.path || []];
33297
+ const { data, path: path13, errorMaps, issueData } = params;
33298
+ const fullPath = [...path13, ...issueData.path || []];
33299
33299
  const fullIssue = {
33300
33300
  ...issueData,
33301
33301
  path: fullPath
@@ -33411,11 +33411,11 @@ var errorUtil;
33411
33411
 
33412
33412
  // node_modules/zod/v3/types.js
33413
33413
  var ParseInputLazyPath = class {
33414
- constructor(parent, value, path12, key) {
33414
+ constructor(parent, value, path13, key) {
33415
33415
  this._cachedPath = [];
33416
33416
  this.parent = parent;
33417
33417
  this.data = value;
33418
- this._path = path12;
33418
+ this._path = path13;
33419
33419
  this._key = key;
33420
33420
  }
33421
33421
  get path() {
@@ -37052,10 +37052,10 @@ function assignProp(target, prop, value) {
37052
37052
  configurable: true
37053
37053
  });
37054
37054
  }
37055
- function getElementAtPath(obj, path12) {
37056
- if (!path12)
37055
+ function getElementAtPath(obj, path13) {
37056
+ if (!path13)
37057
37057
  return obj;
37058
- return path12.reduce((acc, key) => acc?.[key], obj);
37058
+ return path13.reduce((acc, key) => acc?.[key], obj);
37059
37059
  }
37060
37060
  function promiseAllObject(promisesObj) {
37061
37061
  const keys = Object.keys(promisesObj);
@@ -37375,11 +37375,11 @@ function aborted(x, startIndex = 0) {
37375
37375
  }
37376
37376
  return false;
37377
37377
  }
37378
- function prefixIssues(path12, issues) {
37378
+ function prefixIssues(path13, issues) {
37379
37379
  return issues.map((iss) => {
37380
37380
  var _a3;
37381
37381
  (_a3 = iss).path ?? (_a3.path = []);
37382
- iss.path.unshift(path12);
37382
+ iss.path.unshift(path13);
37383
37383
  return iss;
37384
37384
  });
37385
37385
  }
@@ -47030,10 +47030,73 @@ var StdioServerTransport = class {
47030
47030
 
47031
47031
  // src/tools/manage_knowledge.ts
47032
47032
  init_db();
47033
- import * as os2 from "node:os";
47033
+ import * as os3 from "node:os";
47034
47034
 
47035
47035
  // src/hot_path.ts
47036
47036
  init_db();
47037
+
47038
+ // src/auto_save/buzz_envelope.ts
47039
+ var PREAMBLE_BLOCKS = ["agent-instructions", "core-memory"];
47040
+ var HISTORY_OPEN = /^\s*<((?:thread|conversation)-context)(?:\s[^>]*)?>/;
47041
+ var TURN_OPEN = /^\s*<(?:what-you-were-working-on|buzz-events?|new-message-arrived-while-you-were-working)[\s>]/;
47042
+ var TURN_IN_DROPPED = /(?:^|>)[ \t]*<(?:what-you-were-working-on|buzz-events?|new-message-arrived-while-you-were-working)[\s>]/m;
47043
+ var CONTEXT_OPEN = /^<context>\r?\n/;
47044
+ var CONTEXT_CLOSE = "\n</context>";
47045
+ function isNostrMetaLine(line) {
47046
+ return /^Tags: \[\[".*\]\]\s*$/.test(line) && /[0-9a-f]{64}/.test(line) || /^Parsed: (?:root=[0-9a-f]{64}|mentions=\[.*\([0-9a-f]{64}\))/.test(line);
47047
+ }
47048
+ function skipWhitespace(s, i) {
47049
+ while (i < s.length && /\s/.test(s[i])) i++;
47050
+ return i;
47051
+ }
47052
+ function cleanBuzzEnvelope(message) {
47053
+ try {
47054
+ const text = message.trimStart();
47055
+ if (!text.startsWith("<base>")) return null;
47056
+ const baseEnd = text.indexOf("</base>");
47057
+ if (baseEnd < 0) return null;
47058
+ const rest = text.slice(baseEnd + "</base>".length);
47059
+ let pos = skipWhitespace(rest, 0);
47060
+ for (; ; ) {
47061
+ const name = PREAMBLE_BLOCKS.find((b) => rest.startsWith(`<${b}>`, pos));
47062
+ if (!name) break;
47063
+ const close = rest.indexOf(`</${name}>`, pos);
47064
+ if (close < 0) return null;
47065
+ pos = skipWhitespace(rest, close + name.length + 3);
47066
+ }
47067
+ if (!CONTEXT_OPEN.test(rest.slice(pos, pos + 12))) return null;
47068
+ const bodyStart = rest.indexOf("\n", pos) + 1;
47069
+ const contextClose = rest.indexOf(CONTEXT_CLOSE, bodyStart - 1);
47070
+ if (contextClose < 0) return null;
47071
+ const contextBody = rest.slice(bodyStart, contextClose).replace(/\r$/, "");
47072
+ const tail = rest.slice(contextClose + CONTEXT_CLOSE.length);
47073
+ let turnStart = 0;
47074
+ const history = HISTORY_OPEN.exec(tail);
47075
+ if (history) {
47076
+ const closeTag = `</${history[1]}>`;
47077
+ const close = tail.indexOf(closeTag, history[0].length);
47078
+ if (close < 0) return null;
47079
+ turnStart = close + closeTag.length;
47080
+ }
47081
+ if (TURN_IN_DROPPED.test(rest.slice(0, pos)) || TURN_IN_DROPPED.test(tail.slice(0, turnStart))) return null;
47082
+ const turn = tail.slice(turnStart);
47083
+ if (!TURN_OPEN.test(turn)) return null;
47084
+ const turnText = turn.split("\n").filter((line) => !isNostrMetaLine(line)).join("\n").trim();
47085
+ if (!turnText) return null;
47086
+ const cleaned = `<context>
47087
+ ${contextBody}
47088
+ </context>
47089
+
47090
+ ${turnText}`;
47091
+ if (cleaned.length >= message.length) return null;
47092
+ return cleaned;
47093
+ } catch {
47094
+ return null;
47095
+ }
47096
+ }
47097
+
47098
+ // src/hot_path.ts
47099
+ var rawMessageColumnMissing = false;
47037
47100
  async function insertRawMemory(params) {
47038
47101
  const {
47039
47102
  user_id,
@@ -47053,25 +47116,26 @@ async function insertRawMemory(params) {
47053
47116
  } = params;
47054
47117
  const embeddingSql = embedding && embedding.length > 0 ? `[${embedding.join(",")}]` : null;
47055
47118
  const tagProcessed = p_tag_id !== null;
47056
- const result = await db.query(
47119
+ const cleaned = role === "user" && !is_pinned && p_tag_id === null && embeddingSql === null ? cleanBuzzEnvelope(message) : null;
47120
+ const insert = (text, raw) => db.query(
47057
47121
  `INSERT INTO memory (
47058
- user_id, agent_platform, agent_model,
47059
- subagent, subagent_model, subagent_role,
47060
- role, message,
47061
- p_tag_id, d_tag, embedding,
47062
- is_pinned, tag_processed, external_uuid,
47063
- device_name
47064
- ) VALUES (
47065
- $1, $2, $3,
47066
- $4, $5, $6,
47067
- $7, $8,
47068
- $9, $10::text[], $11::halfvec,
47069
- $12, $13, $14,
47070
- $15
47071
- )
47072
- ON CONFLICT (external_uuid) WHERE external_uuid IS NOT NULL
47073
- DO NOTHING
47074
- RETURNING id, created_at`,
47122
+ user_id, agent_platform, agent_model,
47123
+ subagent, subagent_model, subagent_role,
47124
+ role, message,
47125
+ p_tag_id, d_tag, embedding,
47126
+ is_pinned, tag_processed, external_uuid,
47127
+ device_name${raw !== null ? ", raw_message" : ""}
47128
+ ) VALUES (
47129
+ $1, $2, $3,
47130
+ $4, $5, $6,
47131
+ $7, $8,
47132
+ $9, $10::text[], $11::halfvec,
47133
+ $12, $13, $14,
47134
+ $15${raw !== null ? ", $16" : ""}
47135
+ )
47136
+ ON CONFLICT (external_uuid) WHERE external_uuid IS NOT NULL
47137
+ DO NOTHING
47138
+ RETURNING id, created_at`,
47075
47139
  [
47076
47140
  user_id,
47077
47141
  agent_platform,
@@ -47080,16 +47144,33 @@ async function insertRawMemory(params) {
47080
47144
  subagent_model,
47081
47145
  subagent_role,
47082
47146
  role,
47083
- message,
47147
+ text,
47084
47148
  p_tag_id,
47085
47149
  d_tag,
47086
47150
  embeddingSql,
47087
47151
  is_pinned,
47088
47152
  tagProcessed,
47089
47153
  external_uuid,
47090
- device_name
47154
+ device_name,
47155
+ ...raw !== null ? [raw] : []
47091
47156
  ]
47092
47157
  );
47158
+ let result;
47159
+ if (cleaned !== null && !rawMessageColumnMissing) {
47160
+ try {
47161
+ result = await insert(cleaned, message);
47162
+ } catch (err3) {
47163
+ const e = err3;
47164
+ if (e.code !== "42703" || !e.message?.includes("raw_message")) throw err3;
47165
+ rawMessageColumnMissing = true;
47166
+ console.error(
47167
+ "\u26A0\uFE0F [HotPath] memory.raw_message \uCE78\uC774 \uC5C6\uC2B5\uB2C8\uB2E4 \u2014 `mcp-agents-memory migrate` \uC2E4\uD589 \uD6C4 \uC774 \uD504\uB85C\uC138\uC2A4\uB97C \uC7AC\uC2DC\uC791\uD574\uC57C Buzz \uBD09\uD22C \uC815\uB9AC\uAC00 \uC2DC\uC791\uB429\uB2C8\uB2E4. \uADF8 \uC804\uAE4C\uC9C0\uB294 \uC6D0\uBB38 \uADF8\uB300\uB85C \uC800\uC7A5\uD569\uB2C8\uB2E4."
47168
+ );
47169
+ result = await insert(message, null);
47170
+ }
47171
+ } else {
47172
+ result = await insert(message, null);
47173
+ }
47093
47174
  if (result.rows.length === 0) {
47094
47175
  const existing = await db.query(
47095
47176
  `SELECT id, created_at FROM memory WHERE external_uuid = $1 LIMIT 1`,
@@ -48903,12 +48984,12 @@ function encodeURIPath(str2) {
48903
48984
  return str2.replace(/[^A-Za-z0-9\-._~!$&'()*+,;=:@]+/g, encodeURIComponent);
48904
48985
  }
48905
48986
  var EMPTY = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.create(null));
48906
- var createPathTagFunction = (pathEncoder = encodeURIPath) => function path12(statics, ...params) {
48987
+ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path13(statics, ...params) {
48907
48988
  if (statics.length === 1)
48908
48989
  return statics[0];
48909
48990
  let postPath = false;
48910
48991
  const invalidSegments = [];
48911
- const path13 = statics.reduce((previousValue, currentValue, index) => {
48992
+ const path14 = statics.reduce((previousValue, currentValue, index) => {
48912
48993
  if (/[?#]/.test(currentValue)) {
48913
48994
  postPath = true;
48914
48995
  }
@@ -48925,7 +49006,7 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path12(sta
48925
49006
  }
48926
49007
  return previousValue + currentValue + (index === params.length ? "" : encoded);
48927
49008
  }, "");
48928
- const pathOnly = path13.split(/[?#]/, 1)[0];
49009
+ const pathOnly = path14.split(/[?#]/, 1)[0];
48929
49010
  const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
48930
49011
  let match;
48931
49012
  while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
@@ -48946,10 +49027,10 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path12(sta
48946
49027
  }, "");
48947
49028
  throw new OpenAIError(`Path parameters result in path with invalid segments:
48948
49029
  ${invalidSegments.map((e) => e.error).join("\n")}
48949
- ${path13}
49030
+ ${path14}
48950
49031
  ${underline}`);
48951
49032
  }
48952
- return path13;
49033
+ return path14;
48953
49034
  };
48954
49035
  var path2 = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
48955
49036
 
@@ -53922,9 +54003,9 @@ var OpenAI = class {
53922
54003
  this.apiKey = token;
53923
54004
  return true;
53924
54005
  }
53925
- buildURL(path12, query, defaultBaseURL) {
54006
+ buildURL(path13, query, defaultBaseURL) {
53926
54007
  const baseURL = !__classPrivateFieldGet(this, _OpenAI_instances, "m", _OpenAI_baseURLOverridden).call(this) && defaultBaseURL || this.baseURL;
53927
- const url = isAbsoluteURL(path12) ? new URL(path12) : new URL(baseURL + (baseURL.endsWith("/") && path12.startsWith("/") ? path12.slice(1) : path12));
54008
+ const url = isAbsoluteURL(path13) ? new URL(path13) : new URL(baseURL + (baseURL.endsWith("/") && path13.startsWith("/") ? path13.slice(1) : path13));
53928
54009
  const defaultQuery = this.defaultQuery();
53929
54010
  const pathQuery = Object.fromEntries(url.searchParams);
53930
54011
  if (!isEmptyObj(defaultQuery) || !isEmptyObj(pathQuery)) {
@@ -53949,24 +54030,24 @@ var OpenAI = class {
53949
54030
  */
53950
54031
  async prepareRequest(request, { url, options }) {
53951
54032
  }
53952
- get(path12, opts) {
53953
- return this.methodRequest("get", path12, opts);
54033
+ get(path13, opts) {
54034
+ return this.methodRequest("get", path13, opts);
53954
54035
  }
53955
- post(path12, opts) {
53956
- return this.methodRequest("post", path12, opts);
54036
+ post(path13, opts) {
54037
+ return this.methodRequest("post", path13, opts);
53957
54038
  }
53958
- patch(path12, opts) {
53959
- return this.methodRequest("patch", path12, opts);
54039
+ patch(path13, opts) {
54040
+ return this.methodRequest("patch", path13, opts);
53960
54041
  }
53961
- put(path12, opts) {
53962
- return this.methodRequest("put", path12, opts);
54042
+ put(path13, opts) {
54043
+ return this.methodRequest("put", path13, opts);
53963
54044
  }
53964
- delete(path12, opts) {
53965
- return this.methodRequest("delete", path12, opts);
54045
+ delete(path13, opts) {
54046
+ return this.methodRequest("delete", path13, opts);
53966
54047
  }
53967
- methodRequest(method, path12, opts) {
54048
+ methodRequest(method, path13, opts) {
53968
54049
  return this.request(Promise.resolve(opts).then((opts2) => {
53969
- return { method, path: path12, ...opts2 };
54050
+ return { method, path: path13, ...opts2 };
53970
54051
  }));
53971
54052
  }
53972
54053
  request(options, remainingRetries = null) {
@@ -54084,8 +54165,8 @@ var OpenAI = class {
54084
54165
  }));
54085
54166
  return { response, options, controller, requestLogID, retryOfRequestLogID, startTime };
54086
54167
  }
54087
- getAPIList(path12, Page2, opts) {
54088
- return this.requestAPIList(Page2, opts && "then" in opts ? opts.then((opts2) => ({ method: "get", path: path12, ...opts2 })) : { method: "get", path: path12, ...opts });
54168
+ getAPIList(path13, Page2, opts) {
54169
+ return this.requestAPIList(Page2, opts && "then" in opts ? opts.then((opts2) => ({ method: "get", path: path13, ...opts2 })) : { method: "get", path: path13, ...opts });
54089
54170
  }
54090
54171
  requestAPIList(Page2, options) {
54091
54172
  const request = this.makeRequest(options, null, void 0);
@@ -54176,8 +54257,8 @@ var OpenAI = class {
54176
54257
  }
54177
54258
  async buildRequest(inputOptions, { retryCount = 0 } = {}) {
54178
54259
  const options = { ...inputOptions };
54179
- const { method, path: path12, query, defaultBaseURL } = options;
54180
- const url = this.buildURL(path12, query, defaultBaseURL);
54260
+ const { method, path: path13, query, defaultBaseURL } = options;
54261
+ const url = this.buildURL(path13, query, defaultBaseURL);
54181
54262
  if ("timeout" in options)
54182
54263
  validatePositiveInteger("timeout", options.timeout);
54183
54264
  options.timeout = options.timeout ?? this.timeout;
@@ -55894,17 +55975,357 @@ async function tagMessage(input) {
55894
55975
  };
55895
55976
  }
55896
55977
 
55897
- // src/agent_identity.ts
55898
- function resolveAgentIdentity(server, args) {
55899
- let detectedPlatform = "unknown";
55978
+ // src/auto_save/opencode_capture.ts
55979
+ import * as fs3 from "node:fs";
55980
+ import * as path4 from "node:path";
55981
+ import * as os2 from "node:os";
55982
+ var DEVICE_NAME = os2.hostname();
55983
+ var AGENT_PLATFORM = "opencode";
55984
+ var POLL_INTERVAL_MS = 3e3;
55985
+ var LOOKBACK_MS = 3e4;
55986
+ var PENDING_MAX_AGE_MS = 6 * 60 * 60 * 1e3;
55987
+ var MAX_ROW_ATTEMPTS = 5;
55988
+ var MAX_CONSECUTIVE_FAILURES2 = 5;
55989
+ var OPENCODE_CLIENT_NAMES = /* @__PURE__ */ new Set(["cli", "acp"]);
55990
+ var V2_VERSION_RE = /^([2-9]|\d{2,})\./;
55991
+ function resolveDbPath() {
55992
+ const dataDir = path4.join(
55993
+ process.env.XDG_DATA_HOME || path4.join(os2.homedir(), ".local", "share"),
55994
+ "opencode"
55995
+ );
55996
+ const override = process.env.OPENCODE_DB;
55997
+ if (override) {
55998
+ if (override === ":memory:") return null;
55999
+ return path4.isAbsolute(override) ? override : path4.join(dataDir, override);
56000
+ }
56001
+ return path4.join(dataDir, "opencode.db");
56002
+ }
56003
+ var _DatabaseSync = null;
56004
+ var _sqliteUnavailable = false;
56005
+ async function loadSqlite() {
56006
+ if (_DatabaseSync) return _DatabaseSync;
56007
+ if (_sqliteUnavailable) return null;
55900
56008
  try {
55901
- const clientVersion = server.server.getClientVersion();
55902
- if (clientVersion?.name) {
55903
- detectedPlatform = clientVersion.name;
55904
- }
56009
+ const mod = await import("node:sqlite");
56010
+ _DatabaseSync = mod?.DatabaseSync ?? null;
56011
+ if (!_DatabaseSync) _sqliteUnavailable = true;
56012
+ return _DatabaseSync;
56013
+ } catch {
56014
+ _sqliteUnavailable = true;
56015
+ return null;
56016
+ }
56017
+ }
56018
+ var _state = null;
56019
+ var _pollTimer = null;
56020
+ var _flushInProgress = false;
56021
+ var _consecutiveFailures = 0;
56022
+ function openRo(DatabaseSync, dbPath) {
56023
+ try {
56024
+ return new DatabaseSync(dbPath, { readOnly: true });
56025
+ } catch {
56026
+ return null;
56027
+ }
56028
+ }
56029
+ var ROW_COLUMNS = `m.id, m.type, m.time_created, m.data, s.parent_id,
56030
+ s.fork_session_id, s.time_created AS session_created
56031
+ FROM session_message m
56032
+ LEFT JOIN session_v2 s ON s.id = m.session_id`;
56033
+ function toRawRow(r) {
56034
+ return {
56035
+ id: String(r.id),
56036
+ type: String(r.type),
56037
+ time_created: Number(r.time_created),
56038
+ data: String(r.data ?? ""),
56039
+ parent_id: r.parent_id == null ? null : String(r.parent_id),
56040
+ fork_session_id: r.fork_session_id == null ? null : String(r.fork_session_id),
56041
+ session_created: r.session_created == null ? null : Number(r.session_created)
56042
+ };
56043
+ }
56044
+ function windowFloor(t) {
56045
+ return Math.min(t.createdCursor, Date.now()) - LOOKBACK_MS;
56046
+ }
56047
+ function selectCandidates(db2, floor, pendingIds = []) {
56048
+ const byId = /* @__PURE__ */ new Map();
56049
+ const recent = db2.prepare(`SELECT ${ROW_COLUMNS} WHERE m.time_created >= ? ORDER BY m.time_created ASC, m.id ASC`).all(floor);
56050
+ for (const r of recent) byId.set(String(r.id), toRawRow(r));
56051
+ const one = db2.prepare(`SELECT ${ROW_COLUMNS} WHERE m.id = ?`);
56052
+ for (const id of pendingIds) {
56053
+ if (byId.has(id)) continue;
56054
+ const r = one.get(id);
56055
+ if (r) byId.set(id, toRawRow(r));
56056
+ }
56057
+ return [...byId.values()].sort(
56058
+ (a, b) => a.time_created - b.time_created || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)
56059
+ );
56060
+ }
56061
+ function clean(text) {
56062
+ return text.replace(/\u0000/g, "").trim();
56063
+ }
56064
+ function classifyRow(r) {
56065
+ if (r.parent_id) return { kind: "skip" };
56066
+ if (r.fork_session_id && r.session_created != null && r.time_created < r.session_created) {
56067
+ return { kind: "skip" };
56068
+ }
56069
+ if (r.type !== "user" && r.type !== "assistant") return { kind: "skip" };
56070
+ let data;
56071
+ try {
56072
+ data = JSON.parse(r.data);
55905
56073
  } catch {
56074
+ return { kind: "skip" };
56075
+ }
56076
+ if (r.type === "user") {
56077
+ const message2 = typeof data?.text === "string" ? clean(data.text) : "";
56078
+ return message2 ? { kind: "row", role: "user", message: message2, model: null } : { kind: "skip" };
56079
+ }
56080
+ if (!data?.time?.completed) return { kind: "pending" };
56081
+ const texts = [];
56082
+ for (const part of Array.isArray(data.content) ? data.content : []) {
56083
+ if (part && part.type === "text" && typeof part.text === "string") texts.push(part.text);
56084
+ }
56085
+ const message = clean(texts.join("\n"));
56086
+ if (!message) return { kind: "skip" };
56087
+ const model = typeof data.model?.id === "string" ? data.model.id : null;
56088
+ return { kind: "row", role: "assistant", message, model };
56089
+ }
56090
+ async function processBatch(raw, t, insert) {
56091
+ let inserted = 0;
56092
+ let dedup = 0;
56093
+ let failed = 0;
56094
+ let gaveUp = 0;
56095
+ const markDone = (r) => {
56096
+ t.done.set(r.id, r.time_created);
56097
+ t.pending.delete(r.id);
56098
+ t.failures.delete(r.id);
56099
+ };
56100
+ for (const r of raw) {
56101
+ if (r.time_created > t.createdCursor) t.createdCursor = r.time_created;
56102
+ if (t.done.has(r.id)) continue;
56103
+ const c = classifyRow(r);
56104
+ if (c.kind === "pending") {
56105
+ t.pending.set(r.id, r.time_created);
56106
+ continue;
56107
+ }
56108
+ if (c.kind === "skip") {
56109
+ markDone(r);
56110
+ continue;
56111
+ }
56112
+ try {
56113
+ if (await insert(r, c)) inserted++;
56114
+ else dedup++;
56115
+ markDone(r);
56116
+ } catch (err3) {
56117
+ t.pending.set(r.id, r.time_created);
56118
+ failed++;
56119
+ if (!isDataError(err3)) continue;
56120
+ const attempts = (t.failures.get(r.id) ?? 0) + 1;
56121
+ if (attempts >= MAX_ROW_ATTEMPTS) {
56122
+ console.error(
56123
+ `\u26A0\uFE0F [OpenCode] insert ${attempts}\uD68C \uC2E4\uD328 \u2014 ${r.id} \uD3EC\uAE30:`,
56124
+ err3 instanceof Error ? err3.message : err3
56125
+ );
56126
+ markDone(r);
56127
+ failed--;
56128
+ gaveUp++;
56129
+ } else {
56130
+ t.failures.set(r.id, attempts);
56131
+ }
56132
+ }
56133
+ }
56134
+ const floor = windowFloor(t);
56135
+ for (const [id, tc] of t.done) if (tc < floor) t.done.delete(id);
56136
+ for (const [id, tc] of t.pending) {
56137
+ if (tc < t.createdCursor - PENDING_MAX_AGE_MS) {
56138
+ t.pending.delete(id);
56139
+ t.failures.delete(id);
56140
+ }
56141
+ }
56142
+ return { inserted, dedup, failed, gaveUp };
56143
+ }
56144
+ function isDataError(err3) {
56145
+ const code = err3?.code;
56146
+ return typeof code === "string" && /^(22|23)/.test(code);
56147
+ }
56148
+ function loadKnownVersions(db2) {
56149
+ const rows = db2.prepare(`SELECT DISTINCT version FROM session_v2`).all();
56150
+ return new Set(rows.map((r) => String(r.version)).filter(Boolean));
56151
+ }
56152
+ function hasV2Schema(db2) {
56153
+ const rows = db2.prepare(
56154
+ `SELECT name FROM sqlite_master WHERE type = 'table' AND name IN ('session_message', 'session_v2')`
56155
+ ).all();
56156
+ return rows.length === 2;
56157
+ }
56158
+ function isCaptureArmed() {
56159
+ return _state !== null;
56160
+ }
56161
+ function isOpencodeClientInfo(name, version2) {
56162
+ if (!name) return false;
56163
+ if (name.toLowerCase() === "opencode") return true;
56164
+ if (!_state || !version2 || !V2_VERSION_RE.test(version2)) return false;
56165
+ return OPENCODE_CLIENT_NAMES.has(name) && _state.knownVersions.has(version2);
56166
+ }
56167
+ async function captureSessionStart(_cwd) {
56168
+ if (_pollTimer) {
56169
+ clearInterval(_pollTimer);
56170
+ _pollTimer = null;
56171
+ }
56172
+ _state = null;
56173
+ _consecutiveFailures = 0;
56174
+ const dbPath = resolveDbPath();
56175
+ if (!dbPath || !fs3.existsSync(dbPath)) return;
56176
+ const DatabaseSync = await loadSqlite();
56177
+ if (!DatabaseSync) {
56178
+ console.error(
56179
+ "\u{1F4DD} [OpenCode] node:sqlite \uBBF8\uC9C0\uC6D0 (Node < 22.13?) \u2014 capture \uBE44\uD65C\uC131, save_message fallback"
56180
+ );
56181
+ return;
56182
+ }
56183
+ const db2 = openRo(DatabaseSync, dbPath);
56184
+ if (!db2) {
56185
+ console.error("\u{1F4DD} [OpenCode] opencode.db \uC5F4\uAE30 \uC2E4\uD328 \u2014 capture \uBE44\uD65C\uC131");
56186
+ return;
56187
+ }
56188
+ let state;
56189
+ try {
56190
+ if (!hasV2Schema(db2)) {
56191
+ console.error("\u{1F4DD} [OpenCode] session_v2 \uC2A4\uD0A4\uB9C8 \uC544\uB2D8 (OpenCode v1?) \u2014 capture \uBE44\uD65C\uC131, save_message fallback");
56192
+ return;
56193
+ }
56194
+ const row = db2.prepare(`SELECT COALESCE(MAX(time_created), 0) AS m FROM session_message`).get();
56195
+ const createdCursor = Number(row?.m ?? 0);
56196
+ state = {
56197
+ dbPath,
56198
+ createdCursor,
56199
+ done: /* @__PURE__ */ new Map(),
56200
+ pending: /* @__PURE__ */ new Map(),
56201
+ failures: /* @__PURE__ */ new Map(),
56202
+ knownVersions: loadKnownVersions(db2)
56203
+ };
56204
+ for (const r of selectCandidates(db2, windowFloor(state))) {
56205
+ if (classifyRow(r).kind === "pending") state.pending.set(r.id, r.time_created);
56206
+ else state.done.set(r.id, r.time_created);
56207
+ }
56208
+ } catch (err3) {
56209
+ console.error(
56210
+ "\u{1F4DD} [OpenCode] opencode.db \uC870\uD68C \uC2E4\uD328 \u2014 capture \uBE44\uD65C\uC131:",
56211
+ err3 instanceof Error ? err3.message : err3
56212
+ );
56213
+ return;
56214
+ } finally {
56215
+ try {
56216
+ db2.close();
56217
+ } catch {
56218
+ }
56219
+ }
56220
+ _state = state;
56221
+ console.error(
56222
+ `\u{1F4DD} [OpenCode] capture armed: cursor=${state.createdCursor} versions=[${[...state.knownVersions].join(",")}] (live-from-now)`
56223
+ );
56224
+ _pollTimer = setInterval(() => {
56225
+ void flush();
56226
+ }, POLL_INTERVAL_MS);
56227
+ }
56228
+ function recordFailure(what, err3) {
56229
+ _consecutiveFailures++;
56230
+ if (_consecutiveFailures >= MAX_CONSECUTIVE_FAILURES2) {
56231
+ console.error(
56232
+ `\u{1F4DD} [OpenCode] ${what} ${_consecutiveFailures}\uD68C \uC5F0\uC18D \uC2E4\uD328 \u2014 capture \uBE44\uD65C\uC131(save_message fallback \uBCF5\uADC0):`,
56233
+ err3 instanceof Error ? err3.message : err3 ?? ""
56234
+ );
56235
+ resetCaptureState();
56236
+ }
56237
+ }
56238
+ async function flush() {
56239
+ const empty = { inserted: 0, dedup: 0, failed: 0, gaveUp: 0 };
56240
+ if (!_state || _flushInProgress) return empty;
56241
+ _flushInProgress = true;
56242
+ const DatabaseSync = await loadSqlite();
56243
+ if (!DatabaseSync) {
56244
+ _flushInProgress = false;
56245
+ return empty;
56246
+ }
56247
+ const state = _state;
56248
+ const db2 = openRo(DatabaseSync, state.dbPath);
56249
+ if (!db2) {
56250
+ recordFailure("openRo");
56251
+ _flushInProgress = false;
56252
+ return empty;
56253
+ }
56254
+ let result = empty;
56255
+ try {
56256
+ let raw;
56257
+ try {
56258
+ state.knownVersions = loadKnownVersions(db2);
56259
+ raw = selectCandidates(db2, windowFloor(state), state.pending.keys());
56260
+ _consecutiveFailures = 0;
56261
+ } catch (err3) {
56262
+ recordFailure("query", err3);
56263
+ return empty;
56264
+ }
56265
+ let userId = null;
56266
+ result = await processBatch(raw, state, async (row, c) => {
56267
+ userId ??= await getDefaultUserId();
56268
+ const res = await insertRawMemory({
56269
+ user_id: userId,
56270
+ agent_platform: AGENT_PLATFORM,
56271
+ agent_model: c.role === "user" ? null : c.model ?? "unknown",
56272
+ role: c.role,
56273
+ message: c.message,
56274
+ external_uuid: `opencode:${row.id}`,
56275
+ device_name: DEVICE_NAME
56276
+ });
56277
+ return res.inserted;
56278
+ });
56279
+ } catch (err3) {
56280
+ console.error(
56281
+ "\u26A0\uFE0F [OpenCode] flush error:",
56282
+ err3 instanceof Error ? err3.message : err3
56283
+ );
56284
+ } finally {
56285
+ try {
56286
+ db2.close();
56287
+ } catch {
56288
+ }
56289
+ _flushInProgress = false;
56290
+ }
56291
+ const { inserted, dedup, failed, gaveUp } = result;
56292
+ if (inserted || dedup || failed || gaveUp) {
56293
+ console.error(
56294
+ `\u{1F4DD} [OpenCode] flush: inserted=${inserted}, dedup=${dedup}, failed=${failed}, gaveUp=${gaveUp}, pending=${state.pending.size}`
56295
+ );
56296
+ }
56297
+ return result;
56298
+ }
56299
+ async function captureSessionEnd() {
56300
+ if (_pollTimer) {
56301
+ clearInterval(_pollTimer);
56302
+ _pollTimer = null;
56303
+ }
56304
+ const waitStart = Date.now();
56305
+ while (_flushInProgress && Date.now() - waitStart < 2e3) {
56306
+ await new Promise((r2) => setTimeout(r2, 50));
56307
+ }
56308
+ if (!_state) return { inserted: 0, skipped: 0, error: "session not armed" };
56309
+ const r = await flush();
56310
+ if (r.inserted || r.failed || r.gaveUp) {
56311
+ console.error(
56312
+ `\u{1F4DD} [OpenCode] final flush: inserted=${r.inserted}, dedup=${r.dedup}, failed=${r.failed}, gaveUp=${r.gaveUp}`
56313
+ );
56314
+ }
56315
+ return { inserted: r.inserted, skipped: r.failed + r.gaveUp };
56316
+ }
56317
+ function resetCaptureState() {
56318
+ if (_pollTimer) {
56319
+ clearInterval(_pollTimer);
56320
+ _pollTimer = null;
55906
56321
  }
55907
- const agent_platform = args.agent_platform ?? detectedPlatform;
56322
+ _state = null;
56323
+ _flushInProgress = false;
56324
+ }
56325
+
56326
+ // src/agent_identity.ts
56327
+ function resolveAgentIdentity(server, args) {
56328
+ const agent_platform = args.agent_platform ?? detectClientPlatform(server) ?? "unknown";
55908
56329
  const agent_model = args.agent_model ?? "unknown";
55909
56330
  const subagent = args.subagent === true;
55910
56331
  const subagent_model = subagent ? args.subagent_model ?? null : null;
@@ -55917,9 +56338,24 @@ function resolveAgentIdentity(server, args) {
55917
56338
  subagent_role
55918
56339
  };
55919
56340
  }
56341
+ var _loggedClientInfo = false;
56342
+ function detectClientPlatform(server) {
56343
+ try {
56344
+ const cv = server.server.getClientVersion();
56345
+ if (!cv?.name) return null;
56346
+ const platform = isOpencodeClientInfo(cv.name, cv.version) ? "opencode" : cv.name;
56347
+ if (!_loggedClientInfo) {
56348
+ _loggedClientInfo = true;
56349
+ console.error(`\u{1F4DD} [client] clientInfo=${cv.name}@${cv.version ?? "?"} \u2192 agent_platform=${platform}`);
56350
+ }
56351
+ return platform;
56352
+ } catch {
56353
+ return null;
56354
+ }
56355
+ }
55920
56356
 
55921
56357
  // src/tools/manage_knowledge.ts
55922
- var DEVICE_NAME = os2.hostname();
56358
+ var DEVICE_NAME2 = os3.hostname();
55923
56359
  function ok(payload) {
55924
56360
  return {
55925
56361
  content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
@@ -56085,7 +56521,7 @@ ${args.content}` : args.content;
56085
56521
  p_tag_id,
56086
56522
  d_tag,
56087
56523
  embedding,
56088
- device_name: DEVICE_NAME
56524
+ device_name: DEVICE_NAME2
56089
56525
  });
56090
56526
  return ok({
56091
56527
  stored: true,
@@ -56134,7 +56570,7 @@ function vectorToHalfvecSql(embedding) {
56134
56570
  }
56135
56571
 
56136
56572
  // src/tools/search_memory.ts
56137
- import os3 from "node:os";
56573
+ import os4 from "node:os";
56138
56574
  var DEFAULT_LIMIT = 10;
56139
56575
  var DEFAULT_FALLBACK_THRESHOLD = 0.3;
56140
56576
  function parseDateRange(s) {
@@ -56234,7 +56670,7 @@ date_range \uC778\uC2DD \uD615\uC2DD:
56234
56670
  }
56235
56671
  const sinceDate = parseDateRange(args.date_range);
56236
56672
  const includeArchived = args.include_archived === true;
56237
- const localDevice = os3.hostname();
56673
+ const localDevice = os4.hostname();
56238
56674
  const filters = [`m.user_id = $1`];
56239
56675
  const params = [userId];
56240
56676
  let p = 2;
@@ -57725,7 +58161,7 @@ Actions:
57725
58161
 
57726
58162
  // src/briefing.ts
57727
58163
  init_db();
57728
- import * as os4 from "node:os";
58164
+ import * as os5 from "node:os";
57729
58165
  var RECENT_CURRENT_LIMIT = 8;
57730
58166
  var RECENT_OTHERS_LIMIT = 4;
57731
58167
  var MAX_PREVIEW_STORE = 500;
@@ -57740,7 +58176,7 @@ async function collectBrief(opts = {}) {
57740
58176
  const userId = opts.userId ?? await getDefaultUserId();
57741
58177
  const shortTermDays = opts.shortTermDays ?? Number(process.env.SHORT_TERM_DAYS ?? 3);
57742
58178
  const currentPlatform = opts.currentPlatform ?? null;
57743
- const deviceName = opts.deviceName ?? os4.hostname();
58179
+ const deviceName = opts.deviceName ?? os5.hostname();
57744
58180
  const u = await db.query(
57745
58181
  `SELECT user_name, core_profile, sub_profile FROM users WHERE user_id = $1`,
57746
58182
  [userId]
@@ -57870,7 +58306,7 @@ function formatBriefFull(brief) {
57870
58306
  const gLines = [];
57871
58307
  gLines.push(`# Memory Briefing (user: ${brief.user_name})`);
57872
58308
  if (brief.current_platform) {
57873
- gLines.push(`Current platform: \`${brief.current_platform} @ ${os4.hostname()}\``);
58309
+ gLines.push(`Current platform: \`${brief.current_platform} @ ${os5.hostname()}\``);
57874
58310
  }
57875
58311
  gLines.push("");
57876
58312
  if (brief.core_profile) {
@@ -57943,7 +58379,7 @@ function formatBriefFull(brief) {
57943
58379
  function formatBriefInject(brief, maxChars) {
57944
58380
  const headLines = [`# Memory Briefing (user: ${brief.user_name})`];
57945
58381
  if (brief.current_platform) {
57946
- headLines.push(`Current platform: \`${brief.current_platform} @ ${os4.hostname()}\``);
58382
+ headLines.push(`Current platform: \`${brief.current_platform} @ ${os5.hostname()}\``);
57947
58383
  }
57948
58384
  headLines.push("");
57949
58385
  if (brief.core_profile) {
@@ -58021,12 +58457,7 @@ agent_platform_filter=false.`,
58021
58457
  let currentPlatform = null;
58022
58458
  const useFilter = args.agent_platform_filter ?? true;
58023
58459
  if (useFilter) {
58024
- try {
58025
- const cv = server.server.getClientVersion();
58026
- currentPlatform = cv?.name ?? null;
58027
- } catch {
58028
- currentPlatform = null;
58029
- }
58460
+ currentPlatform = detectClientPlatform(server);
58030
58461
  }
58031
58462
  const brief = await collectBrief({
58032
58463
  shortTermDays: args.short_term_days,
@@ -58041,23 +58472,23 @@ agent_platform_filter=false.`,
58041
58472
  }
58042
58473
 
58043
58474
  // src/auto_save/save_message_tool.ts
58044
- import * as os9 from "node:os";
58475
+ import * as os10 from "node:os";
58045
58476
 
58046
58477
  // src/auto_save/gemini_capture.ts
58047
- import * as fs3 from "node:fs";
58048
- import * as path4 from "node:path";
58049
- import * as os5 from "node:os";
58478
+ import * as fs4 from "node:fs";
58479
+ import * as path5 from "node:path";
58480
+ import * as os6 from "node:os";
58050
58481
  import * as crypto2 from "node:crypto";
58051
58482
  var CLIENT_PLATFORM = "gemini-cli-mcp-client";
58052
- var DEVICE_NAME2 = os5.hostname();
58053
- var GEMINI_TMP_ROOT = path4.join(os5.homedir(), ".gemini", "tmp");
58483
+ var DEVICE_NAME3 = os6.hostname();
58484
+ var GEMINI_TMP_ROOT = path5.join(os6.homedir(), ".gemini", "tmp");
58054
58485
  var FLUSH_DEBOUNCE_MS = 200;
58055
58486
  var PARSE_RETRY_MS = 80;
58056
- var POLL_INTERVAL_MS = 3e3;
58057
- var _state = null;
58487
+ var POLL_INTERVAL_MS2 = 3e3;
58488
+ var _state2 = null;
58058
58489
  var _watchers = [];
58059
- var _pollTimer = null;
58060
- var _flushInProgress = false;
58490
+ var _pollTimer2 = null;
58491
+ var _flushInProgress2 = false;
58061
58492
  var _flushPending = false;
58062
58493
  var _flushDebounceTimer = null;
58063
58494
  function extractShortId(filename) {
@@ -58067,15 +58498,15 @@ function extractShortId(filename) {
58067
58498
  function deriveChatsDirCandidates(cwd) {
58068
58499
  const cwdHash = crypto2.createHash("sha256").update(cwd).digest("hex");
58069
58500
  const candidates = [
58070
- path4.join(GEMINI_TMP_ROOT, cwdHash, "chats"),
58071
- path4.join(GEMINI_TMP_ROOT, path4.basename(cwd), "chats")
58501
+ path5.join(GEMINI_TMP_ROOT, cwdHash, "chats"),
58502
+ path5.join(GEMINI_TMP_ROOT, path5.basename(cwd), "chats")
58072
58503
  ];
58073
- return candidates.filter((d) => fs3.existsSync(d));
58504
+ return candidates.filter((d) => fs4.existsSync(d));
58074
58505
  }
58075
58506
  async function readSessionFile(filePath) {
58076
58507
  for (let attempt = 0; attempt < 2; attempt++) {
58077
58508
  try {
58078
- const raw = fs3.readFileSync(filePath, "utf-8");
58509
+ const raw = fs4.readFileSync(filePath, "utf-8");
58079
58510
  if (!raw.trim()) return null;
58080
58511
  return JSON.parse(raw);
58081
58512
  } catch {
@@ -58152,7 +58583,7 @@ async function flushJsonFile(filePath, fileState, contentSeen) {
58152
58583
  role: parsed.role,
58153
58584
  message: parsed.message,
58154
58585
  external_uuid: externalUuid,
58155
- device_name: DEVICE_NAME2
58586
+ device_name: DEVICE_NAME3
58156
58587
  });
58157
58588
  if (result.inserted) inserted++;
58158
58589
  else dedup++;
@@ -58165,23 +58596,23 @@ async function flushJsonFile(filePath, fileState, contentSeen) {
58165
58596
  return { inserted, skipped, dedup };
58166
58597
  }
58167
58598
  async function flushJsonlFile(filePath, fileState, contentSeen) {
58168
- if (!fs3.existsSync(filePath)) return { inserted: 0, skipped: 0, dedup: 0 };
58599
+ if (!fs4.existsSync(filePath)) return { inserted: 0, skipped: 0, dedup: 0 };
58169
58600
  let stat;
58170
58601
  try {
58171
- stat = fs3.statSync(filePath);
58602
+ stat = fs4.statSync(filePath);
58172
58603
  } catch {
58173
58604
  return { inserted: 0, skipped: 0, dedup: 0 };
58174
58605
  }
58175
58606
  if (stat.size <= fileState.cursor) return { inserted: 0, skipped: 0, dedup: 0 };
58176
58607
  const length = stat.size - fileState.cursor;
58177
- const fd = fs3.openSync(filePath, "r");
58608
+ const fd = fs4.openSync(filePath, "r");
58178
58609
  let raw;
58179
58610
  try {
58180
58611
  const buf = Buffer.alloc(length);
58181
- fs3.readSync(fd, buf, 0, length, fileState.cursor);
58612
+ fs4.readSync(fd, buf, 0, length, fileState.cursor);
58182
58613
  raw = buf.toString("utf-8");
58183
58614
  } finally {
58184
- fs3.closeSync(fd);
58615
+ fs4.closeSync(fd);
58185
58616
  }
58186
58617
  const lastNl = raw.lastIndexOf("\n");
58187
58618
  if (lastNl === -1) return { inserted: 0, skipped: 0, dedup: 0 };
@@ -58232,7 +58663,7 @@ async function flushJsonlFile(filePath, fileState, contentSeen) {
58232
58663
  role: parsed.role,
58233
58664
  message: parsed.message,
58234
58665
  external_uuid: externalUuid,
58235
- device_name: DEVICE_NAME2
58666
+ device_name: DEVICE_NAME3
58236
58667
  });
58237
58668
  if (result.inserted) inserted++;
58238
58669
  else dedup++;
@@ -58244,18 +58675,18 @@ async function flushJsonlFile(filePath, fileState, contentSeen) {
58244
58675
  fileState.cursor = newCursor;
58245
58676
  return { inserted, skipped, dedup };
58246
58677
  }
58247
- function isCaptureArmed() {
58248
- return _state !== null && _state.chatsDirs.length > 0;
58678
+ function isCaptureArmed2() {
58679
+ return _state2 !== null && _state2.chatsDirs.length > 0;
58249
58680
  }
58250
58681
  async function flushAllFiles() {
58251
- if (!_state) return { inserted: 0, skipped: 0, dedup: 0 };
58682
+ if (!_state2) return { inserted: 0, skipped: 0, dedup: 0 };
58252
58683
  let totalI = 0, totalS = 0, totalD = 0;
58253
58684
  const contentSeen = /* @__PURE__ */ new Set();
58254
- for (const dir of _state.chatsDirs) {
58255
- if (!fs3.existsSync(dir)) continue;
58685
+ for (const dir of _state2.chatsDirs) {
58686
+ if (!fs4.existsSync(dir)) continue;
58256
58687
  let entries;
58257
58688
  try {
58258
- entries = fs3.readdirSync(dir, { withFileTypes: true });
58689
+ entries = fs4.readdirSync(dir, { withFileTypes: true });
58259
58690
  } catch {
58260
58691
  continue;
58261
58692
  }
@@ -58263,13 +58694,13 @@ async function flushAllFiles() {
58263
58694
  if (!entry.isFile()) continue;
58264
58695
  if (!entry.name.startsWith("session-")) continue;
58265
58696
  if (!entry.name.endsWith(".json") && !entry.name.endsWith(".jsonl")) continue;
58266
- const filePath = path4.join(dir, entry.name);
58267
- let fileState = _state.files.get(filePath);
58697
+ const filePath = path5.join(dir, entry.name);
58698
+ let fileState = _state2.files.get(filePath);
58268
58699
  if (!fileState) {
58269
58700
  const sessionId = extractShortId(entry.name);
58270
58701
  const format = entry.name.endsWith(".jsonl") ? "jsonl" : "json";
58271
58702
  fileState = { cursor: 0, format, sessionId };
58272
- _state.files.set(filePath, fileState);
58703
+ _state2.files.set(filePath, fileState);
58273
58704
  console.error(`\u{1F4DD} [Gemini] new session detected: ${entry.name} (${format})`);
58274
58705
  }
58275
58706
  const r = await flushDeltaForFile(filePath, fileState, contentSeen);
@@ -58281,11 +58712,11 @@ async function flushAllFiles() {
58281
58712
  return { inserted: totalI, skipped: totalS, dedup: totalD };
58282
58713
  }
58283
58714
  async function flushWithMutex() {
58284
- if (_flushInProgress) {
58715
+ if (_flushInProgress2) {
58285
58716
  _flushPending = true;
58286
58717
  return;
58287
58718
  }
58288
- _flushInProgress = true;
58719
+ _flushInProgress2 = true;
58289
58720
  try {
58290
58721
  const r = await flushAllFiles();
58291
58722
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -58294,7 +58725,7 @@ async function flushWithMutex() {
58294
58725
  } catch (err3) {
58295
58726
  console.error("\u26A0\uFE0F [Gemini] live flush error:", err3);
58296
58727
  } finally {
58297
- _flushInProgress = false;
58728
+ _flushInProgress2 = false;
58298
58729
  if (_flushPending) {
58299
58730
  _flushPending = false;
58300
58731
  setImmediate(() => {
@@ -58310,9 +58741,9 @@ function scheduleFlush() {
58310
58741
  void flushWithMutex();
58311
58742
  }, FLUSH_DEBOUNCE_MS);
58312
58743
  }
58313
- function captureSessionStart(cwd) {
58744
+ function captureSessionStart2(cwd) {
58314
58745
  const chatsDirs = deriveChatsDirCandidates(cwd);
58315
- _state = { cwd, chatsDirs, files: /* @__PURE__ */ new Map() };
58746
+ _state2 = { cwd, chatsDirs, files: /* @__PURE__ */ new Map() };
58316
58747
  if (chatsDirs.length === 0) {
58317
58748
  return;
58318
58749
  }
@@ -58320,7 +58751,7 @@ function captureSessionStart(cwd) {
58320
58751
  for (const dir of chatsDirs) {
58321
58752
  let entries;
58322
58753
  try {
58323
- entries = fs3.readdirSync(dir, { withFileTypes: true });
58754
+ entries = fs4.readdirSync(dir, { withFileTypes: true });
58324
58755
  } catch {
58325
58756
  continue;
58326
58757
  }
@@ -58328,7 +58759,7 @@ function captureSessionStart(cwd) {
58328
58759
  if (!entry.isFile()) continue;
58329
58760
  if (!entry.name.startsWith("session-")) continue;
58330
58761
  if (!entry.name.endsWith(".json") && !entry.name.endsWith(".jsonl")) continue;
58331
- const filePath = path4.join(dir, entry.name);
58762
+ const filePath = path5.join(dir, entry.name);
58332
58763
  const format = entry.name.endsWith(".jsonl") ? "jsonl" : "json";
58333
58764
  const sessionId = extractShortId(entry.name);
58334
58765
  let cursor = 0;
@@ -58336,21 +58767,21 @@ function captureSessionStart(cwd) {
58336
58767
  if (format === "json") {
58337
58768
  let session = null;
58338
58769
  try {
58339
- session = JSON.parse(fs3.readFileSync(filePath, "utf-8"));
58770
+ session = JSON.parse(fs4.readFileSync(filePath, "utf-8"));
58340
58771
  } catch {
58341
58772
  }
58342
58773
  cursor = session && Array.isArray(session.messages) ? session.messages.length : 0;
58343
58774
  if (session?.sessionId) realSessionId = session.sessionId;
58344
58775
  } else {
58345
58776
  try {
58346
- cursor = fs3.statSync(filePath).size;
58777
+ cursor = fs4.statSync(filePath).size;
58347
58778
  } catch {
58348
58779
  }
58349
58780
  try {
58350
- const fd = fs3.openSync(filePath, "r");
58781
+ const fd = fs4.openSync(filePath, "r");
58351
58782
  const buf = Buffer.alloc(512);
58352
- const n = fs3.readSync(fd, buf, 0, 512, 0);
58353
- fs3.closeSync(fd);
58783
+ const n = fs4.readSync(fd, buf, 0, 512, 0);
58784
+ fs4.closeSync(fd);
58354
58785
  const firstLine = buf.slice(0, n).toString("utf-8").split("\n")[0].trim();
58355
58786
  const header = JSON.parse(firstLine);
58356
58787
  if (typeof header.sessionId === "string" && header.sessionId) {
@@ -58359,7 +58790,7 @@ function captureSessionStart(cwd) {
58359
58790
  } catch {
58360
58791
  }
58361
58792
  }
58362
- _state.files.set(filePath, { cursor, format, sessionId: realSessionId });
58793
+ _state2.files.set(filePath, { cursor, format, sessionId: realSessionId });
58363
58794
  count++;
58364
58795
  }
58365
58796
  }
@@ -58369,11 +58800,11 @@ function captureSessionStart(cwd) {
58369
58800
  armDirWatchers();
58370
58801
  }
58371
58802
  function armDirWatchers() {
58372
- if (!_state) return;
58803
+ if (!_state2) return;
58373
58804
  if (_watchers.length > 0) return;
58374
- for (const dir of _state.chatsDirs) {
58805
+ for (const dir of _state2.chatsDirs) {
58375
58806
  try {
58376
- const w = fs3.watch(dir, (_evt, filename) => {
58807
+ const w = fs4.watch(dir, (_evt, filename) => {
58377
58808
  if (filename && !filename.endsWith(".json") && !filename.endsWith(".jsonl")) return;
58378
58809
  scheduleFlush();
58379
58810
  });
@@ -58385,18 +58816,18 @@ function armDirWatchers() {
58385
58816
  if (_watchers.length > 0) {
58386
58817
  console.error(`\u{1F4DD} [Gemini] dir watcher(s) armed: ${_watchers.length}`);
58387
58818
  }
58388
- _pollTimer = setInterval(() => {
58819
+ _pollTimer2 = setInterval(() => {
58389
58820
  void flushWithMutex();
58390
- }, POLL_INTERVAL_MS);
58821
+ }, POLL_INTERVAL_MS2);
58391
58822
  }
58392
58823
  function disarmDirWatchers() {
58393
58824
  if (_flushDebounceTimer) {
58394
58825
  clearTimeout(_flushDebounceTimer);
58395
58826
  _flushDebounceTimer = null;
58396
58827
  }
58397
- if (_pollTimer) {
58398
- clearInterval(_pollTimer);
58399
- _pollTimer = null;
58828
+ if (_pollTimer2) {
58829
+ clearInterval(_pollTimer2);
58830
+ _pollTimer2 = null;
58400
58831
  }
58401
58832
  for (const w of _watchers) {
58402
58833
  try {
@@ -58406,16 +58837,16 @@ function disarmDirWatchers() {
58406
58837
  }
58407
58838
  _watchers.length = 0;
58408
58839
  }
58409
- async function captureSessionEnd() {
58840
+ async function captureSessionEnd2() {
58410
58841
  disarmDirWatchers();
58411
58842
  const waitStart = Date.now();
58412
- while (_flushInProgress && Date.now() - waitStart < 2e3) {
58843
+ while (_flushInProgress2 && Date.now() - waitStart < 2e3) {
58413
58844
  await new Promise((r) => setTimeout(r, 50));
58414
58845
  }
58415
- if (!_state || _state.chatsDirs.length === 0) {
58846
+ if (!_state2 || _state2.chatsDirs.length === 0) {
58416
58847
  return { inserted: 0, skipped: 0, error: "session not armed" };
58417
58848
  }
58418
- _flushInProgress = true;
58849
+ _flushInProgress2 = true;
58419
58850
  try {
58420
58851
  const r = await flushAllFiles();
58421
58852
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -58423,33 +58854,33 @@ async function captureSessionEnd() {
58423
58854
  }
58424
58855
  return { inserted: r.inserted, skipped: r.skipped };
58425
58856
  } finally {
58426
- _flushInProgress = false;
58857
+ _flushInProgress2 = false;
58427
58858
  }
58428
58859
  }
58429
58860
 
58430
58861
  // src/auto_save/grok_capture.ts
58431
- import * as fs4 from "node:fs";
58432
- import * as path5 from "node:path";
58433
- import * as os6 from "node:os";
58434
- var DEVICE_NAME3 = os6.hostname();
58435
- var SESSIONS_ROOT = path5.join(os6.homedir(), ".grok", "sessions");
58862
+ import * as fs5 from "node:fs";
58863
+ import * as path6 from "node:path";
58864
+ import * as os7 from "node:os";
58865
+ var DEVICE_NAME4 = os7.hostname();
58866
+ var SESSIONS_ROOT = path6.join(os7.homedir(), ".grok", "sessions");
58436
58867
  var CHAT_FILE = "chat_history.jsonl";
58437
- var AGENT_PLATFORM = "grok-cli";
58868
+ var AGENT_PLATFORM2 = "grok-cli";
58438
58869
  var FLUSH_DEBOUNCE_MS2 = 200;
58439
- var POLL_INTERVAL_MS2 = 3e3;
58440
- var _state2 = null;
58870
+ var POLL_INTERVAL_MS3 = 3e3;
58871
+ var _state3 = null;
58441
58872
  var SERVER_START_MS = Date.now();
58442
58873
  var _watcher = null;
58443
- var _pollTimer2 = null;
58444
- var _flushInProgress2 = false;
58874
+ var _pollTimer3 = null;
58875
+ var _flushInProgress3 = false;
58445
58876
  var _flushPending2 = false;
58446
58877
  var _flushDebounceTimer2 = null;
58447
58878
  function extractSessionId(filePath) {
58448
- return path5.basename(path5.dirname(filePath));
58879
+ return path6.basename(path6.dirname(filePath));
58449
58880
  }
58450
58881
  function countCompleteLines(filePath) {
58451
58882
  try {
58452
- const content = fs4.readFileSync(filePath, "utf-8");
58883
+ const content = fs5.readFileSync(filePath, "utf-8");
58453
58884
  let n = 0;
58454
58885
  for (let i = 0; i < content.length; i++) if (content[i] === "\n") n++;
58455
58886
  return n;
@@ -58458,18 +58889,18 @@ function countCompleteLines(filePath) {
58458
58889
  }
58459
58890
  }
58460
58891
  function* walkChatHistories(root) {
58461
- if (!fs4.existsSync(root)) return;
58892
+ if (!fs5.existsSync(root)) return;
58462
58893
  const stack = [root];
58463
58894
  while (stack.length) {
58464
58895
  const dir = stack.pop();
58465
58896
  let entries;
58466
58897
  try {
58467
- entries = fs4.readdirSync(dir, { withFileTypes: true });
58898
+ entries = fs5.readdirSync(dir, { withFileTypes: true });
58468
58899
  } catch {
58469
58900
  continue;
58470
58901
  }
58471
58902
  for (const e of entries) {
58472
- const p = path5.join(dir, e.name);
58903
+ const p = path6.join(dir, e.name);
58473
58904
  if (e.isDirectory()) {
58474
58905
  stack.push(p);
58475
58906
  } else if (e.isFile() && e.name === CHAT_FILE) {
@@ -58478,9 +58909,9 @@ function* walkChatHistories(root) {
58478
58909
  }
58479
58910
  }
58480
58911
  }
58481
- function captureSessionStart2(_cwd) {
58482
- const rootExists = fs4.existsSync(SESSIONS_ROOT);
58483
- _state2 = {
58912
+ function captureSessionStart3(_cwd) {
58913
+ const rootExists = fs5.existsSync(SESSIONS_ROOT);
58914
+ _state3 = {
58484
58915
  rootExists,
58485
58916
  files: /* @__PURE__ */ new Map()
58486
58917
  };
@@ -58491,11 +58922,11 @@ function captureSessionStart2(_cwd) {
58491
58922
  for (const filePath of walkChatHistories(SESSIONS_ROOT)) {
58492
58923
  let stat;
58493
58924
  try {
58494
- stat = fs4.statSync(filePath);
58925
+ stat = fs5.statSync(filePath);
58495
58926
  } catch {
58496
58927
  continue;
58497
58928
  }
58498
- _state2.files.set(filePath, {
58929
+ _state3.files.set(filePath, {
58499
58930
  cursorLines: countCompleteLines(filePath),
58500
58931
  lastSize: stat.size,
58501
58932
  sessionId: extractSessionId(filePath)
@@ -58542,14 +58973,14 @@ function parseEntry(line, lineIndex) {
58542
58973
  async function flushDeltaForFile2(filePath, fileState) {
58543
58974
  let stat;
58544
58975
  try {
58545
- stat = fs4.statSync(filePath);
58976
+ stat = fs5.statSync(filePath);
58546
58977
  } catch {
58547
58978
  return { inserted: 0, skipped: 0, dedup: 0 };
58548
58979
  }
58549
58980
  if (stat.size === fileState.lastSize) return { inserted: 0, skipped: 0, dedup: 0 };
58550
58981
  let content;
58551
58982
  try {
58552
- content = fs4.readFileSync(filePath, "utf-8");
58983
+ content = fs5.readFileSync(filePath, "utf-8");
58553
58984
  } catch {
58554
58985
  return { inserted: 0, skipped: 0, dedup: 0 };
58555
58986
  }
@@ -58571,12 +59002,12 @@ async function flushDeltaForFile2(filePath, fileState) {
58571
59002
  try {
58572
59003
  const result = await insertRawMemory({
58573
59004
  user_id: userId,
58574
- agent_platform: AGENT_PLATFORM,
59005
+ agent_platform: AGENT_PLATFORM2,
58575
59006
  agent_model: parsed.agentModel,
58576
59007
  role: parsed.role,
58577
59008
  message: parsed.message,
58578
59009
  external_uuid: externalUuid,
58579
- device_name: DEVICE_NAME3
59010
+ device_name: DEVICE_NAME4
58580
59011
  });
58581
59012
  if (result.inserted) inserted++;
58582
59013
  else dedup++;
@@ -58589,14 +59020,14 @@ async function flushDeltaForFile2(filePath, fileState) {
58589
59020
  return { inserted, skipped, dedup };
58590
59021
  }
58591
59022
  async function flushAllFiles2() {
58592
- if (!_state2 || !_state2.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
59023
+ if (!_state3 || !_state3.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
58593
59024
  let totalI = 0, totalS = 0, totalD = 0;
58594
59025
  for (const filePath of walkChatHistories(SESSIONS_ROOT)) {
58595
- let fileState = _state2.files.get(filePath);
59026
+ let fileState = _state3.files.get(filePath);
58596
59027
  if (!fileState) {
58597
59028
  let stat = null;
58598
59029
  try {
58599
- stat = fs4.statSync(filePath);
59030
+ stat = fs5.statSync(filePath);
58600
59031
  } catch {
58601
59032
  }
58602
59033
  const fileBirthMs = stat ? stat.birthtimeMs || stat.ctimeMs : SERVER_START_MS;
@@ -58613,7 +59044,7 @@ async function flushAllFiles2() {
58613
59044
  lastSize: initialSize,
58614
59045
  sessionId: extractSessionId(filePath)
58615
59046
  };
58616
- _state2.files.set(filePath, fileState);
59047
+ _state3.files.set(filePath, fileState);
58617
59048
  }
58618
59049
  const r = await flushDeltaForFile2(filePath, fileState);
58619
59050
  totalI += r.inserted;
@@ -58623,11 +59054,11 @@ async function flushAllFiles2() {
58623
59054
  return { inserted: totalI, skipped: totalS, dedup: totalD };
58624
59055
  }
58625
59056
  async function flushWithMutex2() {
58626
- if (_flushInProgress2) {
59057
+ if (_flushInProgress3) {
58627
59058
  _flushPending2 = true;
58628
59059
  return;
58629
59060
  }
58630
- _flushInProgress2 = true;
59061
+ _flushInProgress3 = true;
58631
59062
  try {
58632
59063
  const r = await flushAllFiles2();
58633
59064
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -58636,7 +59067,7 @@ async function flushWithMutex2() {
58636
59067
  } catch (err3) {
58637
59068
  console.error("\u26A0\uFE0F [Grok] live flush error:", err3);
58638
59069
  } finally {
58639
- _flushInProgress2 = false;
59070
+ _flushInProgress3 = false;
58640
59071
  if (_flushPending2) {
58641
59072
  _flushPending2 = false;
58642
59073
  setImmediate(() => {
@@ -58653,30 +59084,30 @@ function scheduleFlush2() {
58653
59084
  }, FLUSH_DEBOUNCE_MS2);
58654
59085
  }
58655
59086
  function armDirWatcher() {
58656
- if (!_state2 || !_state2.rootExists) return;
59087
+ if (!_state3 || !_state3.rootExists) return;
58657
59088
  if (_watcher) return;
58658
59089
  try {
58659
- _watcher = fs4.watch(SESSIONS_ROOT, { recursive: true }, (_evt, filename) => {
59090
+ _watcher = fs5.watch(SESSIONS_ROOT, { recursive: true }, (_evt, filename) => {
58660
59091
  if (!filename) return;
58661
- if (path5.basename(filename) !== CHAT_FILE) return;
59092
+ if (path6.basename(filename) !== CHAT_FILE) return;
58662
59093
  scheduleFlush2();
58663
59094
  });
58664
59095
  console.error(`\u{1F4DD} [Grok] dir watcher armed (recursive)`);
58665
59096
  } catch (err3) {
58666
59097
  console.error("\u26A0\uFE0F [Grok] fs.watch failed \u2014 polling only:", err3);
58667
59098
  }
58668
- _pollTimer2 = setInterval(() => {
59099
+ _pollTimer3 = setInterval(() => {
58669
59100
  void flushWithMutex2();
58670
- }, POLL_INTERVAL_MS2);
59101
+ }, POLL_INTERVAL_MS3);
58671
59102
  }
58672
59103
  function disarmDirWatcher() {
58673
59104
  if (_flushDebounceTimer2) {
58674
59105
  clearTimeout(_flushDebounceTimer2);
58675
59106
  _flushDebounceTimer2 = null;
58676
59107
  }
58677
- if (_pollTimer2) {
58678
- clearInterval(_pollTimer2);
58679
- _pollTimer2 = null;
59108
+ if (_pollTimer3) {
59109
+ clearInterval(_pollTimer3);
59110
+ _pollTimer3 = null;
58680
59111
  }
58681
59112
  if (_watcher) {
58682
59113
  try {
@@ -58686,16 +59117,16 @@ function disarmDirWatcher() {
58686
59117
  _watcher = null;
58687
59118
  }
58688
59119
  }
58689
- async function captureSessionEnd2() {
59120
+ async function captureSessionEnd3() {
58690
59121
  disarmDirWatcher();
58691
59122
  const waitStart = Date.now();
58692
- while (_flushInProgress2 && Date.now() - waitStart < 2e3) {
59123
+ while (_flushInProgress3 && Date.now() - waitStart < 2e3) {
58693
59124
  await new Promise((r) => setTimeout(r, 50));
58694
59125
  }
58695
- if (!_state2 || !_state2.rootExists) {
59126
+ if (!_state3 || !_state3.rootExists) {
58696
59127
  return { inserted: 0, skipped: 0, error: "session not armed" };
58697
59128
  }
58698
- _flushInProgress2 = true;
59129
+ _flushInProgress3 = true;
58699
59130
  try {
58700
59131
  const r = await flushAllFiles2();
58701
59132
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -58703,40 +59134,40 @@ async function captureSessionEnd2() {
58703
59134
  }
58704
59135
  return { inserted: r.inserted, skipped: r.skipped };
58705
59136
  } finally {
58706
- _flushInProgress2 = false;
59137
+ _flushInProgress3 = false;
58707
59138
  }
58708
59139
  }
58709
- function isCaptureArmed2() {
58710
- return _state2 !== null && _state2.rootExists;
59140
+ function isCaptureArmed3() {
59141
+ return _state3 !== null && _state3.rootExists;
58711
59142
  }
58712
59143
 
58713
59144
  // src/auto_save/antigravity_capture.ts
58714
- import * as fs5 from "node:fs";
58715
- import * as path6 from "node:path";
58716
- import * as os7 from "node:os";
58717
- var DEVICE_NAME4 = os7.hostname();
58718
- var GEMINI_ROOT = path6.join(os7.homedir(), ".gemini");
59145
+ import * as fs6 from "node:fs";
59146
+ import * as path7 from "node:path";
59147
+ import * as os8 from "node:os";
59148
+ var DEVICE_NAME5 = os8.hostname();
59149
+ var GEMINI_ROOT = path7.join(os8.homedir(), ".gemini");
58719
59150
  var CHAT_FILE2 = "transcript_full.jsonl";
58720
59151
  var FLUSH_DEBOUNCE_MS3 = 200;
58721
- var POLL_INTERVAL_MS3 = 3e3;
59152
+ var POLL_INTERVAL_MS4 = 3e3;
58722
59153
  var ROOTS = [
58723
- { dir: path6.join(GEMINI_ROOT, "antigravity", "brain"), platform: "antigravity" },
58724
- { dir: path6.join(GEMINI_ROOT, "antigravity-cli", "brain"), platform: "antigravity-cli" },
58725
- { dir: path6.join(GEMINI_ROOT, "antigravity-ide", "brain"), platform: "antigravity-ide" }
59154
+ { dir: path7.join(GEMINI_ROOT, "antigravity", "brain"), platform: "antigravity" },
59155
+ { dir: path7.join(GEMINI_ROOT, "antigravity-cli", "brain"), platform: "antigravity-cli" },
59156
+ { dir: path7.join(GEMINI_ROOT, "antigravity-ide", "brain"), platform: "antigravity-ide" }
58726
59157
  ];
58727
- var _state3 = null;
59158
+ var _state4 = null;
58728
59159
  var SERVER_START_MS2 = Date.now();
58729
59160
  var _watchers2 = [];
58730
- var _pollTimer3 = null;
58731
- var _flushInProgress3 = false;
59161
+ var _pollTimer4 = null;
59162
+ var _flushInProgress4 = false;
58732
59163
  var _flushPending3 = false;
58733
59164
  var _flushDebounceTimer3 = null;
58734
59165
  function extractSid(filePath) {
58735
- return path6.basename(path6.dirname(path6.dirname(path6.dirname(filePath))));
59166
+ return path7.basename(path7.dirname(path7.dirname(path7.dirname(filePath))));
58736
59167
  }
58737
59168
  function countCompleteLines2(filePath) {
58738
59169
  try {
58739
- const content = fs5.readFileSync(filePath, "utf-8");
59170
+ const content = fs6.readFileSync(filePath, "utf-8");
58740
59171
  let n = 0;
58741
59172
  for (let i = 0; i < content.length; i++) if (content[i] === "\n") n++;
58742
59173
  return n;
@@ -58745,18 +59176,18 @@ function countCompleteLines2(filePath) {
58745
59176
  }
58746
59177
  }
58747
59178
  function* walkTranscripts(root) {
58748
- if (!fs5.existsSync(root)) return;
59179
+ if (!fs6.existsSync(root)) return;
58749
59180
  const stack = [root];
58750
59181
  while (stack.length) {
58751
59182
  const dir = stack.pop();
58752
59183
  let entries;
58753
59184
  try {
58754
- entries = fs5.readdirSync(dir, { withFileTypes: true });
59185
+ entries = fs6.readdirSync(dir, { withFileTypes: true });
58755
59186
  } catch {
58756
59187
  continue;
58757
59188
  }
58758
59189
  for (const e of entries) {
58759
- const p = path6.join(dir, e.name);
59190
+ const p = path7.join(dir, e.name);
58760
59191
  if (e.isDirectory()) {
58761
59192
  stack.push(p);
58762
59193
  } else if (e.isFile() && e.name === CHAT_FILE2) {
@@ -58772,9 +59203,9 @@ function* walkAllTranscripts() {
58772
59203
  }
58773
59204
  }
58774
59205
  }
58775
- function captureSessionStart3(_cwd) {
58776
- const rootExists = ROOTS.some((r) => fs5.existsSync(r.dir));
58777
- _state3 = {
59206
+ function captureSessionStart4(_cwd) {
59207
+ const rootExists = ROOTS.some((r) => fs6.existsSync(r.dir));
59208
+ _state4 = {
58778
59209
  rootExists,
58779
59210
  files: /* @__PURE__ */ new Map()
58780
59211
  };
@@ -58785,11 +59216,11 @@ function captureSessionStart3(_cwd) {
58785
59216
  for (const { filePath, platform } of walkAllTranscripts()) {
58786
59217
  let stat;
58787
59218
  try {
58788
- stat = fs5.statSync(filePath);
59219
+ stat = fs6.statSync(filePath);
58789
59220
  } catch {
58790
59221
  continue;
58791
59222
  }
58792
- _state3.files.set(filePath, {
59223
+ _state4.files.set(filePath, {
58793
59224
  cursorLines: countCompleteLines2(filePath),
58794
59225
  lastSize: stat.size,
58795
59226
  sessionId: extractSid(filePath),
@@ -58798,7 +59229,7 @@ function captureSessionStart3(_cwd) {
58798
59229
  });
58799
59230
  count++;
58800
59231
  }
58801
- const liveRoots = ROOTS.filter((r) => fs5.existsSync(r.dir)).map((r) => r.platform);
59232
+ const liveRoots = ROOTS.filter((r) => fs6.existsSync(r.dir)).map((r) => r.platform);
58802
59233
  console.error(`\u{1F4DD} [Antigravity] capture armed: ${count} transcript(s) across [${liveRoots.join(", ")}]`);
58803
59234
  armDirWatcher2();
58804
59235
  }
@@ -58836,14 +59267,14 @@ function parseEntry2(line) {
58836
59267
  async function flushDeltaForFile3(filePath, fileState) {
58837
59268
  let stat;
58838
59269
  try {
58839
- stat = fs5.statSync(filePath);
59270
+ stat = fs6.statSync(filePath);
58840
59271
  } catch {
58841
59272
  return { inserted: 0, skipped: 0, dedup: 0 };
58842
59273
  }
58843
59274
  if (stat.size === fileState.lastSize) return { inserted: 0, skipped: 0, dedup: 0 };
58844
59275
  let content;
58845
59276
  try {
58846
- content = fs5.readFileSync(filePath, "utf-8");
59277
+ content = fs6.readFileSync(filePath, "utf-8");
58847
59278
  } catch {
58848
59279
  return { inserted: 0, skipped: 0, dedup: 0 };
58849
59280
  }
@@ -58872,7 +59303,7 @@ async function flushDeltaForFile3(filePath, fileState) {
58872
59303
  role: parsed.role,
58873
59304
  message: parsed.message,
58874
59305
  external_uuid: externalUuid,
58875
- device_name: DEVICE_NAME4
59306
+ device_name: DEVICE_NAME5
58876
59307
  });
58877
59308
  if (result.inserted) inserted++;
58878
59309
  else dedup++;
@@ -58885,14 +59316,14 @@ async function flushDeltaForFile3(filePath, fileState) {
58885
59316
  return { inserted, skipped, dedup };
58886
59317
  }
58887
59318
  async function flushAllFiles3() {
58888
- if (!_state3 || !_state3.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
59319
+ if (!_state4 || !_state4.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
58889
59320
  let totalI = 0, totalS = 0, totalD = 0;
58890
59321
  for (const { filePath, platform } of walkAllTranscripts()) {
58891
- let fileState = _state3.files.get(filePath);
59322
+ let fileState = _state4.files.get(filePath);
58892
59323
  if (!fileState) {
58893
59324
  let stat = null;
58894
59325
  try {
58895
- stat = fs5.statSync(filePath);
59326
+ stat = fs6.statSync(filePath);
58896
59327
  } catch {
58897
59328
  }
58898
59329
  const fileBirthMs = stat ? stat.birthtimeMs || stat.ctimeMs : SERVER_START_MS2;
@@ -58911,7 +59342,7 @@ async function flushAllFiles3() {
58911
59342
  agentPlatform: platform,
58912
59343
  currentModel: null
58913
59344
  };
58914
- _state3.files.set(filePath, fileState);
59345
+ _state4.files.set(filePath, fileState);
58915
59346
  }
58916
59347
  const r = await flushDeltaForFile3(filePath, fileState);
58917
59348
  totalI += r.inserted;
@@ -58921,11 +59352,11 @@ async function flushAllFiles3() {
58921
59352
  return { inserted: totalI, skipped: totalS, dedup: totalD };
58922
59353
  }
58923
59354
  async function flushWithMutex3() {
58924
- if (_flushInProgress3) {
59355
+ if (_flushInProgress4) {
58925
59356
  _flushPending3 = true;
58926
59357
  return;
58927
59358
  }
58928
- _flushInProgress3 = true;
59359
+ _flushInProgress4 = true;
58929
59360
  try {
58930
59361
  const r = await flushAllFiles3();
58931
59362
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -58934,7 +59365,7 @@ async function flushWithMutex3() {
58934
59365
  } catch (err3) {
58935
59366
  console.error("\u26A0\uFE0F [Antigravity] live flush error:", err3);
58936
59367
  } finally {
58937
- _flushInProgress3 = false;
59368
+ _flushInProgress4 = false;
58938
59369
  if (_flushPending3) {
58939
59370
  _flushPending3 = false;
58940
59371
  setImmediate(() => {
@@ -58951,14 +59382,14 @@ function scheduleFlush3() {
58951
59382
  }, FLUSH_DEBOUNCE_MS3);
58952
59383
  }
58953
59384
  function armDirWatcher2() {
58954
- if (!_state3 || !_state3.rootExists) return;
59385
+ if (!_state4 || !_state4.rootExists) return;
58955
59386
  if (_watchers2.length) return;
58956
59387
  for (const { dir } of ROOTS) {
58957
- if (!fs5.existsSync(dir)) continue;
59388
+ if (!fs6.existsSync(dir)) continue;
58958
59389
  try {
58959
- const w = fs5.watch(dir, { recursive: true }, (_evt, filename) => {
59390
+ const w = fs6.watch(dir, { recursive: true }, (_evt, filename) => {
58960
59391
  if (!filename) return;
58961
- if (path6.basename(filename) !== CHAT_FILE2) return;
59392
+ if (path7.basename(filename) !== CHAT_FILE2) return;
58962
59393
  scheduleFlush3();
58963
59394
  });
58964
59395
  _watchers2.push(w);
@@ -58967,18 +59398,18 @@ function armDirWatcher2() {
58967
59398
  }
58968
59399
  }
58969
59400
  console.error(`\u{1F4DD} [Antigravity] dir watchers armed: ${_watchers2.length} root(s)`);
58970
- _pollTimer3 = setInterval(() => {
59401
+ _pollTimer4 = setInterval(() => {
58971
59402
  void flushWithMutex3();
58972
- }, POLL_INTERVAL_MS3);
59403
+ }, POLL_INTERVAL_MS4);
58973
59404
  }
58974
59405
  function disarmDirWatcher2() {
58975
59406
  if (_flushDebounceTimer3) {
58976
59407
  clearTimeout(_flushDebounceTimer3);
58977
59408
  _flushDebounceTimer3 = null;
58978
59409
  }
58979
- if (_pollTimer3) {
58980
- clearInterval(_pollTimer3);
58981
- _pollTimer3 = null;
59410
+ if (_pollTimer4) {
59411
+ clearInterval(_pollTimer4);
59412
+ _pollTimer4 = null;
58982
59413
  }
58983
59414
  for (const w of _watchers2) {
58984
59415
  try {
@@ -58988,16 +59419,16 @@ function disarmDirWatcher2() {
58988
59419
  }
58989
59420
  _watchers2 = [];
58990
59421
  }
58991
- async function captureSessionEnd3() {
59422
+ async function captureSessionEnd4() {
58992
59423
  disarmDirWatcher2();
58993
59424
  const waitStart = Date.now();
58994
- while (_flushInProgress3 && Date.now() - waitStart < 2e3) {
59425
+ while (_flushInProgress4 && Date.now() - waitStart < 2e3) {
58995
59426
  await new Promise((r) => setTimeout(r, 50));
58996
59427
  }
58997
- if (!_state3 || !_state3.rootExists) {
59428
+ if (!_state4 || !_state4.rootExists) {
58998
59429
  return { inserted: 0, skipped: 0, error: "session not armed" };
58999
59430
  }
59000
- _flushInProgress3 = true;
59431
+ _flushInProgress4 = true;
59001
59432
  try {
59002
59433
  const r = await flushAllFiles3();
59003
59434
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -59005,42 +59436,42 @@ async function captureSessionEnd3() {
59005
59436
  }
59006
59437
  return { inserted: r.inserted, skipped: r.skipped };
59007
59438
  } finally {
59008
- _flushInProgress3 = false;
59439
+ _flushInProgress4 = false;
59009
59440
  }
59010
59441
  }
59011
- function isCaptureArmed3() {
59012
- return _state3 !== null && _state3.rootExists;
59442
+ function isCaptureArmed4() {
59443
+ return _state4 !== null && _state4.rootExists;
59013
59444
  }
59014
59445
 
59015
59446
  // src/auto_save/hermes_capture.ts
59016
- import * as fs6 from "node:fs";
59017
- import * as path7 from "node:path";
59018
- import * as os8 from "node:os";
59019
- var DEVICE_NAME5 = os8.hostname();
59020
- var STATE_DB = path7.join(os8.homedir(), ".hermes", "state.db");
59021
- var AGENT_PLATFORM2 = "hermes";
59022
- var POLL_INTERVAL_MS4 = 3e3;
59023
- var _DatabaseSync = null;
59024
- var _sqliteUnavailable = false;
59025
- async function loadSqlite() {
59026
- if (_DatabaseSync) return _DatabaseSync;
59027
- if (_sqliteUnavailable) return null;
59447
+ import * as fs7 from "node:fs";
59448
+ import * as path8 from "node:path";
59449
+ import * as os9 from "node:os";
59450
+ var DEVICE_NAME6 = os9.hostname();
59451
+ var STATE_DB = path8.join(os9.homedir(), ".hermes", "state.db");
59452
+ var AGENT_PLATFORM3 = "hermes";
59453
+ var POLL_INTERVAL_MS5 = 3e3;
59454
+ var _DatabaseSync2 = null;
59455
+ var _sqliteUnavailable2 = false;
59456
+ async function loadSqlite2() {
59457
+ if (_DatabaseSync2) return _DatabaseSync2;
59458
+ if (_sqliteUnavailable2) return null;
59028
59459
  try {
59029
59460
  const mod = await import("node:sqlite");
59030
- _DatabaseSync = mod?.DatabaseSync ?? null;
59031
- if (!_DatabaseSync) _sqliteUnavailable = true;
59032
- return _DatabaseSync;
59461
+ _DatabaseSync2 = mod?.DatabaseSync ?? null;
59462
+ if (!_DatabaseSync2) _sqliteUnavailable2 = true;
59463
+ return _DatabaseSync2;
59033
59464
  } catch {
59034
- _sqliteUnavailable = true;
59465
+ _sqliteUnavailable2 = true;
59035
59466
  return null;
59036
59467
  }
59037
59468
  }
59038
- var _state4 = null;
59039
- var _pollTimer4 = null;
59040
- var _flushInProgress4 = false;
59469
+ var _state5 = null;
59470
+ var _pollTimer5 = null;
59471
+ var _flushInProgress5 = false;
59041
59472
  var _consecutiveOpenFailures = 0;
59042
59473
  var MAX_OPEN_FAILURES = 5;
59043
- function openRo(DatabaseSync) {
59474
+ function openRo2(DatabaseSync) {
59044
59475
  try {
59045
59476
  return new DatabaseSync(STATE_DB, { readOnly: true });
59046
59477
  } catch {
@@ -59081,25 +59512,25 @@ function lookupModel(db2, sessionId, cache2) {
59081
59512
  cache2.set(sessionId, model);
59082
59513
  return model;
59083
59514
  }
59084
- function isCaptureArmed4() {
59085
- return _state4 !== null;
59515
+ function isCaptureArmed5() {
59516
+ return _state5 !== null;
59086
59517
  }
59087
- async function captureSessionStart4(_cwd) {
59088
- if (_pollTimer4) {
59089
- clearInterval(_pollTimer4);
59090
- _pollTimer4 = null;
59518
+ async function captureSessionStart5(_cwd) {
59519
+ if (_pollTimer5) {
59520
+ clearInterval(_pollTimer5);
59521
+ _pollTimer5 = null;
59091
59522
  }
59092
- _state4 = null;
59523
+ _state5 = null;
59093
59524
  _consecutiveOpenFailures = 0;
59094
- if (!fs6.existsSync(STATE_DB)) return;
59095
- const DatabaseSync = await loadSqlite();
59525
+ if (!fs7.existsSync(STATE_DB)) return;
59526
+ const DatabaseSync = await loadSqlite2();
59096
59527
  if (!DatabaseSync) {
59097
59528
  console.error(
59098
59529
  "\u{1F4DD} [Hermes] node:sqlite \uBBF8\uC9C0\uC6D0 (Node < 22.5?) \u2014 capture \uBE44\uD65C\uC131, save_message fallback"
59099
59530
  );
59100
59531
  return;
59101
59532
  }
59102
- const db2 = openRo(DatabaseSync);
59533
+ const db2 = openRo2(DatabaseSync);
59103
59534
  if (!db2) {
59104
59535
  console.error("\u{1F4DD} [Hermes] state.db \uC5F4\uAE30 \uC2E4\uD328 \u2014 capture \uBE44\uD65C\uC131");
59105
59536
  return;
@@ -59123,32 +59554,32 @@ async function captureSessionStart4(_cwd) {
59123
59554
  db2.close();
59124
59555
  } catch {
59125
59556
  }
59126
- _state4 = { cursor: maxId, modelCache: /* @__PURE__ */ new Map() };
59557
+ _state5 = { cursor: maxId, modelCache: /* @__PURE__ */ new Map() };
59127
59558
  console.error(`\u{1F4DD} [Hermes] capture armed: cursor=${maxId} (live-from-now)`);
59128
- if (_pollTimer4) clearInterval(_pollTimer4);
59129
- _pollTimer4 = setInterval(() => {
59130
- void flush();
59131
- }, POLL_INTERVAL_MS4);
59559
+ if (_pollTimer5) clearInterval(_pollTimer5);
59560
+ _pollTimer5 = setInterval(() => {
59561
+ void flush2();
59562
+ }, POLL_INTERVAL_MS5);
59132
59563
  }
59133
- async function flush() {
59564
+ async function flush2() {
59134
59565
  const empty = { inserted: 0, dedup: 0, skipped: 0 };
59135
- if (!_state4 || _flushInProgress4) return empty;
59136
- _flushInProgress4 = true;
59137
- const DatabaseSync = await loadSqlite();
59566
+ if (!_state5 || _flushInProgress5) return empty;
59567
+ _flushInProgress5 = true;
59568
+ const DatabaseSync = await loadSqlite2();
59138
59569
  if (!DatabaseSync) {
59139
- _flushInProgress4 = false;
59570
+ _flushInProgress5 = false;
59140
59571
  return empty;
59141
59572
  }
59142
- const db2 = openRo(DatabaseSync);
59573
+ const db2 = openRo2(DatabaseSync);
59143
59574
  if (!db2) {
59144
59575
  _consecutiveOpenFailures++;
59145
59576
  if (_consecutiveOpenFailures >= MAX_OPEN_FAILURES) {
59146
59577
  console.error(
59147
59578
  `\u{1F4DD} [Hermes] openRo ${_consecutiveOpenFailures}\uD68C \uC5F0\uC18D \uC2E4\uD328 \u2014 capture \uBE44\uD65C\uC131(save_message fallback \uBCF5\uADC0)`
59148
59579
  );
59149
- resetCaptureState();
59580
+ resetCaptureState2();
59150
59581
  }
59151
- _flushInProgress4 = false;
59582
+ _flushInProgress5 = false;
59152
59583
  return empty;
59153
59584
  }
59154
59585
  _consecutiveOpenFailures = 0;
@@ -59156,21 +59587,21 @@ async function flush() {
59156
59587
  let dedup = 0;
59157
59588
  let skipped = 0;
59158
59589
  try {
59159
- const { rows, maxId } = parseNewRows(db2, _state4.cursor);
59590
+ const { rows, maxId } = parseNewRows(db2, _state5.cursor);
59160
59591
  let firstFailedId = null;
59161
59592
  if (rows.length > 0) {
59162
59593
  const userId = await getDefaultUserId();
59163
59594
  for (const r of rows) {
59164
- const agentModel = r.role === "user" ? null : lookupModel(db2, r.sessionId, _state4.modelCache) ?? "unknown";
59595
+ const agentModel = r.role === "user" ? null : lookupModel(db2, r.sessionId, _state5.modelCache) ?? "unknown";
59165
59596
  try {
59166
59597
  const res = await insertRawMemory({
59167
59598
  user_id: userId,
59168
- agent_platform: AGENT_PLATFORM2,
59599
+ agent_platform: AGENT_PLATFORM3,
59169
59600
  agent_model: agentModel,
59170
59601
  role: r.role,
59171
59602
  message: r.message,
59172
59603
  external_uuid: `hermes:${r.id}`,
59173
- device_name: DEVICE_NAME5
59604
+ device_name: DEVICE_NAME6
59174
59605
  });
59175
59606
  if (res.inserted) inserted++;
59176
59607
  else dedup++;
@@ -59185,7 +59616,7 @@ async function flush() {
59185
59616
  }
59186
59617
  }
59187
59618
  const advanceTo = firstFailedId !== null ? firstFailedId - 1 : maxId;
59188
- if (advanceTo > _state4.cursor) _state4.cursor = advanceTo;
59619
+ if (advanceTo > _state5.cursor) _state5.cursor = advanceTo;
59189
59620
  } catch (err3) {
59190
59621
  console.error(
59191
59622
  "\u26A0\uFE0F [Hermes] flush error:",
@@ -59196,26 +59627,26 @@ async function flush() {
59196
59627
  db2.close();
59197
59628
  } catch {
59198
59629
  }
59199
- _flushInProgress4 = false;
59630
+ _flushInProgress5 = false;
59200
59631
  }
59201
59632
  if (inserted || dedup || skipped) {
59202
59633
  console.error(
59203
- `\u{1F4DD} [Hermes] flush: inserted=${inserted}, dedup=${dedup}, skipped=${skipped}, cursor=${_state4?.cursor}`
59634
+ `\u{1F4DD} [Hermes] flush: inserted=${inserted}, dedup=${dedup}, skipped=${skipped}, cursor=${_state5?.cursor}`
59204
59635
  );
59205
59636
  }
59206
59637
  return { inserted, dedup, skipped };
59207
59638
  }
59208
- async function captureSessionEnd4() {
59209
- if (_pollTimer4) {
59210
- clearInterval(_pollTimer4);
59211
- _pollTimer4 = null;
59639
+ async function captureSessionEnd5() {
59640
+ if (_pollTimer5) {
59641
+ clearInterval(_pollTimer5);
59642
+ _pollTimer5 = null;
59212
59643
  }
59213
59644
  const waitStart = Date.now();
59214
- while (_flushInProgress4 && Date.now() - waitStart < 2e3) {
59645
+ while (_flushInProgress5 && Date.now() - waitStart < 2e3) {
59215
59646
  await new Promise((r2) => setTimeout(r2, 50));
59216
59647
  }
59217
- if (!_state4) return { inserted: 0, skipped: 0, error: "session not armed" };
59218
- const r = await flush();
59648
+ if (!_state5) return { inserted: 0, skipped: 0, error: "session not armed" };
59649
+ const r = await flush2();
59219
59650
  if (r.inserted || r.skipped) {
59220
59651
  console.error(
59221
59652
  `\u{1F4DD} [Hermes] final flush: inserted=${r.inserted}, dedup=${r.dedup}, skipped=${r.skipped}`
@@ -59223,17 +59654,17 @@ async function captureSessionEnd4() {
59223
59654
  }
59224
59655
  return { inserted: r.inserted, skipped: r.skipped };
59225
59656
  }
59226
- function resetCaptureState() {
59227
- if (_pollTimer4) {
59228
- clearInterval(_pollTimer4);
59229
- _pollTimer4 = null;
59657
+ function resetCaptureState2() {
59658
+ if (_pollTimer5) {
59659
+ clearInterval(_pollTimer5);
59660
+ _pollTimer5 = null;
59230
59661
  }
59231
- _state4 = null;
59232
- _flushInProgress4 = false;
59662
+ _state5 = null;
59663
+ _flushInProgress5 = false;
59233
59664
  }
59234
59665
 
59235
59666
  // src/auto_save/save_message_tool.ts
59236
- var DEVICE_NAME6 = os9.hostname();
59667
+ var DEVICE_NAME7 = os10.hostname();
59237
59668
  function registerSaveMessage(server) {
59238
59669
  server.registerTool(
59239
59670
  "save_message",
@@ -59266,7 +59697,15 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59266
59697
  async (args) => {
59267
59698
  const userId = await getDefaultUserId();
59268
59699
  const id = resolveAgentIdentity(server, args);
59269
- if (id.agent_platform === "gemini-cli-mcp-client" && isCaptureArmed()) {
59700
+ if (id.agent_platform === "gemini-cli-mcp-client" && isCaptureArmed2()) {
59701
+ return {
59702
+ content: [{
59703
+ type: "text",
59704
+ text: JSON.stringify({ stored: false, skipped: "passive capture active" }, null, 2)
59705
+ }]
59706
+ };
59707
+ }
59708
+ if (id.agent_platform?.startsWith("grok") && isCaptureArmed3()) {
59270
59709
  return {
59271
59710
  content: [{
59272
59711
  type: "text",
@@ -59274,7 +59713,7 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59274
59713
  }]
59275
59714
  };
59276
59715
  }
59277
- if (id.agent_platform?.startsWith("grok") && isCaptureArmed2()) {
59716
+ if (id.agent_platform?.startsWith("antigravity") && isCaptureArmed4()) {
59278
59717
  return {
59279
59718
  content: [{
59280
59719
  type: "text",
@@ -59282,7 +59721,7 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59282
59721
  }]
59283
59722
  };
59284
59723
  }
59285
- if (id.agent_platform?.startsWith("antigravity") && isCaptureArmed3()) {
59724
+ if (id.agent_platform === "mcp" && isCaptureArmed5()) {
59286
59725
  return {
59287
59726
  content: [{
59288
59727
  type: "text",
@@ -59290,7 +59729,7 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59290
59729
  }]
59291
59730
  };
59292
59731
  }
59293
- if (id.agent_platform === "mcp" && isCaptureArmed4()) {
59732
+ if (id.agent_platform === "opencode" && isCaptureArmed()) {
59294
59733
  return {
59295
59734
  content: [{
59296
59735
  type: "text",
@@ -59308,7 +59747,7 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59308
59747
  subagent_role: id.subagent_role,
59309
59748
  role: args.role,
59310
59749
  message: args.message,
59311
- device_name: DEVICE_NAME6
59750
+ device_name: DEVICE_NAME7
59312
59751
  // tag/embed NULL — Cold Path가 background 처리 (Hot Path latency 보장)
59313
59752
  });
59314
59753
  return {
@@ -59328,8 +59767,8 @@ subagent \uCEE8\uD14D\uC2A4\uD2B8\uB77C\uBA74 subagent=true + subagent_model + s
59328
59767
 
59329
59768
  // src/tools/task_pin.ts
59330
59769
  init_db();
59331
- import * as os10 from "node:os";
59332
- var DEVICE_NAME7 = os10.hostname();
59770
+ import * as os11 from "node:os";
59771
+ var DEVICE_NAME8 = os11.hostname();
59333
59772
  var STATUSES = ["pending", "in_progress", "done", "failed"];
59334
59773
  function ok3(payload) {
59335
59774
  return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
@@ -59362,7 +59801,7 @@ async function insertTaskRow(opts) {
59362
59801
  'task', FALSE, TRUE, TRUE,
59363
59802
  NULL, '{}', NULL, $5)
59364
59803
  RETURNING id`,
59365
- [opts.userId, opts.agent_platform, opts.agent_model, opts.message, DEVICE_NAME7]
59804
+ [opts.userId, opts.agent_platform, opts.agent_model, opts.message, DEVICE_NAME8]
59366
59805
  );
59367
59806
  return Number(r.rows[0].id);
59368
59807
  }
@@ -60246,16 +60685,16 @@ async function drainColdPath(maxTicks = 12) {
60246
60685
  }
60247
60686
 
60248
60687
  // src/auto_save/jsonl_capture.ts
60249
- import * as fs7 from "node:fs";
60250
- import * as path8 from "node:path";
60251
- import * as os11 from "node:os";
60688
+ import * as fs8 from "node:fs";
60689
+ import * as path9 from "node:path";
60690
+ import * as os12 from "node:os";
60252
60691
  var CLIENT_PLATFORM2 = "claude-code";
60253
- var DEVICE_NAME8 = os11.hostname();
60254
- var PROJECTS_ROOT = path8.join(os11.homedir(), ".claude", "projects");
60692
+ var DEVICE_NAME9 = os12.hostname();
60693
+ var PROJECTS_ROOT = path9.join(os12.homedir(), ".claude", "projects");
60255
60694
  var FLUSH_DEBOUNCE_MS4 = 200;
60256
- var _state5 = null;
60695
+ var _state6 = null;
60257
60696
  var _watcher2 = null;
60258
- var _flushInProgress5 = false;
60697
+ var _flushInProgress6 = false;
60259
60698
  var _flushPending4 = false;
60260
60699
  var _flushDebounceTimer4 = null;
60261
60700
  function cwdToSlug(cwd) {
@@ -60263,29 +60702,29 @@ function cwdToSlug(cwd) {
60263
60702
  }
60264
60703
  function findProjectDir(cwd) {
60265
60704
  const slug = cwdToSlug(cwd);
60266
- const slugPath = path8.join(PROJECTS_ROOT, slug);
60705
+ const slugPath = path9.join(PROJECTS_ROOT, slug);
60267
60706
  try {
60268
- if (fs7.statSync(slugPath).isDirectory()) return slugPath;
60707
+ if (fs8.statSync(slugPath).isDirectory()) return slugPath;
60269
60708
  } catch {
60270
60709
  }
60271
60710
  let subdirs;
60272
60711
  try {
60273
- subdirs = fs7.readdirSync(PROJECTS_ROOT, { withFileTypes: true });
60712
+ subdirs = fs8.readdirSync(PROJECTS_ROOT, { withFileTypes: true });
60274
60713
  } catch {
60275
60714
  return null;
60276
60715
  }
60277
60716
  for (const subdir of subdirs) {
60278
60717
  if (!subdir.isDirectory()) continue;
60279
- const dirPath = path8.join(PROJECTS_ROOT, subdir.name);
60718
+ const dirPath = path9.join(PROJECTS_ROOT, subdir.name);
60280
60719
  let files;
60281
60720
  try {
60282
- files = fs7.readdirSync(dirPath, { withFileTypes: true });
60721
+ files = fs8.readdirSync(dirPath, { withFileTypes: true });
60283
60722
  } catch {
60284
60723
  continue;
60285
60724
  }
60286
60725
  for (const f of files) {
60287
60726
  if (!f.isFile() || !f.name.endsWith(".jsonl")) continue;
60288
- const foundCwd = readCwdFromJsonl(path8.join(dirPath, f.name));
60727
+ const foundCwd = readCwdFromJsonl(path9.join(dirPath, f.name));
60289
60728
  if (foundCwd === cwd) return dirPath;
60290
60729
  }
60291
60730
  }
@@ -60294,13 +60733,13 @@ function findProjectDir(cwd) {
60294
60733
  function readCwdFromJsonl(jsonlPath) {
60295
60734
  let fd;
60296
60735
  try {
60297
- fd = fs7.openSync(jsonlPath, "r");
60736
+ fd = fs8.openSync(jsonlPath, "r");
60298
60737
  } catch {
60299
60738
  return null;
60300
60739
  }
60301
60740
  try {
60302
60741
  const buf = Buffer.alloc(2048);
60303
- const bytesRead = fs7.readSync(fd, buf, 0, 2048, 0);
60742
+ const bytesRead = fs8.readSync(fd, buf, 0, 2048, 0);
60304
60743
  const raw = buf.slice(0, bytesRead).toString("utf-8");
60305
60744
  for (const line of raw.split("\n")) {
60306
60745
  if (!line.trim()) continue;
@@ -60312,11 +60751,11 @@ function readCwdFromJsonl(jsonlPath) {
60312
60751
  }
60313
60752
  return null;
60314
60753
  } finally {
60315
- fs7.closeSync(fd);
60754
+ fs8.closeSync(fd);
60316
60755
  }
60317
60756
  }
60318
- function captureSessionStart5(cwd) {
60319
- _state5 = { cwd, projectDir: null, files: /* @__PURE__ */ new Map() };
60757
+ function captureSessionStart6(cwd) {
60758
+ _state6 = { cwd, projectDir: null, files: /* @__PURE__ */ new Map() };
60320
60759
  _tryArm(cwd, 0);
60321
60760
  }
60322
60761
  var _MAX_ARM_RETRIES = 20;
@@ -60325,7 +60764,7 @@ function _tryArm(cwd, attempt) {
60325
60764
  if (!projectDir) {
60326
60765
  if (attempt < _MAX_ARM_RETRIES) {
60327
60766
  setTimeout(() => {
60328
- if (!_state5 || _state5.cwd !== cwd) return;
60767
+ if (!_state6 || _state6.cwd !== cwd) return;
60329
60768
  _tryArm(cwd, attempt + 1);
60330
60769
  }, 500);
60331
60770
  } else {
@@ -60338,30 +60777,30 @@ function _tryArm(cwd, attempt) {
60338
60777
  }
60339
60778
  return;
60340
60779
  }
60341
- if (!_state5 || _state5.cwd !== cwd) return;
60342
- _state5.projectDir = projectDir;
60780
+ if (!_state6 || _state6.cwd !== cwd) return;
60781
+ _state6.projectDir = projectDir;
60343
60782
  let entries;
60344
60783
  try {
60345
- entries = fs7.readdirSync(projectDir, { withFileTypes: true });
60784
+ entries = fs8.readdirSync(projectDir, { withFileTypes: true });
60346
60785
  } catch {
60347
60786
  return;
60348
60787
  }
60349
60788
  for (const entry of entries) {
60350
60789
  if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
60351
- const jsonlPath = path8.join(projectDir, entry.name);
60790
+ const jsonlPath = path9.join(projectDir, entry.name);
60352
60791
  let stat;
60353
60792
  try {
60354
- stat = fs7.statSync(jsonlPath);
60793
+ stat = fs8.statSync(jsonlPath);
60355
60794
  } catch {
60356
60795
  continue;
60357
60796
  }
60358
60797
  const sessionId = entry.name.replace(/\.jsonl$/, "");
60359
- _state5.files.set(jsonlPath, { cursorBytes: stat.size, sessionId, contentSeen: /* @__PURE__ */ new Set() });
60798
+ _state6.files.set(jsonlPath, { cursorBytes: stat.size, sessionId, contentSeen: /* @__PURE__ */ new Set() });
60360
60799
  }
60361
60800
  if (attempt > 0) {
60362
- console.error(`\u{1F4DD} [JSONL] project dir found on retry #${attempt}: ${path8.basename(projectDir)}/`);
60801
+ console.error(`\u{1F4DD} [JSONL] project dir found on retry #${attempt}: ${path9.basename(projectDir)}/`);
60363
60802
  }
60364
- console.error(`\u{1F4DD} [JSONL] capture armed: ${_state5.files.size} jsonl(s) in ${path8.basename(projectDir)}/`);
60803
+ console.error(`\u{1F4DD} [JSONL] capture armed: ${_state6.files.size} jsonl(s) in ${path9.basename(projectDir)}/`);
60365
60804
  armDirWatcher3();
60366
60805
  }
60367
60806
  function parseEntry3(line) {
@@ -60401,23 +60840,23 @@ function parseEntry3(line) {
60401
60840
  };
60402
60841
  }
60403
60842
  async function flushDeltaForFile4(jsonlPath, fileState) {
60404
- if (!fs7.existsSync(jsonlPath)) return { inserted: 0, skipped: 0, dedup: 0 };
60843
+ if (!fs8.existsSync(jsonlPath)) return { inserted: 0, skipped: 0, dedup: 0 };
60405
60844
  let stat;
60406
60845
  try {
60407
- stat = fs7.statSync(jsonlPath);
60846
+ stat = fs8.statSync(jsonlPath);
60408
60847
  } catch {
60409
60848
  return { inserted: 0, skipped: 0, dedup: 0 };
60410
60849
  }
60411
60850
  if (stat.size <= fileState.cursorBytes) return { inserted: 0, skipped: 0, dedup: 0 };
60412
60851
  const length = stat.size - fileState.cursorBytes;
60413
- const fd = fs7.openSync(jsonlPath, "r");
60852
+ const fd = fs8.openSync(jsonlPath, "r");
60414
60853
  let raw;
60415
60854
  try {
60416
60855
  const buf = Buffer.alloc(length);
60417
- fs7.readSync(fd, buf, 0, length, fileState.cursorBytes);
60856
+ fs8.readSync(fd, buf, 0, length, fileState.cursorBytes);
60418
60857
  raw = buf.toString("utf-8");
60419
60858
  } finally {
60420
- fs7.closeSync(fd);
60859
+ fs8.closeSync(fd);
60421
60860
  }
60422
60861
  const lastNl = raw.lastIndexOf("\n");
60423
60862
  if (lastNl === -1) return { inserted: 0, skipped: 0, dedup: 0 };
@@ -60451,7 +60890,7 @@ async function flushDeltaForFile4(jsonlPath, fileState) {
60451
60890
  role: parsed.role,
60452
60891
  message: parsed.message,
60453
60892
  external_uuid: externalUuid,
60454
- device_name: DEVICE_NAME8
60893
+ device_name: DEVICE_NAME9
60455
60894
  });
60456
60895
  if (result.inserted) inserted++;
60457
60896
  else dedup++;
@@ -60464,24 +60903,24 @@ async function flushDeltaForFile4(jsonlPath, fileState) {
60464
60903
  return { inserted, skipped, dedup };
60465
60904
  }
60466
60905
  async function flushAllFiles4() {
60467
- if (!_state5 || !_state5.projectDir) return { inserted: 0, skipped: 0, dedup: 0 };
60468
- const projectDir = _state5.projectDir;
60469
- if (!fs7.existsSync(projectDir)) return { inserted: 0, skipped: 0, dedup: 0 };
60906
+ if (!_state6 || !_state6.projectDir) return { inserted: 0, skipped: 0, dedup: 0 };
60907
+ const projectDir = _state6.projectDir;
60908
+ if (!fs8.existsSync(projectDir)) return { inserted: 0, skipped: 0, dedup: 0 };
60470
60909
  let entries;
60471
60910
  try {
60472
- entries = fs7.readdirSync(projectDir, { withFileTypes: true });
60911
+ entries = fs8.readdirSync(projectDir, { withFileTypes: true });
60473
60912
  } catch {
60474
60913
  return { inserted: 0, skipped: 0, dedup: 0 };
60475
60914
  }
60476
60915
  let totalI = 0, totalS = 0, totalD = 0;
60477
60916
  for (const entry of entries) {
60478
60917
  if (!entry.isFile() || !entry.name.endsWith(".jsonl")) continue;
60479
- const jsonlPath = path8.join(projectDir, entry.name);
60480
- let fileState = _state5.files.get(jsonlPath);
60918
+ const jsonlPath = path9.join(projectDir, entry.name);
60919
+ let fileState = _state6.files.get(jsonlPath);
60481
60920
  if (!fileState) {
60482
60921
  const sessionId = entry.name.replace(/\.jsonl$/, "");
60483
60922
  fileState = { cursorBytes: 0, sessionId, contentSeen: /* @__PURE__ */ new Set() };
60484
- _state5.files.set(jsonlPath, fileState);
60923
+ _state6.files.set(jsonlPath, fileState);
60485
60924
  console.error(`\u{1F4DD} [JSONL] new session detected: ${entry.name}`);
60486
60925
  }
60487
60926
  const r = await flushDeltaForFile4(jsonlPath, fileState);
@@ -60492,11 +60931,11 @@ async function flushAllFiles4() {
60492
60931
  return { inserted: totalI, skipped: totalS, dedup: totalD };
60493
60932
  }
60494
60933
  async function flushWithMutex4() {
60495
- if (_flushInProgress5) {
60934
+ if (_flushInProgress6) {
60496
60935
  _flushPending4 = true;
60497
60936
  return;
60498
60937
  }
60499
- _flushInProgress5 = true;
60938
+ _flushInProgress6 = true;
60500
60939
  try {
60501
60940
  const r = await flushAllFiles4();
60502
60941
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -60505,7 +60944,7 @@ async function flushWithMutex4() {
60505
60944
  } catch (err3) {
60506
60945
  console.error("\u26A0\uFE0F [JSONL] live flush error:", err3);
60507
60946
  } finally {
60508
- _flushInProgress5 = false;
60947
+ _flushInProgress6 = false;
60509
60948
  if (_flushPending4) {
60510
60949
  _flushPending4 = false;
60511
60950
  setImmediate(() => {
@@ -60522,10 +60961,10 @@ function scheduleFlush4() {
60522
60961
  }, FLUSH_DEBOUNCE_MS4);
60523
60962
  }
60524
60963
  function armDirWatcher3() {
60525
- if (!_state5 || !_state5.projectDir) return;
60964
+ if (!_state6 || !_state6.projectDir) return;
60526
60965
  if (_watcher2) return;
60527
60966
  try {
60528
- _watcher2 = fs7.watch(_state5.projectDir, (_eventType, filename) => {
60967
+ _watcher2 = fs8.watch(_state6.projectDir, (_eventType, filename) => {
60529
60968
  if (filename && !filename.endsWith(".jsonl")) return;
60530
60969
  scheduleFlush4();
60531
60970
  });
@@ -60547,16 +60986,16 @@ function disarmDirWatcher3() {
60547
60986
  _watcher2 = null;
60548
60987
  }
60549
60988
  }
60550
- async function captureSessionEnd5() {
60989
+ async function captureSessionEnd6() {
60551
60990
  disarmDirWatcher3();
60552
60991
  const waitStart = Date.now();
60553
- while (_flushInProgress5 && Date.now() - waitStart < 2e3) {
60992
+ while (_flushInProgress6 && Date.now() - waitStart < 2e3) {
60554
60993
  await new Promise((r) => setTimeout(r, 50));
60555
60994
  }
60556
- if (!_state5 || !_state5.projectDir) {
60995
+ if (!_state6 || !_state6.projectDir) {
60557
60996
  return { inserted: 0, skipped: 0, error: "session not armed" };
60558
60997
  }
60559
- _flushInProgress5 = true;
60998
+ _flushInProgress6 = true;
60560
60999
  try {
60561
61000
  const r = await flushAllFiles4();
60562
61001
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -60564,20 +61003,20 @@ async function captureSessionEnd5() {
60564
61003
  }
60565
61004
  return { inserted: r.inserted, skipped: r.skipped };
60566
61005
  } finally {
60567
- _flushInProgress5 = false;
61006
+ _flushInProgress6 = false;
60568
61007
  }
60569
61008
  }
60570
61009
 
60571
61010
  // src/auto_save/codex_capture.ts
60572
- import * as fs8 from "node:fs";
60573
- import * as path9 from "node:path";
60574
- import * as os12 from "node:os";
61011
+ import * as fs9 from "node:fs";
61012
+ import * as path10 from "node:path";
61013
+ import * as os13 from "node:os";
60575
61014
  import { spawnSync } from "node:child_process";
60576
- var DEVICE_NAME9 = os12.hostname();
60577
- var SESSIONS_ROOT2 = path9.join(os12.homedir(), ".codex", "sessions");
60578
- var STATE_DB2 = path9.join(os12.homedir(), ".codex", "state_5.sqlite");
61015
+ var DEVICE_NAME10 = os13.hostname();
61016
+ var SESSIONS_ROOT2 = path10.join(os13.homedir(), ".codex", "sessions");
61017
+ var STATE_DB2 = path10.join(os13.homedir(), ".codex", "state_5.sqlite");
60579
61018
  var FLUSH_DEBOUNCE_MS5 = 200;
60580
- var POLL_INTERVAL_MS5 = 3e3;
61019
+ var POLL_INTERVAL_MS6 = 3e3;
60581
61020
  function sourceToPlatform(source) {
60582
61021
  switch (source) {
60583
61022
  case "cli":
@@ -60605,11 +61044,11 @@ function lookupPlatform(sessionId) {
60605
61044
  }
60606
61045
  return "codex-mcp-client";
60607
61046
  }
60608
- var _state6 = null;
61047
+ var _state7 = null;
60609
61048
  var SERVER_START_MS3 = Date.now();
60610
61049
  var _watcher3 = null;
60611
- var _pollTimer5 = null;
60612
- var _flushInProgress6 = false;
61050
+ var _pollTimer6 = null;
61051
+ var _flushInProgress7 = false;
60613
61052
  var _flushPending5 = false;
60614
61053
  var _flushDebounceTimer5 = null;
60615
61054
  function extractSessionId2(filename) {
@@ -60617,18 +61056,18 @@ function extractSessionId2(filename) {
60617
61056
  return m ? m[1] : null;
60618
61057
  }
60619
61058
  function* walkRollouts(root) {
60620
- if (!fs8.existsSync(root)) return;
61059
+ if (!fs9.existsSync(root)) return;
60621
61060
  const stack = [root];
60622
61061
  while (stack.length) {
60623
61062
  const dir = stack.pop();
60624
61063
  let entries;
60625
61064
  try {
60626
- entries = fs8.readdirSync(dir, { withFileTypes: true });
61065
+ entries = fs9.readdirSync(dir, { withFileTypes: true });
60627
61066
  } catch {
60628
61067
  continue;
60629
61068
  }
60630
61069
  for (const e of entries) {
60631
- const p = path9.join(dir, e.name);
61070
+ const p = path10.join(dir, e.name);
60632
61071
  if (e.isDirectory()) {
60633
61072
  stack.push(p);
60634
61073
  } else if (e.isFile() && e.name.startsWith("rollout-") && e.name.endsWith(".jsonl")) {
@@ -60637,9 +61076,9 @@ function* walkRollouts(root) {
60637
61076
  }
60638
61077
  }
60639
61078
  }
60640
- function captureSessionStart6(_cwd) {
60641
- const rootExists = fs8.existsSync(SESSIONS_ROOT2);
60642
- _state6 = {
61079
+ function captureSessionStart7(_cwd) {
61080
+ const rootExists = fs9.existsSync(SESSIONS_ROOT2);
61081
+ _state7 = {
60643
61082
  rootExists,
60644
61083
  files: /* @__PURE__ */ new Map()
60645
61084
  };
@@ -60650,13 +61089,13 @@ function captureSessionStart6(_cwd) {
60650
61089
  for (const filePath of walkRollouts(SESSIONS_ROOT2)) {
60651
61090
  let stat;
60652
61091
  try {
60653
- stat = fs8.statSync(filePath);
61092
+ stat = fs9.statSync(filePath);
60654
61093
  } catch {
60655
61094
  continue;
60656
61095
  }
60657
- const sessionId = extractSessionId2(path9.basename(filePath));
61096
+ const sessionId = extractSessionId2(path10.basename(filePath));
60658
61097
  if (!sessionId) continue;
60659
- _state6.files.set(filePath, {
61098
+ _state7.files.set(filePath, {
60660
61099
  cursorBytes: stat.size,
60661
61100
  sessionId,
60662
61101
  agentPlatform: lookupPlatform(sessionId),
@@ -60704,23 +61143,23 @@ function extractModelFromTurnContext(line) {
60704
61143
  }
60705
61144
  }
60706
61145
  async function flushDeltaForFile5(filePath, fileState) {
60707
- if (!fs8.existsSync(filePath)) return { inserted: 0, skipped: 0, dedup: 0 };
61146
+ if (!fs9.existsSync(filePath)) return { inserted: 0, skipped: 0, dedup: 0 };
60708
61147
  let stat;
60709
61148
  try {
60710
- stat = fs8.statSync(filePath);
61149
+ stat = fs9.statSync(filePath);
60711
61150
  } catch {
60712
61151
  return { inserted: 0, skipped: 0, dedup: 0 };
60713
61152
  }
60714
61153
  if (stat.size <= fileState.cursorBytes) return { inserted: 0, skipped: 0, dedup: 0 };
60715
61154
  const length = stat.size - fileState.cursorBytes;
60716
- const fd = fs8.openSync(filePath, "r");
61155
+ const fd = fs9.openSync(filePath, "r");
60717
61156
  let raw;
60718
61157
  try {
60719
61158
  const buf = Buffer.alloc(length);
60720
- fs8.readSync(fd, buf, 0, length, fileState.cursorBytes);
61159
+ fs9.readSync(fd, buf, 0, length, fileState.cursorBytes);
60721
61160
  raw = buf.toString("utf-8");
60722
61161
  } finally {
60723
- fs8.closeSync(fd);
61162
+ fs9.closeSync(fd);
60724
61163
  }
60725
61164
  const lastNl = raw.lastIndexOf("\n");
60726
61165
  if (lastNl === -1) return { inserted: 0, skipped: 0, dedup: 0 };
@@ -60761,7 +61200,7 @@ async function flushDeltaForFile5(filePath, fileState) {
60761
61200
  role: parsed.role,
60762
61201
  message: parsed.message,
60763
61202
  external_uuid: externalUuid,
60764
- device_name: DEVICE_NAME9
61203
+ device_name: DEVICE_NAME10
60765
61204
  });
60766
61205
  if (result.inserted) inserted++;
60767
61206
  else dedup++;
@@ -60775,25 +61214,25 @@ async function flushDeltaForFile5(filePath, fileState) {
60775
61214
  return { inserted, skipped, dedup };
60776
61215
  }
60777
61216
  async function flushAllFiles5() {
60778
- if (!_state6 || !_state6.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
61217
+ if (!_state7 || !_state7.rootExists) return { inserted: 0, skipped: 0, dedup: 0 };
60779
61218
  let totalI = 0, totalS = 0, totalD = 0;
60780
61219
  for (const filePath of walkRollouts(SESSIONS_ROOT2)) {
60781
- let fileState = _state6.files.get(filePath);
61220
+ let fileState = _state7.files.get(filePath);
60782
61221
  if (!fileState) {
60783
- const sessionId = extractSessionId2(path9.basename(filePath));
61222
+ const sessionId = extractSessionId2(path10.basename(filePath));
60784
61223
  if (!sessionId) continue;
60785
61224
  let stat = null;
60786
61225
  try {
60787
- stat = fs8.statSync(filePath);
61226
+ stat = fs9.statSync(filePath);
60788
61227
  } catch {
60789
61228
  }
60790
61229
  const fileBirthMs = stat ? stat.birthtimeMs || stat.ctimeMs : SERVER_START_MS3;
60791
61230
  const isPreExisting = fileBirthMs < SERVER_START_MS3 - 5e3;
60792
61231
  const initialCursor = isPreExisting ? stat?.size ?? 0 : 0;
60793
61232
  if (isPreExisting) {
60794
- console.error(`\u{1F4DD} [Codex] pre-existing rollout skipped (cursor=${initialCursor}): ${path9.basename(filePath)}`);
61233
+ console.error(`\u{1F4DD} [Codex] pre-existing rollout skipped (cursor=${initialCursor}): ${path10.basename(filePath)}`);
60795
61234
  } else {
60796
- console.error(`\u{1F4DD} [Codex] new rollout detected: ${path9.basename(filePath)}`);
61235
+ console.error(`\u{1F4DD} [Codex] new rollout detected: ${path10.basename(filePath)}`);
60797
61236
  }
60798
61237
  fileState = {
60799
61238
  cursorBytes: initialCursor,
@@ -60801,7 +61240,7 @@ async function flushAllFiles5() {
60801
61240
  agentPlatform: lookupPlatform(sessionId),
60802
61241
  currentModel: null
60803
61242
  };
60804
- _state6.files.set(filePath, fileState);
61243
+ _state7.files.set(filePath, fileState);
60805
61244
  }
60806
61245
  const r = await flushDeltaForFile5(filePath, fileState);
60807
61246
  totalI += r.inserted;
@@ -60811,11 +61250,11 @@ async function flushAllFiles5() {
60811
61250
  return { inserted: totalI, skipped: totalS, dedup: totalD };
60812
61251
  }
60813
61252
  async function flushWithMutex5() {
60814
- if (_flushInProgress6) {
61253
+ if (_flushInProgress7) {
60815
61254
  _flushPending5 = true;
60816
61255
  return;
60817
61256
  }
60818
- _flushInProgress6 = true;
61257
+ _flushInProgress7 = true;
60819
61258
  try {
60820
61259
  const r = await flushAllFiles5();
60821
61260
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -60824,7 +61263,7 @@ async function flushWithMutex5() {
60824
61263
  } catch (err3) {
60825
61264
  console.error("\u26A0\uFE0F [Codex] live flush error:", err3);
60826
61265
  } finally {
60827
- _flushInProgress6 = false;
61266
+ _flushInProgress7 = false;
60828
61267
  if (_flushPending5) {
60829
61268
  _flushPending5 = false;
60830
61269
  setImmediate(() => {
@@ -60841,12 +61280,12 @@ function scheduleFlush5() {
60841
61280
  }, FLUSH_DEBOUNCE_MS5);
60842
61281
  }
60843
61282
  function armDirWatcher4() {
60844
- if (!_state6 || !_state6.rootExists) return;
61283
+ if (!_state7 || !_state7.rootExists) return;
60845
61284
  if (_watcher3) return;
60846
61285
  try {
60847
- _watcher3 = fs8.watch(SESSIONS_ROOT2, { recursive: true }, (_evt, filename) => {
61286
+ _watcher3 = fs9.watch(SESSIONS_ROOT2, { recursive: true }, (_evt, filename) => {
60848
61287
  if (!filename) return;
60849
- const base = path9.basename(filename);
61288
+ const base = path10.basename(filename);
60850
61289
  if (!base.startsWith("rollout-") || !base.endsWith(".jsonl")) return;
60851
61290
  scheduleFlush5();
60852
61291
  });
@@ -60854,18 +61293,18 @@ function armDirWatcher4() {
60854
61293
  } catch (err3) {
60855
61294
  console.error("\u26A0\uFE0F [Codex] fs.watch failed \u2014 polling only:", err3);
60856
61295
  }
60857
- _pollTimer5 = setInterval(() => {
61296
+ _pollTimer6 = setInterval(() => {
60858
61297
  void flushWithMutex5();
60859
- }, POLL_INTERVAL_MS5);
61298
+ }, POLL_INTERVAL_MS6);
60860
61299
  }
60861
61300
  function disarmDirWatcher4() {
60862
61301
  if (_flushDebounceTimer5) {
60863
61302
  clearTimeout(_flushDebounceTimer5);
60864
61303
  _flushDebounceTimer5 = null;
60865
61304
  }
60866
- if (_pollTimer5) {
60867
- clearInterval(_pollTimer5);
60868
- _pollTimer5 = null;
61305
+ if (_pollTimer6) {
61306
+ clearInterval(_pollTimer6);
61307
+ _pollTimer6 = null;
60869
61308
  }
60870
61309
  if (_watcher3) {
60871
61310
  try {
@@ -60875,16 +61314,16 @@ function disarmDirWatcher4() {
60875
61314
  _watcher3 = null;
60876
61315
  }
60877
61316
  }
60878
- async function captureSessionEnd6() {
61317
+ async function captureSessionEnd7() {
60879
61318
  disarmDirWatcher4();
60880
61319
  const waitStart = Date.now();
60881
- while (_flushInProgress6 && Date.now() - waitStart < 2e3) {
61320
+ while (_flushInProgress7 && Date.now() - waitStart < 2e3) {
60882
61321
  await new Promise((r) => setTimeout(r, 50));
60883
61322
  }
60884
- if (!_state6 || !_state6.rootExists) {
61323
+ if (!_state7 || !_state7.rootExists) {
60885
61324
  return { inserted: 0, skipped: 0, error: "session not armed" };
60886
61325
  }
60887
- _flushInProgress6 = true;
61326
+ _flushInProgress7 = true;
60888
61327
  try {
60889
61328
  const r = await flushAllFiles5();
60890
61329
  if (r.inserted > 0 || r.skipped > 0 || r.dedup > 0) {
@@ -60892,35 +61331,38 @@ async function captureSessionEnd6() {
60892
61331
  }
60893
61332
  return { inserted: r.inserted, skipped: r.skipped };
60894
61333
  } finally {
60895
- _flushInProgress6 = false;
61334
+ _flushInProgress7 = false;
60896
61335
  }
60897
61336
  }
60898
61337
 
60899
61338
  // src/version.ts
60900
- import fs9 from "fs";
60901
- import path10 from "path";
61339
+ import fs10 from "fs";
61340
+ import path11 from "path";
60902
61341
  import { fileURLToPath as fileURLToPath3 } from "url";
60903
- var __dirname3 = path10.dirname(fileURLToPath3(import.meta.url));
60904
- var packageJsonPath = path10.resolve(__dirname3, "..", "package.json");
60905
- var packageJson = JSON.parse(fs9.readFileSync(packageJsonPath, "utf8"));
61342
+ var __dirname3 = path11.dirname(fileURLToPath3(import.meta.url));
61343
+ var packageJsonPath = path11.resolve(__dirname3, "..", "package.json");
61344
+ var packageJson = JSON.parse(fs10.readFileSync(packageJsonPath, "utf8"));
60906
61345
  var PACKAGE_VERSION2 = packageJson.version || "0.0.0";
60907
61346
 
60908
61347
  // src/index.ts
60909
- import fs11 from "fs";
61348
+ import fs12 from "fs";
60910
61349
  var BRIEF_DB_TIMEOUT_MS = 5e3;
60911
61350
  var INSTRUCTIONS_MAX_CHARS = Number(process.env.INSTRUCTIONS_MAX_CHARS ?? 1900);
60912
61351
  var INSTRUCTIONS_SEP = "\n\n---\n\n";
60913
- var STATIC_INSTRUCTIONS = `Long-term memory MCP server (RESPEC v1).
61352
+ function staticInstructions() {
61353
+ const autoCaptured = "Claude Code / Codex CLI / Gemini CLI / Grok Build / Antigravity / Hermes" + (isCaptureArmed() ? " / OpenCode" : "");
61354
+ return `Long-term memory MCP server (RESPEC v1).
60914
61355
 
60915
61356
  \u25B6 \uC138\uC158 \uC2DC\uC791 \uC2DC \`memory_startup\`\uC744 \uD55C \uBC88 \uD638\uCD9C\uD574 \uCD5C\uADFC \uB300\uD654\xB7\uD65C\uC131 \uD504\uB85C\uC81D\uD2B8\xB7\uC0C1\uC138 \uD504\uB85C\uD544 \uB9E5\uB77D\uC744 \uC774\uC5B4\uBC1B\uC73C\uC138\uC694.
60916
61357
 
60917
61358
  Tools: memory_startup(\uC2DC\uC791 brief) \xB7 search_memory(\uACFC\uAC70 \uC870\uD68C/\uAC80\uC0C9) \xB7 manage_knowledge(\uC800\uC7A5/\uC218\uC815/\uC0AD\uC81C; \uAC15\uC81C\uAE30\uC5B5 is_pinned) \xB7 save_message(transcript \uBBF8\uC9C0\uC6D0 platform fallback).
60918
61359
 
60919
- \uC790\uB3D9 \uC800\uC7A5: Claude Code / Codex CLI / Gemini CLI / Grok Build / Antigravity / Hermes\uB294 transcript \uC790\uB3D9 \uCEA1\uCC98 \u2014 save_message \uD638\uCD9C \uAE08\uC9C0(\uC911\uBCF5 row). \uADF8 \uC678 platform\uB9CC \uB9E4 turn save_message.
61360
+ \uC790\uB3D9 \uC800\uC7A5: ${autoCaptured}\uB294 transcript \uC790\uB3D9 \uCEA1\uCC98 \u2014 save_message \uD638\uCD9C \uAE08\uC9C0(\uC911\uBCF5 row). \uADF8 \uC678 platform\uB9CC \uB9E4 turn save_message.
60920
61361
 
60921
61362
  \uB2A5\uB3D9 \uADDC\uCE59(mandatory): named entity(\uD504\uB85C\uC81D\uD2B8\xB7repo\xB7\uC778\uBB3C) \uC5B8\uAE09 \uC2DC, \uB610\uB294 \uACFC\uAC70 \uC120\uD638\xB7\uACB0\uC815\uC744 \uAC00\uC815\uD558\uAE30 \uC804 \uBA3C\uC800 search_memory. \uC791\uC5C5\uB2F9 1-2\uD68C.
60922
61363
 
60923
61364
  \uD638\uCD9C \uC2DC agent_model \uBA85\uC2DC (subagent\uBA74 subagent:true + subagent_model/role \uB3D9\uBD09).`;
61365
+ }
60924
61366
  var STATIC_INSTRUCTIONS_BRIEF_UNAVAILABLE = `
60925
61367
 
60926
61368
  ---
@@ -60934,6 +61376,7 @@ function detectBootPlatformFromEnv() {
60934
61376
  return null;
60935
61377
  }
60936
61378
  async function buildInstructions() {
61379
+ const STATIC_INSTRUCTIONS = staticInstructions();
60937
61380
  try {
60938
61381
  const work = (async () => {
60939
61382
  const { db: db2 } = await Promise.resolve().then(() => (init_db(), db_exports));
@@ -60975,12 +61418,13 @@ async function shutdown(reason) {
60975
61418
  try {
60976
61419
  await Promise.race([
60977
61420
  Promise.allSettled([
60978
- captureSessionEnd5(),
60979
61421
  captureSessionEnd6(),
60980
- captureSessionEnd(),
61422
+ captureSessionEnd7(),
60981
61423
  captureSessionEnd2(),
60982
61424
  captureSessionEnd3(),
60983
- captureSessionEnd4()
61425
+ captureSessionEnd4(),
61426
+ captureSessionEnd5(),
61427
+ captureSessionEnd()
60984
61428
  ]),
60985
61429
  new Promise((resolve) => setTimeout(resolve, 3e3))
60986
61430
  ]);
@@ -61071,6 +61515,7 @@ Required settings:
61071
61515
  XAI_API_KEY=... (Cold Path tagger/librarian \u2014 grok-4-1-fast-non-reasoning default)`);
61072
61516
  }
61073
61517
  async function runMcpServer() {
61518
+ await captureSessionStart(process.cwd());
61074
61519
  const instructions = await buildInstructions();
61075
61520
  const server = new McpServer(
61076
61521
  {
@@ -61087,17 +61532,17 @@ async function runMcpServer() {
61087
61532
  registerTools(server);
61088
61533
  installShutdownHandlers();
61089
61534
  startParentWatchdog();
61090
- captureSessionStart5(process.cwd());
61091
61535
  captureSessionStart6(process.cwd());
61092
- captureSessionStart(process.cwd());
61536
+ captureSessionStart7(process.cwd());
61093
61537
  captureSessionStart2(process.cwd());
61094
61538
  captureSessionStart3(process.cwd());
61095
- void captureSessionStart4(process.cwd());
61539
+ captureSessionStart4(process.cwd());
61540
+ void captureSessionStart5(process.cwd());
61096
61541
  console.error("\u{1F680} Starting Memory MCP Server...");
61097
61542
  if (process.env.SSH_ENABLED === "true" && !process.env.SSH_KEY_PATH) {
61098
61543
  throw new Error("\u274C SSH_KEY_PATH is required when SSH is enabled");
61099
61544
  }
61100
- if (process.env.SSH_KEY_PATH && !fs11.existsSync(process.env.SSH_KEY_PATH)) {
61545
+ if (process.env.SSH_KEY_PATH && !fs12.existsSync(process.env.SSH_KEY_PATH)) {
61101
61546
  console.error(`\u26A0\uFE0F [WARNING] SSH key not found at: ${process.env.SSH_KEY_PATH}`);
61102
61547
  }
61103
61548
  try {