@mrrlin-dev/mcp 0.4.57 → 0.4.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/bin.cjs +752 -485
  2. package/package.json +1 -1
package/dist/bin.cjs CHANGED
@@ -7729,14 +7729,14 @@ var require_polyfills = __commonJS({
7729
7729
  fs11.fstatSync = statFixSync(fs11.fstatSync);
7730
7730
  fs11.lstatSync = statFixSync(fs11.lstatSync);
7731
7731
  if (fs11.chmod && !fs11.lchmod) {
7732
- fs11.lchmod = function(path24, mode, cb) {
7732
+ fs11.lchmod = function(path25, mode, cb) {
7733
7733
  if (cb) process.nextTick(cb);
7734
7734
  };
7735
7735
  fs11.lchmodSync = function() {
7736
7736
  };
7737
7737
  }
7738
7738
  if (fs11.chown && !fs11.lchown) {
7739
- fs11.lchown = function(path24, uid, gid, cb) {
7739
+ fs11.lchown = function(path25, uid, gid, cb) {
7740
7740
  if (cb) process.nextTick(cb);
7741
7741
  };
7742
7742
  fs11.lchownSync = function() {
@@ -7803,9 +7803,9 @@ var require_polyfills = __commonJS({
7803
7803
  };
7804
7804
  }(fs11.readSync);
7805
7805
  function patchLchmod(fs12) {
7806
- fs12.lchmod = function(path24, mode, callback) {
7806
+ fs12.lchmod = function(path25, mode, callback) {
7807
7807
  fs12.open(
7808
- path24,
7808
+ path25,
7809
7809
  constants2.O_WRONLY | constants2.O_SYMLINK,
7810
7810
  mode,
7811
7811
  function(err, fd) {
@@ -7821,8 +7821,8 @@ var require_polyfills = __commonJS({
7821
7821
  }
7822
7822
  );
7823
7823
  };
7824
- fs12.lchmodSync = function(path24, mode) {
7825
- var fd = fs12.openSync(path24, constants2.O_WRONLY | constants2.O_SYMLINK, mode);
7824
+ fs12.lchmodSync = function(path25, mode) {
7825
+ var fd = fs12.openSync(path25, constants2.O_WRONLY | constants2.O_SYMLINK, mode);
7826
7826
  var threw = true;
7827
7827
  var ret;
7828
7828
  try {
@@ -7843,8 +7843,8 @@ var require_polyfills = __commonJS({
7843
7843
  }
7844
7844
  function patchLutimes(fs12) {
7845
7845
  if (constants2.hasOwnProperty("O_SYMLINK") && fs12.futimes) {
7846
- fs12.lutimes = function(path24, at, mt, cb) {
7847
- fs12.open(path24, constants2.O_SYMLINK, function(er, fd) {
7846
+ fs12.lutimes = function(path25, at, mt, cb) {
7847
+ fs12.open(path25, constants2.O_SYMLINK, function(er, fd) {
7848
7848
  if (er) {
7849
7849
  if (cb) cb(er);
7850
7850
  return;
@@ -7856,8 +7856,8 @@ var require_polyfills = __commonJS({
7856
7856
  });
7857
7857
  });
7858
7858
  };
7859
- fs12.lutimesSync = function(path24, at, mt) {
7860
- var fd = fs12.openSync(path24, constants2.O_SYMLINK);
7859
+ fs12.lutimesSync = function(path25, at, mt) {
7860
+ var fd = fs12.openSync(path25, constants2.O_SYMLINK);
7861
7861
  var ret;
7862
7862
  var threw = true;
7863
7863
  try {
@@ -7975,11 +7975,11 @@ var require_legacy_streams = __commonJS({
7975
7975
  ReadStream,
7976
7976
  WriteStream
7977
7977
  };
7978
- function ReadStream(path24, options) {
7979
- if (!(this instanceof ReadStream)) return new ReadStream(path24, options);
7978
+ function ReadStream(path25, options) {
7979
+ if (!(this instanceof ReadStream)) return new ReadStream(path25, options);
7980
7980
  Stream.call(this);
7981
7981
  var self = this;
7982
- this.path = path24;
7982
+ this.path = path25;
7983
7983
  this.fd = null;
7984
7984
  this.readable = true;
7985
7985
  this.paused = false;
@@ -8024,10 +8024,10 @@ var require_legacy_streams = __commonJS({
8024
8024
  self._read();
8025
8025
  });
8026
8026
  }
8027
- function WriteStream(path24, options) {
8028
- if (!(this instanceof WriteStream)) return new WriteStream(path24, options);
8027
+ function WriteStream(path25, options) {
8028
+ if (!(this instanceof WriteStream)) return new WriteStream(path25, options);
8029
8029
  Stream.call(this);
8030
- this.path = path24;
8030
+ this.path = path25;
8031
8031
  this.fd = null;
8032
8032
  this.writable = true;
8033
8033
  this.flags = "w";
@@ -8170,14 +8170,14 @@ var require_graceful_fs = __commonJS({
8170
8170
  fs12.createWriteStream = createWriteStream;
8171
8171
  var fs$readFile = fs12.readFile;
8172
8172
  fs12.readFile = readFile9;
8173
- function readFile9(path24, options, cb) {
8173
+ function readFile9(path25, options, cb) {
8174
8174
  if (typeof options === "function")
8175
8175
  cb = options, options = null;
8176
- return go$readFile(path24, options, cb);
8177
- function go$readFile(path25, options2, cb2, startTime) {
8178
- return fs$readFile(path25, options2, function(err) {
8176
+ return go$readFile(path25, options, cb);
8177
+ function go$readFile(path26, options2, cb2, startTime) {
8178
+ return fs$readFile(path26, options2, function(err) {
8179
8179
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
8180
- enqueue([go$readFile, [path25, options2, cb2], err, startTime || Date.now(), Date.now()]);
8180
+ enqueue([go$readFile, [path26, options2, cb2], err, startTime || Date.now(), Date.now()]);
8181
8181
  else {
8182
8182
  if (typeof cb2 === "function")
8183
8183
  cb2.apply(this, arguments);
@@ -8187,14 +8187,14 @@ var require_graceful_fs = __commonJS({
8187
8187
  }
8188
8188
  var fs$writeFile = fs12.writeFile;
8189
8189
  fs12.writeFile = writeFile5;
8190
- function writeFile5(path24, data, options, cb) {
8190
+ function writeFile5(path25, data, options, cb) {
8191
8191
  if (typeof options === "function")
8192
8192
  cb = options, options = null;
8193
- return go$writeFile(path24, data, options, cb);
8194
- function go$writeFile(path25, data2, options2, cb2, startTime) {
8195
- return fs$writeFile(path25, data2, options2, function(err) {
8193
+ return go$writeFile(path25, data, options, cb);
8194
+ function go$writeFile(path26, data2, options2, cb2, startTime) {
8195
+ return fs$writeFile(path26, data2, options2, function(err) {
8196
8196
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
8197
- enqueue([go$writeFile, [path25, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
8197
+ enqueue([go$writeFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
8198
8198
  else {
8199
8199
  if (typeof cb2 === "function")
8200
8200
  cb2.apply(this, arguments);
@@ -8205,14 +8205,14 @@ var require_graceful_fs = __commonJS({
8205
8205
  var fs$appendFile = fs12.appendFile;
8206
8206
  if (fs$appendFile)
8207
8207
  fs12.appendFile = appendFile2;
8208
- function appendFile2(path24, data, options, cb) {
8208
+ function appendFile2(path25, data, options, cb) {
8209
8209
  if (typeof options === "function")
8210
8210
  cb = options, options = null;
8211
- return go$appendFile(path24, data, options, cb);
8212
- function go$appendFile(path25, data2, options2, cb2, startTime) {
8213
- return fs$appendFile(path25, data2, options2, function(err) {
8211
+ return go$appendFile(path25, data, options, cb);
8212
+ function go$appendFile(path26, data2, options2, cb2, startTime) {
8213
+ return fs$appendFile(path26, data2, options2, function(err) {
8214
8214
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
8215
- enqueue([go$appendFile, [path25, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
8215
+ enqueue([go$appendFile, [path26, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
8216
8216
  else {
8217
8217
  if (typeof cb2 === "function")
8218
8218
  cb2.apply(this, arguments);
@@ -8243,31 +8243,31 @@ var require_graceful_fs = __commonJS({
8243
8243
  var fs$readdir = fs12.readdir;
8244
8244
  fs12.readdir = readdir5;
8245
8245
  var noReaddirOptionVersions = /^v[0-5]\./;
8246
- function readdir5(path24, options, cb) {
8246
+ function readdir5(path25, options, cb) {
8247
8247
  if (typeof options === "function")
8248
8248
  cb = options, options = null;
8249
- var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path25, options2, cb2, startTime) {
8250
- return fs$readdir(path25, fs$readdirCallback(
8251
- path25,
8249
+ var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path26, options2, cb2, startTime) {
8250
+ return fs$readdir(path26, fs$readdirCallback(
8251
+ path26,
8252
8252
  options2,
8253
8253
  cb2,
8254
8254
  startTime
8255
8255
  ));
8256
- } : function go$readdir2(path25, options2, cb2, startTime) {
8257
- return fs$readdir(path25, options2, fs$readdirCallback(
8258
- path25,
8256
+ } : function go$readdir2(path26, options2, cb2, startTime) {
8257
+ return fs$readdir(path26, options2, fs$readdirCallback(
8258
+ path26,
8259
8259
  options2,
8260
8260
  cb2,
8261
8261
  startTime
8262
8262
  ));
8263
8263
  };
8264
- return go$readdir(path24, options, cb);
8265
- function fs$readdirCallback(path25, options2, cb2, startTime) {
8264
+ return go$readdir(path25, options, cb);
8265
+ function fs$readdirCallback(path26, options2, cb2, startTime) {
8266
8266
  return function(err, files) {
8267
8267
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
8268
8268
  enqueue([
8269
8269
  go$readdir,
8270
- [path25, options2, cb2],
8270
+ [path26, options2, cb2],
8271
8271
  err,
8272
8272
  startTime || Date.now(),
8273
8273
  Date.now()
@@ -8338,7 +8338,7 @@ var require_graceful_fs = __commonJS({
8338
8338
  enumerable: true,
8339
8339
  configurable: true
8340
8340
  });
8341
- function ReadStream(path24, options) {
8341
+ function ReadStream(path25, options) {
8342
8342
  if (this instanceof ReadStream)
8343
8343
  return fs$ReadStream.apply(this, arguments), this;
8344
8344
  else
@@ -8358,7 +8358,7 @@ var require_graceful_fs = __commonJS({
8358
8358
  }
8359
8359
  });
8360
8360
  }
8361
- function WriteStream(path24, options) {
8361
+ function WriteStream(path25, options) {
8362
8362
  if (this instanceof WriteStream)
8363
8363
  return fs$WriteStream.apply(this, arguments), this;
8364
8364
  else
@@ -8376,22 +8376,22 @@ var require_graceful_fs = __commonJS({
8376
8376
  }
8377
8377
  });
8378
8378
  }
8379
- function createReadStream2(path24, options) {
8380
- return new fs12.ReadStream(path24, options);
8379
+ function createReadStream2(path25, options) {
8380
+ return new fs12.ReadStream(path25, options);
8381
8381
  }
8382
- function createWriteStream(path24, options) {
8383
- return new fs12.WriteStream(path24, options);
8382
+ function createWriteStream(path25, options) {
8383
+ return new fs12.WriteStream(path25, options);
8384
8384
  }
8385
8385
  var fs$open = fs12.open;
8386
8386
  fs12.open = open;
8387
- function open(path24, flags, mode, cb) {
8387
+ function open(path25, flags, mode, cb) {
8388
8388
  if (typeof mode === "function")
8389
8389
  cb = mode, mode = null;
8390
- return go$open(path24, flags, mode, cb);
8391
- function go$open(path25, flags2, mode2, cb2, startTime) {
8392
- return fs$open(path25, flags2, mode2, function(err, fd) {
8390
+ return go$open(path25, flags, mode, cb);
8391
+ function go$open(path26, flags2, mode2, cb2, startTime) {
8392
+ return fs$open(path26, flags2, mode2, function(err, fd) {
8393
8393
  if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
8394
- enqueue([go$open, [path25, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
8394
+ enqueue([go$open, [path26, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
8395
8395
  else {
8396
8396
  if (typeof cb2 === "function")
8397
8397
  cb2.apply(this, arguments);
@@ -8920,7 +8920,7 @@ var require_mtime_precision = __commonJS({
8920
8920
  var require_lockfile = __commonJS({
8921
8921
  "../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js"(exports2, module2) {
8922
8922
  "use strict";
8923
- var path24 = require("path");
8923
+ var path25 = require("path");
8924
8924
  var fs11 = require_graceful_fs();
8925
8925
  var retry = require_retry2();
8926
8926
  var onExit = require_signal_exit();
@@ -8931,7 +8931,7 @@ var require_lockfile = __commonJS({
8931
8931
  }
8932
8932
  function resolveCanonicalPath(file2, options, callback) {
8933
8933
  if (!options.realpath) {
8934
- return callback(null, path24.resolve(file2));
8934
+ return callback(null, path25.resolve(file2));
8935
8935
  }
8936
8936
  options.fs.realpath(file2, callback);
8937
8937
  }
@@ -10795,10 +10795,10 @@ var require_segments = __commonJS({
10795
10795
  const segs = getSegmentsFromString(data, Utils.isKanjiModeEnabled());
10796
10796
  const nodes = buildNodes(segs);
10797
10797
  const graph = buildGraph(nodes, version2);
10798
- const path24 = dijkstra.find_path(graph.map, "start", "end");
10798
+ const path25 = dijkstra.find_path(graph.map, "start", "end");
10799
10799
  const optimizedSegs = [];
10800
- for (let i = 1; i < path24.length - 1; i++) {
10801
- optimizedSegs.push(graph.table[path24[i]].node);
10800
+ for (let i = 1; i < path25.length - 1; i++) {
10801
+ optimizedSegs.push(graph.table[path25[i]].node);
10802
10802
  }
10803
10803
  return exports2.fromArray(mergeSegments(optimizedSegs));
10804
10804
  };
@@ -13275,7 +13275,7 @@ var require_png2 = __commonJS({
13275
13275
  });
13276
13276
  png.pack();
13277
13277
  };
13278
- exports2.renderToFile = function renderToFile(path24, qrData, options, cb) {
13278
+ exports2.renderToFile = function renderToFile(path25, qrData, options, cb) {
13279
13279
  if (typeof cb === "undefined") {
13280
13280
  cb = options;
13281
13281
  options = void 0;
@@ -13286,7 +13286,7 @@ var require_png2 = __commonJS({
13286
13286
  called = true;
13287
13287
  cb.apply(null, args);
13288
13288
  };
13289
- const stream = fs11.createWriteStream(path24);
13289
+ const stream = fs11.createWriteStream(path25);
13290
13290
  stream.on("error", done);
13291
13291
  stream.on("close", done);
13292
13292
  exports2.renderToFileStream(stream, qrData, options);
@@ -13348,14 +13348,14 @@ var require_utf8 = __commonJS({
13348
13348
  }
13349
13349
  return output3;
13350
13350
  };
13351
- exports2.renderToFile = function renderToFile(path24, qrData, options, cb) {
13351
+ exports2.renderToFile = function renderToFile(path25, qrData, options, cb) {
13352
13352
  if (typeof cb === "undefined") {
13353
13353
  cb = options;
13354
13354
  options = void 0;
13355
13355
  }
13356
13356
  const fs11 = require("fs");
13357
13357
  const utf8 = exports2.render(qrData, options);
13358
- fs11.writeFile(path24, utf8, cb);
13358
+ fs11.writeFile(path25, utf8, cb);
13359
13359
  };
13360
13360
  }
13361
13361
  });
@@ -13476,7 +13476,7 @@ var require_svg_tag = __commonJS({
13476
13476
  return str;
13477
13477
  }
13478
13478
  function qrToPath(data, size, margin) {
13479
- let path24 = "";
13479
+ let path25 = "";
13480
13480
  let moveBy = 0;
13481
13481
  let newRow = false;
13482
13482
  let lineLength = 0;
@@ -13487,19 +13487,19 @@ var require_svg_tag = __commonJS({
13487
13487
  if (data[i]) {
13488
13488
  lineLength++;
13489
13489
  if (!(i > 0 && col > 0 && data[i - 1])) {
13490
- path24 += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
13490
+ path25 += newRow ? svgCmd("M", col + margin, 0.5 + row + margin) : svgCmd("m", moveBy, 0);
13491
13491
  moveBy = 0;
13492
13492
  newRow = false;
13493
13493
  }
13494
13494
  if (!(col + 1 < size && data[i + 1])) {
13495
- path24 += svgCmd("h", lineLength);
13495
+ path25 += svgCmd("h", lineLength);
13496
13496
  lineLength = 0;
13497
13497
  }
13498
13498
  } else {
13499
13499
  moveBy++;
13500
13500
  }
13501
13501
  }
13502
- return path24;
13502
+ return path25;
13503
13503
  }
13504
13504
  exports2.render = function render(qrData, options, cb) {
13505
13505
  const opts = Utils.getOptions(options);
@@ -13507,10 +13507,10 @@ var require_svg_tag = __commonJS({
13507
13507
  const data = qrData.modules.data;
13508
13508
  const qrcodesize = size + opts.margin * 2;
13509
13509
  const bg = !opts.color.light.a ? "" : "<path " + getColorAttrib(opts.color.light, "fill") + ' d="M0 0h' + qrcodesize + "v" + qrcodesize + 'H0z"/>';
13510
- const path24 = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
13510
+ const path25 = "<path " + getColorAttrib(opts.color.dark, "stroke") + ' d="' + qrToPath(data, size, opts.margin) + '"/>';
13511
13511
  const viewBox = 'viewBox="0 0 ' + qrcodesize + " " + qrcodesize + '"';
13512
13512
  const width = !opts.width ? "" : 'width="' + opts.width + '" height="' + opts.width + '" ';
13513
- const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path24 + "</svg>\n";
13513
+ const svgTag = '<svg xmlns="http://www.w3.org/2000/svg" ' + width + viewBox + ' shape-rendering="crispEdges">' + bg + path25 + "</svg>\n";
13514
13514
  if (typeof cb === "function") {
13515
13515
  cb(null, svgTag);
13516
13516
  }
@@ -13524,7 +13524,7 @@ var require_svg = __commonJS({
13524
13524
  "../../node_modules/.pnpm/qrcode@1.5.4/node_modules/qrcode/lib/renderer/svg.js"(exports2) {
13525
13525
  var svgTagRenderer = require_svg_tag();
13526
13526
  exports2.render = svgTagRenderer.render;
13527
- exports2.renderToFile = function renderToFile(path24, qrData, options, cb) {
13527
+ exports2.renderToFile = function renderToFile(path25, qrData, options, cb) {
13528
13528
  if (typeof cb === "undefined") {
13529
13529
  cb = options;
13530
13530
  options = void 0;
@@ -13532,7 +13532,7 @@ var require_svg = __commonJS({
13532
13532
  const fs11 = require("fs");
13533
13533
  const svgTag = exports2.render(qrData, options);
13534
13534
  const xmlStr = '<?xml version="1.0" encoding="utf-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">' + svgTag;
13535
- fs11.writeFile(path24, xmlStr, cb);
13535
+ fs11.writeFile(path25, xmlStr, cb);
13536
13536
  };
13537
13537
  }
13538
13538
  });
@@ -13690,8 +13690,8 @@ var require_server = __commonJS({
13690
13690
  cb
13691
13691
  };
13692
13692
  }
13693
- function getTypeFromFilename(path24) {
13694
- return path24.slice((path24.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
13693
+ function getTypeFromFilename(path25) {
13694
+ return path25.slice((path25.lastIndexOf(".") - 1 >>> 0) + 2).toLowerCase();
13695
13695
  }
13696
13696
  function getRendererFromType(type) {
13697
13697
  switch (type) {
@@ -13755,17 +13755,17 @@ var require_server = __commonJS({
13755
13755
  const renderer = getRendererFromType(params.opts.type);
13756
13756
  return render(renderer.renderToBuffer, text, params);
13757
13757
  };
13758
- exports2.toFile = function toFile(path24, text, opts, cb) {
13759
- if (typeof path24 !== "string" || !(typeof text === "string" || typeof text === "object")) {
13758
+ exports2.toFile = function toFile(path25, text, opts, cb) {
13759
+ if (typeof path25 !== "string" || !(typeof text === "string" || typeof text === "object")) {
13760
13760
  throw new Error("Invalid argument");
13761
13761
  }
13762
13762
  if (arguments.length < 3 && !canPromise()) {
13763
13763
  throw new Error("Too few arguments provided");
13764
13764
  }
13765
13765
  const params = checkParams(text, opts, cb);
13766
- const type = params.opts.type || getTypeFromFilename(path24);
13766
+ const type = params.opts.type || getTypeFromFilename(path25);
13767
13767
  const renderer = getRendererFromType(type);
13768
- const renderToFile = renderer.renderToFile.bind(null, path24);
13768
+ const renderToFile = renderer.renderToFile.bind(null, path25);
13769
13769
  return render(renderToFile, text, params);
13770
13770
  };
13771
13771
  exports2.toFileStream = function toFileStream(stream, text, opts) {
@@ -16983,8 +16983,8 @@ var require_utils3 = __commonJS({
16983
16983
  }
16984
16984
  return ind;
16985
16985
  }
16986
- function removeDotSegments(path24) {
16987
- let input = path24;
16986
+ function removeDotSegments(path25) {
16987
+ let input = path25;
16988
16988
  const output3 = [];
16989
16989
  let nextSlash = -1;
16990
16990
  let len = 0;
@@ -17236,8 +17236,8 @@ var require_schemes = __commonJS({
17236
17236
  wsComponent.secure = void 0;
17237
17237
  }
17238
17238
  if (wsComponent.resourceName) {
17239
- const [path24, query] = wsComponent.resourceName.split("?");
17240
- wsComponent.path = path24 && path24 !== "/" ? path24 : void 0;
17239
+ const [path25, query] = wsComponent.resourceName.split("?");
17240
+ wsComponent.path = path25 && path25 !== "/" ? path25 : void 0;
17241
17241
  wsComponent.query = query;
17242
17242
  wsComponent.resourceName = void 0;
17243
17243
  }
@@ -20644,11 +20644,11 @@ var require_dist = __commonJS({
20644
20644
  });
20645
20645
 
20646
20646
  // src/bin.ts
20647
- var import_node_path36 = __toESM(require("node:path"), 1);
20648
- var import_node_child_process18 = require("node:child_process");
20649
- var import_node_fs23 = require("node:fs");
20650
- var import_node_os18 = require("node:os");
20651
20647
  var import_node_path37 = __toESM(require("node:path"), 1);
20648
+ var import_node_child_process18 = require("node:child_process");
20649
+ var import_node_fs24 = require("node:fs");
20650
+ var import_node_os19 = require("node:os");
20651
+ var import_node_path38 = __toESM(require("node:path"), 1);
20652
20652
 
20653
20653
  // src/install-codex.ts
20654
20654
  var import_promises = __toESM(require("node:fs/promises"), 1);
@@ -21636,10 +21636,10 @@ async function verifyProviderReadiness(provider, run3, opts = {}) {
21636
21636
  }
21637
21637
 
21638
21638
  // src/director-bridge.ts
21639
- var import_node_fs21 = __toESM(require("node:fs"), 1);
21639
+ var import_node_fs22 = __toESM(require("node:fs"), 1);
21640
21640
  var import_node_http = __toESM(require("node:http"), 1);
21641
- var import_node_os14 = __toESM(require("node:os"), 1);
21642
- var import_node_path29 = __toESM(require("node:path"), 1);
21641
+ var import_node_os15 = __toESM(require("node:os"), 1);
21642
+ var import_node_path30 = __toESM(require("node:path"), 1);
21643
21643
  var import_node_child_process15 = require("node:child_process");
21644
21644
  var import_node_crypto11 = __toESM(require("node:crypto"), 1);
21645
21645
 
@@ -23201,10 +23201,10 @@ function mergeDefs(...defs) {
23201
23201
  function cloneDef(schema) {
23202
23202
  return mergeDefs(schema._zod.def);
23203
23203
  }
23204
- function getElementAtPath(obj, path24) {
23205
- if (!path24)
23204
+ function getElementAtPath(obj, path25) {
23205
+ if (!path25)
23206
23206
  return obj;
23207
- return path24.reduce((acc, key) => acc?.[key], obj);
23207
+ return path25.reduce((acc, key) => acc?.[key], obj);
23208
23208
  }
23209
23209
  function promiseAllObject(promisesObj) {
23210
23210
  const keys = Object.keys(promisesObj);
@@ -23613,11 +23613,11 @@ function explicitlyAborted(x, startIndex = 0) {
23613
23613
  }
23614
23614
  return false;
23615
23615
  }
23616
- function prefixIssues(path24, issues) {
23616
+ function prefixIssues(path25, issues) {
23617
23617
  return issues.map((iss) => {
23618
23618
  var _a3;
23619
23619
  (_a3 = iss).path ?? (_a3.path = []);
23620
- iss.path.unshift(path24);
23620
+ iss.path.unshift(path25);
23621
23621
  return iss;
23622
23622
  });
23623
23623
  }
@@ -23764,16 +23764,16 @@ function flattenError(error51, mapper = (issue2) => issue2.message) {
23764
23764
  }
23765
23765
  function formatError(error51, mapper = (issue2) => issue2.message) {
23766
23766
  const fieldErrors = { _errors: [] };
23767
- const processError = (error52, path24 = []) => {
23767
+ const processError = (error52, path25 = []) => {
23768
23768
  for (const issue2 of error52.issues) {
23769
23769
  if (issue2.code === "invalid_union" && issue2.errors.length) {
23770
- issue2.errors.map((issues) => processError({ issues }, [...path24, ...issue2.path]));
23770
+ issue2.errors.map((issues) => processError({ issues }, [...path25, ...issue2.path]));
23771
23771
  } else if (issue2.code === "invalid_key") {
23772
- processError({ issues: issue2.issues }, [...path24, ...issue2.path]);
23772
+ processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
23773
23773
  } else if (issue2.code === "invalid_element") {
23774
- processError({ issues: issue2.issues }, [...path24, ...issue2.path]);
23774
+ processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
23775
23775
  } else {
23776
- const fullpath = [...path24, ...issue2.path];
23776
+ const fullpath = [...path25, ...issue2.path];
23777
23777
  if (fullpath.length === 0) {
23778
23778
  fieldErrors._errors.push(mapper(issue2));
23779
23779
  } else {
@@ -23800,17 +23800,17 @@ function formatError(error51, mapper = (issue2) => issue2.message) {
23800
23800
  }
23801
23801
  function treeifyError(error51, mapper = (issue2) => issue2.message) {
23802
23802
  const result = { errors: [] };
23803
- const processError = (error52, path24 = []) => {
23803
+ const processError = (error52, path25 = []) => {
23804
23804
  var _a3, _b;
23805
23805
  for (const issue2 of error52.issues) {
23806
23806
  if (issue2.code === "invalid_union" && issue2.errors.length) {
23807
- issue2.errors.map((issues) => processError({ issues }, [...path24, ...issue2.path]));
23807
+ issue2.errors.map((issues) => processError({ issues }, [...path25, ...issue2.path]));
23808
23808
  } else if (issue2.code === "invalid_key") {
23809
- processError({ issues: issue2.issues }, [...path24, ...issue2.path]);
23809
+ processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
23810
23810
  } else if (issue2.code === "invalid_element") {
23811
- processError({ issues: issue2.issues }, [...path24, ...issue2.path]);
23811
+ processError({ issues: issue2.issues }, [...path25, ...issue2.path]);
23812
23812
  } else {
23813
- const fullpath = [...path24, ...issue2.path];
23813
+ const fullpath = [...path25, ...issue2.path];
23814
23814
  if (fullpath.length === 0) {
23815
23815
  result.errors.push(mapper(issue2));
23816
23816
  continue;
@@ -23842,8 +23842,8 @@ function treeifyError(error51, mapper = (issue2) => issue2.message) {
23842
23842
  }
23843
23843
  function toDotPath(_path) {
23844
23844
  const segs = [];
23845
- const path24 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
23846
- for (const seg of path24) {
23845
+ const path25 = _path.map((seg) => typeof seg === "object" ? seg.key : seg);
23846
+ for (const seg of path25) {
23847
23847
  if (typeof seg === "number")
23848
23848
  segs.push(`[${seg}]`);
23849
23849
  else if (typeof seg === "symbol")
@@ -36535,13 +36535,13 @@ function resolveRef(ref, ctx) {
36535
36535
  if (!ref.startsWith("#")) {
36536
36536
  throw new Error("External $ref is not supported, only local refs (#/...) are allowed");
36537
36537
  }
36538
- const path24 = ref.slice(1).split("/").filter(Boolean);
36539
- if (path24.length === 0) {
36538
+ const path25 = ref.slice(1).split("/").filter(Boolean);
36539
+ if (path25.length === 0) {
36540
36540
  return ctx.rootSchema;
36541
36541
  }
36542
36542
  const defsKey = ctx.version === "draft-2020-12" ? "$defs" : "definitions";
36543
- if (path24[0] === defsKey) {
36544
- const key = path24[1];
36543
+ if (path25[0] === defsKey) {
36544
+ const key = path25[1];
36545
36545
  if (!key || !ctx.defs[key]) {
36546
36546
  throw new Error(`Reference not found: ${ref}`);
36547
36547
  }
@@ -36969,7 +36969,7 @@ var ARTIFACT_CHECKS = {
36969
36969
  var ARTIFACT_DESTINATIONS = {
36970
36970
  document: "wiki",
36971
36971
  page: "git",
36972
- file_set: null,
36972
+ file_set: "artifacts",
36973
36973
  code_change: "git",
36974
36974
  structured_data: null,
36975
36975
  message: null
@@ -36978,6 +36978,52 @@ function resolveKindCapability(kind) {
36978
36978
  return ARTIFACT_DESTINATIONS[kind];
36979
36979
  }
36980
36980
 
36981
+ // ../../packages/schemas/dist/capability-refusal.js
36982
+ var REFUSAL_TEMPLATES = {
36983
+ no_route: {
36984
+ happened: ({ artifactKind, projectSlug }) => `Nothing is configured to deliver \`${artifactKind}\` for project \`${projectSlug}\`.`,
36985
+ action: ({ capability }) => `Grant an MCP server that provides the "${capability}" capability and route it on the Integrations page. Retrying before that will refuse identically.`
36986
+ },
36987
+ no_grant: {
36988
+ happened: ({ projectSlug, capability }) => `Project \`${projectSlug}\` routes "${capability}" to a server whose access has been revoked.`,
36989
+ action: () => "Grant that server again on the Integrations page, or re-point the route. Retrying before that will refuse identically."
36990
+ },
36991
+ project_mismatch: {
36992
+ happened: ({ capability }) => `The route for "${capability}" belongs to a different project than this task does.`,
36993
+ action: () => "Mrrlin refuses rather than delivering one project's work into another project's destination. Re-point the route in the task's own project."
36994
+ },
36995
+ ambiguous_route: {
36996
+ happened: ({ projectSlug, artifactKind }) => `Project \`${projectSlug}\` has more than one route that delivers \`${artifactKind}\`.`,
36997
+ action: () => "Mrrlin will not guess which one. Name the capability explicitly, or remove the route you do not want."
36998
+ },
36999
+ blocked_kind: {
37000
+ happened: ({ artifactKind }) => `Mrrlin has no destination for \`${artifactKind}\` yet.`,
37001
+ action: () => "Produce a kind that does have one, or record the result on the task instead."
37002
+ },
37003
+ gate_refused: {
37004
+ happened: ({ projectSlug }) => `The operator declined this action for project \`${projectSlug}\`.`,
37005
+ action: () => "This is an answer, not a failure \u2014 do not retry it. Ask the operator directly if it should be allowed."
37006
+ },
37007
+ transport_error: {
37008
+ happened: () => "Mrrlin could not reach the service that decides whether this delivery is allowed, so nothing was sent.",
37009
+ action: () => "This is safe to retry."
37010
+ },
37011
+ delivery_failed: {
37012
+ happened: ({ projectSlug }) => `The delivery was allowed, but the destination itself failed for project \`${projectSlug}\`.`,
37013
+ action: () => "It may have partly completed, so do not blindly retry \u2014 check whether the result already exists first."
37014
+ }
37015
+ };
37016
+ function describeCapabilityRefusal(input) {
37017
+ const ctx = {
37018
+ projectSlug: input.projectSlug,
37019
+ capability: input.capability ?? "the requested capability",
37020
+ artifactKind: input.artifactKind ?? "this artifact kind"
37021
+ };
37022
+ const template = REFUSAL_TEMPLATES[input.reason];
37023
+ const happened = typeof input.detail === "string" && input.detail.length > 0 ? input.detail : template.happened(ctx);
37024
+ return `${happened} ${template.action(ctx)}`;
37025
+ }
37026
+
36981
37027
  // ../../packages/schemas/dist/operationIds.js
36982
37028
  var openApiOperationIds = {
36983
37029
  appendExecutionArtifact: "appendExecutionArtifact",
@@ -40855,18 +40901,18 @@ function createMrrlinClient(config2) {
40855
40901
  const customFetch = config2.fetch ?? globalThis.fetch;
40856
40902
  const baseUrl = config2.baseUrl.replace(/\/$/, "");
40857
40903
  const token = config2.token;
40858
- async function request(path24, init) {
40904
+ async function request(path25, init) {
40859
40905
  const method = init?.method ?? "GET";
40860
40906
  const headers = new Headers(init?.headers ?? {});
40861
40907
  if (token && !headers.has("authorization")) {
40862
40908
  headers.set("authorization", `Bearer ${token}`);
40863
40909
  }
40864
- const response = await customFetch(`${baseUrl}${path24}`, { ...init, headers });
40910
+ const response = await customFetch(`${baseUrl}${path25}`, { ...init, headers });
40865
40911
  if (!response.ok) {
40866
40912
  const body = await response.text();
40867
40913
  let code = `HTTP_${response.status}`;
40868
40914
  let violations = null;
40869
- let message = `Mrrlin API ${method} ${path24} failed: ${response.status}`;
40915
+ let message = `Mrrlin API ${method} ${path25} failed: ${response.status}`;
40870
40916
  try {
40871
40917
  const parsed = JSON.parse(body);
40872
40918
  const violationsParsed = apiViolationsErrorSchema.safeParse(parsed);
@@ -40886,7 +40932,7 @@ function createMrrlinClient(config2) {
40886
40932
  throw new MrrlinApiError({
40887
40933
  code,
40888
40934
  method,
40889
- path: path24,
40935
+ path: path25,
40890
40936
  responseBody: body,
40891
40937
  status: response.status,
40892
40938
  violations,
@@ -40895,18 +40941,18 @@ function createMrrlinClient(config2) {
40895
40941
  }
40896
40942
  return response.json();
40897
40943
  }
40898
- async function requestText(path24, init) {
40944
+ async function requestText(path25, init) {
40899
40945
  const method = init?.method ?? "GET";
40900
40946
  const headers = new Headers(init?.headers ?? {});
40901
40947
  if (token && !headers.has("authorization")) {
40902
40948
  headers.set("authorization", `Bearer ${token}`);
40903
40949
  }
40904
- const response = await customFetch(`${baseUrl}${path24}`, { ...init, headers });
40950
+ const response = await customFetch(`${baseUrl}${path25}`, { ...init, headers });
40905
40951
  if (!response.ok) {
40906
40952
  const body = await response.text();
40907
40953
  let code = `HTTP_${response.status}`;
40908
40954
  let violations = null;
40909
- let message = `Mrrlin API ${method} ${path24} failed: ${response.status}`;
40955
+ let message = `Mrrlin API ${method} ${path25} failed: ${response.status}`;
40910
40956
  try {
40911
40957
  const parsed = JSON.parse(body);
40912
40958
  const violationsParsed = apiViolationsErrorSchema.safeParse(parsed);
@@ -40926,7 +40972,7 @@ function createMrrlinClient(config2) {
40926
40972
  throw new MrrlinApiError({
40927
40973
  code,
40928
40974
  method,
40929
- path: path24,
40975
+ path: path25,
40930
40976
  responseBody: body,
40931
40977
  status: response.status,
40932
40978
  violations,
@@ -41191,16 +41237,16 @@ function createMrrlinClient(config2) {
41191
41237
  // rejected against the first, MrrlinTask[]-only overload) -- the `any` here is contained to
41192
41238
  // this one implementation signature; MrrlinClient's declared overloads keep callers precise.
41193
41239
  async listTasks(projectSlug, filters = {}, options) {
41194
- const path24 = buildTaskListPath(projectSlug, filters, options?.view);
41195
- const body = await request(path24);
41240
+ const path25 = buildTaskListPath(projectSlug, filters, options?.view);
41241
+ const body = await request(path25);
41196
41242
  if (options?.view === "summary") {
41197
41243
  return taskSummaryListResponseSchema.parse(body).data;
41198
41244
  }
41199
41245
  return taskListResponseSchema.parse(body).data;
41200
41246
  },
41201
41247
  async listTaskSummaries(projectSlug, filters = {}) {
41202
- const path24 = buildTaskListPath(projectSlug, filters, "summary");
41203
- const body = await request(path24);
41248
+ const path25 = buildTaskListPath(projectSlug, filters, "summary");
41249
+ const body = await request(path25);
41204
41250
  return taskSummaryListResponseSchema.parse(body).data;
41205
41251
  },
41206
41252
  async listTaxonomy(projectSlug) {
@@ -41208,22 +41254,22 @@ function createMrrlinClient(config2) {
41208
41254
  return taxonomyListResponseSchema.parse(body).data;
41209
41255
  },
41210
41256
  async listWikiPages(projectSlug, filters = {}) {
41211
- const path24 = appendQuery(`${projectPath(projectSlug)}/wiki`, {
41257
+ const path25 = appendQuery(`${projectPath(projectSlug)}/wiki`, {
41212
41258
  folder: filters.folder,
41213
41259
  q: filters.q,
41214
41260
  taskId: filters.taskId
41215
41261
  });
41216
- const body = await request(path24);
41262
+ const body = await request(path25);
41217
41263
  return wikiPageListResponseSchema.parse(body).data;
41218
41264
  },
41219
41265
  async searchWikiPages(projectSlug, query) {
41220
- const path24 = appendQuery(`${projectPath(projectSlug)}/wiki/search`, {
41266
+ const path25 = appendQuery(`${projectPath(projectSlug)}/wiki/search`, {
41221
41267
  folder: query.folder,
41222
41268
  limit: query.limit === void 0 ? void 0 : String(query.limit),
41223
41269
  pathPrefix: query.pathPrefix,
41224
41270
  q: query.q
41225
41271
  });
41226
- const body = await request(path24);
41272
+ const body = await request(path25);
41227
41273
  return wikiPageSearchResponseSchema.parse(body).data;
41228
41274
  },
41229
41275
  async updatePlan(projectSlug, planId, patch) {
@@ -42214,12 +42260,150 @@ function createTurnLock() {
42214
42260
  // src/self-update.ts
42215
42261
  var import_node_child_process7 = require("node:child_process");
42216
42262
  var import_node_crypto2 = require("node:crypto");
42263
+ var import_node_fs4 = require("node:fs");
42264
+ var import_node_path7 = __toESM(require("node:path"), 1);
42265
+ var import_semver3 = __toESM(require_semver2(), 1);
42266
+
42267
+ // src/codex-auth-preflight.ts
42217
42268
  var import_node_fs3 = require("node:fs");
42269
+ var import_node_os6 = __toESM(require("node:os"), 1);
42218
42270
  var import_node_path6 = __toESM(require("node:path"), 1);
42219
- var import_semver3 = __toESM(require_semver2(), 1);
42271
+ var DEFAULT_CODEX_AUTH_MIN_TTL_SECONDS = 15 * 60;
42272
+ function positiveInt(raw) {
42273
+ if (!raw) return null;
42274
+ const parsed = Number.parseInt(raw, 10);
42275
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : null;
42276
+ }
42277
+ function codexAuthMinTtlSeconds(env = process.env) {
42278
+ return positiveInt(env.MRRLIN_DIRECTOR_BRIDGE_UPDATE_AUTH_MIN_TTL_SECONDS) ?? DEFAULT_CODEX_AUTH_MIN_TTL_SECONDS;
42279
+ }
42280
+ function resolveCodexAuthPath(opts = {}) {
42281
+ const env = opts.env ?? process.env;
42282
+ const codexHome = env.CODEX_HOME?.trim();
42283
+ return import_node_path6.default.join(codexHome || import_node_path6.default.join(opts.homeDir ?? import_node_os6.default.homedir(), ".codex"), "auth.json");
42284
+ }
42285
+ function decodeJwtExpMs(token) {
42286
+ const parts = token.split(".");
42287
+ if (parts.length < 2 || !parts[1]) return null;
42288
+ try {
42289
+ const payload = JSON.parse(Buffer.from(parts[1], "base64url").toString("utf8"));
42290
+ return typeof payload.exp === "number" && Number.isFinite(payload.exp) ? payload.exp * 1e3 : null;
42291
+ } catch {
42292
+ return null;
42293
+ }
42294
+ }
42295
+ function inspectCodexAuthForBridgeUpdate(opts = {}) {
42296
+ const env = opts.env ?? process.env;
42297
+ const nowMs = opts.nowMs ?? Date.now();
42298
+ const minTtlSeconds = opts.minTtlSeconds ?? codexAuthMinTtlSeconds(env);
42299
+ const authPath = resolveCodexAuthPath({ env, homeDir: opts.homeDir });
42300
+ const readFile9 = opts.readFileSyncImpl ?? ((p, encoding) => (0, import_node_fs3.readFileSync)(p, encoding));
42301
+ let raw;
42302
+ try {
42303
+ raw = readFile9(authPath, "utf8");
42304
+ } catch (e) {
42305
+ const code = typeof e === "object" && e !== null && "code" in e ? String(e.code) : "";
42306
+ const status = code === "ENOENT" ? "missing" : "unreadable";
42307
+ return {
42308
+ ok: false,
42309
+ status,
42310
+ authPath,
42311
+ checkedAtMs: nowMs,
42312
+ minTtlSeconds,
42313
+ tokenKinds: [],
42314
+ expiresAtMs: null,
42315
+ expiresInSeconds: null,
42316
+ detail: status === "missing" ? "Codex CLI auth file is missing." : "Codex CLI auth file could not be read."
42317
+ };
42318
+ }
42319
+ let parsed;
42320
+ try {
42321
+ parsed = JSON.parse(raw);
42322
+ } catch {
42323
+ return {
42324
+ ok: false,
42325
+ status: "malformed",
42326
+ authPath,
42327
+ checkedAtMs: nowMs,
42328
+ minTtlSeconds,
42329
+ tokenKinds: [],
42330
+ expiresAtMs: null,
42331
+ expiresInSeconds: null,
42332
+ detail: "Codex CLI auth file is not valid JSON."
42333
+ };
42334
+ }
42335
+ const tokenEntries = [
42336
+ ["access_token", parsed.tokens?.access_token],
42337
+ ["id_token", parsed.tokens?.id_token]
42338
+ ];
42339
+ const expiries = tokenEntries.flatMap(([kind, token]) => {
42340
+ if (typeof token !== "string" || token.trim() === "") return [];
42341
+ const expMs = decodeJwtExpMs(token);
42342
+ return expMs === null ? [] : [{ kind, expMs }];
42343
+ });
42344
+ const earliest = expiries.reduce(
42345
+ (current2, entry) => current2 === null || entry.expMs < current2.expMs ? entry : current2,
42346
+ null
42347
+ );
42348
+ if (earliest === null) {
42349
+ return {
42350
+ ok: false,
42351
+ status: "no_usable_jwt_exp",
42352
+ authPath,
42353
+ checkedAtMs: nowMs,
42354
+ minTtlSeconds,
42355
+ tokenKinds: [],
42356
+ expiresAtMs: null,
42357
+ expiresInSeconds: null,
42358
+ detail: "Codex CLI auth file has no access_token or id_token JWT expiry to verify."
42359
+ };
42360
+ }
42361
+ const expiresInSeconds = Math.floor((earliest.expMs - nowMs) / 1e3);
42362
+ const tokenKinds = expiries.map((entry) => entry.kind).sort();
42363
+ if (expiresInSeconds <= 0) {
42364
+ return {
42365
+ ok: false,
42366
+ status: "expired",
42367
+ authPath,
42368
+ checkedAtMs: nowMs,
42369
+ minTtlSeconds,
42370
+ tokenKinds,
42371
+ expiresAtMs: earliest.expMs,
42372
+ expiresInSeconds,
42373
+ detail: `Codex CLI ${earliest.kind} JWT is expired.`
42374
+ };
42375
+ }
42376
+ if (expiresInSeconds < minTtlSeconds) {
42377
+ return {
42378
+ ok: false,
42379
+ status: "expiring_soon",
42380
+ authPath,
42381
+ checkedAtMs: nowMs,
42382
+ minTtlSeconds,
42383
+ tokenKinds,
42384
+ expiresAtMs: earliest.expMs,
42385
+ expiresInSeconds,
42386
+ detail: `Codex CLI ${earliest.kind} JWT expires too soon for a bridge update restart.`
42387
+ };
42388
+ }
42389
+ return {
42390
+ ok: true,
42391
+ status: "ok",
42392
+ authPath,
42393
+ checkedAtMs: nowMs,
42394
+ minTtlSeconds,
42395
+ tokenKinds,
42396
+ expiresAtMs: earliest.expMs,
42397
+ expiresInSeconds,
42398
+ detail: "Codex CLI JWT expiry is far enough in the future for a bridge update restart."
42399
+ };
42400
+ }
42401
+
42402
+ // src/self-update.ts
42220
42403
  var BIN_NAME = "mrrlin-mcp";
42404
+ var SELF_UPDATE_AUTH_PREFLIGHT_OFFER_PREFIX = "[bridge:update:auth-preflight]";
42221
42405
  function resolveBinPath(opts) {
42222
- if (opts.argv1 && import_node_path6.default.basename(opts.argv1).includes("mrrlin")) {
42406
+ if (opts.argv1 && import_node_path7.default.basename(opts.argv1).includes("mrrlin")) {
42223
42407
  return { path: opts.argv1, source: "argv" };
42224
42408
  }
42225
42409
  const whichSync = opts.whichSync ?? ((name) => {
@@ -42229,15 +42413,15 @@ function resolveBinPath(opts) {
42229
42413
  return null;
42230
42414
  }
42231
42415
  });
42232
- const existsSync5 = opts.existsSync ?? import_node_fs3.existsSync;
42416
+ const existsSync5 = opts.existsSync ?? import_node_fs4.existsSync;
42233
42417
  const resolved = whichSync(BIN_NAME);
42234
42418
  if (resolved && existsSync5(resolved)) {
42235
42419
  return { path: resolved, source: "which" };
42236
42420
  }
42237
42421
  const envPath = (opts.env ?? process.env).PATH ?? "";
42238
- for (const dir of envPath.split(import_node_path6.default.delimiter)) {
42422
+ for (const dir of envPath.split(import_node_path7.default.delimiter)) {
42239
42423
  if (!dir) continue;
42240
- const candidate = import_node_path6.default.join(dir, BIN_NAME);
42424
+ const candidate = import_node_path7.default.join(dir, BIN_NAME);
42241
42425
  if (existsSync5(candidate)) {
42242
42426
  return { path: candidate, source: "path-walk" };
42243
42427
  }
@@ -42249,6 +42433,7 @@ var DEFAULT_IDLE_MS = 2e3;
42249
42433
  var DEFAULT_REGISTRY_POLL_MS = 6 * 60 * 60 * 1e3;
42250
42434
  var DEFAULT_STARTUP_JITTER_MS = 30 * 1e3;
42251
42435
  var DEFAULT_COOLDOWN_MS = 48 * 60 * 60 * 1e3;
42436
+ var DEFAULT_AUTH_BLOCK_COOLDOWN_MS = 15 * 60 * 1e3;
42252
42437
  var REGISTRY_URL_DEFAULT = "https://registry.npmjs.org/@mrrlin-dev/mcp/latest";
42253
42438
  var STRICT_SEMVER = /^\d+\.\d+\.\d+(-[A-Za-z0-9.-]+)?(\+[A-Za-z0-9.-]+)?$/;
42254
42439
  var UPDATE_INBOX_BODY = "A newer version of the mrrlin bridge is available. Updating pulls the latest fixes and improvements. Changelog: https://mrrlin-changelog.s3.eu-central-1.amazonaws.com/index.html . Ask the Director to update, or run `npm install -g @mrrlin-dev/mcp@latest` yourself.";
@@ -42267,7 +42452,7 @@ function sha256(buf) {
42267
42452
  function startSelfUpdate(deps) {
42268
42453
  const log = deps.log ?? (() => {
42269
42454
  });
42270
- const readFile9 = deps.readFileSyncImpl ?? ((p) => (0, import_node_fs3.readFileSync)(p));
42455
+ const readFile9 = deps.readFileSyncImpl ?? ((p) => (0, import_node_fs4.readFileSync)(p));
42271
42456
  const setIntervalFn = deps.setIntervalImpl ?? setInterval;
42272
42457
  const clearIntervalFn = deps.clearIntervalImpl ?? clearInterval;
42273
42458
  const intervalMs = deps.intervalMs ?? readIntervalEnv("MRRLIN_DIRECTOR_BRIDGE_SELF_UPDATE_INTERVAL_MS", DEFAULT_INTERVAL_MS);
@@ -42280,17 +42465,55 @@ function startSelfUpdate(deps) {
42280
42465
  const registryPollIntervalMs = deps.registryPollIntervalMs ?? readIntervalEnv("MRRLIN_DIRECTOR_BRIDGE_REGISTRY_POLL_INTERVAL_MS", DEFAULT_REGISTRY_POLL_MS);
42281
42466
  const startupJitterMs = deps.startupJitterMs ?? DEFAULT_STARTUP_JITTER_MS;
42282
42467
  const cooldownMs = deps.cooldownMs ?? readIntervalEnv("MRRLIN_DIRECTOR_BRIDGE_UPDATE_COOLDOWN_MS", DEFAULT_COOLDOWN_MS);
42468
+ const authBlockCooldownMs = deps.authBlockCooldownMs ?? readIntervalEnv("MRRLIN_DIRECTOR_BRIDGE_UPDATE_AUTH_BLOCK_COOLDOWN_MS", DEFAULT_AUTH_BLOCK_COOLDOWN_MS);
42283
42469
  const nowFn = deps.now ?? (() => Date.now());
42470
+ const codexAuthPreflight = deps.codexAuthPreflight ?? (() => inspectCodexAuthForBridgeUpdate({
42471
+ nowMs: nowFn()
42472
+ }));
42284
42473
  const disabled = isDisabled();
42285
42474
  let drainOnQuiet = false;
42286
42475
  let drainSource = null;
42287
42476
  let shutdownCalled = false;
42288
42477
  let latestVersion = null;
42289
42478
  let lastUpdateMentionAt = null;
42479
+ let lastAuthBlockMentionAt = null;
42480
+ function blockedAuthOffer(auth2) {
42481
+ const expires = auth2.expiresInSeconds === null ? "unknown" : `${auth2.expiresInSeconds}s`;
42482
+ return `${SELF_UPDATE_AUTH_PREFLIGHT_OFFER_PREFIX} An update for @mrrlin-dev/mcp is available: ${pkgVersion} -> ${latestVersion}.
42483
+
42484
+ Do NOT install it yet. The local Codex CLI auth that the restarted bridge will use is not update-safe:
42485
+ - status: ${auth2.status}
42486
+ - auth file: ${auth2.authPath}
42487
+ - nearest JWT expiry: ${expires}
42488
+ - detail: ${auth2.detail}
42489
+
42490
+ Tell the operator, in their language, that the bridge update is ready but the Codex CLI session should be refreshed first because the update restarts the bridge and starts a fresh headless Codex process.
42491
+
42492
+ Ask the operator to run \`codex login\` as the re-auth action only. Do not present \`codex login\` as a readiness check; it opens the login flow even when auth is already fine.
42493
+
42494
+ After the operator re-authenticates, ask them to verify the CLI with:
42495
+ \`codex exec --model gpt-5.4-mini 'Reply with exactly: OK'\`
42496
+
42497
+ Once that returns OK, they can ask again and you may offer the normal update command \`npm install -g @mrrlin-dev/mcp@latest\`.`;
42498
+ }
42290
42499
  function maybeUpdateOffer() {
42291
42500
  if (disabled) return null;
42292
42501
  if (latestVersion === null) return null;
42293
42502
  if (!import_semver3.default.gt(latestVersion, pkgVersion)) return null;
42503
+ const auth2 = codexAuthPreflight();
42504
+ if (!auth2.ok) {
42505
+ if (lastAuthBlockMentionAt !== null && nowFn() - lastAuthBlockMentionAt < authBlockCooldownMs) return null;
42506
+ lastAuthBlockMentionAt = nowFn();
42507
+ log("warn", "bridge.self_update.auth_preflight_blocked", {
42508
+ version: pkgVersion,
42509
+ latestVersion,
42510
+ status: auth2.status,
42511
+ authPath: auth2.authPath,
42512
+ expiresInSeconds: auth2.expiresInSeconds,
42513
+ minTtlSeconds: auth2.minTtlSeconds
42514
+ });
42515
+ return blockedAuthOffer(auth2);
42516
+ }
42294
42517
  if (lastUpdateMentionAt !== null && nowFn() - lastUpdateMentionAt < cooldownMs) return null;
42295
42518
  lastUpdateMentionAt = nowFn();
42296
42519
  log("info", "bridge.self_update.hint_injected", {
@@ -42488,17 +42711,17 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
42488
42711
  }
42489
42712
 
42490
42713
  // src/_generated/version.ts
42491
- var PKG_VERSION = "0.4.57";
42714
+ var PKG_VERSION = "0.4.60";
42492
42715
 
42493
42716
  // src/api-base-url-migrate.ts
42494
- var import_node_fs4 = __toESM(require("node:fs"), 1);
42495
- var import_node_os6 = __toESM(require("node:os"), 1);
42496
- var import_node_path8 = __toESM(require("node:path"), 1);
42717
+ var import_node_fs5 = __toESM(require("node:fs"), 1);
42718
+ var import_node_os7 = __toESM(require("node:os"), 1);
42719
+ var import_node_path9 = __toESM(require("node:path"), 1);
42497
42720
 
42498
42721
  // src/service-paths.ts
42499
- var import_node_path7 = __toESM(require("node:path"), 1);
42722
+ var import_node_path8 = __toESM(require("node:path"), 1);
42500
42723
  function isWorktreePath(p) {
42501
- const norm = import_node_path7.default.normalize(p).split(import_node_path7.default.sep).join("/");
42724
+ const norm = import_node_path8.default.normalize(p).split(import_node_path8.default.sep).join("/");
42502
42725
  return norm.includes("/.claude/worktrees/");
42503
42726
  }
42504
42727
  function resolveServiceCwd(opts) {
@@ -42551,20 +42774,20 @@ ${envLines}
42551
42774
 
42552
42775
  // src/api-base-url-migrate.ts
42553
42776
  function defaultDeps(deps) {
42554
- const home = deps.home ?? process.env.HOME ?? import_node_os6.default.homedir();
42777
+ const home = deps.home ?? process.env.HOME ?? import_node_os7.default.homedir();
42555
42778
  return {
42556
42779
  home,
42557
- codexHome: deps.codexHome ?? process.env.CODEX_HOME?.trim() ?? import_node_path8.default.join(home, ".codex"),
42558
- readFile: deps.readFile ?? ((p) => import_node_fs4.default.readFileSync(p, "utf8")),
42780
+ codexHome: deps.codexHome ?? process.env.CODEX_HOME?.trim() ?? import_node_path9.default.join(home, ".codex"),
42781
+ readFile: deps.readFile ?? ((p) => import_node_fs5.default.readFileSync(p, "utf8")),
42559
42782
  // Temp-file + atomic rename so a concurrent `serve` and `director-bridge` startup can never
42560
42783
  // interleave partial writes into a config the next start has to parse. Note this normalizes the
42561
42784
  // file to 0o600 — deliberate, since both files can carry a credential-bearing URL.
42562
42785
  writeFile: deps.writeFile ?? ((p, c) => {
42563
42786
  const tmp = `${p}.tmp-${process.pid}`;
42564
- import_node_fs4.default.writeFileSync(tmp, c, { mode: 384 });
42565
- import_node_fs4.default.renameSync(tmp, p);
42787
+ import_node_fs5.default.writeFileSync(tmp, c, { mode: 384 });
42788
+ import_node_fs5.default.renameSync(tmp, p);
42566
42789
  }),
42567
- exists: deps.exists ?? ((p) => import_node_fs4.default.existsSync(p)),
42790
+ exists: deps.exists ?? ((p) => import_node_fs5.default.existsSync(p)),
42568
42791
  log: deps.log ?? ((m) => process.stderr.write(`${m}
42569
42792
  `))
42570
42793
  };
@@ -42603,7 +42826,7 @@ function backupOnce(file2, text, deps) {
42603
42826
  }
42604
42827
  function migrateEcosystemConfig(deps = {}) {
42605
42828
  const d = defaultDeps(deps);
42606
- const file2 = import_node_path8.default.join(d.home, ".mrrlin", "ecosystem.config.cjs");
42829
+ const file2 = import_node_path9.default.join(d.home, ".mrrlin", "ecosystem.config.cjs");
42607
42830
  if (!d.exists(file2)) return { file: file2, status: "absent" };
42608
42831
  const text = d.readFile(file2);
42609
42832
  if (!findRetiredHost(text) && !hasLiveLegacyStagingFlag(text, "js"))
@@ -42753,7 +42976,7 @@ ${envLines}
42753
42976
  }
42754
42977
  function migrateCodexConfig(deps = {}) {
42755
42978
  const d = defaultDeps(deps);
42756
- const file2 = import_node_path8.default.join(d.codexHome, "config.toml");
42979
+ const file2 = import_node_path9.default.join(d.codexHome, "config.toml");
42757
42980
  if (!d.exists(file2)) return { file: file2, status: "absent" };
42758
42981
  const text = d.readFile(file2);
42759
42982
  const host = findRetiredHost(text);
@@ -42839,7 +43062,7 @@ $1`
42839
43062
  }
42840
43063
  function migrateClaudeConfig(deps = {}) {
42841
43064
  const d = defaultDeps(deps);
42842
- const file2 = import_node_path8.default.join(d.home, ".claude.json");
43065
+ const file2 = import_node_path9.default.join(d.home, ".claude.json");
42843
43066
  if (!d.exists(file2)) return { file: file2, status: "absent" };
42844
43067
  const text = d.readFile(file2);
42845
43068
  let parsed;
@@ -42889,9 +43112,9 @@ function migrateRetiredApiBaseUrls(deps = {}) {
42889
43112
  const d = defaultDeps(deps);
42890
43113
  const results = [];
42891
43114
  const steps = [
42892
- { run: migrateEcosystemConfig, file: import_node_path8.default.join(d.home, ".mrrlin", "ecosystem.config.cjs") },
42893
- { run: migrateCodexConfig, file: import_node_path8.default.join(d.codexHome, "config.toml") },
42894
- { run: migrateClaudeConfig, file: import_node_path8.default.join(d.home, ".claude.json") }
43115
+ { run: migrateEcosystemConfig, file: import_node_path9.default.join(d.home, ".mrrlin", "ecosystem.config.cjs") },
43116
+ { run: migrateCodexConfig, file: import_node_path9.default.join(d.codexHome, "config.toml") },
43117
+ { run: migrateClaudeConfig, file: import_node_path9.default.join(d.home, ".claude.json") }
42895
43118
  ];
42896
43119
  for (const step of steps) {
42897
43120
  try {
@@ -42917,8 +43140,8 @@ function migrateRetiredApiBaseUrls(deps = {}) {
42917
43140
  }
42918
43141
 
42919
43142
  // src/bridge-health.ts
42920
- var import_node_fs5 = require("node:fs");
42921
- var import_node_path9 = __toESM(require("node:path"), 1);
43143
+ var import_node_fs6 = require("node:fs");
43144
+ var import_node_path10 = __toESM(require("node:path"), 1);
42922
43145
  var SENTINEL_FILE_NAME = "bridge-health-circuit-breaker.json";
42923
43146
  var CRASH_WINDOW_MS = 60 * 60 * 1e3;
42924
43147
  var MAX_CRASHES_PER_WINDOW = 3;
@@ -42930,9 +43153,9 @@ function isCrashSentinel(value) {
42930
43153
  return typeof candidate.crashCount === "number" && Number.isInteger(candidate.crashCount) && candidate.crashCount >= 0 && typeof candidate.windowStartedAt === "string";
42931
43154
  }
42932
43155
  async function readCrashSentinel(stateDir, now = Date.now) {
42933
- const sentinelPath = import_node_path9.default.join(stateDir, SENTINEL_FILE_NAME);
43156
+ const sentinelPath = import_node_path10.default.join(stateDir, SENTINEL_FILE_NAME);
42934
43157
  try {
42935
- const raw = await import_node_fs5.promises.readFile(sentinelPath, "utf8");
43158
+ const raw = await import_node_fs6.promises.readFile(sentinelPath, "utf8");
42936
43159
  const parsed = JSON.parse(raw);
42937
43160
  if (isCrashSentinel(parsed)) return parsed;
42938
43161
  } catch {
@@ -42940,11 +43163,11 @@ async function readCrashSentinel(stateDir, now = Date.now) {
42940
43163
  return { crashCount: 0, windowStartedAt: new Date(now()).toISOString() };
42941
43164
  }
42942
43165
  async function writeCrashSentinel(stateDir, sentinel) {
42943
- await import_node_fs5.promises.mkdir(stateDir, { recursive: true });
42944
- const sentinelPath = import_node_path9.default.join(stateDir, SENTINEL_FILE_NAME);
43166
+ await import_node_fs6.promises.mkdir(stateDir, { recursive: true });
43167
+ const sentinelPath = import_node_path10.default.join(stateDir, SENTINEL_FILE_NAME);
42945
43168
  const tmpPath = `${sentinelPath}.tmp-${process.pid}-${Math.random().toString(36).slice(2)}`;
42946
- await import_node_fs5.promises.writeFile(tmpPath, JSON.stringify(sentinel), "utf8");
42947
- await import_node_fs5.promises.rename(tmpPath, sentinelPath);
43169
+ await import_node_fs6.promises.writeFile(tmpPath, JSON.stringify(sentinel), "utf8");
43170
+ await import_node_fs6.promises.rename(tmpPath, sentinelPath);
42948
43171
  }
42949
43172
  function withTimeout(fn, ms = DEFAULT_OPERATION_TIMEOUT_MS) {
42950
43173
  const controller = new AbortController();
@@ -43271,12 +43494,12 @@ function startSchedulerTickLoop(deps) {
43271
43494
 
43272
43495
  // src/retention/pruner.ts
43273
43496
  var import_promises4 = require("node:fs/promises");
43274
- var import_node_path10 = __toESM(require("node:path"), 1);
43497
+ var import_node_path11 = __toESM(require("node:path"), 1);
43275
43498
  function protectedDayFloor(protectedSinceMs) {
43276
43499
  return new Date(protectedSinceMs).toISOString().slice(0, 10);
43277
43500
  }
43278
43501
  async function prune(stateDir, bounds) {
43279
- const logsDir = import_node_path10.default.join(stateDir, "logs");
43502
+ const logsDir = import_node_path11.default.join(stateDir, "logs");
43280
43503
  let entries;
43281
43504
  try {
43282
43505
  entries = await (0, import_promises4.readdir)(logsDir);
@@ -43292,7 +43515,7 @@ async function prune(stateDir, bounds) {
43292
43515
  for (const entry of entries) {
43293
43516
  const m = bridgeRe.exec(entry);
43294
43517
  if (!m?.[1]) continue;
43295
- const fullPath = import_node_path10.default.join(logsDir, entry);
43518
+ const fullPath = import_node_path11.default.join(logsDir, entry);
43296
43519
  const s = await (0, import_promises4.stat)(fullPath);
43297
43520
  files.push({ day: m[1], size: s.size, fullPath });
43298
43521
  }
@@ -43301,7 +43524,7 @@ async function prune(stateDir, bounds) {
43301
43524
  const reasonByDay = {};
43302
43525
  let bytesRemoved = 0;
43303
43526
  async function isDaySafeToDelete(day) {
43304
- const telemetryDir = import_node_path10.default.join(stateDir, "telemetry");
43527
+ const telemetryDir = import_node_path11.default.join(stateDir, "telemetry");
43305
43528
  let telemetryEntries;
43306
43529
  try {
43307
43530
  telemetryEntries = await (0, import_promises4.readdir)(telemetryDir);
@@ -43317,7 +43540,7 @@ async function prune(stateDir, bounds) {
43317
43540
  }
43318
43541
  if (projectSlugs.length === 0) return true;
43319
43542
  for (const slug of projectSlugs) {
43320
- const markerPath = import_node_path10.default.join(telemetryDir, `.processed-${slug}-${day}`);
43543
+ const markerPath = import_node_path11.default.join(telemetryDir, `.processed-${slug}-${day}`);
43321
43544
  try {
43322
43545
  await (0, import_promises4.stat)(markerPath);
43323
43546
  } catch (err) {
@@ -43367,7 +43590,7 @@ async function prune(stateDir, bounds) {
43367
43590
  const budgetOvershootBytes = Math.max(0, totalSize2 - budgetBytes);
43368
43591
  await emitPruneLog(stateDir, daysRemoved, reasonByDay, bytesRemoved, oldestDayRemaining);
43369
43592
  if (daysRemoved.length > 0) {
43370
- const sessionsPath = import_node_path10.default.join(logsDir, ".sessions.json");
43593
+ const sessionsPath = import_node_path11.default.join(logsDir, ".sessions.json");
43371
43594
  let sessionsObj = {};
43372
43595
  let fileExists = true;
43373
43596
  try {
@@ -43389,8 +43612,8 @@ async function prune(stateDir, bounds) {
43389
43612
  return { daysRemoved, reasonByDay, bytesRemoved, oldestDayRemaining, budgetOvershootBytes };
43390
43613
  }
43391
43614
  async function emitPruneLog(stateDir, daysRemoved, reasonByDay, bytesRemoved, oldestDayRemaining) {
43392
- const logsDir = import_node_path10.default.join(stateDir, "logs");
43393
- const logPath = import_node_path10.default.join(logsDir, ".pruned.jsonl");
43615
+ const logsDir = import_node_path11.default.join(stateDir, "logs");
43616
+ const logPath = import_node_path11.default.join(logsDir, ".pruned.jsonl");
43394
43617
  await (0, import_promises4.mkdir)(logsDir, { recursive: true });
43395
43618
  const record2 = { ts: Date.now(), dir: "logs", daysRemoved, reasonByDay, bytesRemoved, oldestDayRemaining };
43396
43619
  await (0, import_promises4.appendFile)(logPath, `${JSON.stringify(record2)}
@@ -43400,7 +43623,7 @@ async function emitPruneLog(stateDir, daysRemoved, reasonByDay, bytesRemoved, ol
43400
43623
  // src/telemetry/turn-aggregator.ts
43401
43624
  var import_node_crypto3 = require("node:crypto");
43402
43625
  var import_promises5 = require("node:fs/promises");
43403
- var import_node_path11 = require("node:path");
43626
+ var import_node_path12 = require("node:path");
43404
43627
  var BRIDGE_FILE_RE = /^bridge-(\d{4}-\d{2}-\d{2})\.jsonl$/;
43405
43628
  var PLUMBING_COUNTER_KEY = {
43406
43629
  socket_close: "socketCloses",
@@ -43429,7 +43652,7 @@ function inheritSlug(seeds, index) {
43429
43652
  return (preceding ?? following)?.slug;
43430
43653
  }
43431
43654
  async function foldClosedDays(stateDir, today) {
43432
- const logsDir = (0, import_node_path11.join)(stateDir, "logs");
43655
+ const logsDir = (0, import_node_path12.join)(stateDir, "logs");
43433
43656
  let entries;
43434
43657
  try {
43435
43658
  entries = await (0, import_promises5.readdir)(logsDir);
@@ -43441,7 +43664,7 @@ async function foldClosedDays(stateDir, today) {
43441
43664
  if (!m) continue;
43442
43665
  const day = m[1];
43443
43666
  if (day === today) continue;
43444
- const raw = await (0, import_promises5.readFile)((0, import_node_path11.join)(logsDir, entry), "utf8");
43667
+ const raw = await (0, import_promises5.readFile)((0, import_node_path12.join)(logsDir, entry), "utf8");
43445
43668
  const groups = /* @__PURE__ */ new Map();
43446
43669
  let groupCounter = 0;
43447
43670
  for (const line of raw.split("\n")) {
@@ -43552,10 +43775,10 @@ async function foldClosedDays(stateDir, today) {
43552
43775
  rowsByProject.set(slug, rows);
43553
43776
  }
43554
43777
  if (rowsByProject.size === 0) continue;
43555
- const telemetryDir = (0, import_node_path11.join)(stateDir, "telemetry");
43778
+ const telemetryDir = (0, import_node_path12.join)(stateDir, "telemetry");
43556
43779
  await (0, import_promises5.mkdir)(telemetryDir, { recursive: true });
43557
43780
  for (const [slug, rows] of rowsByProject) {
43558
- const finalPath = (0, import_node_path11.join)(telemetryDir, `rows-${slug}-${day}.jsonl`);
43781
+ const finalPath = (0, import_node_path12.join)(telemetryDir, `rows-${slug}-${day}.jsonl`);
43559
43782
  const tmpPath = `${finalPath}.tmp-${process.pid}-${(0, import_node_crypto3.randomBytes)(6).toString("hex")}`;
43560
43783
  try {
43561
43784
  await (0, import_promises5.writeFile)(tmpPath, rows.map((r) => JSON.stringify(r)).join("\n") + "\n", "utf8");
@@ -43570,22 +43793,22 @@ async function foldClosedDays(stateDir, today) {
43570
43793
 
43571
43794
  // src/telemetry/daily-uploader.ts
43572
43795
  var import_promises6 = require("node:fs/promises");
43573
- var import_node_path16 = require("node:path");
43796
+ var import_node_path17 = require("node:path");
43574
43797
 
43575
43798
  // src/consensus/wiring.ts
43576
43799
  var import_node_crypto4 = __toESM(require("node:crypto"), 1);
43577
- var import_node_fs8 = __toESM(require("node:fs"), 1);
43578
- var import_node_path14 = __toESM(require("node:path"), 1);
43800
+ var import_node_fs9 = __toESM(require("node:fs"), 1);
43801
+ var import_node_path15 = __toESM(require("node:path"), 1);
43579
43802
  var import_node_url2 = require("node:url");
43580
43803
 
43581
43804
  // src/consensus/gate-usage-log.ts
43582
- var import_node_fs6 = require("node:fs");
43583
- var import_node_path12 = require("node:path");
43805
+ var import_node_fs7 = require("node:fs");
43806
+ var import_node_path13 = require("node:path");
43584
43807
  function recordGateCall(stateDir, projectSlug, record2) {
43585
43808
  try {
43586
- const dir = (0, import_node_path12.join)(stateDir, "telemetry");
43587
- (0, import_node_fs6.mkdirSync)(dir, { recursive: true });
43588
- (0, import_node_fs6.appendFileSync)((0, import_node_path12.join)(dir, gateFileName(projectSlug, record2.day)), `${JSON.stringify(record2)}
43809
+ const dir = (0, import_node_path13.join)(stateDir, "telemetry");
43810
+ (0, import_node_fs7.mkdirSync)(dir, { recursive: true });
43811
+ (0, import_node_fs7.appendFileSync)((0, import_node_path13.join)(dir, gateFileName(projectSlug, record2.day)), `${JSON.stringify(record2)}
43589
43812
  `, "utf8");
43590
43813
  } catch {
43591
43814
  }
@@ -44451,12 +44674,12 @@ ${issuesBlock}`,
44451
44674
  }
44452
44675
 
44453
44676
  // src/consensus/sterile-cwd.ts
44454
- var import_node_fs7 = require("node:fs");
44455
- var import_node_os7 = require("node:os");
44456
- var import_node_path13 = require("node:path");
44677
+ var import_node_fs8 = require("node:fs");
44678
+ var import_node_os8 = require("node:os");
44679
+ var import_node_path14 = require("node:path");
44457
44680
  var sterileDir = null;
44458
44681
  function sterileCwd() {
44459
- sterileDir ??= (0, import_node_fs7.mkdtempSync)((0, import_node_path13.join)((0, import_node_os7.tmpdir)(), "mrrlin-gate-"));
44682
+ sterileDir ??= (0, import_node_fs8.mkdtempSync)((0, import_node_path14.join)((0, import_node_os8.tmpdir)(), "mrrlin-gate-"));
44460
44683
  return sterileDir;
44461
44684
  }
44462
44685
 
@@ -44692,15 +44915,15 @@ ${res.stdout}${res.stderr}`);
44692
44915
  var import_meta2 = {};
44693
44916
  function getPersonasDir() {
44694
44917
  if (typeof __dirname !== "undefined") {
44695
- return import_node_path14.default.join(__dirname, "consensus", "personas");
44918
+ return import_node_path15.default.join(__dirname, "consensus", "personas");
44696
44919
  }
44697
- return import_node_path14.default.join(import_node_path14.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url)), "personas");
44920
+ return import_node_path15.default.join(import_node_path15.default.dirname((0, import_node_url2.fileURLToPath)(import_meta2.url)), "personas");
44698
44921
  }
44699
44922
  var personaCache = /* @__PURE__ */ new Map();
44700
44923
  function loadPersona(name) {
44701
44924
  const cached2 = personaCache.get(name);
44702
44925
  if (cached2 !== void 0) return cached2;
44703
- const content = import_node_fs8.default.readFileSync(import_node_path14.default.join(getPersonasDir(), `${name}.md`), "utf8");
44926
+ const content = import_node_fs9.default.readFileSync(import_node_path15.default.join(getPersonasDir(), `${name}.md`), "utf8");
44704
44927
  personaCache.set(name, content);
44705
44928
  return content;
44706
44929
  }
@@ -45289,8 +45512,8 @@ You revise a deliverable to address the accepted issues so it satisfies the acce
45289
45512
  function isRecord2(v) {
45290
45513
  return v !== null && typeof v === "object";
45291
45514
  }
45292
- function resolvePath(root, path24) {
45293
- const parts = path24.split(".");
45515
+ function resolvePath(root, path25) {
45516
+ const parts = path25.split(".");
45294
45517
  let cur = root;
45295
45518
  for (let i = 0; i < parts.length - 1; i += 1) {
45296
45519
  const part = parts[i];
@@ -45358,9 +45581,9 @@ async function gate(artifact, prose, ctx) {
45358
45581
  return { ok: true, gated: true, artifact: withheldExcerptClone(artifact) };
45359
45582
  }
45360
45583
  const maskedClone = typeof structuredClone === "function" ? structuredClone(artifact) : JSON.parse(JSON.stringify(artifact));
45361
- for (const { path: path24, masked } of fields) {
45362
- const target = resolvePath(maskedClone, path24);
45363
- if (!target) throw new Error(`pii-gate: path "${path24}" failed to resolve on the clone after validating on the original`);
45584
+ for (const { path: path25, masked } of fields) {
45585
+ const target = resolvePath(maskedClone, path25);
45586
+ if (!target) throw new Error(`pii-gate: path "${path25}" failed to resolve on the clone after validating on the original`);
45364
45587
  target.parent[target.key] = masked;
45365
45588
  }
45366
45589
  return { ok: true, gated: false, artifact: maskedClone };
@@ -45368,23 +45591,23 @@ async function gate(artifact, prose, ctx) {
45368
45591
 
45369
45592
  // src/telemetry/installation-id.ts
45370
45593
  var import_node_crypto5 = require("node:crypto");
45371
- var import_node_fs9 = require("node:fs");
45372
- var import_node_path15 = require("node:path");
45594
+ var import_node_fs10 = require("node:fs");
45595
+ var import_node_path16 = require("node:path");
45373
45596
  var FILE_NAME = "installation-id";
45374
45597
  var UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
45375
45598
  var cache = /* @__PURE__ */ new Map();
45376
45599
  function resolveInstallationId(stateDir) {
45377
45600
  const cached2 = cache.get(stateDir);
45378
45601
  if (cached2 !== void 0) return cached2;
45379
- const path24 = (0, import_node_path15.join)(stateDir, FILE_NAME);
45602
+ const path25 = (0, import_node_path16.join)(stateDir, FILE_NAME);
45380
45603
  let id;
45381
45604
  try {
45382
- id = (0, import_node_fs9.readFileSync)(path24, "utf8").trim();
45605
+ id = (0, import_node_fs10.readFileSync)(path25, "utf8").trim();
45383
45606
  if (!UUID.test(id)) throw new Error("unusable");
45384
45607
  } catch {
45385
45608
  id = (0, import_node_crypto5.randomUUID)();
45386
- (0, import_node_fs9.mkdirSync)((0, import_node_path15.dirname)(path24), { recursive: true });
45387
- (0, import_node_fs9.writeFileSync)(path24, `${id}
45609
+ (0, import_node_fs10.mkdirSync)((0, import_node_path16.dirname)(path25), { recursive: true });
45610
+ (0, import_node_fs10.writeFileSync)(path25, `${id}
45388
45611
  `, "utf8");
45389
45612
  }
45390
45613
  cache.set(stateDir, id);
@@ -45401,7 +45624,7 @@ function truncateCause(err) {
45401
45624
  return `${message.slice(0, MAX_CAUSE_CHARS - 3)}...`;
45402
45625
  }
45403
45626
  async function uploadPendingDays(stateDir, client, bridgeHealth, gateCtx) {
45404
- const telemetryDir = (0, import_node_path16.join)(stateDir, "telemetry");
45627
+ const telemetryDir = (0, import_node_path17.join)(stateDir, "telemetry");
45405
45628
  let files;
45406
45629
  try {
45407
45630
  files = await (0, import_promises6.readdir)(telemetryDir);
@@ -45417,14 +45640,14 @@ async function uploadPendingDays(stateDir, client, bridgeHealth, gateCtx) {
45417
45640
  const [, projectSlug, day] = match;
45418
45641
  const key = `${projectSlug}\0${day}`;
45419
45642
  const entry = discovered.get(key) ?? { projectSlug, day, rowsPath: null };
45420
- if (rowsMatch) entry.rowsPath = (0, import_node_path16.join)(telemetryDir, file2);
45643
+ if (rowsMatch) entry.rowsPath = (0, import_node_path17.join)(telemetryDir, file2);
45421
45644
  discovered.set(key, entry);
45422
45645
  }
45423
45646
  const today = telemetryDay();
45424
45647
  const pending = [];
45425
45648
  const deferred = [];
45426
45649
  for (const { projectSlug, day, rowsPath } of discovered.values()) {
45427
- const markerPath = (0, import_node_path16.join)(telemetryDir, `.processed-${projectSlug}-${day}`);
45650
+ const markerPath = (0, import_node_path17.join)(telemetryDir, `.processed-${projectSlug}-${day}`);
45428
45651
  if (rowsPath === null && day >= today) {
45429
45652
  try {
45430
45653
  await (0, import_promises6.access)(markerPath);
@@ -45444,7 +45667,7 @@ async function uploadPendingDays(stateDir, client, bridgeHealth, gateCtx) {
45444
45667
  const fullUnprocessed = [...pending.map((p) => ({ projectSlug: p.projectSlug, day: p.day })), ...deferred];
45445
45668
  pending.sort((a, b) => a.day.localeCompare(b.day));
45446
45669
  for (const cur of pending) {
45447
- const failurePath = (0, import_node_path16.join)(telemetryDir, `.failed-${cur.projectSlug}-${cur.day}.json`);
45670
+ const failurePath = (0, import_node_path17.join)(telemetryDir, `.failed-${cur.projectSlug}-${cur.day}.json`);
45448
45671
  let failureState = null;
45449
45672
  try {
45450
45673
  const data = await (0, import_promises6.readFile)(failurePath, "utf8");
@@ -45478,7 +45701,7 @@ async function uploadPendingDays(stateDir, client, bridgeHealth, gateCtx) {
45478
45701
  }
45479
45702
  const gateCalls = [];
45480
45703
  try {
45481
- const rawGate = await (0, import_promises6.readFile)((0, import_node_path16.join)(telemetryDir, gateFileName(cur.projectSlug, cur.day)), "utf8");
45704
+ const rawGate = await (0, import_promises6.readFile)((0, import_node_path17.join)(telemetryDir, gateFileName(cur.projectSlug, cur.day)), "utf8");
45482
45705
  for (const line of rawGate.split("\n")) {
45483
45706
  if (!line.trim()) continue;
45484
45707
  try {
@@ -45900,7 +46123,7 @@ function setSelectedProvider(value) {
45900
46123
  // src/execution-consumer.ts
45901
46124
  var import_node_child_process12 = require("node:child_process");
45902
46125
  var import_node_crypto7 = __toESM(require("node:crypto"), 1);
45903
- var import_node_path19 = __toESM(require("node:path"), 1);
46126
+ var import_node_path20 = __toESM(require("node:path"), 1);
45904
46127
  var import_node_util = require("node:util");
45905
46128
 
45906
46129
  // src/consensus/deliverable-gate-outcome.ts
@@ -47196,18 +47419,18 @@ async function awaitTurnWithDeadline(opts) {
47196
47419
 
47197
47420
  // src/worktree.ts
47198
47421
  var import_node_child_process11 = require("node:child_process");
47199
- var import_node_fs11 = require("node:fs");
47200
- var import_node_os8 = require("node:os");
47201
- var import_node_path18 = require("node:path");
47422
+ var import_node_fs12 = require("node:fs");
47423
+ var import_node_os9 = require("node:os");
47424
+ var import_node_path19 = require("node:path");
47202
47425
 
47203
47426
  // src/checkout-lock.ts
47204
- var import_node_fs10 = require("node:fs");
47205
- var import_node_path17 = require("node:path");
47427
+ var import_node_fs11 = require("node:fs");
47428
+ var import_node_path18 = require("node:path");
47206
47429
  var import_proper_lockfile = __toESM(require_proper_lockfile(), 1);
47207
47430
  async function withCheckoutLock(locksDir, slug, fn) {
47208
- (0, import_node_fs10.mkdirSync)(locksDir, { recursive: true });
47209
- const target = (0, import_node_path17.join)(locksDir, `${slug}.lock`);
47210
- if (!(0, import_node_fs10.existsSync)(target)) (0, import_node_fs10.writeFileSync)(target, "");
47431
+ (0, import_node_fs11.mkdirSync)(locksDir, { recursive: true });
47432
+ const target = (0, import_node_path18.join)(locksDir, `${slug}.lock`);
47433
+ if (!(0, import_node_fs11.existsSync)(target)) (0, import_node_fs11.writeFileSync)(target, "");
47211
47434
  const release = await import_proper_lockfile.default.lock(target, {
47212
47435
  retries: { retries: 600, factor: 1, minTimeout: 100, maxTimeout: 100 },
47213
47436
  stale: 5 * 6e4
@@ -47232,12 +47455,12 @@ function git(checkout, args) {
47232
47455
  });
47233
47456
  }
47234
47457
  async function createRunWorktree(opts) {
47235
- const worktreePath = (0, import_node_path18.join)(opts.worktreeRoot, opts.slug, opts.runId);
47458
+ const worktreePath = (0, import_node_path19.join)(opts.worktreeRoot, opts.slug, opts.runId);
47236
47459
  await withCheckoutLock(opts.locksDir, opts.slug, async () => {
47237
- (0, import_node_fs11.mkdirSync)(opts.worktreeRoot, { recursive: true });
47460
+ (0, import_node_fs12.mkdirSync)(opts.worktreeRoot, { recursive: true });
47238
47461
  try {
47239
47462
  git(opts.checkout, ["fetch", "origin", opts.defaultBranch]);
47240
- if (!(0, import_node_fs11.existsSync)(worktreePath)) {
47463
+ if (!(0, import_node_fs12.existsSync)(worktreePath)) {
47241
47464
  git(opts.checkout, [
47242
47465
  "worktree",
47243
47466
  "add",
@@ -47309,15 +47532,15 @@ async function doPushRunBranch(opts, execGit) {
47309
47532
  if (localConfig.trim()) {
47310
47533
  throw new Error(`push aborted: agent-controlled git config present in worktree: ${localConfig.trim().split("\n")[0]}`);
47311
47534
  }
47312
- const dir = (0, import_node_fs11.mkdtempSync)((0, import_node_path18.join)((0, import_node_os8.tmpdir)(), "mrrlin-push-"));
47313
- const askpass = (0, import_node_path18.join)(dir, "askpass");
47535
+ const dir = (0, import_node_fs12.mkdtempSync)((0, import_node_path19.join)((0, import_node_os9.tmpdir)(), "mrrlin-push-"));
47536
+ const askpass = (0, import_node_path19.join)(dir, "askpass");
47314
47537
  try {
47315
- (0, import_node_fs11.writeFileSync)(
47538
+ (0, import_node_fs12.writeFileSync)(
47316
47539
  askpass,
47317
47540
  '#!/bin/sh\ncase "$1" in *[Uu]sername*) printf %s "x-access-token" ;; *) printf %s "$MRRLIN_PUSH_TOKEN" ;; esac\n',
47318
47541
  { mode: 320 }
47319
47542
  );
47320
- (0, import_node_fs11.chmodSync)(askpass, 320);
47543
+ (0, import_node_fs12.chmodSync)(askpass, 320);
47321
47544
  execGit(
47322
47545
  [
47323
47546
  "-C",
@@ -47336,18 +47559,18 @@ async function doPushRunBranch(opts, execGit) {
47336
47559
  );
47337
47560
  return { pushedSha: localSha };
47338
47561
  } finally {
47339
- (0, import_node_fs11.rmSync)(dir, { recursive: true, force: true });
47562
+ (0, import_node_fs12.rmSync)(dir, { recursive: true, force: true });
47340
47563
  }
47341
47564
  }
47342
47565
  async function sweepOrphanWorktrees(opts) {
47343
47566
  const reaped = [];
47344
47567
  const ownedPrefix = (() => {
47345
47568
  try {
47346
- return (0, import_node_fs11.realpathSync)(opts.worktreeRoot);
47569
+ return (0, import_node_fs12.realpathSync)(opts.worktreeRoot);
47347
47570
  } catch {
47348
47571
  return opts.worktreeRoot;
47349
47572
  }
47350
- })() + import_node_path18.sep + opts.slug + import_node_path18.sep;
47573
+ })() + import_node_path19.sep + opts.slug + import_node_path19.sep;
47351
47574
  await withCheckoutLock(opts.locksDir, opts.slug, async () => {
47352
47575
  const listing = git(opts.checkout, ["worktree", "list", "--porcelain"]);
47353
47576
  for (const block of listing.split("\n\n")) {
@@ -47870,8 +48093,8 @@ function newArtifactId() {
47870
48093
  return `EA-${import_node_crypto7.default.randomUUID()}`;
47871
48094
  }
47872
48095
  var BLAST_RADIUS_FLOOR_PATTERNS = [/^supabase\/migrations\//, /^packages\/db\/src\/schema\.ts$/];
47873
- function isBlastRadiusFloorPath(path24) {
47874
- return BLAST_RADIUS_FLOOR_PATTERNS.some((re) => re.test(path24));
48096
+ function isBlastRadiusFloorPath(path25) {
48097
+ return BLAST_RADIUS_FLOOR_PATTERNS.some((re) => re.test(path25));
47875
48098
  }
47876
48099
  var execFileAsync = (0, import_node_util.promisify)(import_node_child_process12.execFile);
47877
48100
  async function defaultListRunDiffPaths(opts) {
@@ -48135,7 +48358,7 @@ async function driveRun(deps, projectSlug, runId) {
48135
48358
  task,
48136
48359
  runId,
48137
48360
  leaseId,
48138
- `capability_not_routed: run ${runId} targets ${task.id}, which requires artifact kind "${kind}" -- that kind has no capability at all`,
48361
+ `capability_not_routed: run ${runId} targets ${task.id}, ${describeCapabilityRefusal({ reason: "blocked_kind", projectSlug, artifactKind: kind })}`,
48139
48362
  "capability_not_routed"
48140
48363
  );
48141
48364
  return;
@@ -48148,7 +48371,12 @@ async function driveRun(deps, projectSlug, runId) {
48148
48371
  task,
48149
48372
  runId,
48150
48373
  leaseId,
48151
- `capability_not_routed: run ${runId} targets ${task.id}, which requires artifact kind "${kind}" -- no route (${routeResolution.reason})`,
48374
+ // Consensus round 1 (chunk 4): capability was omitted here, so no_route/no_grant/
48375
+ // project_mismatch's action text (which interpolates it) fell back to the literal string
48376
+ // "the requested capability" instead of naming "wiki"/"artifacts"/"git" -- resolveKindCapability
48377
+ // is non-null on this branch (the blocked_kind check above already returned if it were),
48378
+ // matching deliverBuiltIn's identical call in tools.ts.
48379
+ `capability_not_routed: run ${runId} targets ${task.id}, ${describeCapabilityRefusal({ reason: routeResolution.reason, projectSlug, artifactKind: kind, capability: resolveKindCapability(kind), detail: routeResolution.message })}`,
48152
48380
  "capability_not_routed"
48153
48381
  );
48154
48382
  return;
@@ -49496,8 +49724,8 @@ async function runBackstopSweep(deps, drive = (slug, id) => driveRun(deps, slug,
49496
49724
  function isRunRecoverableByThisBridge(run3, worktreeRoot) {
49497
49725
  if (!worktreeRoot) return true;
49498
49726
  if (!run3.worktreeId) return false;
49499
- const relative = import_node_path19.default.relative(import_node_path19.default.resolve(worktreeRoot), import_node_path19.default.resolve(run3.worktreeId));
49500
- return relative === "" || relative.length > 0 && !relative.startsWith("..") && !import_node_path19.default.isAbsolute(relative);
49727
+ const relative = import_node_path20.default.relative(import_node_path20.default.resolve(worktreeRoot), import_node_path20.default.resolve(run3.worktreeId));
49728
+ return relative === "" || relative.length > 0 && !relative.startsWith("..") && !import_node_path20.default.isAbsolute(relative);
49501
49729
  }
49502
49730
  async function deployGateHandoff(deps, projectSlug, task, runId, reason, leaseId) {
49503
49731
  await deps.client.updateExecutionRun(projectSlug, runId, { status: "failed", finishedAt: (/* @__PURE__ */ new Date()).toISOString(), leaseId: leaseId ?? void 0 }).catch(() => {
@@ -49546,9 +49774,9 @@ function getAsyncToolDescriptor(toolName) {
49546
49774
  }
49547
49775
 
49548
49776
  // src/bridge-log.ts
49549
- var import_node_fs12 = require("node:fs");
49777
+ var import_node_fs13 = require("node:fs");
49550
49778
  var import_promises7 = require("node:fs/promises");
49551
- var import_node_path20 = require("node:path");
49779
+ var import_node_path21 = require("node:path");
49552
49780
 
49553
49781
  // src/redact.ts
49554
49782
  var REDACTED = "[REDACTED]";
@@ -49824,14 +50052,14 @@ function resolvePromptsEnabled(env = process.env) {
49824
50052
  }
49825
50053
  function createBridgeLogger(stateDir, env = process.env) {
49826
50054
  if (!resolveBridgeLogEnabled(env)) return NOOP_LOGGER;
49827
- const logsDir = (0, import_node_path20.join)(stateDir, "logs");
50055
+ const logsDir = (0, import_node_path21.join)(stateDir, "logs");
49828
50056
  try {
49829
- (0, import_node_fs12.mkdirSync)(logsDir, { recursive: true });
50057
+ (0, import_node_fs13.mkdirSync)(logsDir, { recursive: true });
49830
50058
  } catch {
49831
50059
  return NOOP_LOGGER;
49832
50060
  }
49833
50061
  const includePrompts = resolvePromptsEnabled(env);
49834
- const fileFor = () => (0, import_node_path20.join)(logsDir, `bridge-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.jsonl`);
50062
+ const fileFor = () => (0, import_node_path21.join)(logsDir, `bridge-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}.jsonl`);
49835
50063
  const MAX_TRACKED_SESSIONS = 64;
49836
50064
  const contextSlugBySession = /* @__PURE__ */ new Map();
49837
50065
  const rememberContextSlug = (sessionId, payload) => {
@@ -49872,10 +50100,10 @@ function createBridgeLogger(stateDir, env = process.env) {
49872
50100
  return { isGap, isNewTurn };
49873
50101
  };
49874
50102
  const gainDay = (sessionId) => {
49875
- const sessionsPath = (0, import_node_path20.join)(logsDir, ".sessions.json");
50103
+ const sessionsPath = (0, import_node_path21.join)(logsDir, ".sessions.json");
49876
50104
  let sessionsObj = {};
49877
50105
  try {
49878
- const parsed = JSON.parse((0, import_node_fs12.readFileSync)(sessionsPath, "utf8"));
50106
+ const parsed = JSON.parse((0, import_node_fs13.readFileSync)(sessionsPath, "utf8"));
49879
50107
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) sessionsObj = parsed;
49880
50108
  } catch {
49881
50109
  sessionsObj = {};
@@ -49885,8 +50113,8 @@ function createBridgeLogger(stateDir, env = process.env) {
49885
50113
  if (idsToday.includes(sessionId)) return;
49886
50114
  sessionsObj[day] = [...idsToday, sessionId];
49887
50115
  const tmpPath = `${sessionsPath}.tmp`;
49888
- (0, import_node_fs12.writeFileSync)(tmpPath, JSON.stringify(sessionsObj));
49889
- (0, import_node_fs12.renameSync)(tmpPath, sessionsPath);
50116
+ (0, import_node_fs13.writeFileSync)(tmpPath, JSON.stringify(sessionsObj));
50117
+ (0, import_node_fs13.renameSync)(tmpPath, sessionsPath);
49890
50118
  };
49891
50119
  const write = (dir, rec) => {
49892
50120
  try {
@@ -49977,7 +50205,7 @@ function createBridgeLogger(stateDir, env = process.env) {
49977
50205
  ...recordingObligationUnresolved ? { recordingObligationUnresolved } : {},
49978
50206
  ...recordingObligationMultiResolve ? { recordingObligationMultiResolve } : {}
49979
50207
  }) + "\n";
49980
- (0, import_node_fs12.appendFileSync)(fileFor(), line);
50208
+ (0, import_node_fs13.appendFileSync)(fileFor(), line);
49981
50209
  if (rec.sessionId !== null) gainDay(rec.sessionId);
49982
50210
  } catch {
49983
50211
  }
@@ -49990,7 +50218,7 @@ function createBridgeLogger(stateDir, env = process.env) {
49990
50218
  };
49991
50219
  }
49992
50220
  async function findSessionDays(stateDir, sessionId) {
49993
- const sessionsPath = (0, import_node_path20.join)(stateDir, "logs", ".sessions.json");
50221
+ const sessionsPath = (0, import_node_path21.join)(stateDir, "logs", ".sessions.json");
49994
50222
  let sessionsObj;
49995
50223
  try {
49996
50224
  const parsed = JSON.parse(await (0, import_promises7.readFile)(sessionsPath, "utf8"));
@@ -50172,12 +50400,12 @@ async function runAsyncBackstopSweep(deps, drive = (slug, jobId) => driveAsyncJo
50172
50400
  }
50173
50401
 
50174
50402
  // src/state-dir.ts
50175
- var import_node_os9 = __toESM(require("node:os"), 1);
50176
- var import_node_path21 = __toESM(require("node:path"), 1);
50403
+ var import_node_os10 = __toESM(require("node:os"), 1);
50404
+ var import_node_path22 = __toESM(require("node:path"), 1);
50177
50405
  function resolveStateDir(env = process.env) {
50178
50406
  const codexHome = env.CODEX_HOME;
50179
- if (codexHome) return import_node_path21.default.join(codexHome, "mrrlin", "director-bridge");
50180
- return import_node_path21.default.join(import_node_os9.default.homedir(), ".mrrlin", "director-bridge");
50407
+ if (codexHome) return import_node_path22.default.join(codexHome, "mrrlin", "director-bridge");
50408
+ return import_node_path22.default.join(import_node_os10.default.homedir(), ".mrrlin", "director-bridge");
50181
50409
  }
50182
50410
 
50183
50411
  // src/consensus/deliverable-gate.ts
@@ -50433,19 +50661,19 @@ function agentIdleMs(provider) {
50433
50661
  }
50434
50662
 
50435
50663
  // src/operator-token.ts
50436
- var import_node_fs13 = require("node:fs");
50437
- var import_node_os10 = __toESM(require("node:os"), 1);
50438
- var import_node_path22 = __toESM(require("node:path"), 1);
50664
+ var import_node_fs14 = require("node:fs");
50665
+ var import_node_os11 = __toESM(require("node:os"), 1);
50666
+ var import_node_path23 = __toESM(require("node:path"), 1);
50439
50667
  function operatorDir() {
50440
- const base = process.env.CODEX_HOME ? import_node_path22.default.join(process.env.CODEX_HOME, "mrrlin") : import_node_path22.default.join(import_node_os10.default.homedir(), ".mrrlin");
50668
+ const base = process.env.CODEX_HOME ? import_node_path23.default.join(process.env.CODEX_HOME, "mrrlin") : import_node_path23.default.join(import_node_os11.default.homedir(), ".mrrlin");
50441
50669
  return base;
50442
50670
  }
50443
50671
  function operatorTokenPath() {
50444
- return import_node_path22.default.join(operatorDir(), "operator-token");
50672
+ return import_node_path23.default.join(operatorDir(), "operator-token");
50445
50673
  }
50446
50674
  function readOperatorToken() {
50447
50675
  try {
50448
- const token = (0, import_node_fs13.readFileSync)(operatorTokenPath(), "utf8").trim();
50676
+ const token = (0, import_node_fs14.readFileSync)(operatorTokenPath(), "utf8").trim();
50449
50677
  return token.length > 0 ? token : null;
50450
50678
  } catch {
50451
50679
  return null;
@@ -50453,24 +50681,24 @@ function readOperatorToken() {
50453
50681
  }
50454
50682
  function persistOperatorToken(token) {
50455
50683
  const dir = operatorDir();
50456
- (0, import_node_fs13.mkdirSync)(dir, { recursive: true, mode: 448 });
50457
- (0, import_node_fs13.writeFileSync)(operatorTokenPath(), `${token.trim()}
50684
+ (0, import_node_fs14.mkdirSync)(dir, { recursive: true, mode: 448 });
50685
+ (0, import_node_fs14.writeFileSync)(operatorTokenPath(), `${token.trim()}
50458
50686
  `, { encoding: "utf8", mode: 384 });
50459
50687
  }
50460
50688
  function agentCredentialPath() {
50461
- return import_node_path22.default.join(operatorDir(), "agent-credential");
50689
+ return import_node_path23.default.join(operatorDir(), "agent-credential");
50462
50690
  }
50463
50691
  function persistAgentSecret(secret) {
50464
50692
  const dir = operatorDir();
50465
- (0, import_node_fs13.mkdirSync)(dir, { recursive: true, mode: 448 });
50466
- (0, import_node_fs13.writeFileSync)(agentCredentialPath(), `${secret.trim()}
50693
+ (0, import_node_fs14.mkdirSync)(dir, { recursive: true, mode: 448 });
50694
+ (0, import_node_fs14.writeFileSync)(agentCredentialPath(), `${secret.trim()}
50467
50695
  `, { encoding: "utf8", mode: 384 });
50468
50696
  }
50469
50697
  function readAgentSecret() {
50470
50698
  const fromEnv = process.env.MRRLIN_AGENT_SECRET?.trim();
50471
50699
  if (fromEnv) return fromEnv;
50472
50700
  try {
50473
- const raw = (0, import_node_fs13.readFileSync)(agentCredentialPath(), "utf8").trim();
50701
+ const raw = (0, import_node_fs14.readFileSync)(agentCredentialPath(), "utf8").trim();
50474
50702
  return raw || void 0;
50475
50703
  } catch {
50476
50704
  return void 0;
@@ -50478,16 +50706,16 @@ function readAgentSecret() {
50478
50706
  }
50479
50707
 
50480
50708
  // src/thread-index.ts
50481
- var import_node_fs14 = require("node:fs");
50482
- var import_node_path23 = __toESM(require("node:path"), 1);
50709
+ var import_node_fs15 = require("node:fs");
50710
+ var import_node_path24 = __toESM(require("node:path"), 1);
50483
50711
  function threadIndexPath(stateDir) {
50484
- return import_node_path23.default.join(stateDir, "threads.json");
50712
+ return import_node_path24.default.join(stateDir, "threads.json");
50485
50713
  }
50486
50714
  function loadThreadIndex(stateDir, ttlMs, now) {
50487
50715
  const result = /* @__PURE__ */ new Map();
50488
50716
  let parsed;
50489
50717
  try {
50490
- parsed = JSON.parse((0, import_node_fs14.readFileSync)(threadIndexPath(stateDir), "utf8"));
50718
+ parsed = JSON.parse((0, import_node_fs15.readFileSync)(threadIndexPath(stateDir), "utf8"));
50491
50719
  } catch {
50492
50720
  return result;
50493
50721
  }
@@ -50510,8 +50738,8 @@ function loadThreadIndex(stateDir, ttlMs, now) {
50510
50738
  return result;
50511
50739
  }
50512
50740
  function saveThreadIndex(stateDir, entries) {
50513
- (0, import_node_fs14.mkdirSync)(stateDir, { recursive: true, mode: 448 });
50514
- (0, import_node_fs14.writeFileSync)(threadIndexPath(stateDir), `${JSON.stringify(Object.fromEntries(entries), null, 2)}
50741
+ (0, import_node_fs15.mkdirSync)(stateDir, { recursive: true, mode: 448 });
50742
+ (0, import_node_fs15.writeFileSync)(threadIndexPath(stateDir), `${JSON.stringify(Object.fromEntries(entries), null, 2)}
50515
50743
  `, {
50516
50744
  encoding: "utf8",
50517
50745
  mode: 384
@@ -50647,9 +50875,9 @@ function createToolBusyClock(opts) {
50647
50875
 
50648
50876
  // src/worker-token.ts
50649
50877
  var import_node_crypto10 = require("node:crypto");
50650
- var import_node_fs15 = require("node:fs");
50651
- var import_node_os11 = __toESM(require("node:os"), 1);
50652
- var import_node_path24 = __toESM(require("node:path"), 1);
50878
+ var import_node_fs16 = require("node:fs");
50879
+ var import_node_os12 = __toESM(require("node:os"), 1);
50880
+ var import_node_path25 = __toESM(require("node:path"), 1);
50653
50881
  var DEFAULT_WORKER_PORT = 8792;
50654
50882
  function workerPort() {
50655
50883
  const raw = process.env.MRRLIN_WORKER_PORT;
@@ -50658,15 +50886,15 @@ function workerPort() {
50658
50886
  return Number.isFinite(parsed) && parsed > 0 ? parsed : DEFAULT_WORKER_PORT;
50659
50887
  }
50660
50888
  function workerDir() {
50661
- const base = process.env.CODEX_HOME ? import_node_path24.default.join(process.env.CODEX_HOME, "mrrlin") : import_node_path24.default.join(import_node_os11.default.homedir(), ".mrrlin");
50662
- return import_node_path24.default.join(base, "worker");
50889
+ const base = process.env.CODEX_HOME ? import_node_path25.default.join(process.env.CODEX_HOME, "mrrlin") : import_node_path25.default.join(import_node_os12.default.homedir(), ".mrrlin");
50890
+ return import_node_path25.default.join(base, "worker");
50663
50891
  }
50664
50892
  function workerTokenPath() {
50665
- return import_node_path24.default.join(workerDir(), "token");
50893
+ return import_node_path25.default.join(workerDir(), "token");
50666
50894
  }
50667
50895
  function readWorkerToken() {
50668
50896
  try {
50669
- const token = (0, import_node_fs15.readFileSync)(workerTokenPath(), "utf8").trim();
50897
+ const token = (0, import_node_fs16.readFileSync)(workerTokenPath(), "utf8").trim();
50670
50898
  return token.length > 0 ? token : null;
50671
50899
  } catch {
50672
50900
  return null;
@@ -50676,18 +50904,18 @@ function readOrCreateWorkerToken() {
50676
50904
  const existing = readWorkerToken();
50677
50905
  if (existing) return existing;
50678
50906
  const dir = workerDir();
50679
- (0, import_node_fs15.mkdirSync)(dir, { recursive: true, mode: 448 });
50907
+ (0, import_node_fs16.mkdirSync)(dir, { recursive: true, mode: 448 });
50680
50908
  const token = (0, import_node_crypto10.randomBytes)(32).toString("hex");
50681
- (0, import_node_fs15.writeFileSync)(workerTokenPath(), `${token}
50909
+ (0, import_node_fs16.writeFileSync)(workerTokenPath(), `${token}
50682
50910
  `, { encoding: "utf8", mode: 384 });
50683
50911
  return token;
50684
50912
  }
50685
50913
 
50686
50914
  // src/remote-phone-relay.ts
50687
50915
  var import_node_events2 = require("node:events");
50688
- var import_node_fs16 = require("node:fs");
50689
- var import_node_os12 = require("node:os");
50690
- var import_node_path25 = require("node:path");
50916
+ var import_node_fs17 = require("node:fs");
50917
+ var import_node_os13 = require("node:os");
50918
+ var import_node_path26 = require("node:path");
50691
50919
 
50692
50920
  // ../../node_modules/.pnpm/@noble+hashes@1.3.3/node_modules/@noble/hashes/esm/cryptoNode.js
50693
50921
  var nc = __toESM(require("node:crypto"), 1);
@@ -54258,9 +54486,9 @@ var DirectorRelay = class {
54258
54486
 
54259
54487
  // src/remote-phone-relay.ts
54260
54488
  function loadOrCreateAgentDeviceKey() {
54261
- const path24 = (0, import_node_path25.join)((0, import_node_os12.homedir)(), ".mrrlin", "agent-device-key");
54489
+ const path25 = (0, import_node_path26.join)((0, import_node_os13.homedir)(), ".mrrlin", "agent-device-key");
54262
54490
  try {
54263
- const raw = JSON.parse((0, import_node_fs16.readFileSync)(path24, "utf8"));
54491
+ const raw = JSON.parse((0, import_node_fs17.readFileSync)(path25, "utf8"));
54264
54492
  if (typeof raw.priv === "string" && typeof raw.pub === "string") {
54265
54493
  return { privateKey: fromBase64Url(raw.priv), publicKey: fromBase64Url(raw.pub) };
54266
54494
  }
@@ -54268,9 +54496,9 @@ function loadOrCreateAgentDeviceKey() {
54268
54496
  }
54269
54497
  const kp = generateIdentityKeyPair();
54270
54498
  try {
54271
- (0, import_node_fs16.mkdirSync)((0, import_node_path25.join)((0, import_node_os12.homedir)(), ".mrrlin"), { recursive: true });
54272
- (0, import_node_fs16.writeFileSync)(
54273
- path24,
54499
+ (0, import_node_fs17.mkdirSync)((0, import_node_path26.join)((0, import_node_os13.homedir)(), ".mrrlin"), { recursive: true });
54500
+ (0, import_node_fs17.writeFileSync)(
54501
+ path25,
54274
54502
  JSON.stringify({ priv: toBase64Url(kp.privateKey), pub: toBase64Url(kp.publicKey) }),
54275
54503
  { mode: 384 }
54276
54504
  );
@@ -54278,10 +54506,10 @@ function loadOrCreateAgentDeviceKey() {
54278
54506
  }
54279
54507
  return kp;
54280
54508
  }
54281
- var AGENT_PAIRING_PATH = (0, import_node_path25.join)((0, import_node_os12.homedir)(), ".mrrlin", "agent-pairing.json");
54509
+ var AGENT_PAIRING_PATH = (0, import_node_path26.join)((0, import_node_os13.homedir)(), ".mrrlin", "agent-pairing.json");
54282
54510
  function loadAgentPairing() {
54283
54511
  try {
54284
- const raw = JSON.parse((0, import_node_fs16.readFileSync)(AGENT_PAIRING_PATH, "utf8"));
54512
+ const raw = JSON.parse((0, import_node_fs17.readFileSync)(AGENT_PAIRING_PATH, "utf8"));
54285
54513
  if (typeof raw.channelId === "string" && typeof raw.agentControlSecret === "string" && typeof raw.relayAuth === "string" && typeof raw.peerIdentityKey === "string") {
54286
54514
  return {
54287
54515
  channelId: raw.channelId,
@@ -54296,8 +54524,8 @@ function loadAgentPairing() {
54296
54524
  }
54297
54525
  function saveAgentPairing(record2) {
54298
54526
  try {
54299
- (0, import_node_fs16.mkdirSync)((0, import_node_path25.join)((0, import_node_os12.homedir)(), ".mrrlin"), { recursive: true });
54300
- (0, import_node_fs16.writeFileSync)(AGENT_PAIRING_PATH, JSON.stringify(record2), { mode: 384 });
54527
+ (0, import_node_fs17.mkdirSync)((0, import_node_path26.join)((0, import_node_os13.homedir)(), ".mrrlin"), { recursive: true });
54528
+ (0, import_node_fs17.writeFileSync)(AGENT_PAIRING_PATH, JSON.stringify(record2), { mode: 384 });
54301
54529
  } catch {
54302
54530
  }
54303
54531
  }
@@ -54475,18 +54703,18 @@ async function renderPairingQrSvg(payload) {
54475
54703
  }
54476
54704
 
54477
54705
  // src/checkout-registry.ts
54478
- var import_node_fs17 = require("node:fs");
54479
- var import_node_path26 = require("node:path");
54706
+ var import_node_fs18 = require("node:fs");
54707
+ var import_node_path27 = require("node:path");
54480
54708
  var CheckoutRegistry = class {
54481
54709
  file;
54482
54710
  constructor(stateDir) {
54483
- this.file = (0, import_node_path26.join)(stateDir, "checkouts.json");
54484
- (0, import_node_fs17.mkdirSync)(stateDir, { recursive: true });
54711
+ this.file = (0, import_node_path27.join)(stateDir, "checkouts.json");
54712
+ (0, import_node_fs18.mkdirSync)(stateDir, { recursive: true });
54485
54713
  }
54486
54714
  read() {
54487
- if (!(0, import_node_fs17.existsSync)(this.file)) return {};
54715
+ if (!(0, import_node_fs18.existsSync)(this.file)) return {};
54488
54716
  try {
54489
- return JSON.parse((0, import_node_fs17.readFileSync)(this.file, "utf8"));
54717
+ return JSON.parse((0, import_node_fs18.readFileSync)(this.file, "utf8"));
54490
54718
  } catch {
54491
54719
  return {};
54492
54720
  }
@@ -54494,10 +54722,10 @@ var CheckoutRegistry = class {
54494
54722
  get(slug) {
54495
54723
  return this.read()[slug] ?? null;
54496
54724
  }
54497
- confirm(slug, path24, now) {
54725
+ confirm(slug, path25, now) {
54498
54726
  const all = this.read();
54499
- all[slug] = { path: path24, confirmedAt: now };
54500
- (0, import_node_fs17.writeFileSync)(this.file, JSON.stringify(all, null, 2));
54727
+ all[slug] = { path: path25, confirmedAt: now };
54728
+ (0, import_node_fs18.writeFileSync)(this.file, JSON.stringify(all, null, 2));
54501
54729
  }
54502
54730
  /**
54503
54731
  * Task 5.2 (github-via-capabilities): another slug whose registered path resolves, via
@@ -54520,14 +54748,14 @@ var CheckoutRegistry = class {
54520
54748
  if (!own) return null;
54521
54749
  let ownReal;
54522
54750
  try {
54523
- ownReal = (0, import_node_fs17.realpathSync)(own.path);
54751
+ ownReal = (0, import_node_fs18.realpathSync)(own.path);
54524
54752
  } catch {
54525
54753
  return null;
54526
54754
  }
54527
54755
  for (const [otherSlug, entry] of Object.entries(this.read())) {
54528
54756
  if (otherSlug === slug) continue;
54529
54757
  try {
54530
- if ((0, import_node_fs17.realpathSync)(entry.path) === ownReal) return otherSlug;
54758
+ if ((0, import_node_fs18.realpathSync)(entry.path) === ownReal) return otherSlug;
54531
54759
  } catch {
54532
54760
  continue;
54533
54761
  }
@@ -54538,7 +54766,7 @@ var CheckoutRegistry = class {
54538
54766
 
54539
54767
  // src/checkout-handlers.ts
54540
54768
  var import_node_child_process13 = require("node:child_process");
54541
- var import_node_fs18 = require("node:fs");
54769
+ var import_node_fs19 = require("node:fs");
54542
54770
 
54543
54771
  // src/git-remote-match.ts
54544
54772
  function normalizeRemote(url2) {
@@ -54573,7 +54801,7 @@ function validateCheckoutPath(checkoutPath, repo) {
54573
54801
  }
54574
54802
  let resolvedPath;
54575
54803
  try {
54576
- resolvedPath = (0, import_node_fs18.realpathSync)(trimmedPath);
54804
+ resolvedPath = (0, import_node_fs19.realpathSync)(trimmedPath);
54577
54805
  } catch {
54578
54806
  return {
54579
54807
  ok: false,
@@ -54879,9 +55107,9 @@ function extractVerificationSection(markdown) {
54879
55107
  }
54880
55108
 
54881
55109
  // src/director-reseed.ts
54882
- var import_node_fs19 = require("node:fs");
55110
+ var import_node_fs20 = require("node:fs");
54883
55111
  var import_node_readline = require("node:readline");
54884
- var import_node_path27 = require("node:path");
55112
+ var import_node_path28 = require("node:path");
54885
55113
  function estimateTokens(s) {
54886
55114
  return Buffer.byteLength(s, "utf8");
54887
55115
  }
@@ -55013,9 +55241,9 @@ async function readSessionRows(logsDir, files, sessionIds) {
55013
55241
  const lines2 = [];
55014
55242
  let missingFiles = 0;
55015
55243
  for (const f of files) {
55016
- const filePath = (0, import_node_path27.join)(logsDir, f);
55244
+ const filePath = (0, import_node_path28.join)(logsDir, f);
55017
55245
  try {
55018
- const stream = (0, import_node_fs19.createReadStream)(filePath, { encoding: "utf8" });
55246
+ const stream = (0, import_node_fs20.createReadStream)(filePath, { encoding: "utf8" });
55019
55247
  const rl = (0, import_node_readline.createInterface)({ input: stream, crlfDelay: Infinity });
55020
55248
  try {
55021
55249
  for await (const line of rl) {
@@ -55039,18 +55267,18 @@ async function readSessionRows(logsDir, files, sessionIds) {
55039
55267
  }
55040
55268
 
55041
55269
  // src/external-agents-scrub.ts
55042
- var import_node_fs20 = __toESM(require("node:fs"), 1);
55043
- var import_node_os13 = __toESM(require("node:os"), 1);
55044
- var import_node_path28 = __toESM(require("node:path"), 1);
55270
+ var import_node_fs21 = __toESM(require("node:fs"), 1);
55271
+ var import_node_os14 = __toESM(require("node:os"), 1);
55272
+ var import_node_path29 = __toESM(require("node:path"), 1);
55045
55273
  var REDACTION = "[REDACTED]";
55046
55274
  var SHORT_VALUE_THRESHOLD = 8;
55047
- var KEYS_ENV_PATH = () => import_node_path28.default.join(import_node_os13.default.homedir(), ".local", "state", "external-agents", "keys.env");
55275
+ var KEYS_ENV_PATH = () => import_node_path29.default.join(import_node_os14.default.homedir(), ".local", "state", "external-agents", "keys.env");
55048
55276
  var keysEnvCache = null;
55049
55277
  function readKeysEnv() {
55050
55278
  const filePath = KEYS_ENV_PATH();
55051
55279
  let mtimeMs = 0;
55052
55280
  try {
55053
- mtimeMs = import_node_fs20.default.statSync(filePath).mtimeMs;
55281
+ mtimeMs = import_node_fs21.default.statSync(filePath).mtimeMs;
55054
55282
  } catch {
55055
55283
  mtimeMs = 0;
55056
55284
  }
@@ -55059,7 +55287,7 @@ function readKeysEnv() {
55059
55287
  }
55060
55288
  const map2 = /* @__PURE__ */ new Map();
55061
55289
  try {
55062
- const content = import_node_fs20.default.readFileSync(filePath, "utf8");
55290
+ const content = import_node_fs21.default.readFileSync(filePath, "utf8");
55063
55291
  for (const rawLine of content.split(/\r?\n/)) {
55064
55292
  const line = rawLine.trim();
55065
55293
  if (line === "" || line.startsWith("#")) continue;
@@ -55477,7 +55705,7 @@ function addBridgeModel(target, model) {
55477
55705
  }
55478
55706
  function readTextIfExists(filePath) {
55479
55707
  try {
55480
- return import_node_fs21.default.readFileSync(filePath, "utf8");
55708
+ return import_node_fs22.default.readFileSync(filePath, "utf8");
55481
55709
  } catch {
55482
55710
  return null;
55483
55711
  }
@@ -55488,9 +55716,9 @@ function readKnownGptSlugsFromTomlFile(filePath) {
55488
55716
  return Array.from(raw.matchAll(/^\s*model\s*=\s*"([^"]+)"/gm)).map((match) => match[1]?.trim() ?? "").filter(isSelectableModelSlug);
55489
55717
  }
55490
55718
  function readCodexFallbackModels() {
55491
- const codexHome = process.env.CODEX_HOME?.trim() || import_node_path29.default.join(import_node_os14.default.homedir(), ".codex");
55719
+ const codexHome = process.env.CODEX_HOME?.trim() || import_node_path30.default.join(import_node_os15.default.homedir(), ".codex");
55492
55720
  const models = /* @__PURE__ */ new Map();
55493
- const cachePath = import_node_path29.default.join(codexHome, "models_cache.json");
55721
+ const cachePath = import_node_path30.default.join(codexHome, "models_cache.json");
55494
55722
  const cacheRaw = readTextIfExists(cachePath);
55495
55723
  if (cacheRaw) {
55496
55724
  try {
@@ -55540,7 +55768,7 @@ function readCodexFallbackModels() {
55540
55768
  );
55541
55769
  }
55542
55770
  }
55543
- for (const slug of readKnownGptSlugsFromTomlFile(import_node_path29.default.join(codexHome, "config.toml"))) {
55771
+ for (const slug of readKnownGptSlugsFromTomlFile(import_node_path30.default.join(codexHome, "config.toml"))) {
55544
55772
  addBridgeModel(
55545
55773
  models,
55546
55774
  mapBridgeModel({
@@ -55554,11 +55782,11 @@ function readCodexFallbackModels() {
55554
55782
  })
55555
55783
  );
55556
55784
  }
55557
- const automationsDir = import_node_path29.default.join(codexHome, "automations");
55785
+ const automationsDir = import_node_path30.default.join(codexHome, "automations");
55558
55786
  try {
55559
- for (const entry of import_node_fs21.default.readdirSync(automationsDir, { withFileTypes: true })) {
55787
+ for (const entry of import_node_fs22.default.readdirSync(automationsDir, { withFileTypes: true })) {
55560
55788
  if (!entry.isDirectory()) continue;
55561
- for (const slug of readKnownGptSlugsFromTomlFile(import_node_path29.default.join(automationsDir, entry.name, "automation.toml"))) {
55789
+ for (const slug of readKnownGptSlugsFromTomlFile(import_node_path30.default.join(automationsDir, entry.name, "automation.toml"))) {
55562
55790
  addBridgeModel(
55563
55791
  models,
55564
55792
  mapBridgeModel({
@@ -55584,9 +55812,9 @@ function selfUpdateInboxItemId(offeredVersion) {
55584
55812
  return `II-MCPUPD-${offeredVersion.replace(/[^A-Za-z0-9._-]/g, "-")}-${hash3}`;
55585
55813
  }
55586
55814
  function neutralCheckoutCwd(stateDir) {
55587
- const dir = import_node_path29.default.join(stateDir, "no-checkout");
55815
+ const dir = import_node_path30.default.join(stateDir, "no-checkout");
55588
55816
  try {
55589
- import_node_fs21.default.mkdirSync(dir, { recursive: true });
55817
+ import_node_fs22.default.mkdirSync(dir, { recursive: true });
55590
55818
  } catch {
55591
55819
  }
55592
55820
  return dir;
@@ -56096,7 +56324,7 @@ async function runOrphanWorktreeSweep(client, opts) {
56096
56324
  const cutoff = Date.now() - worktreeRetentionMs();
56097
56325
  const isReapable = (worktreePath) => {
56098
56326
  try {
56099
- return import_node_fs21.default.statSync(worktreePath).mtimeMs < cutoff;
56327
+ return import_node_fs22.default.statSync(worktreePath).mtimeMs < cutoff;
56100
56328
  } catch {
56101
56329
  return false;
56102
56330
  }
@@ -56572,7 +56800,7 @@ function createBridgeMessageHandler(deps) {
56572
56800
  sendForSpan({ type: "checkout-state", ok: false, error: { code: "invalid_input", fields: { projectSlug: "required" } } });
56573
56801
  return;
56574
56802
  }
56575
- const state = readCheckoutState(deps.checkoutRegistry, projectSlug, import_node_os14.default.hostname());
56803
+ const state = readCheckoutState(deps.checkoutRegistry, projectSlug, import_node_os15.default.hostname());
56576
56804
  if (!state) {
56577
56805
  sendForSpan({ type: "checkout-state", ok: false, error: { code: "checkout_missing" } });
56578
56806
  return;
@@ -56604,7 +56832,7 @@ function createBridgeMessageHandler(deps) {
56604
56832
  const result = registerCheckout(
56605
56833
  deps.checkoutRegistry,
56606
56834
  { projectSlug, path: typeof msg.path === "string" ? msg.path : "", repo },
56607
- import_node_os14.default.hostname()
56835
+ import_node_os15.default.hostname()
56608
56836
  );
56609
56837
  if (!result.ok) {
56610
56838
  sendForSpan({ type: "checkout-register", ok: false, error: { code: result.code, detail: result.detail } });
@@ -57320,7 +57548,7 @@ function createBridgeMessageHandler(deps) {
57320
57548
  if (effectiveText.length > 0) {
57321
57549
  const updateOffer = deps.maybeUpdateOffer ? deps.maybeUpdateOffer() : null;
57322
57550
  const updateOfferProjectSlug = msg.context?.projectSlug?.trim();
57323
- if (updateOffer !== null && updateOfferProjectSlug && deps.fileUpdateInboxItem) {
57551
+ if (updateOffer !== null && !updateOffer.startsWith(SELF_UPDATE_AUTH_PREFLIGHT_OFFER_PREFIX) && updateOfferProjectSlug && deps.fileUpdateInboxItem) {
57324
57552
  void deps.fileUpdateInboxItem(updateOfferProjectSlug);
57325
57553
  }
57326
57554
  let reseedPrefix = null;
@@ -57706,8 +57934,8 @@ async function startDirectorBridge() {
57706
57934
  codexCwd: config2.codexCwd,
57707
57935
  codexExecutable: config2.codexExecutable,
57708
57936
  checkoutRegistry,
57709
- worktreeRoot: import_node_path29.default.join(config2.stateDir, "worktrees"),
57710
- locksDir: import_node_path29.default.join(config2.stateDir, "locks"),
57937
+ worktreeRoot: import_node_path30.default.join(config2.stateDir, "worktrees"),
57938
+ locksDir: import_node_path30.default.join(config2.stateDir, "locks"),
57711
57939
  // Wire the executor server for code-execution runs. Each run gets its own provider process
57712
57940
  // (app-server for codex, a resident CLI child for claude) at the run worktree, running
57713
57941
  // UNRESTRICTED from the real operator config (owner no-sandbox decision — auth + mrrlin MCP
@@ -57751,13 +57979,13 @@ async function startDirectorBridge() {
57751
57979
  // egressDomains is retained in the seam signature (verification-turn.ts still computes the
57752
57980
  // env host) but no longer constrains anything — the executor is unrestricted.
57753
57981
  startSandbox: async (_egressDomains, providerId) => {
57754
- const cwd = import_node_fs21.default.mkdtempSync(import_node_path29.default.join(import_node_os14.default.tmpdir(), "mrrlin-verify-"));
57982
+ const cwd = import_node_fs22.default.mkdtempSync(import_node_path30.default.join(import_node_os15.default.tmpdir(), "mrrlin-verify-"));
57755
57983
  let executor;
57756
57984
  try {
57757
57985
  executor = await startExecutorServer({ worktree: cwd, provider: providerId });
57758
57986
  } catch (error51) {
57759
57987
  try {
57760
- import_node_fs21.default.rmSync(cwd, { recursive: true, force: true });
57988
+ import_node_fs22.default.rmSync(cwd, { recursive: true, force: true });
57761
57989
  } catch {
57762
57990
  }
57763
57991
  throw error51;
@@ -57768,7 +57996,7 @@ async function startDirectorBridge() {
57768
57996
  dispose: () => {
57769
57997
  executor.dispose();
57770
57998
  try {
57771
- import_node_fs21.default.rmSync(cwd, { recursive: true, force: true });
57999
+ import_node_fs22.default.rmSync(cwd, { recursive: true, force: true });
57772
58000
  } catch {
57773
58001
  }
57774
58002
  }
@@ -57979,7 +58207,7 @@ async function startDirectorBridge() {
57979
58207
  }
57980
58208
  const files = dayFilesInWindow(/* @__PURE__ */ new Date(), reseedWindowMs);
57981
58209
  const sessionIds = [args.directorSessionId, ...args.priorSessionIds];
57982
- const { lines: lines2, missingFiles } = await readSessionRows(import_node_path29.default.join(config2.stateDir, "logs"), files, sessionIds);
58210
+ const { lines: lines2, missingFiles } = await readSessionRows(import_node_path30.default.join(config2.stateDir, "logs"), files, sessionIds);
57983
58211
  const { items, skipped: skipped2 } = extractItems(lines2, sessionIds);
57984
58212
  if (items.length === 0) return refuse2("no-rows");
57985
58213
  const budget = Math.max(0, Math.min(config2.reseedMaxTokens, config2.turnMaxTokens - args.otherBytes));
@@ -58086,7 +58314,7 @@ async function startDirectorBridge() {
58086
58314
  const bridgeLogger = createBridgeLogger(config2.stateDir, process.env);
58087
58315
  let bridgeBinShaShort = "unknown00000";
58088
58316
  try {
58089
- bridgeBinShaShort = import_node_crypto11.default.createHash("sha256").update(import_node_fs21.default.readFileSync(process.argv[1] ?? "")).digest("hex").slice(0, 12);
58317
+ bridgeBinShaShort = import_node_crypto11.default.createHash("sha256").update(import_node_fs22.default.readFileSync(process.argv[1] ?? "")).digest("hex").slice(0, 12);
58090
58318
  } catch {
58091
58319
  }
58092
58320
  attachBridgeWss(server, {
@@ -58222,8 +58450,8 @@ async function startDirectorBridge() {
58222
58450
  );
58223
58451
  void runOrphanWorktreeSweep(client, {
58224
58452
  checkoutRegistry,
58225
- worktreeRoot: import_node_path29.default.join(config2.stateDir, "worktrees"),
58226
- locksDir: import_node_path29.default.join(config2.stateDir, "locks")
58453
+ worktreeRoot: import_node_path30.default.join(config2.stateDir, "worktrees"),
58454
+ locksDir: import_node_path30.default.join(config2.stateDir, "locks")
58227
58455
  });
58228
58456
  {
58229
58457
  const { retainedBuffers, retainedBytes, tombstonesRemoved } = sweepReplayBuffers(threads, tombstones, {
@@ -58548,15 +58776,15 @@ function readDispatchBody(req) {
58548
58776
  function readOrCreateBridgeToken(stateDir) {
58549
58777
  const explicit = (process.env.MRRLIN_DIRECTOR_BRIDGE_TOKEN ?? "").trim();
58550
58778
  if (explicit) return explicit;
58551
- const tokenPath = import_node_path29.default.join(stateDir, "token.txt");
58779
+ const tokenPath = import_node_path30.default.join(stateDir, "token.txt");
58552
58780
  try {
58553
- const existing = import_node_fs21.default.readFileSync(tokenPath, "utf8").trim();
58781
+ const existing = import_node_fs22.default.readFileSync(tokenPath, "utf8").trim();
58554
58782
  if (existing) return existing;
58555
58783
  } catch {
58556
58784
  }
58557
- import_node_fs21.default.mkdirSync(stateDir, { recursive: true, mode: 448 });
58785
+ import_node_fs22.default.mkdirSync(stateDir, { recursive: true, mode: 448 });
58558
58786
  const token = import_node_crypto11.default.randomBytes(32).toString("base64url");
58559
- import_node_fs21.default.writeFileSync(tokenPath, `${token}
58787
+ import_node_fs22.default.writeFileSync(tokenPath, `${token}
58560
58788
  `, { mode: 384 });
58561
58789
  return token;
58562
58790
  }
@@ -61947,15 +62175,15 @@ var StdioServerTransport = class {
61947
62175
  // src/tools.ts
61948
62176
  var import_node_crypto14 = require("node:crypto");
61949
62177
  var import_promises10 = require("node:fs/promises");
61950
- var import_node_path32 = __toESM(require("node:path"), 1);
61951
- var import_node_os15 = __toESM(require("node:os"), 1);
62178
+ var import_node_path33 = __toESM(require("node:path"), 1);
62179
+ var import_node_os16 = __toESM(require("node:os"), 1);
61952
62180
 
61953
62181
  // ../../packages/wiki/dist/index.js
61954
62182
  var import_promises8 = __toESM(require("node:fs/promises"), 1);
61955
- var import_node_path30 = __toESM(require("node:path"), 1);
62183
+ var import_node_path31 = __toESM(require("node:path"), 1);
61956
62184
  var INCLUDED_DOC_FOLDERS = /* @__PURE__ */ new Set(["_meta", "explanation", "how-to", "reference", "sdd", "tutorials"]);
61957
62185
  function toPosixPath(input) {
61958
- return input.split(import_node_path30.default.sep).join("/");
62186
+ return input.split(import_node_path31.default.sep).join("/");
61959
62187
  }
61960
62188
  function slugifyWikiSegment(input) {
61961
62189
  return input.trim().toLowerCase().replace(/`/g, "").replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
@@ -61969,12 +62197,12 @@ async function pathExists3(input) {
61969
62197
  }
61970
62198
  }
61971
62199
  async function findWorkspaceRoot(start = process.cwd()) {
61972
- let current2 = import_node_path30.default.resolve(start);
62200
+ let current2 = import_node_path31.default.resolve(start);
61973
62201
  while (true) {
61974
- if (await pathExists3(import_node_path30.default.join(current2, "pnpm-workspace.yaml")) && await pathExists3(import_node_path30.default.join(current2, "docs"))) {
62202
+ if (await pathExists3(import_node_path31.default.join(current2, "pnpm-workspace.yaml")) && await pathExists3(import_node_path31.default.join(current2, "docs"))) {
61975
62203
  return current2;
61976
62204
  }
61977
- const parent = import_node_path30.default.dirname(current2);
62205
+ const parent = import_node_path31.default.dirname(current2);
61978
62206
  if (parent === current2) {
61979
62207
  throw new Error(`Unable to find Mrrlin workspace root from ${start}`);
61980
62208
  }
@@ -61983,28 +62211,28 @@ async function findWorkspaceRoot(start = process.cwd()) {
61983
62211
  }
61984
62212
  async function resolveDocsRoot(input) {
61985
62213
  if (input) {
61986
- return import_node_path30.default.resolve(input);
62214
+ return import_node_path31.default.resolve(input);
61987
62215
  }
61988
62216
  if (process.env.MRRLIN_DOCS_ROOT) {
61989
- return import_node_path30.default.resolve(process.env.MRRLIN_DOCS_ROOT);
62217
+ return import_node_path31.default.resolve(process.env.MRRLIN_DOCS_ROOT);
61990
62218
  }
61991
- return import_node_path30.default.join(await findWorkspaceRoot(), "docs");
62219
+ return import_node_path31.default.join(await findWorkspaceRoot(), "docs");
61992
62220
  }
61993
62221
  async function resolveIndexPath(input) {
61994
62222
  if (input) {
61995
- return import_node_path30.default.resolve(input);
62223
+ return import_node_path31.default.resolve(input);
61996
62224
  }
61997
62225
  if (process.env.MRRLIN_WIKI_INDEX_PATH) {
61998
- return import_node_path30.default.resolve(process.env.MRRLIN_WIKI_INDEX_PATH);
62226
+ return import_node_path31.default.resolve(process.env.MRRLIN_WIKI_INDEX_PATH);
61999
62227
  }
62000
62228
  const workspaceRoot = await findWorkspaceRoot();
62001
- return import_node_path30.default.join(workspaceRoot, "apps", "web", "public", "wiki-index.json");
62229
+ return import_node_path31.default.join(workspaceRoot, "apps", "web", "public", "wiki-index.json");
62002
62230
  }
62003
62231
  async function walkMarkdownFiles(root, dir = root) {
62004
62232
  const entries = await import_promises8.default.readdir(dir, { withFileTypes: true });
62005
62233
  const files = [];
62006
62234
  for (const entry of entries) {
62007
- const absolute = import_node_path30.default.join(dir, entry.name);
62235
+ const absolute = import_node_path31.default.join(dir, entry.name);
62008
62236
  if (entry.isDirectory()) {
62009
62237
  files.push(...await walkMarkdownFiles(root, absolute));
62010
62238
  continue;
@@ -62023,7 +62251,7 @@ function parseTitle(markdown, sourcePath) {
62023
62251
  return title;
62024
62252
  }
62025
62253
  function documentFromFile(docsRoot, absolutePath, markdown) {
62026
- const relativePath = toPosixPath(import_node_path30.default.relative(docsRoot, absolutePath));
62254
+ const relativePath = toPosixPath(import_node_path31.default.relative(docsRoot, absolutePath));
62027
62255
  const [section, fileName] = relativePath.split("/");
62028
62256
  if (!section || !fileName || !INCLUDED_DOC_FOLDERS.has(section)) {
62029
62257
  return null;
@@ -64924,6 +65152,81 @@ async function deliverToGit(server, toolName, payload) {
64924
65152
  return invokeCapability(server, toolName, args);
64925
65153
  }
64926
65154
 
65155
+ // src/mcp-tool-error.ts
65156
+ var McpToolCodedError = class extends Error {
65157
+ code;
65158
+ violations;
65159
+ constructor(code, message, violations) {
65160
+ super(message);
65161
+ this.name = "McpToolCodedError";
65162
+ this.code = code;
65163
+ this.violations = violations;
65164
+ }
65165
+ };
65166
+
65167
+ // src/delivery/artifacts.ts
65168
+ async function deliverToArtifacts(client, projectSlug, payload, bareFetch) {
65169
+ const { bytes: bytes3, class: artifactClass, contentType, description, filename, runId, taskId } = payload;
65170
+ const created = await client.createArtifactFile(projectSlug, {
65171
+ class: artifactClass,
65172
+ contentType,
65173
+ filename,
65174
+ runId,
65175
+ sizeBytes: bytes3.byteLength,
65176
+ taskId
65177
+ });
65178
+ let stage = "upload";
65179
+ try {
65180
+ if (created.upload.kind === "presigned-post") {
65181
+ const form = new FormData();
65182
+ for (const [field, value] of Object.entries(created.upload.fields)) {
65183
+ form.append(field, value);
65184
+ }
65185
+ form.append("file", new Blob([bytes3], { type: contentType }), filename);
65186
+ const fetchImpl = bareFetch ?? globalThis.fetch;
65187
+ const uploadResponse = await fetchImpl(created.upload.url, { body: form, method: "POST" });
65188
+ if (!uploadResponse.ok) {
65189
+ throw new Error(`Presigned upload failed: ${uploadResponse.status} ${await uploadResponse.text()}`);
65190
+ }
65191
+ } else {
65192
+ await client.uploadArtifactFileContent(projectSlug, created.artifact.id, bytes3, contentType);
65193
+ }
65194
+ stage = "complete";
65195
+ const completed = await client.completeArtifactFile(projectSlug, created.artifact.id);
65196
+ if (completed.runId) {
65197
+ stage = "append-run-artifact";
65198
+ await client.appendExecutionArtifact(projectSlug, completed.runId, {
65199
+ id: `EA-${completed.id}`,
65200
+ kind: "file",
65201
+ payload: {
65202
+ artifactFileId: completed.id,
65203
+ class: completed.class,
65204
+ contentType: completed.contentType,
65205
+ description: description ?? null,
65206
+ filename: completed.filename,
65207
+ sizeBytes: completed.sizeBytes,
65208
+ stableUrl: created.stableUrl
65209
+ }
65210
+ });
65211
+ }
65212
+ const markdown = contentType.startsWith("image/") ? `![${completed.filename}](${created.stableUrl})` : `[${completed.filename}](${created.stableUrl})`;
65213
+ return {
65214
+ artifactFile: completed,
65215
+ markdown,
65216
+ stableUrl: created.stableUrl
65217
+ };
65218
+ } catch (error51) {
65219
+ const original = error51 instanceof MrrlinApiError ? error51.code : error51 instanceof McpToolCodedError ? error51.code : "ARTIFACT_FILE_UPLOAD_FAILED";
65220
+ const message = error51 instanceof Error ? error51.message : String(error51);
65221
+ const note = stage === "append-run-artifact" ? "file uploaded and completed successfully; only the run-history append failed \u2014 do NOT re-upload, reference the stableUrl directly" : "a pending row may remain; it is reaped automatically after 1h";
65222
+ throw new McpToolCodedError(
65223
+ original,
65224
+ `artifactFileId=${created.artifact.id} stableUrl=${created.stableUrl} (failed at ${stage}; ${note}): ${message}`,
65225
+ error51 instanceof MrrlinApiError ? error51.violations ?? void 0 : error51 instanceof McpToolCodedError ? error51.violations : void 0
65226
+ );
65227
+ }
65228
+ }
65229
+
64927
65230
  // src/delivery/index.ts
64928
65231
  async function deliverThroughCapability(client, input) {
64929
65232
  if (resolveKindCapability(input.artifactKind) === null) {
@@ -64941,7 +65244,7 @@ async function deliverThroughCapability(client, input) {
64941
65244
  return { ok: false, reason: "transport_error" };
64942
65245
  }
64943
65246
  if (!resolution.ok) {
64944
- return { ok: false, reason: resolution.reason };
65247
+ return { ok: false, reason: resolution.reason, message: resolution.message };
64945
65248
  }
64946
65249
  const { route, verdict } = resolution;
64947
65250
  if (verdict === "silent") {
@@ -64963,7 +65266,14 @@ var NoGrantForServerError = class extends Error {
64963
65266
  };
64964
65267
  async function proceedToDestination(client, route, input) {
64965
65268
  try {
64966
- const result = await callDestination(client, input.taskProjectSlug, route, input.payload, input.mcpConfigPath);
65269
+ const result = await callDestination(
65270
+ client,
65271
+ input.taskProjectSlug,
65272
+ route,
65273
+ input.payload,
65274
+ input.mcpConfigPath,
65275
+ input.bareFetch
65276
+ );
64967
65277
  const recorded = await recordUse(client, route, input, "ok");
64968
65278
  return { ok: true, use: recorded, result };
64969
65279
  } catch (error51) {
@@ -64972,7 +65282,15 @@ async function proceedToDestination(client, route, input) {
64972
65282
  return { ok: false, reason: "no_grant" };
64973
65283
  }
64974
65284
  await recordUse(client, route, input, "error");
64975
- return { ok: false, reason: "delivery_failed" };
65285
+ const code = error51 instanceof McpToolCodedError || error51 instanceof MrrlinApiError ? error51.code : void 0;
65286
+ const violations = error51 instanceof MrrlinApiError || error51 instanceof McpToolCodedError ? error51.violations : void 0;
65287
+ return {
65288
+ ok: false,
65289
+ reason: "delivery_failed",
65290
+ message: error51 instanceof Error ? error51.message : void 0,
65291
+ code,
65292
+ violations
65293
+ };
64976
65294
  }
64977
65295
  }
64978
65296
  async function refuse(client, route, input) {
@@ -65129,7 +65447,7 @@ async function recordUse(client, route, input, outcome) {
65129
65447
  return null;
65130
65448
  }
65131
65449
  }
65132
- async function callDestination(client, projectSlug, route, payload, mcpConfigPath) {
65450
+ async function callDestination(client, projectSlug, route, payload, mcpConfigPath, bareFetch) {
65133
65451
  const operation = isRecord6(payload) ? payload.operation : void 0;
65134
65452
  if (route.capability === "wiki") {
65135
65453
  if (operation !== "create" && operation !== "update") {
@@ -65145,6 +65463,12 @@ async function callDestination(client, projectSlug, route, payload, mcpConfigPat
65145
65463
  if (server === null) throw new NoGrantForServerError(`no local MCP config for server "${route.serverId}"`);
65146
65464
  return deliverToGit(server, route.toolName, payload);
65147
65465
  }
65466
+ if (route.capability === "artifacts") {
65467
+ if (operation !== "upload") {
65468
+ throw new Error(`callDestination: payload.operation "${String(operation)}" is not valid for artifacts`);
65469
+ }
65470
+ return deliverToArtifacts(client, projectSlug, payload, bareFetch);
65471
+ }
65148
65472
  throw new Error(`callDestination: no destination wired for capability "${route.capability}"`);
65149
65473
  }
65150
65474
  function isRecord6(value) {
@@ -66193,7 +66517,7 @@ var intentCheckDescriptor = createIntentCheckDescriptor();
66193
66517
 
66194
66518
  // src/evidence/assembler.ts
66195
66519
  var import_promises9 = require("node:fs/promises");
66196
- var import_node_path31 = require("node:path");
66520
+ var import_node_path32 = require("node:path");
66197
66521
  function evidenceDedupKey(sessionId, reportId) {
66198
66522
  return `${sessionId}:${reportId}`;
66199
66523
  }
@@ -66203,7 +66527,7 @@ function isRecord7(v) {
66203
66527
  async function readDayLines(stateDir, day, sessionId) {
66204
66528
  let raw;
66205
66529
  try {
66206
- raw = await (0, import_promises9.readFile)((0, import_node_path31.join)(stateDir, "logs", `bridge-${day}.jsonl`), "utf8");
66530
+ raw = await (0, import_promises9.readFile)((0, import_node_path32.join)(stateDir, "logs", `bridge-${day}.jsonl`), "utf8");
66207
66531
  } catch {
66208
66532
  return [];
66209
66533
  }
@@ -66277,7 +66601,7 @@ async function assembleEvidence(stateDir, sessionId, reportId, gateCtx) {
66277
66601
  }
66278
66602
  let windowPruned = false;
66279
66603
  try {
66280
- const raw = await (0, import_promises9.readFile)((0, import_node_path31.join)(stateDir, "logs", ".pruned.jsonl"), "utf8");
66604
+ const raw = await (0, import_promises9.readFile)((0, import_node_path32.join)(stateDir, "logs", ".pruned.jsonl"), "utf8");
66281
66605
  outer: for (const line of raw.split("\n")) {
66282
66606
  if (!line.trim()) continue;
66283
66607
  let rec;
@@ -67316,14 +67640,6 @@ var ARTIFACT_EXTENSION_TYPES = {
67316
67640
  ".webp": "image/webp",
67317
67641
  ".gif": "image/gif"
67318
67642
  };
67319
- var McpToolCodedError = class extends Error {
67320
- code;
67321
- constructor(code, message) {
67322
- super(message);
67323
- this.name = "McpToolCodedError";
67324
- this.code = code;
67325
- }
67326
- };
67327
67643
  function withAuth(options) {
67328
67644
  const baseFetch = options.fetch ?? globalThis.fetch;
67329
67645
  const authedFetch = async (input, init = {}) => {
@@ -67361,7 +67677,11 @@ function classifyClientError(fallbackCode, fallbackMessage, raw) {
67361
67677
  };
67362
67678
  }
67363
67679
  if (raw instanceof McpToolCodedError) {
67364
- return { code: raw.code, message: raw.message || fallbackMessage };
67680
+ return {
67681
+ code: raw.code,
67682
+ message: raw.message || fallbackMessage,
67683
+ ...raw.violations ? { violations: raw.violations } : {}
67684
+ };
67365
67685
  }
67366
67686
  if (raw instanceof Error) {
67367
67687
  return { code: fallbackCode, message: raw.message || fallbackMessage };
@@ -67388,18 +67708,33 @@ function pingAsyncWorkerDispatch(projectSlug, jobId) {
67388
67708
  }).catch(() => {
67389
67709
  });
67390
67710
  }
67391
- async function deliverBuiltIn(client, projectSlug, artifactKind, payload, mcpConfigPath) {
67711
+ async function deliverBuiltIn(client, projectSlug, artifactKind, payload, extra = {}) {
67392
67712
  const result = await deliverThroughCapability(client, {
67393
67713
  projectSlug,
67394
67714
  taskProjectSlug: projectSlug,
67395
67715
  artifactKind,
67396
- taskId: null,
67397
- runId: null,
67716
+ taskId: extra.taskId ?? null,
67717
+ runId: extra.runId ?? null,
67398
67718
  payload,
67399
- mcpConfigPath
67719
+ mcpConfigPath: extra.mcpConfigPath,
67720
+ bareFetch: extra.bareFetch
67400
67721
  });
67401
67722
  if (!result.ok) {
67402
- throw new McpToolCodedError(`CAPABILITY_${result.reason.toUpperCase()}`, `Delivery refused: ${result.reason}`);
67723
+ throw new McpToolCodedError(
67724
+ result.code ?? `CAPABILITY_${result.reason.toUpperCase()}`,
67725
+ describeCapabilityRefusal({
67726
+ reason: result.reason,
67727
+ projectSlug,
67728
+ artifactKind,
67729
+ capability: resolveKindCapability(artifactKind),
67730
+ detail: result.message
67731
+ }),
67732
+ // Consensus round 1 (chunk 4): a destination's own MrrlinApiError (e.g. artifact-file creation's
67733
+ // 409) carries structured violations that classifyClientError already surfaces for every other
67734
+ // tool -- deliverThroughCapability threads them onto DeliveryResult, converted here from the
67735
+ // nullable client shape to McpToolCodedError's optional-array one.
67736
+ result.violations ?? void 0
67737
+ );
67403
67738
  }
67404
67739
  return result.result;
67405
67740
  }
@@ -67481,68 +67816,6 @@ async function getAgentProviderForPanel(client, opts = {}) {
67481
67816
  }
67482
67817
  function createMrrlinTools(options) {
67483
67818
  const client = createMrrlinClient(withAuth(options));
67484
- async function uploadArtifactBytes(c, args) {
67485
- const { bytes: bytes3, class: artifactClass, contentType, description, filename, projectSlug, runId, taskId } = args;
67486
- const created = await c.createArtifactFile(projectSlug, {
67487
- class: artifactClass,
67488
- contentType,
67489
- filename,
67490
- runId,
67491
- sizeBytes: bytes3.byteLength,
67492
- taskId
67493
- });
67494
- let stage = "upload";
67495
- try {
67496
- if (created.upload.kind === "presigned-post") {
67497
- const form = new FormData();
67498
- for (const [field, value] of Object.entries(created.upload.fields)) {
67499
- form.append(field, value);
67500
- }
67501
- form.append("file", new Blob([bytes3], { type: contentType }), filename);
67502
- const bareFetch = options.fetch ?? globalThis.fetch;
67503
- const uploadResponse = await bareFetch(created.upload.url, { body: form, method: "POST" });
67504
- if (!uploadResponse.ok) {
67505
- throw new Error(
67506
- `Presigned upload failed: ${uploadResponse.status} ${await uploadResponse.text()}`
67507
- );
67508
- }
67509
- } else {
67510
- await c.uploadArtifactFileContent(projectSlug, created.artifact.id, bytes3, contentType);
67511
- }
67512
- stage = "complete";
67513
- const completed = await c.completeArtifactFile(projectSlug, created.artifact.id);
67514
- if (completed.runId) {
67515
- stage = "append-run-artifact";
67516
- await c.appendExecutionArtifact(projectSlug, completed.runId, {
67517
- id: `EA-${completed.id}`,
67518
- kind: "file",
67519
- payload: {
67520
- artifactFileId: completed.id,
67521
- class: completed.class,
67522
- contentType: completed.contentType,
67523
- description: description ?? null,
67524
- filename: completed.filename,
67525
- sizeBytes: completed.sizeBytes,
67526
- stableUrl: created.stableUrl
67527
- }
67528
- });
67529
- }
67530
- const markdown = contentType.startsWith("image/") ? `![${completed.filename}](${created.stableUrl})` : `[${completed.filename}](${created.stableUrl})`;
67531
- return {
67532
- artifactFile: completed,
67533
- markdown,
67534
- stableUrl: created.stableUrl
67535
- };
67536
- } catch (error51) {
67537
- const original = error51 instanceof MrrlinApiError ? error51.code : error51 instanceof McpToolCodedError ? error51.code : "ARTIFACT_FILE_UPLOAD_FAILED";
67538
- const message = error51 instanceof Error ? error51.message : String(error51);
67539
- const note = stage === "append-run-artifact" ? "file uploaded and completed successfully; only the run-history append failed \u2014 do NOT re-upload, reference the stableUrl directly" : "a pending row may remain; it is reaped automatically after 1h";
67540
- throw new McpToolCodedError(
67541
- original,
67542
- `artifactFileId=${created.artifact.id} stableUrl=${created.stableUrl} (failed at ${stage}; ${note}): ${message}`
67543
- );
67544
- }
67545
- }
67546
67819
  return {
67547
67820
  [mcpToolNames.archivePlan]: makeTool(
67548
67821
  client,
@@ -67587,7 +67860,7 @@ function createMrrlinTools(options) {
67587
67860
  projectSlug,
67588
67861
  "code_change",
67589
67862
  { operation: "branch", ...input },
67590
- options.mcpConfigPath
67863
+ { mcpConfigPath: options.mcpConfigPath }
67591
67864
  )
67592
67865
  ),
67593
67866
  [mcpToolNames.createGithubPullRequest]: makeTool(
@@ -67600,7 +67873,7 @@ function createMrrlinTools(options) {
67600
67873
  projectSlug,
67601
67874
  "code_change",
67602
67875
  { operation: "pull_request", ...input },
67603
- options.mcpConfigPath
67876
+ { mcpConfigPath: options.mcpConfigPath }
67604
67877
  )
67605
67878
  ),
67606
67879
  [mcpToolNames.createPlan]: makeTool(
@@ -67677,7 +67950,7 @@ function createMrrlinTools(options) {
67677
67950
  projectSlug,
67678
67951
  "document",
67679
67952
  { operation: "create", page: input },
67680
- options.mcpConfigPath
67953
+ { mcpConfigPath: options.mcpConfigPath }
67681
67954
  )
67682
67955
  ),
67683
67956
  [mcpToolNames.deleteTaskDependency]: makeTool(
@@ -67872,7 +68145,7 @@ function createMrrlinTools(options) {
67872
68145
  projectSlug,
67873
68146
  "document",
67874
68147
  { operation: "update", pageId, patch },
67875
- options.mcpConfigPath
68148
+ { mcpConfigPath: options.mcpConfigPath }
67876
68149
  )
67877
68150
  ),
67878
68151
  [mcpToolNames.markSpecReady]: makeTool(
@@ -68141,7 +68414,7 @@ function createMrrlinTools(options) {
68141
68414
  "ARTIFACT_FILE_UPLOAD_FAILED",
68142
68415
  "Unable to upload artifact file.",
68143
68416
  async (c, { projectSlug, path: filePath, class: artifactClass, taskId, runId, description }) => {
68144
- const extension2 = import_node_path32.default.extname(filePath).toLowerCase();
68417
+ const extension2 = import_node_path33.default.extname(filePath).toLowerCase();
68145
68418
  const contentType = ARTIFACT_EXTENSION_TYPES[extension2];
68146
68419
  if (!contentType) {
68147
68420
  throw new McpToolCodedError(
@@ -68169,17 +68442,14 @@ function createMrrlinTools(options) {
68169
68442
  "Artifact exceeds 5MB; split or summarize instead."
68170
68443
  );
68171
68444
  }
68172
- const filename = import_node_path32.default.basename(filePath);
68173
- return uploadArtifactBytes(c, {
68174
- bytes: bytes3,
68175
- class: artifactClass,
68176
- contentType,
68177
- description,
68178
- filename,
68445
+ const filename = import_node_path33.default.basename(filePath);
68446
+ return deliverBuiltIn(
68447
+ c,
68179
68448
  projectSlug,
68180
- runId,
68181
- taskId
68182
- });
68449
+ "file_set",
68450
+ { operation: "upload", bytes: bytes3, class: artifactClass, contentType, description, filename, runId, taskId },
68451
+ { mcpConfigPath: options.mcpConfigPath, bareFetch: options.fetch ?? globalThis.fetch, taskId, runId }
68452
+ );
68183
68453
  }
68184
68454
  ),
68185
68455
  [mcpToolNames.deliverFile]: makeTool(
@@ -68194,7 +68464,7 @@ function createMrrlinTools(options) {
68194
68464
  `Invalid filename '${filename}'; provide a bare filename with no path separators or '..'.`
68195
68465
  );
68196
68466
  }
68197
- const extension2 = import_node_path32.default.extname(filename).toLowerCase();
68467
+ const extension2 = import_node_path33.default.extname(filename).toLowerCase();
68198
68468
  const contentType = ARTIFACT_EXTENSION_TYPES[extension2];
68199
68469
  if (!contentType) {
68200
68470
  throw new McpToolCodedError(
@@ -68215,16 +68485,13 @@ function createMrrlinTools(options) {
68215
68485
  "Artifact exceeds 5MB; split or summarize instead."
68216
68486
  );
68217
68487
  }
68218
- return uploadArtifactBytes(c, {
68219
- bytes: bytes3,
68220
- class: artifactClass,
68221
- contentType,
68222
- description,
68223
- filename,
68488
+ return deliverBuiltIn(
68489
+ c,
68224
68490
  projectSlug,
68225
- runId,
68226
- taskId
68227
- });
68491
+ "file_set",
68492
+ { operation: "upload", bytes: bytes3, class: artifactClass, contentType, description, filename, runId, taskId },
68493
+ { mcpConfigPath: options.mcpConfigPath, bareFetch: options.fetch ?? globalThis.fetch, taskId, runId }
68494
+ );
68228
68495
  }
68229
68496
  ),
68230
68497
  [mcpToolNames.listArtifactFiles]: makeTool(
@@ -68269,7 +68536,7 @@ function createMrrlinTools(options) {
68269
68536
  "Unable to register local checkout.",
68270
68537
  async (_c, { projectSlug, path: checkoutPath, repo }) => {
68271
68538
  const registry3 = new CheckoutRegistry(resolveStateDir());
68272
- const result = registerCheckout(registry3, { projectSlug, path: checkoutPath, repo }, import_node_os15.default.hostname());
68539
+ const result = registerCheckout(registry3, { projectSlug, path: checkoutPath, repo }, import_node_os16.default.hostname());
68273
68540
  if (!result.ok) {
68274
68541
  const codeMap = {
68275
68542
  not_absolute: "LOCAL_CHECKOUT_PATH_NOT_ABSOLUTE",
@@ -68506,9 +68773,9 @@ function runSetCredential(args) {
68506
68773
  }
68507
68774
 
68508
68775
  // src/install-service.ts
68509
- var import_node_os16 = __toESM(require("node:os"), 1);
68510
- var import_node_fs22 = require("node:fs");
68511
- var import_node_path33 = __toESM(require("node:path"), 1);
68776
+ var import_node_os17 = __toESM(require("node:os"), 1);
68777
+ var import_node_fs23 = require("node:fs");
68778
+ var import_node_path34 = __toESM(require("node:path"), 1);
68512
68779
  function readExistingTelemetryDefaultProject(deps, ecoPath) {
68513
68780
  try {
68514
68781
  const existing = deps.readFile?.(ecoPath);
@@ -68568,7 +68835,7 @@ function deriveServiceApiTarget(deps, ecoPath) {
68568
68835
  var SYSTEM_PATH_DIRS = ["/usr/bin", "/bin", "/usr/sbin", "/sbin"];
68569
68836
  function defaultHomeOwnerUid(home) {
68570
68837
  try {
68571
- return (0, import_node_fs22.statSync)(home).uid;
68838
+ return (0, import_node_fs23.statSync)(home).uid;
68572
68839
  } catch {
68573
68840
  return null;
68574
68841
  }
@@ -68609,11 +68876,11 @@ function installService(deps) {
68609
68876
  deps.log(resolved.reason);
68610
68877
  return { ok: false };
68611
68878
  }
68612
- const home = deps.env.HOME ?? import_node_os16.default.homedir();
68879
+ const home = deps.env.HOME ?? import_node_os17.default.homedir();
68613
68880
  const user = resolveBridgeUser({
68614
68881
  env: deps.env,
68615
68882
  home,
68616
- userInfo: deps.userInfo ?? (() => import_node_os16.default.userInfo()),
68883
+ userInfo: deps.userInfo ?? (() => import_node_os17.default.userInfo()),
68617
68884
  homeOwnerUid: deps.homeOwnerUid ?? defaultHomeOwnerUid,
68618
68885
  log: deps.log
68619
68886
  });
@@ -68629,9 +68896,9 @@ function installService(deps) {
68629
68896
  const claudeBin = deps.which("claude");
68630
68897
  const resolvedBins = [...bins, claudeBin].filter((b) => b !== null);
68631
68898
  const pathEnv = Array.from(
68632
- /* @__PURE__ */ new Set([...resolvedBins.map((b) => import_node_path33.default.dirname(b)), ...SYSTEM_PATH_DIRS])
68899
+ /* @__PURE__ */ new Set([...resolvedBins.map((b) => import_node_path34.default.dirname(b)), ...SYSTEM_PATH_DIRS])
68633
68900
  ).join(":");
68634
- const ecoPath = import_node_path33.default.join(home, ".mrrlin", "ecosystem.config.cjs");
68901
+ const ecoPath = import_node_path34.default.join(home, ".mrrlin", "ecosystem.config.cjs");
68635
68902
  const apiTarget = deriveServiceApiTarget(deps, ecoPath);
68636
68903
  const telemetryDefaultProject = "MRRLIN_TELEMETRY_DEFAULT_PROJECT" in deps.env ? deps.env.MRRLIN_TELEMETRY_DEFAULT_PROJECT?.trim() || void 0 : readExistingTelemetryDefaultProject(deps, ecoPath);
68637
68904
  const text = renderEcosystemConfig({
@@ -68695,13 +68962,13 @@ function uninstallService(deps) {
68695
68962
 
68696
68963
  // src/uninstall-codex.ts
68697
68964
  var import_promises11 = __toESM(require("node:fs/promises"), 1);
68698
- var import_node_os17 = __toESM(require("node:os"), 1);
68699
- var import_node_path34 = __toESM(require("node:path"), 1);
68965
+ var import_node_os18 = __toESM(require("node:os"), 1);
68966
+ var import_node_path35 = __toESM(require("node:path"), 1);
68700
68967
  var toml3 = __toESM(require_toml(), 1);
68701
68968
  function resolveCodexHome3(options) {
68702
68969
  if (options.codexHome) return options.codexHome;
68703
68970
  if (process.env.CODEX_HOME) return process.env.CODEX_HOME;
68704
- return import_node_path34.default.join(options.homeDir ?? import_node_os17.default.homedir(), ".codex");
68971
+ return import_node_path35.default.join(options.homeDir ?? import_node_os18.default.homedir(), ".codex");
68705
68972
  }
68706
68973
  async function pathExists4(target) {
68707
68974
  try {
@@ -68714,7 +68981,7 @@ async function pathExists4(target) {
68714
68981
  var MRRLIN_BLOCK_RE = /(^|\n)\[mcp_servers\.(?:mrrlin(?:-browser)?|external-agents)(?:\]|\.[^\]\n]*\])[\s\S]*?(?=\n\[|$)/g;
68715
68982
  async function uninstallCodex(options = {}) {
68716
68983
  const codexHome = resolveCodexHome3(options);
68717
- const configPath = import_node_path34.default.join(codexHome, "config.toml");
68984
+ const configPath = import_node_path35.default.join(codexHome, "config.toml");
68718
68985
  const removePrompts = async () => uninstallPrompts(codexHome, options.promptNames ?? []);
68719
68986
  if (!await pathExists4(configPath)) {
68720
68987
  return { action: "missing", configPath, prompts: await removePrompts() };
@@ -68742,10 +69009,10 @@ async function uninstallCodex(options = {}) {
68742
69009
  }
68743
69010
  async function uninstallPrompts(codexHome, names) {
68744
69011
  if (names.length === 0) return [];
68745
- const promptsDir = import_node_path34.default.join(codexHome, "prompts");
69012
+ const promptsDir = import_node_path35.default.join(codexHome, "prompts");
68746
69013
  const out = [];
68747
69014
  for (const name of names) {
68748
- const promptPath = import_node_path34.default.join(promptsDir, `${name}.md`);
69015
+ const promptPath = import_node_path35.default.join(promptsDir, `${name}.md`);
68749
69016
  try {
68750
69017
  await import_promises11.default.unlink(promptPath);
68751
69018
  out.push({ name, action: "removed", promptPath });
@@ -68763,7 +69030,7 @@ async function uninstallPrompts(codexHome, names) {
68763
69030
 
68764
69031
  // src/extract/command.ts
68765
69032
  var import_promises12 = require("node:fs/promises");
68766
- var import_node_path35 = require("node:path");
69033
+ var import_node_path36 = require("node:path");
68767
69034
  function parseArgs(args) {
68768
69035
  const map2 = /* @__PURE__ */ new Map();
68769
69036
  for (let i = 0; i < args.length; i++) {
@@ -68800,7 +69067,7 @@ Missing required flag(s): ${missing.join(
68800
69067
  const days = await findSessionDays(deps.stateDir, sessionId);
68801
69068
  const matchingLines = [];
68802
69069
  for (const day of days) {
68803
- const logPath = (0, import_node_path35.join)(deps.stateDir, "logs", `bridge-${day}.jsonl`);
69070
+ const logPath = (0, import_node_path36.join)(deps.stateDir, "logs", `bridge-${day}.jsonl`);
68804
69071
  let raw;
68805
69072
  try {
68806
69073
  raw = await (0, import_promises12.readFile)(logPath, "utf8");
@@ -68900,16 +69167,16 @@ function bootHookStatus() {
68900
69167
  if (process.platform !== "darwin") return { status: "unknown" };
68901
69168
  const uid = process.getuid?.();
68902
69169
  if (uid === void 0 || uid === 0) return { status: "unknown" };
68903
- const home = process.env.HOME ?? (0, import_node_os18.homedir)();
68904
- const agents = import_node_path37.default.join(home, "Library", "LaunchAgents");
69170
+ const home = process.env.HOME ?? (0, import_node_os19.homedir)();
69171
+ const agents = import_node_path38.default.join(home, "Library", "LaunchAgents");
68905
69172
  const candidates = [
68906
- { label: "com.mrrlin.director-bridge", plist: import_node_path37.default.join(agents, "com.mrrlin.director-bridge.plist") },
68907
- { label: "com.PM2", plist: import_node_path37.default.join(agents, `pm2.${(0, import_node_os18.userInfo)().username}.plist`) }
69173
+ { label: "com.mrrlin.director-bridge", plist: import_node_path38.default.join(agents, "com.mrrlin.director-bridge.plist") },
69174
+ { label: "com.PM2", plist: import_node_path38.default.join(agents, `pm2.${(0, import_node_os19.userInfo)().username}.plist`) }
68908
69175
  ];
68909
69176
  for (const candidate of candidates) {
68910
69177
  const printed = (0, import_node_child_process18.spawnSync)("launchctl", ["print", `gui/${uid}/${candidate.label}`], { encoding: "utf8" });
68911
69178
  if (printed.status !== 0) continue;
68912
- if (!(0, import_node_fs23.existsSync)(candidate.plist)) continue;
69179
+ if (!(0, import_node_fs24.existsSync)(candidate.plist)) continue;
68913
69180
  const out = printed.stdout ?? "";
68914
69181
  const runs = /^\s*runs\s*=\s*(\d+)/m.exec(out);
68915
69182
  const exitCode = /^\s*last exit code\s*=\s*(-?\d+)/m.exec(out);
@@ -69194,8 +69461,8 @@ async function main() {
69194
69461
  }
69195
69462
  }
69196
69463
  try {
69197
- const codexHome = process.env.CODEX_HOME ?? import_node_path37.default.join(process.env.HOME ?? (0, import_node_os18.homedir)(), ".codex");
69198
- (0, import_node_fs23.rmSync)(import_node_path37.default.join(codexHome, "prompts", "report-issue.md"), { force: true });
69464
+ const codexHome = process.env.CODEX_HOME ?? import_node_path38.default.join(process.env.HOME ?? (0, import_node_os19.homedir)(), ".codex");
69465
+ (0, import_node_fs24.rmSync)(import_node_path38.default.join(codexHome, "prompts", "report-issue.md"), { force: true });
69199
69466
  } catch {
69200
69467
  }
69201
69468
  const claudeResult = await installClaude({ binPath, force, serveEnv });
@@ -69256,15 +69523,15 @@ async function main() {
69256
69523
  env: process.env,
69257
69524
  cwd: process.cwd(),
69258
69525
  writeFile: (p, c) => {
69259
- (0, import_node_fs23.mkdirSync)(import_node_path37.default.dirname(p), { recursive: true, mode: 448 });
69260
- (0, import_node_fs23.writeFileSync)(p, c, { mode: 384 });
69526
+ (0, import_node_fs24.mkdirSync)(import_node_path38.default.dirname(p), { recursive: true, mode: 448 });
69527
+ (0, import_node_fs24.writeFileSync)(p, c, { mode: 384 });
69261
69528
  },
69262
69529
  // Swallows every error on purpose — the only caller uses this to recover settings from the
69263
69530
  // config it is about to overwrite, and a missing or unreadable file means "no previous
69264
69531
  // value", never a failed install. See readExistingTelemetryDefaultProject.
69265
69532
  readFile: (p) => {
69266
69533
  try {
69267
- return (0, import_node_fs23.readFileSync)(p, "utf8");
69534
+ return (0, import_node_fs24.readFileSync)(p, "utf8");
69268
69535
  } catch {
69269
69536
  return null;
69270
69537
  }
@@ -69285,35 +69552,35 @@ async function main() {
69285
69552
  runPm2: (a) => ({ code: pm2Runner(a).code }),
69286
69553
  removeFile: (p) => {
69287
69554
  try {
69288
- (0, import_node_fs23.rmSync)(p, { force: true });
69555
+ (0, import_node_fs24.rmSync)(p, { force: true });
69289
69556
  } catch {
69290
69557
  }
69291
69558
  },
69292
69559
  purgeSecret: purge,
69293
69560
  secretPath: agentCredentialPath(),
69294
69561
  tokenPath: operatorTokenPath(),
69295
- ecoPath: import_node_path37.default.join(process.env.HOME ?? (0, import_node_os18.homedir)(), ".mrrlin", "ecosystem.config.cjs"),
69562
+ ecoPath: import_node_path38.default.join(process.env.HOME ?? (0, import_node_os19.homedir)(), ".mrrlin", "ecosystem.config.cjs"),
69296
69563
  log: (m) => process.stderr.write(`[mrrlin-mcp uninstall-service] ${m}
69297
69564
  `)
69298
69565
  });
69299
69566
  return;
69300
69567
  }
69301
69568
  case "uninstall": {
69302
- const home = process.env.HOME ?? (0, import_node_os18.homedir)();
69569
+ const home = process.env.HOME ?? (0, import_node_os19.homedir)();
69303
69570
  const log = (m) => process.stderr.write(`[mrrlin-mcp uninstall] ${m}
69304
69571
  `);
69305
69572
  uninstallService({
69306
69573
  runPm2: (a) => ({ code: pm2Runner(a).code }),
69307
69574
  removeFile: (p) => {
69308
69575
  try {
69309
- (0, import_node_fs23.rmSync)(p, { force: true });
69576
+ (0, import_node_fs24.rmSync)(p, { force: true });
69310
69577
  } catch {
69311
69578
  }
69312
69579
  },
69313
69580
  purgeSecret: true,
69314
69581
  secretPath: agentCredentialPath(),
69315
69582
  tokenPath: operatorTokenPath(),
69316
- ecoPath: import_node_path37.default.join(home, ".mrrlin", "ecosystem.config.cjs"),
69583
+ ecoPath: import_node_path38.default.join(home, ".mrrlin", "ecosystem.config.cjs"),
69317
69584
  log
69318
69585
  });
69319
69586
  let codexOk = true;
@@ -69333,7 +69600,7 @@ async function main() {
69333
69600
  log(`codex config NOT modified: ${error51 instanceof Error ? error51.message : String(error51)}`);
69334
69601
  }
69335
69602
  try {
69336
- (0, import_node_fs23.rmSync)(import_node_path37.default.join(home, ".mrrlin"), { recursive: true, force: true });
69603
+ (0, import_node_fs24.rmSync)(import_node_path38.default.join(home, ".mrrlin"), { recursive: true, force: true });
69337
69604
  } catch {
69338
69605
  }
69339
69606
  log("removed ~/.mrrlin");
@@ -69374,7 +69641,7 @@ ${HELP_TEXT}`);
69374
69641
  }
69375
69642
  }
69376
69643
  function resolveSelfBinPath() {
69377
- return import_node_path36.default.resolve(process.argv[1] ?? process.execPath);
69644
+ return import_node_path37.default.resolve(process.argv[1] ?? process.execPath);
69378
69645
  }
69379
69646
  main().catch((error51) => {
69380
69647
  process.stderr.write(`mrrlin-mcp fatal error: ${error51 instanceof Error ? error51.message : String(error51)}