@mrrlin-dev/mcp 0.4.160 → 0.4.161
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.cjs +467 -1772
- package/package.json +1 -2
package/dist/bin.cjs
CHANGED
|
@@ -5833,7 +5833,7 @@ var require_fast_uri = __commonJS({
|
|
|
5833
5833
|
normalizeString(uri, options);
|
|
5834
5834
|
} else if (typeof uri === "object") {
|
|
5835
5835
|
uri = /** @type {T} */
|
|
5836
|
-
|
|
5836
|
+
parse9(serialize(uri, options), options);
|
|
5837
5837
|
}
|
|
5838
5838
|
return uri;
|
|
5839
5839
|
}
|
|
@@ -5873,8 +5873,8 @@ var require_fast_uri = __commonJS({
|
|
|
5873
5873
|
function resolveComponent(base, relative, options, skipNormalization) {
|
|
5874
5874
|
const target = {};
|
|
5875
5875
|
if (!skipNormalization) {
|
|
5876
|
-
base =
|
|
5877
|
-
relative =
|
|
5876
|
+
base = parse9(serialize(base, options), options);
|
|
5877
|
+
relative = parse9(serialize(relative, options), options);
|
|
5878
5878
|
}
|
|
5879
5879
|
options = options || {};
|
|
5880
5880
|
if (!options.tolerant && relative.scheme) {
|
|
@@ -6173,7 +6173,7 @@ var require_fast_uri = __commonJS({
|
|
|
6173
6173
|
}
|
|
6174
6174
|
return { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
|
|
6175
6175
|
}
|
|
6176
|
-
function
|
|
6176
|
+
function parse9(uri, opts) {
|
|
6177
6177
|
return parseWithStatus(uri, opts).parsed;
|
|
6178
6178
|
}
|
|
6179
6179
|
function normalizeString(uri, opts) {
|
|
@@ -6210,7 +6210,7 @@ var require_fast_uri = __commonJS({
|
|
|
6210
6210
|
resolveComponent,
|
|
6211
6211
|
equal,
|
|
6212
6212
|
serialize,
|
|
6213
|
-
parse:
|
|
6213
|
+
parse: parse9
|
|
6214
6214
|
};
|
|
6215
6215
|
module2.exports = fastUri;
|
|
6216
6216
|
module2.exports.default = fastUri;
|
|
@@ -9206,7 +9206,7 @@ var require_content_type = __commonJS({
|
|
|
9206
9206
|
var QUOTE_REGEXP = /([\\"])/g;
|
|
9207
9207
|
var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
9208
9208
|
exports2.format = format;
|
|
9209
|
-
exports2.parse =
|
|
9209
|
+
exports2.parse = parse9;
|
|
9210
9210
|
function format(obj) {
|
|
9211
9211
|
if (!obj || typeof obj !== "object") {
|
|
9212
9212
|
throw new TypeError("argument obj is required");
|
|
@@ -9230,7 +9230,7 @@ var require_content_type = __commonJS({
|
|
|
9230
9230
|
}
|
|
9231
9231
|
return string4;
|
|
9232
9232
|
}
|
|
9233
|
-
function
|
|
9233
|
+
function parse9(string4) {
|
|
9234
9234
|
if (!string4) {
|
|
9235
9235
|
throw new TypeError("argument string is required");
|
|
9236
9236
|
}
|
|
@@ -9696,7 +9696,7 @@ var require_parse2 = __commonJS({
|
|
|
9696
9696
|
}
|
|
9697
9697
|
return parsed;
|
|
9698
9698
|
}
|
|
9699
|
-
function
|
|
9699
|
+
function parse9(command, args, options) {
|
|
9700
9700
|
if (args && !Array.isArray(args)) {
|
|
9701
9701
|
options = args;
|
|
9702
9702
|
args = null;
|
|
@@ -9715,7 +9715,7 @@ var require_parse2 = __commonJS({
|
|
|
9715
9715
|
};
|
|
9716
9716
|
return options.shell ? parsed : parseNonShell(parsed);
|
|
9717
9717
|
}
|
|
9718
|
-
module2.exports =
|
|
9718
|
+
module2.exports = parse9;
|
|
9719
9719
|
}
|
|
9720
9720
|
});
|
|
9721
9721
|
|
|
@@ -9774,24 +9774,24 @@ var require_cross_spawn = __commonJS({
|
|
|
9774
9774
|
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports2, module2) {
|
|
9775
9775
|
"use strict";
|
|
9776
9776
|
var cp2 = require("child_process");
|
|
9777
|
-
var
|
|
9777
|
+
var parse9 = require_parse2();
|
|
9778
9778
|
var enoent = require_enoent();
|
|
9779
|
-
function
|
|
9780
|
-
const parsed =
|
|
9779
|
+
function spawn9(command, args, options) {
|
|
9780
|
+
const parsed = parse9(command, args, options);
|
|
9781
9781
|
const spawned = cp2.spawn(parsed.command, parsed.args, parsed.options);
|
|
9782
9782
|
enoent.hookChildProcess(spawned, parsed);
|
|
9783
9783
|
return spawned;
|
|
9784
9784
|
}
|
|
9785
9785
|
function spawnSync9(command, args, options) {
|
|
9786
|
-
const parsed =
|
|
9786
|
+
const parsed = parse9(command, args, options);
|
|
9787
9787
|
const result = cp2.spawnSync(parsed.command, parsed.args, parsed.options);
|
|
9788
9788
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
9789
9789
|
return result;
|
|
9790
9790
|
}
|
|
9791
|
-
module2.exports =
|
|
9792
|
-
module2.exports.spawn =
|
|
9791
|
+
module2.exports = spawn9;
|
|
9792
|
+
module2.exports.spawn = spawn9;
|
|
9793
9793
|
module2.exports.sync = spawnSync9;
|
|
9794
|
-
module2.exports._parse =
|
|
9794
|
+
module2.exports._parse = parse9;
|
|
9795
9795
|
module2.exports._enoent = enoent;
|
|
9796
9796
|
}
|
|
9797
9797
|
});
|
|
@@ -11831,7 +11831,7 @@ var require_parse3 = __commonJS({
|
|
|
11831
11831
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/parse.js"(exports2, module2) {
|
|
11832
11832
|
"use strict";
|
|
11833
11833
|
var SemVer = require_semver();
|
|
11834
|
-
var
|
|
11834
|
+
var parse9 = (version2, options, throwErrors = false) => {
|
|
11835
11835
|
if (version2 instanceof SemVer) {
|
|
11836
11836
|
return version2;
|
|
11837
11837
|
}
|
|
@@ -11844,7 +11844,7 @@ var require_parse3 = __commonJS({
|
|
|
11844
11844
|
throw er;
|
|
11845
11845
|
}
|
|
11846
11846
|
};
|
|
11847
|
-
module2.exports =
|
|
11847
|
+
module2.exports = parse9;
|
|
11848
11848
|
}
|
|
11849
11849
|
});
|
|
11850
11850
|
|
|
@@ -11852,9 +11852,9 @@ var require_parse3 = __commonJS({
|
|
|
11852
11852
|
var require_valid = __commonJS({
|
|
11853
11853
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/valid.js"(exports2, module2) {
|
|
11854
11854
|
"use strict";
|
|
11855
|
-
var
|
|
11855
|
+
var parse9 = require_parse3();
|
|
11856
11856
|
var valid = (version2, options) => {
|
|
11857
|
-
const v =
|
|
11857
|
+
const v = parse9(version2, options);
|
|
11858
11858
|
return v ? v.version : null;
|
|
11859
11859
|
};
|
|
11860
11860
|
module2.exports = valid;
|
|
@@ -11865,9 +11865,9 @@ var require_valid = __commonJS({
|
|
|
11865
11865
|
var require_clean = __commonJS({
|
|
11866
11866
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/clean.js"(exports2, module2) {
|
|
11867
11867
|
"use strict";
|
|
11868
|
-
var
|
|
11868
|
+
var parse9 = require_parse3();
|
|
11869
11869
|
var clean = (version2, options) => {
|
|
11870
|
-
const s =
|
|
11870
|
+
const s = parse9(version2.trim().replace(/^[=v]+/, ""), options);
|
|
11871
11871
|
return s ? s.version : null;
|
|
11872
11872
|
};
|
|
11873
11873
|
module2.exports = clean;
|
|
@@ -11902,10 +11902,10 @@ var require_inc = __commonJS({
|
|
|
11902
11902
|
var require_diff = __commonJS({
|
|
11903
11903
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/diff.js"(exports2, module2) {
|
|
11904
11904
|
"use strict";
|
|
11905
|
-
var
|
|
11905
|
+
var parse9 = require_parse3();
|
|
11906
11906
|
var diff = (version1, version2) => {
|
|
11907
|
-
const v1 =
|
|
11908
|
-
const v2 =
|
|
11907
|
+
const v1 = parse9(version1, null, true);
|
|
11908
|
+
const v2 = parse9(version2, null, true);
|
|
11909
11909
|
const comparison = v1.compare(v2);
|
|
11910
11910
|
if (comparison === 0) {
|
|
11911
11911
|
return null;
|
|
@@ -11976,9 +11976,9 @@ var require_patch = __commonJS({
|
|
|
11976
11976
|
var require_prerelease = __commonJS({
|
|
11977
11977
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/prerelease.js"(exports2, module2) {
|
|
11978
11978
|
"use strict";
|
|
11979
|
-
var
|
|
11979
|
+
var parse9 = require_parse3();
|
|
11980
11980
|
var prerelease = (version2, options) => {
|
|
11981
|
-
const parsed =
|
|
11981
|
+
const parsed = parse9(version2, options);
|
|
11982
11982
|
return parsed && parsed.prerelease.length ? parsed.prerelease : null;
|
|
11983
11983
|
};
|
|
11984
11984
|
module2.exports = prerelease;
|
|
@@ -12164,7 +12164,7 @@ var require_coerce = __commonJS({
|
|
|
12164
12164
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/coerce.js"(exports2, module2) {
|
|
12165
12165
|
"use strict";
|
|
12166
12166
|
var SemVer = require_semver();
|
|
12167
|
-
var
|
|
12167
|
+
var parse9 = require_parse3();
|
|
12168
12168
|
var { safeRe: re, t } = require_re();
|
|
12169
12169
|
var coerce = (version2, options) => {
|
|
12170
12170
|
if (version2 instanceof SemVer) {
|
|
@@ -12199,7 +12199,7 @@ var require_coerce = __commonJS({
|
|
|
12199
12199
|
const patch = match[4] || "0";
|
|
12200
12200
|
const prerelease = options.includePrerelease && match[5] ? `-${match[5]}` : "";
|
|
12201
12201
|
const build = options.includePrerelease && match[6] ? `+${match[6]}` : "";
|
|
12202
|
-
return
|
|
12202
|
+
return parse9(`${major}.${minor}.${patch}${prerelease}${build}`, options);
|
|
12203
12203
|
};
|
|
12204
12204
|
module2.exports = coerce;
|
|
12205
12205
|
}
|
|
@@ -12209,7 +12209,7 @@ var require_coerce = __commonJS({
|
|
|
12209
12209
|
var require_truncate = __commonJS({
|
|
12210
12210
|
"../../node_modules/.pnpm/semver@7.8.0/node_modules/semver/functions/truncate.js"(exports2, module2) {
|
|
12211
12211
|
"use strict";
|
|
12212
|
-
var
|
|
12212
|
+
var parse9 = require_parse3();
|
|
12213
12213
|
var constants2 = require_constants();
|
|
12214
12214
|
var SemVer = require_semver();
|
|
12215
12215
|
var truncate3 = (version2, truncation, options) => {
|
|
@@ -12221,7 +12221,7 @@ var require_truncate = __commonJS({
|
|
|
12221
12221
|
};
|
|
12222
12222
|
var cloneInputVersion = (version2, options) => {
|
|
12223
12223
|
const versionStringToParse = version2 instanceof SemVer ? version2.version : version2;
|
|
12224
|
-
return
|
|
12224
|
+
return parse9(versionStringToParse, options);
|
|
12225
12225
|
};
|
|
12226
12226
|
var doTruncation = (version2, truncation) => {
|
|
12227
12227
|
if (isPrerelease(truncation)) {
|
|
@@ -13257,7 +13257,7 @@ var require_semver2 = __commonJS({
|
|
|
13257
13257
|
var constants2 = require_constants();
|
|
13258
13258
|
var SemVer = require_semver();
|
|
13259
13259
|
var identifiers = require_identifiers();
|
|
13260
|
-
var
|
|
13260
|
+
var parse9 = require_parse3();
|
|
13261
13261
|
var valid = require_valid();
|
|
13262
13262
|
var clean = require_clean();
|
|
13263
13263
|
var inc = require_inc();
|
|
@@ -13296,7 +13296,7 @@ var require_semver2 = __commonJS({
|
|
|
13296
13296
|
var simplifyRange = require_simplify();
|
|
13297
13297
|
var subset = require_subset();
|
|
13298
13298
|
module2.exports = {
|
|
13299
|
-
parse:
|
|
13299
|
+
parse: parse9,
|
|
13300
13300
|
valid,
|
|
13301
13301
|
clean,
|
|
13302
13302
|
inc,
|
|
@@ -15441,7 +15441,7 @@ var require_extension = __commonJS({
|
|
|
15441
15441
|
if (dest[name] === void 0) dest[name] = [elem];
|
|
15442
15442
|
else dest[name].push(elem);
|
|
15443
15443
|
}
|
|
15444
|
-
function
|
|
15444
|
+
function parse9(header) {
|
|
15445
15445
|
const offers = /* @__PURE__ */ Object.create(null);
|
|
15446
15446
|
let params = /* @__PURE__ */ Object.create(null);
|
|
15447
15447
|
let mustUnescape = false;
|
|
@@ -15581,7 +15581,7 @@ var require_extension = __commonJS({
|
|
|
15581
15581
|
}).join(", ");
|
|
15582
15582
|
}).join(", ");
|
|
15583
15583
|
}
|
|
15584
|
-
module2.exports = { format, parse:
|
|
15584
|
+
module2.exports = { format, parse: parse9 };
|
|
15585
15585
|
}
|
|
15586
15586
|
});
|
|
15587
15587
|
|
|
@@ -15615,7 +15615,7 @@ var require_websocket = __commonJS({
|
|
|
15615
15615
|
var {
|
|
15616
15616
|
EventTarget: { addEventListener, removeEventListener }
|
|
15617
15617
|
} = require_event_target();
|
|
15618
|
-
var { format, parse:
|
|
15618
|
+
var { format, parse: parse9 } = require_extension();
|
|
15619
15619
|
var { toBuffer } = require_buffer_util();
|
|
15620
15620
|
var kAborted = Symbol("kAborted");
|
|
15621
15621
|
var protocolVersions = [8, 13];
|
|
@@ -16292,7 +16292,7 @@ var require_websocket = __commonJS({
|
|
|
16292
16292
|
}
|
|
16293
16293
|
let extensions;
|
|
16294
16294
|
try {
|
|
16295
|
-
extensions =
|
|
16295
|
+
extensions = parse9(secWebSocketExtensions);
|
|
16296
16296
|
} catch (err) {
|
|
16297
16297
|
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
16298
16298
|
abortHandshake(websocket, socket, message);
|
|
@@ -16584,7 +16584,7 @@ var require_subprotocol = __commonJS({
|
|
|
16584
16584
|
"../../node_modules/.pnpm/ws@8.21.0/node_modules/ws/lib/subprotocol.js"(exports2, module2) {
|
|
16585
16585
|
"use strict";
|
|
16586
16586
|
var { tokenChars } = require_validation2();
|
|
16587
|
-
function
|
|
16587
|
+
function parse9(header) {
|
|
16588
16588
|
const protocols = /* @__PURE__ */ new Set();
|
|
16589
16589
|
let start = -1;
|
|
16590
16590
|
let end = -1;
|
|
@@ -16620,7 +16620,7 @@ var require_subprotocol = __commonJS({
|
|
|
16620
16620
|
protocols.add(protocol);
|
|
16621
16621
|
return protocols;
|
|
16622
16622
|
}
|
|
16623
|
-
module2.exports = { parse:
|
|
16623
|
+
module2.exports = { parse: parse9 };
|
|
16624
16624
|
}
|
|
16625
16625
|
});
|
|
16626
16626
|
|
|
@@ -20774,10 +20774,10 @@ var require_packer_sync = __commonJS({
|
|
|
20774
20774
|
var require_png_sync = __commonJS({
|
|
20775
20775
|
"../../node_modules/.pnpm/pngjs@5.0.0/node_modules/pngjs/lib/png-sync.js"(exports2) {
|
|
20776
20776
|
"use strict";
|
|
20777
|
-
var
|
|
20777
|
+
var parse9 = require_parser_sync();
|
|
20778
20778
|
var pack = require_packer_sync();
|
|
20779
20779
|
exports2.read = function(buffer, options) {
|
|
20780
|
-
return
|
|
20780
|
+
return parse9(buffer, options || {});
|
|
20781
20781
|
};
|
|
20782
20782
|
exports2.write = function(png, options) {
|
|
20783
20783
|
return pack(png, options);
|
|
@@ -21565,7 +21565,7 @@ __export(install_public_mcp_exports, {
|
|
|
21565
21565
|
});
|
|
21566
21566
|
async function pathExists5(target) {
|
|
21567
21567
|
try {
|
|
21568
|
-
await
|
|
21568
|
+
await import_promises18.default.access(target);
|
|
21569
21569
|
return true;
|
|
21570
21570
|
} catch {
|
|
21571
21571
|
return false;
|
|
@@ -21573,8 +21573,8 @@ async function pathExists5(target) {
|
|
|
21573
21573
|
}
|
|
21574
21574
|
async function writeAtomic(targetPath, content) {
|
|
21575
21575
|
const tempPath = `${targetPath}.${Date.now()}.tmp`;
|
|
21576
|
-
await
|
|
21577
|
-
await
|
|
21576
|
+
await import_promises18.default.writeFile(tempPath, content, { mode: 384 });
|
|
21577
|
+
await import_promises18.default.rename(tempPath, targetPath);
|
|
21578
21578
|
}
|
|
21579
21579
|
function renderTomlBlock(serverId, expected) {
|
|
21580
21580
|
let tomlStr = `
|
|
@@ -21597,7 +21597,7 @@ async function installPublicMcpServerToConfigs(serverId, expected) {
|
|
|
21597
21597
|
const claudePath = import_node_path42.default.join(homeDir, ".claude.json");
|
|
21598
21598
|
if (await pathExists5(claudePath)) {
|
|
21599
21599
|
try {
|
|
21600
|
-
const content = await
|
|
21600
|
+
const content = await import_promises18.default.readFile(claudePath, "utf8");
|
|
21601
21601
|
const parsed = JSON.parse(content);
|
|
21602
21602
|
if (!parsed.mcpServers) parsed.mcpServers = {};
|
|
21603
21603
|
parsed.mcpServers[serverId] = expected;
|
|
@@ -21611,8 +21611,8 @@ async function installPublicMcpServerToConfigs(serverId, expected) {
|
|
|
21611
21611
|
const codexPath = import_node_path42.default.join(homeDir, ".codex", "config.toml");
|
|
21612
21612
|
if (await pathExists5(codexPath)) {
|
|
21613
21613
|
try {
|
|
21614
|
-
const content = await
|
|
21615
|
-
const parsed =
|
|
21614
|
+
const content = await import_promises18.default.readFile(codexPath, "utf8");
|
|
21615
|
+
const parsed = toml5.parse(content);
|
|
21616
21616
|
if (!parsed.mcp_servers?.[serverId]) {
|
|
21617
21617
|
const appended = content.replace(/\n$/, "") + renderTomlBlock(serverId, expected);
|
|
21618
21618
|
await writeAtomic(codexPath, appended);
|
|
@@ -21623,14 +21623,14 @@ async function installPublicMcpServerToConfigs(serverId, expected) {
|
|
|
21623
21623
|
console.error(`Failed to inject MCP server into ${codexPath}`, e);
|
|
21624
21624
|
}
|
|
21625
21625
|
} else {
|
|
21626
|
-
await
|
|
21626
|
+
await import_promises18.default.mkdir(import_node_path42.default.dirname(codexPath), { recursive: true, mode: 448 }).catch(() => {
|
|
21627
21627
|
});
|
|
21628
21628
|
await writeAtomic(codexPath, renderTomlBlock(serverId, expected).trim() + "\n");
|
|
21629
21629
|
}
|
|
21630
21630
|
const agyPath = import_node_path42.default.join(homeDir, ".gemini", "antigravity", "mcp_config.json");
|
|
21631
21631
|
if (await pathExists5(agyPath)) {
|
|
21632
21632
|
try {
|
|
21633
|
-
const content = await
|
|
21633
|
+
const content = await import_promises18.default.readFile(agyPath, "utf8");
|
|
21634
21634
|
const parsed = JSON.parse(content);
|
|
21635
21635
|
if (!parsed.mcpServers) parsed.mcpServers = {};
|
|
21636
21636
|
parsed.mcpServers[serverId] = expected;
|
|
@@ -21639,19 +21639,19 @@ async function installPublicMcpServerToConfigs(serverId, expected) {
|
|
|
21639
21639
|
console.error(`Failed to inject MCP server into ${agyPath}`, e);
|
|
21640
21640
|
}
|
|
21641
21641
|
} else {
|
|
21642
|
-
await
|
|
21642
|
+
await import_promises18.default.mkdir(import_node_path42.default.dirname(agyPath), { recursive: true, mode: 448 }).catch(() => {
|
|
21643
21643
|
});
|
|
21644
21644
|
await writeAtomic(agyPath, JSON.stringify({ mcpServers: { [serverId]: expected } }, null, 2) + "\n");
|
|
21645
21645
|
}
|
|
21646
21646
|
}
|
|
21647
|
-
var
|
|
21647
|
+
var import_promises18, import_node_os21, import_node_path42, toml5;
|
|
21648
21648
|
var init_install_public_mcp = __esm({
|
|
21649
21649
|
"src/install-public-mcp.ts"() {
|
|
21650
21650
|
"use strict";
|
|
21651
|
-
|
|
21651
|
+
import_promises18 = __toESM(require("node:fs/promises"), 1);
|
|
21652
21652
|
import_node_os21 = __toESM(require("node:os"), 1);
|
|
21653
21653
|
import_node_path42 = __toESM(require("node:path"), 1);
|
|
21654
|
-
|
|
21654
|
+
toml5 = __toESM(require_toml(), 1);
|
|
21655
21655
|
}
|
|
21656
21656
|
});
|
|
21657
21657
|
|
|
@@ -21662,7 +21662,7 @@ __export(bin_exports, {
|
|
|
21662
21662
|
});
|
|
21663
21663
|
module.exports = __toCommonJS(bin_exports);
|
|
21664
21664
|
var import_node_path49 = __toESM(require("node:path"), 1);
|
|
21665
|
-
var
|
|
21665
|
+
var import_node_child_process25 = require("node:child_process");
|
|
21666
21666
|
var import_node_fs32 = require("node:fs");
|
|
21667
21667
|
var import_node_os25 = require("node:os");
|
|
21668
21668
|
var import_node_path50 = __toESM(require("node:path"), 1);
|
|
@@ -22076,13 +22076,6 @@ function reapSelfOwnedBrowserSession(holderPid, directorSessionId, opts = {}) {
|
|
|
22076
22076
|
browserSessionOwners.delete(holderPid);
|
|
22077
22077
|
return { reaped: true, killedPids, killedChildPids };
|
|
22078
22078
|
}
|
|
22079
|
-
function externalAgentsServeArgs() {
|
|
22080
|
-
return {
|
|
22081
|
-
command: process.execPath,
|
|
22082
|
-
// node
|
|
22083
|
-
args: [resolvePackageBin("@mrrlin-dev/external-agents", "external-agents-mcp")]
|
|
22084
|
-
};
|
|
22085
|
-
}
|
|
22086
22079
|
async function installBrowser(opts = {}) {
|
|
22087
22080
|
const homeDir = opts.homeDir ?? import_node_os.default.homedir();
|
|
22088
22081
|
const { browsersPath } = browserPaths(homeDir);
|
|
@@ -22115,12 +22108,40 @@ async function installBrowser(opts = {}) {
|
|
|
22115
22108
|
return { action: "installed", browsersPath };
|
|
22116
22109
|
}
|
|
22117
22110
|
|
|
22111
|
+
// src/toml-mcp-block.ts
|
|
22112
|
+
function blockRegex(id) {
|
|
22113
|
+
const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22114
|
+
return new RegExp(`(^|\\n)\\[mcp_servers\\.${escaped}\\][\\s\\S]*?(?=\\n\\[(?!\\]|mcp_servers\\.${escaped}\\.)|$)`);
|
|
22115
|
+
}
|
|
22116
|
+
|
|
22118
22117
|
// src/mcp-config-reconcile.ts
|
|
22119
22118
|
var import_node_fs2 = __toESM(require("node:fs"), 1);
|
|
22120
22119
|
var import_node_os2 = __toESM(require("node:os"), 1);
|
|
22121
22120
|
var import_node_path2 = __toESM(require("node:path"), 1);
|
|
22122
22121
|
var toml = __toESM(require_toml(), 1);
|
|
22123
22122
|
var KNOWN_MRRLIN_ENV_KEYS = /* @__PURE__ */ new Set(["MRRLIN_API_BASE_URL"]);
|
|
22123
|
+
function isMrrlinServeEntryShape(entry) {
|
|
22124
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return false;
|
|
22125
|
+
const table = entry;
|
|
22126
|
+
if (table.enabled === false) return false;
|
|
22127
|
+
if (table.env !== void 0) {
|
|
22128
|
+
const env = table.env;
|
|
22129
|
+
if (typeof env !== "object" || env === null || Array.isArray(env)) return false;
|
|
22130
|
+
if (!Object.values(env).every((value) => typeof value === "string")) return false;
|
|
22131
|
+
}
|
|
22132
|
+
if (table.startup_timeout_sec !== void 0) {
|
|
22133
|
+
const timeout = table.startup_timeout_sec;
|
|
22134
|
+
if (typeof timeout !== "number" || !Number.isFinite(timeout) || timeout <= 0) return false;
|
|
22135
|
+
}
|
|
22136
|
+
if (typeof table.command !== "string" || !Array.isArray(table.args)) return false;
|
|
22137
|
+
const args = table.args;
|
|
22138
|
+
if (!args.every((a) => typeof a === "string")) return false;
|
|
22139
|
+
if (table.command === "mrrlin-mcp") return args.length === 1 && args[0] === "serve";
|
|
22140
|
+
if (table.command === "node") {
|
|
22141
|
+
return args.length === 2 && args[1] === "serve" && import_node_path2.default.isAbsolute(args[0]) && args[0].endsWith(".cjs");
|
|
22142
|
+
}
|
|
22143
|
+
return false;
|
|
22144
|
+
}
|
|
22124
22145
|
function commandArgsTimeoutEqual(candidate, expected) {
|
|
22125
22146
|
if (candidate.command !== expected.command) return false;
|
|
22126
22147
|
const actualArgs = candidate.args === void 0 && expected.args.length === 0 ? [] : Array.isArray(candidate.args) ? candidate.args : null;
|
|
@@ -22462,18 +22483,10 @@ function mrrlinTable(binPath, distribution, serveEnv) {
|
|
|
22462
22483
|
}
|
|
22463
22484
|
return { ...base, startup_timeout_sec: 30 };
|
|
22464
22485
|
}
|
|
22465
|
-
function externalAgentsTable(binPath, distribution) {
|
|
22466
|
-
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["external-agents-serve"] } : { command: "node", args: [binPath, "external-agents-serve"] };
|
|
22467
|
-
return { ...base, startup_timeout_sec: 30 };
|
|
22468
|
-
}
|
|
22469
22486
|
function browserTable(binPath, distribution, homeDir) {
|
|
22470
22487
|
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["browser-serve"] } : { command: "node", args: [binPath, "browser-serve"] };
|
|
22471
22488
|
return { ...base, startup_timeout_sec: 30, env: { PLAYWRIGHT_BROWSERS_PATH: browserPaths(homeDir).browsersPath } };
|
|
22472
22489
|
}
|
|
22473
|
-
function blockRegex(id) {
|
|
22474
|
-
const escaped = id.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22475
|
-
return new RegExp(`(^|\\n)\\[mcp_servers\\.${escaped}\\][\\s\\S]*?(?=\\n\\[(?!\\]|mcp_servers\\.${escaped}\\.)|$)`);
|
|
22476
|
-
}
|
|
22477
22490
|
function renderBlock(id, expected) {
|
|
22478
22491
|
const lines2 = [
|
|
22479
22492
|
"",
|
|
@@ -22515,25 +22528,6 @@ function managedBlocks(options, distribution) {
|
|
|
22515
22528
|
id: "mrrlin-browser",
|
|
22516
22529
|
expected: browserTable(options.binPath, distribution, homeDir),
|
|
22517
22530
|
blockRe: blockRegex("mrrlin-browser")
|
|
22518
|
-
},
|
|
22519
|
-
{
|
|
22520
|
-
id: "external-agents",
|
|
22521
|
-
expected: externalAgentsTable(options.binPath, distribution),
|
|
22522
|
-
blockRe: blockRegex("external-agents"),
|
|
22523
|
-
// Match ONLY the exact shape this installer used to write: a bare command, optionally with
|
|
22524
|
-
// empty args / a startup_timeout_sec, and NOTHING else. An extra key means the operator
|
|
22525
|
-
// customized the block — most plausibly a hand-added `env` carrying provider API keys, which
|
|
22526
|
-
// renderBlock() would silently drop on rewrite (it renders strictly from `expected`). Such a
|
|
22527
|
-
// block must fall through to CODEX_CONFIG_CONFLICT so replacing it takes an explicit --force,
|
|
22528
|
-
// rather than losing an operator's credentials during a routine update. We deliberately do
|
|
22529
|
-
// NOT carry the env forward instead: KNOWN_MRRLIN_ENV_KEYS treats any foreign key as
|
|
22530
|
-
// operator-authored and never-preserve, so a carried key would turn the NEXT bare re-run into
|
|
22531
|
-
// a conflict and break idempotency.
|
|
22532
|
-
isLegacyOurs: (actual) => {
|
|
22533
|
-
const legacyKeys = /* @__PURE__ */ new Set(["command", "args", "startup_timeout_sec"]);
|
|
22534
|
-
if (!Object.keys(actual).every((key) => legacyKeys.has(key))) return false;
|
|
22535
|
-
return actual.command === "external-agents-mcp" && (actual.args === void 0 || Array.isArray(actual.args) && actual.args.length === 0);
|
|
22536
|
-
}
|
|
22537
22531
|
}
|
|
22538
22532
|
];
|
|
22539
22533
|
}
|
|
@@ -22560,7 +22554,12 @@ async function installCodex(options) {
|
|
|
22560
22554
|
if (!await pathExists(configPath)) {
|
|
22561
22555
|
const content2 = blocks.map((b) => renderBlock(b.id, b.expected)).join("").replace(/^\n/, "");
|
|
22562
22556
|
await import_promises.default.writeFile(configPath, content2, { mode: 384 });
|
|
22563
|
-
return {
|
|
22557
|
+
return {
|
|
22558
|
+
action: "created",
|
|
22559
|
+
configPath,
|
|
22560
|
+
prompts: await writePrompts(),
|
|
22561
|
+
preservedEnvBlocks: []
|
|
22562
|
+
};
|
|
22564
22563
|
}
|
|
22565
22564
|
const realPath = await resolveRealConfigPath(configPath);
|
|
22566
22565
|
let content = await import_promises.default.readFile(realPath, "utf8");
|
|
@@ -22700,10 +22699,6 @@ function mrrlinTable2(binPath, distribution, serveEnv) {
|
|
|
22700
22699
|
}
|
|
22701
22700
|
return base;
|
|
22702
22701
|
}
|
|
22703
|
-
function externalAgentsTable2(binPath, distribution) {
|
|
22704
|
-
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["external-agents-serve"] } : { command: "node", args: [binPath, "external-agents-serve"] };
|
|
22705
|
-
return base;
|
|
22706
|
-
}
|
|
22707
22702
|
function browserTable2(binPath, distribution, homeDir) {
|
|
22708
22703
|
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["browser-serve"] } : { command: "node", args: [binPath, "browser-serve"] };
|
|
22709
22704
|
return { ...base, env: { PLAYWRIGHT_BROWSERS_PATH: browserPaths(homeDir).browsersPath } };
|
|
@@ -22712,8 +22707,7 @@ function managedEntries(options, distribution) {
|
|
|
22712
22707
|
const homeDir = options.homeDir ?? import_node_os4.default.homedir();
|
|
22713
22708
|
return [
|
|
22714
22709
|
{ id: "mrrlin", expected: mrrlinTable2(options.binPath, distribution, options.serveEnv) },
|
|
22715
|
-
{ id: "mrrlin-browser", expected: browserTable2(options.binPath, distribution, homeDir) }
|
|
22716
|
-
{ id: "external-agents", expected: externalAgentsTable2(options.binPath, distribution) }
|
|
22710
|
+
{ id: "mrrlin-browser", expected: browserTable2(options.binPath, distribution, homeDir) }
|
|
22717
22711
|
];
|
|
22718
22712
|
}
|
|
22719
22713
|
async function pathExists2(target) {
|
|
@@ -22733,7 +22727,11 @@ async function installClaude(options) {
|
|
|
22733
22727
|
for (const entry of entries) mcpServers2[entry.id] = entry.expected;
|
|
22734
22728
|
await import_promises2.default.writeFile(configPath, `${JSON.stringify({ mcpServers: mcpServers2 }, null, 2)}
|
|
22735
22729
|
`, { mode: 384 });
|
|
22736
|
-
return {
|
|
22730
|
+
return {
|
|
22731
|
+
action: "created",
|
|
22732
|
+
configPath,
|
|
22733
|
+
preservedEnvBlocks: []
|
|
22734
|
+
};
|
|
22737
22735
|
}
|
|
22738
22736
|
const rawContent = await import_promises2.default.readFile(configPath, "utf8");
|
|
22739
22737
|
let parsed;
|
|
@@ -37567,8 +37565,6 @@ var openApiOperationIds = {
|
|
|
37567
37565
|
updateOperatorSettings: "updateOperatorSettings",
|
|
37568
37566
|
recordOperatorPresence: "recordOperatorPresence",
|
|
37569
37567
|
pauseAutopilotForLimit: "pauseAutopilotForLimit",
|
|
37570
|
-
getAgentPool: "getAgentPool",
|
|
37571
|
-
putAgentPool: "putAgentPool",
|
|
37572
37568
|
getProviderReadiness: "getProviderReadiness",
|
|
37573
37569
|
putProviderReadiness: "putProviderReadiness",
|
|
37574
37570
|
getConsensusConfig: "getConsensusConfig",
|
|
@@ -37743,27 +37739,6 @@ var mrrlinAgentProviderConfigSchema = external_exports.object({
|
|
|
37743
37739
|
agentProvider: external_exports.enum(["codex", "claude", "agy"])
|
|
37744
37740
|
});
|
|
37745
37741
|
var agentProviderConfigResponseSchema = external_exports.object({ data: mrrlinAgentProviderConfigSchema });
|
|
37746
|
-
var agentPoolSnapshotSchema = external_exports.object({
|
|
37747
|
-
collected_at: external_exports.string(),
|
|
37748
|
-
status: external_exports.enum(["ok", "unavailable"]),
|
|
37749
|
-
agents: external_exports.array(external_exports.object({
|
|
37750
|
-
id: external_exports.string(),
|
|
37751
|
-
provider: external_exports.string(),
|
|
37752
|
-
tier: external_exports.string(),
|
|
37753
|
-
tags: external_exports.array(external_exports.string()),
|
|
37754
|
-
state: external_exports.string(),
|
|
37755
|
-
calls: external_exports.number(),
|
|
37756
|
-
tokens_in: external_exports.number(),
|
|
37757
|
-
tokens_out: external_exports.number(),
|
|
37758
|
-
success_rate: external_exports.number(),
|
|
37759
|
-
last_used_at: external_exports.string().nullable()
|
|
37760
|
-
})),
|
|
37761
|
-
totals: external_exports.object({ calls: external_exports.number(), tokens_in: external_exports.number(), tokens_out: external_exports.number() }),
|
|
37762
|
-
estimated_savings_usd: external_exports.number()
|
|
37763
|
-
});
|
|
37764
|
-
var agentPoolResponseSchema = external_exports.object({
|
|
37765
|
-
data: external_exports.object({ snapshot: agentPoolSnapshotSchema.nullable() })
|
|
37766
|
-
});
|
|
37767
37742
|
var agentCapabilitiesSchema = external_exports.object({
|
|
37768
37743
|
listsModels: external_exports.boolean(),
|
|
37769
37744
|
// claude-rate-limit-percent design.md D1/D2 — split from a single `readsRateLimits`, which
|
|
@@ -42283,18 +42258,6 @@ function createMrrlinClient(config2) {
|
|
|
42283
42258
|
});
|
|
42284
42259
|
return operatorPresenceResponseSchema.parse(body).data;
|
|
42285
42260
|
},
|
|
42286
|
-
async getOperatorAgentPool() {
|
|
42287
|
-
const body = await request(`/operator/agent-pool`);
|
|
42288
|
-
return agentPoolResponseSchema.parse(body).data;
|
|
42289
|
-
},
|
|
42290
|
-
async putOperatorAgentPool(snapshot) {
|
|
42291
|
-
const body = await request(`/operator/agent-pool`, {
|
|
42292
|
-
body: JSON.stringify(snapshot),
|
|
42293
|
-
headers: { "content-type": "application/json" },
|
|
42294
|
-
method: "POST"
|
|
42295
|
-
});
|
|
42296
|
-
return agentPoolResponseSchema.parse(body).data;
|
|
42297
|
-
},
|
|
42298
42261
|
async getOperatorProviderReadiness() {
|
|
42299
42262
|
const body = await request(`/operator/provider-readiness`);
|
|
42300
42263
|
return providerReadinessResponseSchema.parse(body).data;
|
|
@@ -46378,7 +46341,7 @@ function firstString(...values) {
|
|
|
46378
46341
|
return null;
|
|
46379
46342
|
}
|
|
46380
46343
|
function runCodexExec(input, deps) {
|
|
46381
|
-
const
|
|
46344
|
+
const spawn9 = deps?.spawn ?? import_node_child_process6.spawn;
|
|
46382
46345
|
const executable = input.codexExecutable ?? "codex";
|
|
46383
46346
|
const sandbox = input.sandbox ?? "read-only";
|
|
46384
46347
|
const fullPrompt = input.developerInstructions.trim() ? `${input.developerInstructions.trim()}
|
|
@@ -46424,7 +46387,7 @@ ${input.prompt}` : input.prompt;
|
|
|
46424
46387
|
}
|
|
46425
46388
|
let child;
|
|
46426
46389
|
try {
|
|
46427
|
-
child =
|
|
46390
|
+
child = spawn9(spawnCmd, spawnArgs, options);
|
|
46428
46391
|
} catch (err) {
|
|
46429
46392
|
finish({ ok: false, error: `Failed to spawn codex exec: ${errMessage(err)}` });
|
|
46430
46393
|
return;
|
|
@@ -46470,7 +46433,7 @@ function errMessage(err) {
|
|
|
46470
46433
|
// ../../packages/agent-client/dist/providers/claude/exec.js
|
|
46471
46434
|
var import_node_child_process7 = require("node:child_process");
|
|
46472
46435
|
function runClaudeExec(input, deps) {
|
|
46473
|
-
const
|
|
46436
|
+
const spawn9 = deps?.spawn ?? import_node_child_process7.spawn;
|
|
46474
46437
|
const executable = input.codexExecutable ?? "claude";
|
|
46475
46438
|
const args = ["--print", "--output-format", "json", "--strict-mcp-config"];
|
|
46476
46439
|
if (input.mcpConfig) {
|
|
@@ -46513,7 +46476,7 @@ function runClaudeExec(input, deps) {
|
|
|
46513
46476
|
}
|
|
46514
46477
|
let child;
|
|
46515
46478
|
try {
|
|
46516
|
-
child =
|
|
46479
|
+
child = spawn9(spawnCmd, spawnArgs, options);
|
|
46517
46480
|
} catch (err) {
|
|
46518
46481
|
finish({ ok: false, error: `Failed to spawn ${executable} exec: ${errMessage2(err)}` });
|
|
46519
46482
|
return;
|
|
@@ -46587,7 +46550,7 @@ function errMessage2(err) {
|
|
|
46587
46550
|
// ../../packages/agent-client/dist/providers/agy/exec.js
|
|
46588
46551
|
var import_node_child_process8 = require("node:child_process");
|
|
46589
46552
|
function runAgyExec(input, deps) {
|
|
46590
|
-
const
|
|
46553
|
+
const spawn9 = deps?.spawn ?? import_node_child_process8.spawn;
|
|
46591
46554
|
const executable = input.codexExecutable ?? "agy";
|
|
46592
46555
|
const args = ["--output-format", "json"];
|
|
46593
46556
|
if (input.sandbox === "read-only") {
|
|
@@ -46640,7 +46603,7 @@ function runAgyExec(input, deps) {
|
|
|
46640
46603
|
}
|
|
46641
46604
|
let child;
|
|
46642
46605
|
try {
|
|
46643
|
-
child =
|
|
46606
|
+
child = spawn9(spawnCmd, spawnArgs, options);
|
|
46644
46607
|
} catch (err) {
|
|
46645
46608
|
finish({ ok: false, error: `Failed to spawn ${executable} exec: ${err instanceof Error ? err.message : String(err)}` });
|
|
46646
46609
|
return;
|
|
@@ -48872,9 +48835,8 @@ function buildSpecGateDeps(args) {
|
|
|
48872
48835
|
return {
|
|
48873
48836
|
rounds,
|
|
48874
48837
|
maxHeadCalls,
|
|
48875
|
-
//
|
|
48876
|
-
//
|
|
48877
|
-
// this factory's seat.
|
|
48838
|
+
// Cost recorder for an externally supplied head runner — see GateHeadCallRecorder.
|
|
48839
|
+
// `{ provider: null }` because such a head does not run on this factory's seat.
|
|
48878
48840
|
recordHeadCall: (persona, agentId, startedAt, result) => recordCost("head", persona, agentId, startedAt, result, { provider: null }),
|
|
48879
48841
|
async consensusEnabled() {
|
|
48880
48842
|
const config2 = await client.getConsensusConfig(projectSlug);
|
|
@@ -49084,9 +49046,7 @@ function buildCodeGateDeps(args) {
|
|
|
49084
49046
|
rounds,
|
|
49085
49047
|
maxHeadCalls,
|
|
49086
49048
|
heads,
|
|
49087
|
-
//
|
|
49088
|
-
// `applyActivePanel`, which replaces `runHead` below. Without this hook the panel's head calls
|
|
49089
|
-
// were recorded nowhere at all — see GateHeadCallRecorder.
|
|
49049
|
+
// Cost recorder for an externally supplied head runner — see GateHeadCallRecorder.
|
|
49090
49050
|
recordHeadCall: (persona, agentId, startedAt, result) => recordCost("head", persona, agentId, startedAt, result, { provider: null }),
|
|
49091
49051
|
async consensusEnabled() {
|
|
49092
49052
|
const config2 = await client.getConsensusConfig(projectSlug);
|
|
@@ -49395,554 +49355,6 @@ You revise a deliverable to address the accepted issues so it satisfies the acce
|
|
|
49395
49355
|
};
|
|
49396
49356
|
}
|
|
49397
49357
|
|
|
49398
|
-
// src/consensus/multi-llm-head.ts
|
|
49399
|
-
var import_node_child_process12 = require("node:child_process");
|
|
49400
|
-
|
|
49401
|
-
// src/external-agents-bin.ts
|
|
49402
|
-
function resolveExternalAgentsCliInvocation(override) {
|
|
49403
|
-
if (override && override.trim()) return { command: override, prefixArgs: [] };
|
|
49404
|
-
try {
|
|
49405
|
-
return {
|
|
49406
|
-
command: "node",
|
|
49407
|
-
prefixArgs: [resolvePackageBin("@mrrlin-dev/external-agents", "external-agents")]
|
|
49408
|
-
};
|
|
49409
|
-
} catch {
|
|
49410
|
-
return { command: "external-agents", prefixArgs: [] };
|
|
49411
|
-
}
|
|
49412
|
-
}
|
|
49413
|
-
|
|
49414
|
-
// src/redact.ts
|
|
49415
|
-
var REDACTED = "[REDACTED]";
|
|
49416
|
-
var SECRET_PATTERNS = [
|
|
49417
|
-
// Mrrlin agent secret: mrrlin_agent_<base64url selector>.<base64url secret>. base64url uses - and
|
|
49418
|
-
// _, which the generic base64 run below does not cover, so most real secrets slipped through it.
|
|
49419
|
-
/mrrlin_agent_[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/g,
|
|
49420
|
-
// GitHub tokens: ghp_ (classic PAT), gho_ (OAuth), ghu_ (user-to-server), ghs_ (server-to-server,
|
|
49421
|
-
// e.g. an App installation token), ghr_ (refresh token).
|
|
49422
|
-
/gh[oprsu]_[A-Za-z0-9]{20,}/g,
|
|
49423
|
-
/github_pat_[A-Za-z0-9_]{20,}/g,
|
|
49424
|
-
// GitHub fine-grained PAT
|
|
49425
|
-
/sk-ant-[A-Za-z0-9_-]{20,}/g,
|
|
49426
|
-
// Anthropic key or OAuth token (sk-ant-api03-..., sk-ant-oat01-...)
|
|
49427
|
-
/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
|
|
49428
|
-
// AWS access key id (long-term AKIA, temporary ASIA)
|
|
49429
|
-
/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi,
|
|
49430
|
-
// Authorization: Bearer <token>
|
|
49431
|
-
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
49432
|
-
// JWT (header.payload.signature)
|
|
49433
|
-
/\b[A-Fa-f0-9]{32,}\b/g,
|
|
49434
|
-
// long hex run (hashes, hex secrets)
|
|
49435
|
-
/\b[A-Za-z0-9+/]{40,}={0,2}\b/g
|
|
49436
|
-
// long base64-ish run (opaque tokens)
|
|
49437
|
-
];
|
|
49438
|
-
function redact(input) {
|
|
49439
|
-
let out = input;
|
|
49440
|
-
for (const re of SECRET_PATTERNS) out = out.replace(re, REDACTED);
|
|
49441
|
-
return out;
|
|
49442
|
-
}
|
|
49443
|
-
var SECRET_FORMAT_PATTERNS = [
|
|
49444
|
-
/\bmrrlin_agent_[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{32,}/g,
|
|
49445
|
-
// Mrrlin agent secret (selector.secret)
|
|
49446
|
-
/\bgh[oprsu]_[A-Za-z0-9]{20,}/g,
|
|
49447
|
-
// GitHub classic/OAuth/user/server/refresh tokens
|
|
49448
|
-
/\bgithub_pat_[A-Za-z0-9_]{20,}/g,
|
|
49449
|
-
// GitHub fine-grained PAT
|
|
49450
|
-
/\bsk-ant-[A-Za-z0-9_-]{20,}/g,
|
|
49451
|
-
// Anthropic API key or OAuth token
|
|
49452
|
-
/\bsk-(?:proj|svcacct|admin|or-v1)-[A-Za-z0-9_-]{20,}/g,
|
|
49453
|
-
// OpenAI project/service/admin, OpenRouter
|
|
49454
|
-
/\bsk-[A-Za-z0-9]{32,}\b/g,
|
|
49455
|
-
// OpenAI legacy, DeepSeek
|
|
49456
|
-
/\bgsk_[A-Za-z0-9]{20,}/g,
|
|
49457
|
-
// Groq
|
|
49458
|
-
/\bAIza[A-Za-z0-9_-]{35}/g,
|
|
49459
|
-
// Google API key
|
|
49460
|
-
/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
|
|
49461
|
-
// AWS access key id
|
|
49462
|
-
/\bxox[abposr]-[A-Za-z0-9-]{10,}/g,
|
|
49463
|
-
// Slack token
|
|
49464
|
-
/-----BEGIN (?:[A-Z0-9]+ )*PRIVATE KEY-----[\s\S]*?-----END (?:[A-Z0-9]+ )*PRIVATE KEY-----/g,
|
|
49465
|
-
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
49466
|
-
// JWT (header.payload.signature)
|
|
49467
|
-
// Authorization: Bearer <token>, only when the token is token-shaped: 20+ chars with a digit.
|
|
49468
|
-
/\bBearer\s+(?=[A-Za-z0-9._~+/-]*[0-9])[A-Za-z0-9._~+/-]{20,}=*/g
|
|
49469
|
-
];
|
|
49470
|
-
function redactSecretFormats(input) {
|
|
49471
|
-
let out = input;
|
|
49472
|
-
for (const re of SECRET_FORMAT_PATTERNS) out = out.replace(re, REDACTED);
|
|
49473
|
-
return out;
|
|
49474
|
-
}
|
|
49475
|
-
|
|
49476
|
-
// src/consensus/provider-limits.ts
|
|
49477
|
-
var import_node_child_process11 = require("node:child_process");
|
|
49478
|
-
var DEFAULT_STATUS_TIMEOUT_MS = 1e4;
|
|
49479
|
-
function errMessage3(err) {
|
|
49480
|
-
return err instanceof Error ? err.message : String(err);
|
|
49481
|
-
}
|
|
49482
|
-
function runExternalAgentsStatus(bin, args, timeoutMs, spawn10) {
|
|
49483
|
-
return new Promise((resolve3) => {
|
|
49484
|
-
let settled = false;
|
|
49485
|
-
const timerRef = { id: void 0 };
|
|
49486
|
-
const finish = (r) => {
|
|
49487
|
-
if (settled) return;
|
|
49488
|
-
settled = true;
|
|
49489
|
-
if (timerRef.id) clearTimeout(timerRef.id);
|
|
49490
|
-
resolve3(r);
|
|
49491
|
-
};
|
|
49492
|
-
const options = { stdio: ["ignore", "pipe", "pipe"], env: process.env, shell: false };
|
|
49493
|
-
let child;
|
|
49494
|
-
try {
|
|
49495
|
-
child = spawn10(bin, args, options);
|
|
49496
|
-
} catch (err) {
|
|
49497
|
-
finish({ stdout: "", error: `spawn ${bin} failed: ${errMessage3(err)}` });
|
|
49498
|
-
return;
|
|
49499
|
-
}
|
|
49500
|
-
let stdout = "";
|
|
49501
|
-
timerRef.id = setTimeout(() => {
|
|
49502
|
-
child.kill("SIGKILL");
|
|
49503
|
-
finish({ stdout, error: `external-agents status timed out after ${timeoutMs}ms` });
|
|
49504
|
-
}, timeoutMs);
|
|
49505
|
-
timerRef.id.unref?.();
|
|
49506
|
-
child.stdout?.on("data", (chunk) => {
|
|
49507
|
-
stdout += chunk.toString();
|
|
49508
|
-
});
|
|
49509
|
-
child.stderr?.on("data", () => {
|
|
49510
|
-
});
|
|
49511
|
-
child.on("error", (err) => finish({ stdout, error: `external-agents status error: ${errMessage3(err)}` }));
|
|
49512
|
-
child.on("close", (code) => {
|
|
49513
|
-
if (code !== 0 && !stdout.trim()) finish({ stdout, error: `external-agents status exited ${code}` });
|
|
49514
|
-
else finish({ stdout });
|
|
49515
|
-
});
|
|
49516
|
-
});
|
|
49517
|
-
}
|
|
49518
|
-
async function fetchRegistrySnapshot(deps) {
|
|
49519
|
-
const spawn10 = deps?.spawn ?? import_node_child_process11.spawn;
|
|
49520
|
-
const { command, prefixArgs } = resolveExternalAgentsCliInvocation(deps?.externalAgentsBin);
|
|
49521
|
-
const { stdout, error: error51 } = await runExternalAgentsStatus(
|
|
49522
|
-
command,
|
|
49523
|
-
[...prefixArgs, "status", "--json"],
|
|
49524
|
-
deps?.statusTimeoutMs ?? DEFAULT_STATUS_TIMEOUT_MS,
|
|
49525
|
-
spawn10
|
|
49526
|
-
);
|
|
49527
|
-
if (error51) return { ok: false, error: error51 };
|
|
49528
|
-
try {
|
|
49529
|
-
const parsed = JSON.parse(stdout);
|
|
49530
|
-
return { ok: true, entries: Array.isArray(parsed) ? parsed : [] };
|
|
49531
|
-
} catch (err) {
|
|
49532
|
-
return { ok: false, error: `unparseable status --json output: ${errMessage3(err)}` };
|
|
49533
|
-
}
|
|
49534
|
-
}
|
|
49535
|
-
function tightestPublishedContextWindow(entries) {
|
|
49536
|
-
const values = entries.map((e) => e.token_limits?.context_window).filter((v) => typeof v === "number" && v > 0);
|
|
49537
|
-
return values.length > 0 ? Math.min(...values) : null;
|
|
49538
|
-
}
|
|
49539
|
-
async function enforceProviderLimits(seat, agentId, tokenCount, deps) {
|
|
49540
|
-
const snapshot = await fetchRegistrySnapshot(deps);
|
|
49541
|
-
if (!snapshot.ok) {
|
|
49542
|
-
console.warn(
|
|
49543
|
-
JSON.stringify({ event: "provider_limits_check_skipped_fetch_failed", agentId, error: snapshot.error })
|
|
49544
|
-
);
|
|
49545
|
-
return { ok: true };
|
|
49546
|
-
}
|
|
49547
|
-
const entries = snapshot.entries;
|
|
49548
|
-
const entry = entries.find((e) => e.id === agentId);
|
|
49549
|
-
const ownContextWindow = entry?.token_limits?.context_window;
|
|
49550
|
-
const borrowedContextWindow = ownContextWindow == null ? tightestPublishedContextWindow(entries) : null;
|
|
49551
|
-
const effectiveContextWindow = ownContextWindow ?? borrowedContextWindow;
|
|
49552
|
-
if (effectiveContextWindow != null && tokenCount > effectiveContextWindow) {
|
|
49553
|
-
return { ok: false, reason: "over_context", borrowed: ownContextWindow == null };
|
|
49554
|
-
}
|
|
49555
|
-
const tpm = entry?.token_limits?.tpm;
|
|
49556
|
-
if (tpm != null && tokenCount > tpm) {
|
|
49557
|
-
return { ok: false, reason: "over_rate" };
|
|
49558
|
-
}
|
|
49559
|
-
return { ok: true };
|
|
49560
|
-
}
|
|
49561
|
-
|
|
49562
|
-
// src/consensus/multi-llm-head.ts
|
|
49563
|
-
function estimateTokenCount(text) {
|
|
49564
|
-
return Math.ceil(text.length / 4);
|
|
49565
|
-
}
|
|
49566
|
-
function errMessage4(err) {
|
|
49567
|
-
return err instanceof Error ? err.message : String(err);
|
|
49568
|
-
}
|
|
49569
|
-
function runExternalAgents(bin, args, label, timeoutMs, spawn10) {
|
|
49570
|
-
return new Promise((resolve3) => {
|
|
49571
|
-
let settled = false;
|
|
49572
|
-
const timerRef = { id: void 0 };
|
|
49573
|
-
const finish = (r) => {
|
|
49574
|
-
if (settled) return;
|
|
49575
|
-
settled = true;
|
|
49576
|
-
if (timerRef.id) clearTimeout(timerRef.id);
|
|
49577
|
-
resolve3(r);
|
|
49578
|
-
};
|
|
49579
|
-
const options = {
|
|
49580
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
49581
|
-
env: process.env,
|
|
49582
|
-
shell: false
|
|
49583
|
-
// SECURITY: prompt is an argv element; never hand it to a shell.
|
|
49584
|
-
};
|
|
49585
|
-
let child;
|
|
49586
|
-
try {
|
|
49587
|
-
child = spawn10(bin, args, options);
|
|
49588
|
-
} catch (err) {
|
|
49589
|
-
finish({ code: null, stdout: "", error: `spawn ${bin} failed: ${errMessage4(err)}` });
|
|
49590
|
-
return;
|
|
49591
|
-
}
|
|
49592
|
-
let stdout = "";
|
|
49593
|
-
timerRef.id = setTimeout(() => {
|
|
49594
|
-
child.kill("SIGKILL");
|
|
49595
|
-
finish({ code: null, stdout, error: `external-agents ${label} timed out after ${timeoutMs}ms` });
|
|
49596
|
-
}, timeoutMs);
|
|
49597
|
-
child.stdout?.on("data", (chunk) => {
|
|
49598
|
-
stdout += chunk.toString();
|
|
49599
|
-
});
|
|
49600
|
-
child.stderr?.on("data", () => {
|
|
49601
|
-
});
|
|
49602
|
-
child.on("error", (err) => finish({ code: null, stdout, error: `external-agents ${label} error: ${errMessage4(err)}` }));
|
|
49603
|
-
child.on("close", (code) => finish({ code, stdout }));
|
|
49604
|
-
});
|
|
49605
|
-
}
|
|
49606
|
-
async function pickPanel(input, deps) {
|
|
49607
|
-
const spawn10 = deps?.spawn ?? import_node_child_process12.spawn;
|
|
49608
|
-
const { command, prefixArgs } = resolveExternalAgentsCliInvocation(deps?.externalAgentsBin);
|
|
49609
|
-
const args = [
|
|
49610
|
-
"pick",
|
|
49611
|
-
"--tier-prefer",
|
|
49612
|
-
input.tierPrefer ?? "strong",
|
|
49613
|
-
"--n",
|
|
49614
|
-
String(input.n),
|
|
49615
|
-
"--min-distinct-providers",
|
|
49616
|
-
String(input.n),
|
|
49617
|
-
"--exclude-providers",
|
|
49618
|
-
input.excludeProvider
|
|
49619
|
-
];
|
|
49620
|
-
const r = await runExternalAgents(command, [...prefixArgs, ...args], "pick", input.timeoutMs, spawn10);
|
|
49621
|
-
if (r.error) return { ok: false, error: r.error };
|
|
49622
|
-
if (r.code === 3) return { ok: true, agents: [] };
|
|
49623
|
-
if (r.code !== 0) return { ok: false, error: `external-agents pick exited ${r.code}` };
|
|
49624
|
-
const agents = r.stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
49625
|
-
return { ok: true, agents };
|
|
49626
|
-
}
|
|
49627
|
-
function dispatchUsage(parsed) {
|
|
49628
|
-
const readCount3 = (value) => typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
49629
|
-
const inputTokens = readCount3(parsed.tokens_in);
|
|
49630
|
-
const outputTokens = readCount3(parsed.tokens_out);
|
|
49631
|
-
if (inputTokens === null && outputTokens === null) return null;
|
|
49632
|
-
return { inputTokens, cachedInputTokens: null, cacheWriteInputTokens: null, outputTokens };
|
|
49633
|
-
}
|
|
49634
|
-
function parseDispatch(agentId, stdout, exitCode) {
|
|
49635
|
-
const lines2 = stdout.split(/\r?\n/).map((l) => l.trim()).filter(Boolean);
|
|
49636
|
-
const jsonLine = [...lines2].reverse().find((l) => l[0] === "{");
|
|
49637
|
-
if (!jsonLine) return { ok: false, error: `dispatch ${agentId}: no JSON on stdout (exit ${exitCode})` };
|
|
49638
|
-
let parsed;
|
|
49639
|
-
try {
|
|
49640
|
-
parsed = JSON.parse(jsonLine);
|
|
49641
|
-
} catch (err) {
|
|
49642
|
-
return { ok: false, error: `dispatch ${agentId}: unparseable JSON (${errMessage4(err)})` };
|
|
49643
|
-
}
|
|
49644
|
-
if (parsed.outcome !== "success") {
|
|
49645
|
-
return { ok: false, error: `dispatch ${agentId}: outcome=${parsed.outcome} (exit ${parsed.exit_code})` };
|
|
49646
|
-
}
|
|
49647
|
-
if (typeof parsed.text !== "string" || parsed.text.trim() === "") {
|
|
49648
|
-
return { ok: false, error: `dispatch ${agentId}: empty text on success` };
|
|
49649
|
-
}
|
|
49650
|
-
const usage = dispatchUsage(parsed);
|
|
49651
|
-
return { ok: true, text: parsed.text, usage };
|
|
49652
|
-
}
|
|
49653
|
-
async function dispatchHead(agentId, prompt, timeoutMs, deps) {
|
|
49654
|
-
const spawn10 = deps?.spawn ?? import_node_child_process12.spawn;
|
|
49655
|
-
const { command, prefixArgs } = resolveExternalAgentsCliInvocation(deps?.externalAgentsBin);
|
|
49656
|
-
const args = ["dispatch", agentId, "--json", redactSecretFormats(prompt)];
|
|
49657
|
-
const r = await runExternalAgents(command, [...prefixArgs, ...args], "dispatch", timeoutMs, spawn10);
|
|
49658
|
-
if (r.error) return { ok: false, error: r.error };
|
|
49659
|
-
return parseDispatch(agentId, r.stdout, r.code);
|
|
49660
|
-
}
|
|
49661
|
-
async function buildMultiHeadRunner(input, deps) {
|
|
49662
|
-
const pickOnce = () => pickPanel(
|
|
49663
|
-
{ n: input.personas.length, excludeProvider: input.excludeProvider, tierPrefer: input.tierPrefer, timeoutMs: input.pickTimeoutMs },
|
|
49664
|
-
deps
|
|
49665
|
-
);
|
|
49666
|
-
const picked = await pickOnce();
|
|
49667
|
-
if (!picked.ok) return { ok: false, error: picked.error };
|
|
49668
|
-
if (picked.agents.length === 0) return { ok: false, error: "pick returned no agents" };
|
|
49669
|
-
function buildFromAgents(agents) {
|
|
49670
|
-
const assignment = {};
|
|
49671
|
-
input.personas.forEach((persona, i) => {
|
|
49672
|
-
const agent = agents[i % agents.length];
|
|
49673
|
-
if (agent) assignment[persona] = agent;
|
|
49674
|
-
});
|
|
49675
|
-
const composition = {
|
|
49676
|
-
requested: input.personas.length,
|
|
49677
|
-
filled: agents.length,
|
|
49678
|
-
agentIds: agents,
|
|
49679
|
-
underpowered: agents.length < input.personas.length
|
|
49680
|
-
};
|
|
49681
|
-
const runHead = async (persona, artifact, dismissed) => {
|
|
49682
|
-
const agentId = assignment[persona];
|
|
49683
|
-
if (!agentId) return { ok: false, error: `no agent assigned for persona ${persona}` };
|
|
49684
|
-
const instructions = input.personaInstructions[persona] ?? "";
|
|
49685
|
-
const dismissedBlock = dismissed.trim() ? `
|
|
49686
|
-
|
|
49687
|
-
${dismissed.trim()}` : "";
|
|
49688
|
-
const prompt = instructions.trim() ? `${instructions.trim()}
|
|
49689
|
-
|
|
49690
|
-
${artifact}${dismissedBlock}` : `${artifact}${dismissedBlock}`;
|
|
49691
|
-
if (input.seat) {
|
|
49692
|
-
const limits = await enforceProviderLimits(input.seat, agentId, estimateTokenCount(prompt), deps);
|
|
49693
|
-
if (!limits.ok) {
|
|
49694
|
-
const borrowed = limits.reason === "over_context" && limits.borrowed === true;
|
|
49695
|
-
console.warn(
|
|
49696
|
-
JSON.stringify({
|
|
49697
|
-
event: borrowed ? "head_skipped_borrowed_ceiling" : "head_skipped_over_budget",
|
|
49698
|
-
persona,
|
|
49699
|
-
agentId,
|
|
49700
|
-
reason: limits.reason
|
|
49701
|
-
})
|
|
49702
|
-
);
|
|
49703
|
-
return {
|
|
49704
|
-
ok: false,
|
|
49705
|
-
error: `${agentId} skipped (${limits.reason}${borrowed ? ", borrowed ceiling" : ""})`
|
|
49706
|
-
};
|
|
49707
|
-
}
|
|
49708
|
-
}
|
|
49709
|
-
console.log(JSON.stringify({ event: "pool_egress", persona, agentId, promptBytes: prompt.length }));
|
|
49710
|
-
return dispatchHead(agentId, prompt, input.dispatchTimeoutMs, deps);
|
|
49711
|
-
};
|
|
49712
|
-
return { agents, assignment, composition, runHead };
|
|
49713
|
-
}
|
|
49714
|
-
const built = buildFromAgents(picked.agents);
|
|
49715
|
-
const repick = async () => {
|
|
49716
|
-
const rePicked = await pickOnce();
|
|
49717
|
-
if (!rePicked.ok || rePicked.agents.length <= built.agents.length) return { ok: false };
|
|
49718
|
-
const rebuilt = buildFromAgents(rePicked.agents);
|
|
49719
|
-
return {
|
|
49720
|
-
ok: true,
|
|
49721
|
-
composition: rebuilt.composition,
|
|
49722
|
-
runHead: rebuilt.runHead,
|
|
49723
|
-
assignment: rebuilt.assignment
|
|
49724
|
-
};
|
|
49725
|
-
};
|
|
49726
|
-
return { ok: true, runner: { ...built, repick } };
|
|
49727
|
-
}
|
|
49728
|
-
|
|
49729
|
-
// src/consensus/multi-llm-shadow.ts
|
|
49730
|
-
var SHADOW_LOG_PREFIX = "__MULTI_LLM_SHADOW__";
|
|
49731
|
-
function rollUpVerdict(verdicts) {
|
|
49732
|
-
if (verdicts.includes("REJECT")) return "REJECT";
|
|
49733
|
-
if (verdicts.includes("REQUEST_CHANGES")) return "REQUEST_CHANGES";
|
|
49734
|
-
return "APPROVE";
|
|
49735
|
-
}
|
|
49736
|
-
async function runShadowPanel(input, deps) {
|
|
49737
|
-
const orchestratorSeat = input.orchestratorSeat;
|
|
49738
|
-
const base = {
|
|
49739
|
-
ran: false,
|
|
49740
|
-
correlationId: input.correlationId,
|
|
49741
|
-
productionVerdict: input.productionVerdict,
|
|
49742
|
-
orchestratorSeat
|
|
49743
|
-
};
|
|
49744
|
-
const built = await buildMultiHeadRunner(
|
|
49745
|
-
{
|
|
49746
|
-
personas: input.heads,
|
|
49747
|
-
personaInstructions: input.personaInstructions,
|
|
49748
|
-
excludeProvider: input.excludeProvider,
|
|
49749
|
-
tierPrefer: "strong",
|
|
49750
|
-
pickTimeoutMs: input.pickTimeoutMs,
|
|
49751
|
-
dispatchTimeoutMs: input.dispatchTimeoutMs,
|
|
49752
|
-
seat: input.seat
|
|
49753
|
-
},
|
|
49754
|
-
deps
|
|
49755
|
-
);
|
|
49756
|
-
if (!built.ok) return { ...base, reason: built.error };
|
|
49757
|
-
const verdicts = [];
|
|
49758
|
-
const perHead = await Promise.all(
|
|
49759
|
-
input.heads.map(async (persona) => {
|
|
49760
|
-
const agent = built.runner.assignment[persona] ?? "(unassigned)";
|
|
49761
|
-
try {
|
|
49762
|
-
const res = await built.runner.runHead(persona, input.artifact, "");
|
|
49763
|
-
if (res.ok) {
|
|
49764
|
-
const parsed = parseVerdict(res.text);
|
|
49765
|
-
return {
|
|
49766
|
-
persona,
|
|
49767
|
-
agent,
|
|
49768
|
-
verdict: parsed.verdict,
|
|
49769
|
-
ok: true,
|
|
49770
|
-
// The optional chain is required by the TYPE, not left over from not knowing the
|
|
49771
|
-
// invariant: `MultiHeadRunResult.usage` is declared `usage?: ExecTokenUsage | null`
|
|
49772
|
-
// (optional so the shape stays assignable to the gate's older `RunResult`), even though
|
|
49773
|
-
// `parseDispatch` always sets it. `?? null` therefore covers both "no usage key" and
|
|
49774
|
-
// "usage was null" — and covers neither zero: a reported 0 is a measurement and
|
|
49775
|
-
// survives, which is the distinction this whole field exists to preserve.
|
|
49776
|
-
inputTokens: res.usage?.inputTokens ?? null,
|
|
49777
|
-
outputTokens: res.usage?.outputTokens ?? null
|
|
49778
|
-
};
|
|
49779
|
-
}
|
|
49780
|
-
} catch {
|
|
49781
|
-
}
|
|
49782
|
-
return { persona, agent, verdict: "ERROR", ok: false, inputTokens: null, outputTokens: null };
|
|
49783
|
-
})
|
|
49784
|
-
);
|
|
49785
|
-
for (const h of perHead) {
|
|
49786
|
-
if (h.ok && h.verdict !== "ERROR") verdicts.push(h.verdict);
|
|
49787
|
-
}
|
|
49788
|
-
if (verdicts.length === 0) {
|
|
49789
|
-
return { ...base, agents: built.runner.agents, perHead, reason: "no head produced a parseable verdict" };
|
|
49790
|
-
}
|
|
49791
|
-
const shadowVerdict = rollUpVerdict(verdicts);
|
|
49792
|
-
return {
|
|
49793
|
-
ran: true,
|
|
49794
|
-
correlationId: input.correlationId,
|
|
49795
|
-
agents: built.runner.agents,
|
|
49796
|
-
perHead,
|
|
49797
|
-
shadowVerdict,
|
|
49798
|
-
productionVerdict: input.productionVerdict,
|
|
49799
|
-
agrees: shadowVerdict === input.productionVerdict,
|
|
49800
|
-
orchestratorSeat
|
|
49801
|
-
};
|
|
49802
|
-
}
|
|
49803
|
-
async function runShadowPanelSafe(input, deps, logger = (line) => console.error(line)) {
|
|
49804
|
-
let record2;
|
|
49805
|
-
try {
|
|
49806
|
-
record2 = await runShadowPanel(input, deps);
|
|
49807
|
-
} catch (err) {
|
|
49808
|
-
record2 = {
|
|
49809
|
-
ran: false,
|
|
49810
|
-
correlationId: input.correlationId,
|
|
49811
|
-
productionVerdict: input.productionVerdict,
|
|
49812
|
-
reason: `shadow panel threw: ${err instanceof Error ? err.message : String(err)}`,
|
|
49813
|
-
orchestratorSeat: input.orchestratorSeat
|
|
49814
|
-
};
|
|
49815
|
-
}
|
|
49816
|
-
try {
|
|
49817
|
-
logger(`${SHADOW_LOG_PREFIX} ${JSON.stringify(record2)}`);
|
|
49818
|
-
} catch {
|
|
49819
|
-
}
|
|
49820
|
-
return record2;
|
|
49821
|
-
}
|
|
49822
|
-
|
|
49823
|
-
// src/consensus/multi-llm-shadow-hook.ts
|
|
49824
|
-
var SHADOW_ENV_FLAG = "MRRLIN_CONSENSUS_MULTI_LLM_SHADOW";
|
|
49825
|
-
var PICK_TIMEOUT_MS = 15e3;
|
|
49826
|
-
var DISPATCH_TIMEOUT_MS = 6e4;
|
|
49827
|
-
function productionVerdictFromOutcome(outcome) {
|
|
49828
|
-
if (outcome === "CONVERGED") return "APPROVE";
|
|
49829
|
-
if (outcome === "CONSENSUS_BLOCKED") return "REQUEST_CHANGES";
|
|
49830
|
-
return null;
|
|
49831
|
-
}
|
|
49832
|
-
async function maybeRunShadow(input, deps, logger) {
|
|
49833
|
-
const env = input.env ?? process.env;
|
|
49834
|
-
if (!env[SHADOW_ENV_FLAG]) return false;
|
|
49835
|
-
const productionVerdict = productionVerdictFromOutcome(input.outcome);
|
|
49836
|
-
if (productionVerdict === null) return false;
|
|
49837
|
-
try {
|
|
49838
|
-
const heads = input.heads ?? [...resolveHeads(input.domains, input.impact), ...input.extraHeads ?? []];
|
|
49839
|
-
const personaInstructions = {};
|
|
49840
|
-
for (const name of heads) {
|
|
49841
|
-
try {
|
|
49842
|
-
personaInstructions[name] = loadPersona(name);
|
|
49843
|
-
} catch {
|
|
49844
|
-
personaInstructions[name] = "";
|
|
49845
|
-
}
|
|
49846
|
-
}
|
|
49847
|
-
const seat = await mintResolvedSeat(resolveProvider(process.env, input.persistedProvider));
|
|
49848
|
-
await runShadowPanelSafe(
|
|
49849
|
-
{
|
|
49850
|
-
heads,
|
|
49851
|
-
personaInstructions,
|
|
49852
|
-
artifact: input.artifact,
|
|
49853
|
-
productionVerdict,
|
|
49854
|
-
excludeProvider: seat.capabilities.poolProviderLabels.join(","),
|
|
49855
|
-
orchestratorSeat: seat.id,
|
|
49856
|
-
// task 1.21: the same seat, forwarded so buildMultiHeadRunner's per-head dispatch path
|
|
49857
|
-
// has one in scope too (see ShadowInput.seat's own comment for why this is separate
|
|
49858
|
-
// from orchestratorSeat above).
|
|
49859
|
-
seat,
|
|
49860
|
-
pickTimeoutMs: PICK_TIMEOUT_MS,
|
|
49861
|
-
dispatchTimeoutMs: DISPATCH_TIMEOUT_MS,
|
|
49862
|
-
correlationId: input.correlationId
|
|
49863
|
-
},
|
|
49864
|
-
deps,
|
|
49865
|
-
logger
|
|
49866
|
-
);
|
|
49867
|
-
} catch {
|
|
49868
|
-
}
|
|
49869
|
-
return true;
|
|
49870
|
-
}
|
|
49871
|
-
|
|
49872
|
-
// src/consensus/multi-llm-activate.ts
|
|
49873
|
-
var PICK_TIMEOUT_MS2 = 15e3;
|
|
49874
|
-
var DISPATCH_TIMEOUT_MS2 = 6e4;
|
|
49875
|
-
function multiLlmActive(_env = process.env) {
|
|
49876
|
-
return true;
|
|
49877
|
-
}
|
|
49878
|
-
function applyActivePanel(deps, panel) {
|
|
49879
|
-
if (!panel) return;
|
|
49880
|
-
const record2 = deps.recordHeadCall;
|
|
49881
|
-
deps.runHead = record2 === void 0 ? panel.runHead : async (persona, artifact, dismissed) => {
|
|
49882
|
-
const agentId = panel.assignment[persona] ?? null;
|
|
49883
|
-
const startedAt = Date.now();
|
|
49884
|
-
try {
|
|
49885
|
-
const result = await panel.runHead(persona, artifact, dismissed);
|
|
49886
|
-
record2(persona, agentId, startedAt, result);
|
|
49887
|
-
return result;
|
|
49888
|
-
} catch (error51) {
|
|
49889
|
-
record2(persona, agentId, startedAt, { ok: false, error: error51 instanceof Error ? error51.message : String(error51) });
|
|
49890
|
-
throw error51;
|
|
49891
|
-
}
|
|
49892
|
-
};
|
|
49893
|
-
deps.panelComposition = panel.composition;
|
|
49894
|
-
}
|
|
49895
|
-
async function resolveActivePanel(input, deps) {
|
|
49896
|
-
if (!multiLlmActive(input.env ?? process.env)) return null;
|
|
49897
|
-
try {
|
|
49898
|
-
const heads = input.heads ?? [...resolveHeads(input.domains, input.impact), ...input.extraHeads ?? []];
|
|
49899
|
-
if (heads.length === 0) return null;
|
|
49900
|
-
const personaInstructions = {};
|
|
49901
|
-
for (const name of heads) {
|
|
49902
|
-
try {
|
|
49903
|
-
personaInstructions[name] = loadPersona(name);
|
|
49904
|
-
} catch {
|
|
49905
|
-
personaInstructions[name] = "";
|
|
49906
|
-
}
|
|
49907
|
-
}
|
|
49908
|
-
const seat = await mintResolvedSeat(resolveProvider(process.env, input.persistedProvider));
|
|
49909
|
-
const built = await buildMultiHeadRunner(
|
|
49910
|
-
{
|
|
49911
|
-
personas: heads,
|
|
49912
|
-
personaInstructions,
|
|
49913
|
-
// .join(",") is forward-compatible with a future multi-label provider — today both
|
|
49914
|
-
// Codex (["openai"]) and Claude (["anthropic"]) are single-element, so this is a
|
|
49915
|
-
// behavior-neutral join; excludeProvider itself is a single (possibly comma-joined,
|
|
49916
|
-
// per --exclude-providers) string, not an array.
|
|
49917
|
-
excludeProvider: seat.capabilities.poolProviderLabels.join(","),
|
|
49918
|
-
tierPrefer: "strong",
|
|
49919
|
-
pickTimeoutMs: PICK_TIMEOUT_MS2,
|
|
49920
|
-
dispatchTimeoutMs: DISPATCH_TIMEOUT_MS2,
|
|
49921
|
-
// task 1.21: same seat that produced excludeProvider above, not a second mint.
|
|
49922
|
-
seat
|
|
49923
|
-
},
|
|
49924
|
-
deps
|
|
49925
|
-
);
|
|
49926
|
-
if (!built.ok) return null;
|
|
49927
|
-
return {
|
|
49928
|
-
runHead: built.runner.runHead,
|
|
49929
|
-
composition: built.runner.composition,
|
|
49930
|
-
assignment: built.runner.assignment
|
|
49931
|
-
};
|
|
49932
|
-
} catch {
|
|
49933
|
-
return null;
|
|
49934
|
-
}
|
|
49935
|
-
}
|
|
49936
|
-
|
|
49937
|
-
// src/selected-provider-store.ts
|
|
49938
|
-
var current = null;
|
|
49939
|
-
function getSelectedProvider() {
|
|
49940
|
-
return current;
|
|
49941
|
-
}
|
|
49942
|
-
function setSelectedProvider(value) {
|
|
49943
|
-
current = value;
|
|
49944
|
-
}
|
|
49945
|
-
|
|
49946
49358
|
// src/state-dir.ts
|
|
49947
49359
|
var import_node_os7 = __toESM(require("node:os"), 1);
|
|
49948
49360
|
var import_node_path11 = __toESM(require("node:path"), 1);
|
|
@@ -56261,8 +55673,6 @@ function errorMessage(value) {
|
|
|
56261
55673
|
|
|
56262
55674
|
// src/decision-consensus.ts
|
|
56263
55675
|
var ANCHOR_TIMEOUT_MS = Number(process.env["MRRLIN_DECISION_TIMEOUT_MS"] ?? 9e4);
|
|
56264
|
-
var PICK_TIMEOUT_MS3 = 15e3;
|
|
56265
|
-
var DISPATCH_TIMEOUT_MS3 = 6e4;
|
|
56266
55676
|
function buildReviewArtifact(input) {
|
|
56267
55677
|
const blocks = [
|
|
56268
55678
|
`--- QUESTION ---
|
|
@@ -56286,12 +55696,20 @@ function boundIssues(issues) {
|
|
|
56286
55696
|
}
|
|
56287
55697
|
async function runDecisionConsensus(input, deps) {
|
|
56288
55698
|
const runExec = deps.runExec ?? runAgentExec;
|
|
56289
|
-
const buildRunner = deps.buildRunner ?? buildMultiHeadRunner;
|
|
56290
55699
|
const persona = deps.loadPersona ?? loadPersona;
|
|
56291
55700
|
const chosen = input.heads && input.heads.length > 0 ? input.heads : LADDER;
|
|
56292
55701
|
const firstChosen = chosen[0];
|
|
56293
55702
|
const anchorPersona = firstChosen === void 0 ? LADDER[0] : firstChosen;
|
|
56294
|
-
const seatedPersonas =
|
|
55703
|
+
const seatedPersonas = (() => {
|
|
55704
|
+
if (input.reviewers === 0) return [];
|
|
55705
|
+
const pool = [];
|
|
55706
|
+
const add2 = (role) => {
|
|
55707
|
+
if (role !== void 0 && role !== anchorPersona && !pool.includes(role)) pool.push(role);
|
|
55708
|
+
};
|
|
55709
|
+
for (const role of chosen.slice(1)) add2(role);
|
|
55710
|
+
for (const role of LADDER) add2(role);
|
|
55711
|
+
return Array.from({ length: input.reviewers }, (_, i) => pool[i % pool.length] ?? anchorPersona);
|
|
55712
|
+
})();
|
|
56295
55713
|
const artifact = buildReviewArtifact(input);
|
|
56296
55714
|
const anchorLeg = async () => {
|
|
56297
55715
|
const result = await runExec(
|
|
@@ -56310,35 +55728,34 @@ async function runDecisionConsensus(input, deps) {
|
|
|
56310
55728
|
const parsed = parseVerdict(result.text);
|
|
56311
55729
|
return { persona: anchorPersona, verdict: parsed.verdict, issues: boundIssues(parsed.issues) };
|
|
56312
55730
|
};
|
|
55731
|
+
const providerLabel = deps.persistedProvider ?? "selected-provider";
|
|
56313
55732
|
const panelLeg = async () => {
|
|
56314
55733
|
if (input.reviewers === 0) return null;
|
|
56315
|
-
const seat = await deps.mintSeat();
|
|
56316
|
-
const personaInstructions = {};
|
|
56317
|
-
for (const name of seatedPersonas) {
|
|
56318
|
-
try {
|
|
56319
|
-
personaInstructions[name] = persona(name);
|
|
56320
|
-
} catch {
|
|
56321
|
-
personaInstructions[name] = "";
|
|
56322
|
-
}
|
|
56323
|
-
}
|
|
56324
|
-
const built = await buildRunner({
|
|
56325
|
-
personas: seatedPersonas,
|
|
56326
|
-
personaInstructions,
|
|
56327
|
-
excludeProvider: seat.capabilities.poolProviderLabels.join(","),
|
|
56328
|
-
tierPrefer: "strong",
|
|
56329
|
-
pickTimeoutMs: PICK_TIMEOUT_MS3,
|
|
56330
|
-
dispatchTimeoutMs: DISPATCH_TIMEOUT_MS3,
|
|
56331
|
-
seat
|
|
56332
|
-
});
|
|
56333
|
-
if (!built.ok) return { ok: false, error: built.error };
|
|
56334
|
-
if (built.runner.agents.length === 0) {
|
|
56335
|
-
return { ok: false, error: "the reviewer pool returned an empty panel" };
|
|
56336
|
-
}
|
|
56337
55734
|
const responses = await Promise.all(
|
|
56338
55735
|
seatedPersonas.map(async (personaName) => {
|
|
56339
|
-
|
|
56340
|
-
|
|
56341
|
-
|
|
55736
|
+
let instructions = "";
|
|
55737
|
+
try {
|
|
55738
|
+
instructions = persona(personaName);
|
|
55739
|
+
} catch {
|
|
55740
|
+
instructions = "";
|
|
55741
|
+
}
|
|
55742
|
+
try {
|
|
55743
|
+
const result = await runExec(
|
|
55744
|
+
{
|
|
55745
|
+
prompt: artifact,
|
|
55746
|
+
developerInstructions: instructions,
|
|
55747
|
+
cwd: input.cwd,
|
|
55748
|
+
timeoutMs: ANCHOR_TIMEOUT_MS,
|
|
55749
|
+
sandbox: "read-only",
|
|
55750
|
+
codexExecutable: process.env["MRRLIN_DIRECTOR_BRIDGE_CODEX_BIN"]?.trim() || void 0
|
|
55751
|
+
},
|
|
55752
|
+
void 0,
|
|
55753
|
+
deps.persistedProvider
|
|
55754
|
+
);
|
|
55755
|
+
return { personaName, result };
|
|
55756
|
+
} catch (error51) {
|
|
55757
|
+
return { personaName, result: { ok: false, error: error51 instanceof Error ? error51.message : String(error51) } };
|
|
55758
|
+
}
|
|
56342
55759
|
})
|
|
56343
55760
|
);
|
|
56344
55761
|
const seats = [];
|
|
@@ -56347,55 +55764,34 @@ async function runDecisionConsensus(input, deps) {
|
|
|
56347
55764
|
const parsed = parseVerdict(response.result.text);
|
|
56348
55765
|
seats.push({
|
|
56349
55766
|
persona: response.personaName,
|
|
56350
|
-
agentId: response.
|
|
55767
|
+
agentId: `${providerLabel}:${response.personaName}`,
|
|
56351
55768
|
verdict: parsed.verdict,
|
|
56352
55769
|
issues: boundIssues(parsed.issues)
|
|
56353
55770
|
});
|
|
56354
55771
|
}
|
|
56355
|
-
return {
|
|
55772
|
+
return { agents: seatedPersonas.map((name) => `${providerLabel}:${name}`), seats };
|
|
56356
55773
|
};
|
|
56357
55774
|
const [anchor, panel] = await Promise.all([anchorLeg(), panelLeg()]);
|
|
56358
55775
|
if (panel === null) return { anchor, panel: null, degraded: null };
|
|
56359
|
-
if (!panel.ok) {
|
|
56360
|
-
return {
|
|
56361
|
-
anchor,
|
|
56362
|
-
panel: {
|
|
56363
|
-
requested: input.reviewers,
|
|
56364
|
-
filled: 0,
|
|
56365
|
-
agentIds: [],
|
|
56366
|
-
underpowered: true,
|
|
56367
|
-
responded: 0,
|
|
56368
|
-
seats: []
|
|
56369
|
-
},
|
|
56370
|
-
degraded: `the reviewer pool could not be seated (${panel.error}); this review is the blind check alone`
|
|
56371
|
-
};
|
|
56372
|
-
}
|
|
56373
|
-
const filled = panel.agents.length;
|
|
56374
55776
|
const responded = panel.seats.length;
|
|
56375
55777
|
return {
|
|
56376
55778
|
anchor,
|
|
56377
|
-
//
|
|
56378
|
-
//
|
|
56379
|
-
//
|
|
56380
|
-
//
|
|
55779
|
+
// Every requested reviewer is launched, so `filled` equals `requested`; `underpowered` is true
|
|
55780
|
+
// when fewer than requested ANSWERED. Seat ids are `<provider>:<persona>` — one model in
|
|
55781
|
+
// different roles — and no "distinct voices" number is computed (D6): the reading rule lives in
|
|
55782
|
+
// the Director's instruction instead.
|
|
56381
55783
|
panel: {
|
|
56382
55784
|
requested: input.reviewers,
|
|
56383
|
-
filled,
|
|
55785
|
+
filled: panel.agents.length,
|
|
56384
55786
|
agentIds: panel.agents,
|
|
56385
|
-
underpowered:
|
|
55787
|
+
underpowered: responded < input.reviewers,
|
|
56386
55788
|
responded,
|
|
56387
55789
|
seats: panel.seats
|
|
56388
55790
|
},
|
|
56389
|
-
// `degraded` fires whenever FEWER
|
|
56390
|
-
// for three and hearing one is a thinner review than the Director requested, and it has
|
|
56391
|
-
// so rather than present one answer as the panel's.
|
|
56392
|
-
|
|
56393
|
-
// Two halves, both load-bearing. `filled` is the honest measure of INDEPENDENCE: two personas
|
|
56394
|
-
// answering from one seated model are one voice wearing two hats, and reporting that as a full
|
|
56395
|
-
// panel is exactly the trap D6 exists to avoid. `responded` catches the other shape — seats
|
|
56396
|
-
// filled that then stayed silent. `underpowered` above is the mechanical flag; this is the
|
|
56397
|
-
// sentence the Director reads out.
|
|
56398
|
-
degraded: filled < input.reviewers || responded < input.reviewers ? `${filled} of ${input.reviewers} requested reviewers seated, ${responded} answered` + (responded === 0 ? "; this review is the blind check alone" : "") : null
|
|
55791
|
+
// `degraded` fires whenever FEWER reviewers answered than were asked for, not only at zero:
|
|
55792
|
+
// asking for three and hearing one is a thinner review than the Director requested, and it has
|
|
55793
|
+
// to say so rather than present one answer as the panel's.
|
|
55794
|
+
degraded: responded < input.reviewers ? `${responded} of ${input.reviewers} requested reviewers answered` + (responded === 0 ? "; this review is the blind check alone" : "") : null
|
|
56399
55795
|
};
|
|
56400
55796
|
}
|
|
56401
55797
|
|
|
@@ -56913,28 +56309,6 @@ async function retireGateQuestionsOnConverge(ctx, input, resolvedTaskId) {
|
|
|
56913
56309
|
}
|
|
56914
56310
|
async function run(ctx, input, builders = defaultNativeSpecGateBuilders) {
|
|
56915
56311
|
const result = await runNativeSpecGate(ctx, input, builders);
|
|
56916
|
-
if (process.env[SHADOW_ENV_FLAG]) {
|
|
56917
|
-
try {
|
|
56918
|
-
const specPage = await ctx.client.getWikiPage(input.projectSlug, input.pageId);
|
|
56919
|
-
if (specPage) {
|
|
56920
|
-
const shadowDomain = await resolveSpecDomain(ctx.client, input.projectSlug, {
|
|
56921
|
-
id: specPage.id,
|
|
56922
|
-
taskId: specPage.taskId ?? null
|
|
56923
|
-
});
|
|
56924
|
-
await maybeRunShadow({
|
|
56925
|
-
outcome: result.outcome,
|
|
56926
|
-
artifact: specPage.markdownBody,
|
|
56927
|
-
domains: [shadowDomain],
|
|
56928
|
-
extraHeads: input.extraHeads,
|
|
56929
|
-
correlationId: `Specs/${input.pageId}`,
|
|
56930
|
-
// task 1.21: ctx's own minted seat, not an ambient read — ctx already carries it by
|
|
56931
|
-
// the time `run` executes (async-job-consumer.ts mints before calling descriptor.run).
|
|
56932
|
-
persistedProvider: ctx.seat?.id ?? null
|
|
56933
|
-
});
|
|
56934
|
-
}
|
|
56935
|
-
} catch {
|
|
56936
|
-
}
|
|
56937
|
-
}
|
|
56938
56312
|
let resolvedTaskId = null;
|
|
56939
56313
|
let resolvedTaskTitle = null;
|
|
56940
56314
|
try {
|
|
@@ -57529,7 +56903,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57529
56903
|
return {
|
|
57530
56904
|
kind: "retry",
|
|
57531
56905
|
failureReason: "provider_unavailable",
|
|
57532
|
-
error: `task fetch failed for ${projectSlug}/${taskId}: ${
|
|
56906
|
+
error: `task fetch failed for ${projectSlug}/${taskId}: ${errMessage3(error51)}`
|
|
57533
56907
|
};
|
|
57534
56908
|
}
|
|
57535
56909
|
if (isTaskTerminalStatus(task.status)) return skipped("task_terminal");
|
|
@@ -57542,7 +56916,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57542
56916
|
return {
|
|
57543
56917
|
kind: "retry",
|
|
57544
56918
|
failureReason: "provider_unavailable",
|
|
57545
|
-
error: `blocker check failed for ${taskId}: ${
|
|
56919
|
+
error: `blocker check failed for ${taskId}: ${errMessage3(error51)}`
|
|
57546
56920
|
};
|
|
57547
56921
|
}
|
|
57548
56922
|
if (getActiveBlockedByIds(task.blockedBy, blockers).length > 0) return skipped("blocked_by_active");
|
|
@@ -57570,7 +56944,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57570
56944
|
return {
|
|
57571
56945
|
kind: "failed",
|
|
57572
56946
|
failureReason: "zero_output",
|
|
57573
|
-
error: `spec-author persona is missing (expected consensus/personas/${DRAFT_SPEC_PERSONA}.md next to the bundle): ${
|
|
56947
|
+
error: `spec-author persona is missing (expected consensus/personas/${DRAFT_SPEC_PERSONA}.md next to the bundle): ${errMessage3(error51)}`
|
|
57574
56948
|
};
|
|
57575
56949
|
}
|
|
57576
56950
|
let adoptedId = null;
|
|
@@ -57581,7 +56955,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57581
56955
|
return {
|
|
57582
56956
|
kind: "retry",
|
|
57583
56957
|
failureReason: "provider_unavailable",
|
|
57584
|
-
error: `orphan-adoption lookup failed for ${taskId}: ${
|
|
56958
|
+
error: `orphan-adoption lookup failed for ${taskId}: ${errMessage3(error51)}`
|
|
57585
56959
|
};
|
|
57586
56960
|
}
|
|
57587
56961
|
let constitution = null;
|
|
@@ -57625,7 +56999,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57625
56999
|
return {
|
|
57626
57000
|
kind: "retry",
|
|
57627
57001
|
failureReason: "provider_unavailable",
|
|
57628
|
-
error: `failed to write authored spec into adopted page ${adoptedId}: ${
|
|
57002
|
+
error: `failed to write authored spec into adopted page ${adoptedId}: ${errMessage3(error51)}`
|
|
57629
57003
|
};
|
|
57630
57004
|
}
|
|
57631
57005
|
pageId = adoptedId;
|
|
@@ -57640,7 +57014,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57640
57014
|
return {
|
|
57641
57015
|
kind: "retry",
|
|
57642
57016
|
failureReason: "provider_unavailable",
|
|
57643
|
-
error: `wiki page listing failed while allocating an id: ${
|
|
57017
|
+
error: `wiki page listing failed while allocating an id: ${errMessage3(error51)}`
|
|
57644
57018
|
};
|
|
57645
57019
|
}
|
|
57646
57020
|
try {
|
|
@@ -57656,14 +57030,14 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57656
57030
|
break;
|
|
57657
57031
|
} catch (error51) {
|
|
57658
57032
|
if (error51 instanceof MrrlinApiError && error51.status === 409) {
|
|
57659
|
-
lastConflict =
|
|
57033
|
+
lastConflict = errMessage3(error51);
|
|
57660
57034
|
if (attempt < PAGE_ID_MAX_ATTEMPTS) await sleep(100 + Math.round(random2() * 400));
|
|
57661
57035
|
continue;
|
|
57662
57036
|
}
|
|
57663
57037
|
return {
|
|
57664
57038
|
kind: "retry",
|
|
57665
57039
|
failureReason: "provider_unavailable",
|
|
57666
|
-
error: `wiki page create failed for ${taskId}: ${
|
|
57040
|
+
error: `wiki page create failed for ${taskId}: ${errMessage3(error51)}`
|
|
57667
57041
|
};
|
|
57668
57042
|
}
|
|
57669
57043
|
}
|
|
@@ -57725,7 +57099,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57725
57099
|
return {
|
|
57726
57100
|
kind: "retry",
|
|
57727
57101
|
failureReason: "provider_unavailable",
|
|
57728
|
-
error: `pre-link task re-fetch failed for ${taskId}: ${
|
|
57102
|
+
error: `pre-link task re-fetch failed for ${taskId}: ${errMessage3(error51)}`
|
|
57729
57103
|
};
|
|
57730
57104
|
}
|
|
57731
57105
|
if (fresh.specWikiPageId) {
|
|
@@ -57741,7 +57115,7 @@ async function runDraftSpec(ctx, input, deps) {
|
|
|
57741
57115
|
return {
|
|
57742
57116
|
kind: "retry",
|
|
57743
57117
|
failureReason: "provider_unavailable",
|
|
57744
|
-
error: `failed to link spec page ${pageId} to task ${taskId}: ${
|
|
57118
|
+
error: `failed to link spec page ${pageId} to task ${taskId}: ${errMessage3(error51)}`
|
|
57745
57119
|
};
|
|
57746
57120
|
}
|
|
57747
57121
|
const drafted = {
|
|
@@ -57817,7 +57191,7 @@ function createDraftSpecDescriptor(deps = {}) {
|
|
|
57817
57191
|
};
|
|
57818
57192
|
}
|
|
57819
57193
|
var draftSpecDescriptor = createDraftSpecDescriptor();
|
|
57820
|
-
function
|
|
57194
|
+
function errMessage3(error51) {
|
|
57821
57195
|
return error51 instanceof Error ? error51.message : String(error51);
|
|
57822
57196
|
}
|
|
57823
57197
|
|
|
@@ -58001,6 +57375,36 @@ var import_node_fs7 = require("node:fs");
|
|
|
58001
57375
|
var import_promises7 = require("node:fs/promises");
|
|
58002
57376
|
var import_node_path12 = require("node:path");
|
|
58003
57377
|
|
|
57378
|
+
// src/redact.ts
|
|
57379
|
+
var REDACTED = "[REDACTED]";
|
|
57380
|
+
var SECRET_PATTERNS = [
|
|
57381
|
+
// Mrrlin agent secret: mrrlin_agent_<base64url selector>.<base64url secret>. base64url uses - and
|
|
57382
|
+
// _, which the generic base64 run below does not cover, so most real secrets slipped through it.
|
|
57383
|
+
/mrrlin_agent_[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/g,
|
|
57384
|
+
// GitHub tokens: ghp_ (classic PAT), gho_ (OAuth), ghu_ (user-to-server), ghs_ (server-to-server,
|
|
57385
|
+
// e.g. an App installation token), ghr_ (refresh token).
|
|
57386
|
+
/gh[oprsu]_[A-Za-z0-9]{20,}/g,
|
|
57387
|
+
/github_pat_[A-Za-z0-9_]{20,}/g,
|
|
57388
|
+
// GitHub fine-grained PAT
|
|
57389
|
+
/sk-ant-[A-Za-z0-9_-]{20,}/g,
|
|
57390
|
+
// Anthropic key or OAuth token (sk-ant-api03-..., sk-ant-oat01-...)
|
|
57391
|
+
/\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
|
|
57392
|
+
// AWS access key id (long-term AKIA, temporary ASIA)
|
|
57393
|
+
/\bBearer\s+[A-Za-z0-9._~+/-]+=*/gi,
|
|
57394
|
+
// Authorization: Bearer <token>
|
|
57395
|
+
/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+/g,
|
|
57396
|
+
// JWT (header.payload.signature)
|
|
57397
|
+
/\b[A-Fa-f0-9]{32,}\b/g,
|
|
57398
|
+
// long hex run (hashes, hex secrets)
|
|
57399
|
+
/\b[A-Za-z0-9+/]{40,}={0,2}\b/g
|
|
57400
|
+
// long base64-ish run (opaque tokens)
|
|
57401
|
+
];
|
|
57402
|
+
function redact(input) {
|
|
57403
|
+
let out = input;
|
|
57404
|
+
for (const re of SECRET_PATTERNS) out = out.replace(re, REDACTED);
|
|
57405
|
+
return out;
|
|
57406
|
+
}
|
|
57407
|
+
|
|
58004
57408
|
// src/telemetry/projector.ts
|
|
58005
57409
|
var import_node_crypto8 = require("node:crypto");
|
|
58006
57410
|
function isRecord4(x) {
|
|
@@ -58791,7 +58195,7 @@ var CheckoutRegistry = class {
|
|
|
58791
58195
|
};
|
|
58792
58196
|
|
|
58793
58197
|
// src/checkout-handlers.ts
|
|
58794
|
-
var
|
|
58198
|
+
var import_node_child_process11 = require("node:child_process");
|
|
58795
58199
|
var import_node_fs9 = require("node:fs");
|
|
58796
58200
|
var import_node_path15 = __toESM(require("node:path"), 1);
|
|
58797
58201
|
|
|
@@ -58838,7 +58242,7 @@ function validateCheckoutPath(checkoutPath, repo) {
|
|
|
58838
58242
|
}
|
|
58839
58243
|
let remoteUrl;
|
|
58840
58244
|
try {
|
|
58841
|
-
remoteUrl = (0,
|
|
58245
|
+
remoteUrl = (0, import_node_child_process11.execFileSync)("git", ["-C", resolvedPath, "remote", "get-url", "origin"], {
|
|
58842
58246
|
encoding: "utf8",
|
|
58843
58247
|
stdio: ["ignore", "pipe", "ignore"],
|
|
58844
58248
|
timeout: 15e3,
|
|
@@ -58889,7 +58293,7 @@ function checkoutStateData(projectSlug, entry, machineLabel) {
|
|
|
58889
58293
|
}
|
|
58890
58294
|
|
|
58891
58295
|
// src/local-checkout.ts
|
|
58892
|
-
var
|
|
58296
|
+
var import_node_child_process12 = require("node:child_process");
|
|
58893
58297
|
var import_node_fs10 = require("node:fs");
|
|
58894
58298
|
var import_node_os8 = require("node:os");
|
|
58895
58299
|
var import_node_path16 = __toESM(require("node:path"), 1);
|
|
@@ -59005,7 +58409,7 @@ function checkLocalPathRules(input, options = {}) {
|
|
|
59005
58409
|
}
|
|
59006
58410
|
function gitTopLevel(realPath) {
|
|
59007
58411
|
try {
|
|
59008
|
-
return (0,
|
|
58412
|
+
return (0, import_node_child_process12.execFileSync)("git", ["-C", realPath, "rev-parse", "--show-toplevel"], {
|
|
59009
58413
|
encoding: "utf8",
|
|
59010
58414
|
stdio: ["ignore", "pipe", "ignore"],
|
|
59011
58415
|
timeout: 15e3,
|
|
@@ -59047,7 +58451,7 @@ function registerLocalOnlyCheckout(registry3, input, machineLabel, options = {},
|
|
|
59047
58451
|
}
|
|
59048
58452
|
var DEFAULT_GITIGNORE = ["node_modules/", "dist/", "build/", ".DS_Store", ".env", ".env.*", "*.log", ""].join("\n");
|
|
59049
58453
|
function runGit(realPath, args) {
|
|
59050
|
-
return (0,
|
|
58454
|
+
return (0, import_node_child_process12.execFileSync)("git", ["-C", realPath, ...args], {
|
|
59051
58455
|
encoding: "utf8",
|
|
59052
58456
|
stdio: ["ignore", "pipe", "pipe"],
|
|
59053
58457
|
timeout: 6e4,
|
|
@@ -59111,7 +58515,7 @@ function initLocalRepo(registry3, input, machineLabel, options = {}, now = (/* @
|
|
|
59111
58515
|
}
|
|
59112
58516
|
|
|
59113
58517
|
// src/local-apply.ts
|
|
59114
|
-
var
|
|
58518
|
+
var import_node_child_process15 = require("node:child_process");
|
|
59115
58519
|
var import_node_crypto13 = __toESM(require("node:crypto"), 1);
|
|
59116
58520
|
var import_node_fs14 = require("node:fs");
|
|
59117
58521
|
var import_node_path20 = __toESM(require("node:path"), 1);
|
|
@@ -59160,7 +58564,7 @@ function isDeliveryLockHeld(locksDir, key) {
|
|
|
59160
58564
|
}
|
|
59161
58565
|
|
|
59162
58566
|
// src/delivery/local-git.ts
|
|
59163
|
-
var
|
|
58567
|
+
var import_node_child_process13 = require("node:child_process");
|
|
59164
58568
|
var import_node_crypto11 = require("node:crypto");
|
|
59165
58569
|
var import_node_fs12 = require("node:fs");
|
|
59166
58570
|
var import_node_os9 = __toESM(require("node:os"), 1);
|
|
@@ -59258,7 +58662,7 @@ function diagnoseGpgError(rawError) {
|
|
|
59258
58662
|
return rawError;
|
|
59259
58663
|
}
|
|
59260
58664
|
function git(repo, args) {
|
|
59261
|
-
return (0,
|
|
58665
|
+
return (0, import_node_child_process13.execFileSync)("git", gitArgs(repo, args), {
|
|
59262
58666
|
encoding: "utf8",
|
|
59263
58667
|
timeout: 3e4,
|
|
59264
58668
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -59266,7 +58670,7 @@ function git(repo, args) {
|
|
|
59266
58670
|
}).trim();
|
|
59267
58671
|
}
|
|
59268
58672
|
function gitRaw(repo, args) {
|
|
59269
|
-
return (0,
|
|
58673
|
+
return (0, import_node_child_process13.execFileSync)("git", gitArgs(repo, args), {
|
|
59270
58674
|
encoding: "utf8",
|
|
59271
58675
|
timeout: 3e4,
|
|
59272
58676
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -59274,7 +58678,7 @@ function gitRaw(repo, args) {
|
|
|
59274
58678
|
});
|
|
59275
58679
|
}
|
|
59276
58680
|
function gitTx(repo, args, stdin) {
|
|
59277
|
-
const result = (0,
|
|
58681
|
+
const result = (0, import_node_child_process13.spawnSync)("git", gitArgs(repo, args), {
|
|
59278
58682
|
encoding: "utf8",
|
|
59279
58683
|
timeout: 3e4,
|
|
59280
58684
|
input: stdin,
|
|
@@ -59289,7 +58693,7 @@ ${result.error.message}` : ""}`.trim()
|
|
|
59289
58693
|
};
|
|
59290
58694
|
}
|
|
59291
58695
|
function gitTry(repo, args) {
|
|
59292
|
-
const result = (0,
|
|
58696
|
+
const result = (0, import_node_child_process13.spawnSync)("git", gitArgs(repo, args), {
|
|
59293
58697
|
encoding: "utf8",
|
|
59294
58698
|
timeout: 3e4,
|
|
59295
58699
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -59369,7 +58773,7 @@ function createStepRunner(options = {}) {
|
|
|
59369
58773
|
let bytes3 = 0;
|
|
59370
58774
|
let timedOut = false;
|
|
59371
58775
|
let killTimer = null;
|
|
59372
|
-
const child = (0,
|
|
58776
|
+
const child = (0, import_node_child_process13.spawn)(command.file, command.args, {
|
|
59373
58777
|
cwd,
|
|
59374
58778
|
env: { ...buildLocalStepEnv(), CI: "1", GIT_TERMINAL_PROMPT: "0" },
|
|
59375
58779
|
stdio: ["ignore", "pipe", "pipe"],
|
|
@@ -59760,14 +59164,14 @@ function worktreesWithBranch(repo, branch) {
|
|
|
59760
59164
|
}
|
|
59761
59165
|
|
|
59762
59166
|
// src/worktree.ts
|
|
59763
|
-
var
|
|
59167
|
+
var import_node_child_process14 = require("node:child_process");
|
|
59764
59168
|
var import_node_crypto12 = require("node:crypto");
|
|
59765
59169
|
var import_node_fs13 = require("node:fs");
|
|
59766
59170
|
var import_node_path19 = require("node:path");
|
|
59767
59171
|
function worktreeBranch(runId) {
|
|
59768
59172
|
return `mrrlin/run-${runId}`;
|
|
59769
59173
|
}
|
|
59770
|
-
var defaultGitExec = (args, env) => (0,
|
|
59174
|
+
var defaultGitExec = (args, env) => (0, import_node_child_process14.execFileSync)("git", args, { encoding: "utf8", timeout: 3e4, env });
|
|
59771
59175
|
function disabledGitHooksPath(locksDir, scope) {
|
|
59772
59176
|
const scopeKey = (0, import_node_crypto12.createHash)("sha256").update(scope).digest("hex").slice(0, 32);
|
|
59773
59177
|
return (0, import_node_path19.resolve)(locksDir, "..", "disabled-git-hooks", scopeKey);
|
|
@@ -59804,7 +59208,7 @@ function withDisabledGitHooksEnv(env, hooksDir) {
|
|
|
59804
59208
|
};
|
|
59805
59209
|
}
|
|
59806
59210
|
function git2(checkout, args, hooksDir, baseEnv = process.env) {
|
|
59807
|
-
return (0,
|
|
59211
|
+
return (0, import_node_child_process14.execFileSync)("git", ["-C", checkout, "-c", `core.hooksPath=${hooksDir}`, ...args], {
|
|
59808
59212
|
encoding: "utf8",
|
|
59809
59213
|
timeout: 3e4,
|
|
59810
59214
|
env: { ...baseEnv, GIT_TERMINAL_PROMPT: "0" }
|
|
@@ -60048,7 +59452,7 @@ function gitEnv() {
|
|
|
60048
59452
|
}
|
|
60049
59453
|
function gitRead(cwd, args) {
|
|
60050
59454
|
try {
|
|
60051
|
-
return (0,
|
|
59455
|
+
return (0, import_node_child_process15.execFileSync)("git", ["-C", cwd, ...args], {
|
|
60052
59456
|
encoding: "utf8",
|
|
60053
59457
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60054
59458
|
timeout: 3e4,
|
|
@@ -60248,12 +59652,12 @@ async function applyLocalRunForTool(deps, input) {
|
|
|
60248
59652
|
return { outcome: "conflict", previousSha: null, headSha: delivered.headSha, detail: integration.files.join(", ") };
|
|
60249
59653
|
}
|
|
60250
59654
|
const build = await runDetectedBuild({ worktreePath, runStep: deps.runStep });
|
|
60251
|
-
const headSha = (0,
|
|
59655
|
+
const headSha = (0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "rev-parse", "HEAD"], { encoding: "utf8", env: gitEnv() }).trim();
|
|
60252
59656
|
if (build.failed) {
|
|
60253
59657
|
record2({ integration, applied: false, reason: "build_failed", headSha, steps: build.steps, logs: build.logs });
|
|
60254
59658
|
return { outcome: "build_failed", previousSha: null, headSha, detail: build.failed.command };
|
|
60255
59659
|
}
|
|
60256
|
-
const changedByBuild = (0,
|
|
59660
|
+
const changedByBuild = (0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "status", "--porcelain", "--untracked-files=no"], {
|
|
60257
59661
|
encoding: "utf8",
|
|
60258
59662
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60259
59663
|
timeout: 3e4,
|
|
@@ -60275,7 +59679,7 @@ async function applyLocalRunForTool(deps, input) {
|
|
|
60275
59679
|
if (lockfilesChanged.length > 0) {
|
|
60276
59680
|
for (const lf of lockfilesChanged) {
|
|
60277
59681
|
try {
|
|
60278
|
-
(0,
|
|
59682
|
+
(0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "add", lf], {
|
|
60279
59683
|
encoding: "utf8",
|
|
60280
59684
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60281
59685
|
env: gitEnv()
|
|
@@ -60336,12 +59740,12 @@ async function applyLocalRunForTool(deps, input) {
|
|
|
60336
59740
|
};
|
|
60337
59741
|
}
|
|
60338
59742
|
if (!runBranchStillSigned()) return branchChanged();
|
|
60339
|
-
(0,
|
|
59743
|
+
(0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "clean", "-q", "-f", "-d"], {
|
|
60340
59744
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60341
59745
|
timeout: 3e4,
|
|
60342
59746
|
env: gitEnv()
|
|
60343
59747
|
});
|
|
60344
|
-
(0,
|
|
59748
|
+
(0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "-c", `core.hooksPath=${hooksDir}`, "checkout", "-q", "-f", "--detach", delivered.headSha], {
|
|
60345
59749
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60346
59750
|
timeout: 3e4,
|
|
60347
59751
|
env: gitEnv()
|
|
@@ -60351,12 +59755,12 @@ async function applyLocalRunForTool(deps, input) {
|
|
|
60351
59755
|
} finally {
|
|
60352
59756
|
abortIntegration({ worktreePath });
|
|
60353
59757
|
if (runBranchStillSigned()) {
|
|
60354
|
-
(0,
|
|
59758
|
+
(0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "-c", `core.hooksPath=${hooksDir}`, "checkout", "-q", "-f", runBranch], {
|
|
60355
59759
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60356
59760
|
timeout: 3e4,
|
|
60357
59761
|
env: gitEnv()
|
|
60358
59762
|
});
|
|
60359
|
-
(0,
|
|
59763
|
+
(0, import_node_child_process15.execFileSync)("git", ["-C", worktreePath, "clean", "-q", "-f", "-d"], {
|
|
60360
59764
|
stdio: ["ignore", "pipe", "pipe"],
|
|
60361
59765
|
timeout: 3e4,
|
|
60362
59766
|
env: gitEnv()
|
|
@@ -61207,10 +60611,10 @@ var runDecisionConsensusInputSchema = external_exports.object({
|
|
|
61207
60611
|
"Only the facts a reviewer needs, in your own words. Reviewers see nothing else \u2014 not this chat, not your reasoning \u2014 so anything you omit here is invisible to them. Keep it an excerpt, not a file dump."
|
|
61208
60612
|
),
|
|
61209
60613
|
reviewers: external_exports.number().int().min(0).max(3).default(0).describe(
|
|
61210
|
-
"How many
|
|
60614
|
+
"How many extra blind reviewers to run on your own provider, each in a reviewer role different from the blind check's own, on top of the blind check that always runs. 0 (default) runs only the blind check."
|
|
61211
60615
|
),
|
|
61212
60616
|
heads: external_exports.array(external_exports.enum(["architect", "plan-reviewer", "scope-analyst", "security-analyst", "debugger", "researcher"])).min(1).max(3).optional().describe(
|
|
61213
|
-
'Which reviewer lenses to use. Omitted, the blind check uses "architect" and seats fill from
|
|
60617
|
+
'Which reviewer lenses to use. The first lens belongs to the blind check; extra reviewers take the remaining lenses in order, padded from architect / plan-reviewer / scope-analyst and never repeating the lens of the blind check. Omitted, the blind check uses "architect" and seats fill from plan-reviewer / scope-analyst. Name one explicitly when the doubt has a shape \u2014 "security-analyst" for auth or secrets, "debugger" for a root-cause claim, "researcher" for a dependency or API behaviour claim.'
|
|
61214
60618
|
)
|
|
61215
60619
|
});
|
|
61216
60620
|
var searchKnowledgeInputSchema = wikiKnowledgeSearchInputSchema;
|
|
@@ -61454,7 +60858,7 @@ var mcpToolDescriptions = {
|
|
|
61454
60858
|
[mcpToolNames.markSpecReady]: "Mark a wiki page (folder=Specs) as ready (or not) for execution-run gating. The Director sets this true after validating the spec; any edit to the page's markdown auto-resets it to false.",
|
|
61455
60859
|
[mcpToolNames.runSpecConsensus]: 'Enqueue the consensus review gate over a Specs/{id} page. Returns IMMEDIATELY with one of: already_converged (a CONVERGED review already exists for the current content \u2014 proceed straight to create_execution_run, do NOT call mark_spec_ready, it is already set), already_reviewed (a terminal CONSENSUS_BLOCKED for this content), already_running (a consensus job is in flight), or queued (a new job was launched). The review runs in the background; its result/blocker arrives in the inbox (info on CONVERGED, handoff on failure) and is surfaced into the open chat. Do NOT call again for the same spec and do NOT poll. On queued/already_running, tell the user it was launched and end the turn. Pass extraHeads: ["researcher"] for specs referencing external libraries/APIs, or ["debugger"] for root-cause/investigation specs to add opt-in specialist reviewers on top of the fixed four. For a NON-code task (domain seo/marketing/content, ADR 0020): the low-risk lanes `seo`, `marketing`, and `content` proceed to `create_execution_run` after consensus, using the same flow as code tasks. When the review agrees, tell the operator "the reviewers agreed on the spec" and proceed to create_execution_run. When it does not, tell them the reviewers could not agree and that there is a decision question in the inbox. Never say "consensus", "converged", or "CONVERGED" to the operator; those are internal words.',
|
|
61456
60860
|
[mcpToolNames.runCodeReviewerGate]: `Review the current branch's code diff (vs baseRef) with a Code Reviewer gate \u2014 independent reviewers iterate review\u2192fix\u2192re-check (checkpoint, scope-limited reviser edits, typecheck/build fast-gate, rollback) until the diff converges or is blocked. Run before opening a PR. Pass extraHeads: ["security-analyst"] for sensitive diffs (auth, secrets, input handling, new endpoints).`,
|
|
61457
|
-
[mcpToolNames.runDecisionConsensus]: 'Check a DECISION you are about to act on, before you act on it \u2014 not a document. Where run_spec_consensus reviews a spec page and run_code_reviewer_gate reviews a branch diff, this one reviews a judgement: "new API route or widen the existing accessor", "does this need a DB change", "is this task ready to start". Pass the `question` and the `position` you are leaning toward; the review tries to break that position. It is BLIND: reviewers see only `question`, `position` and `context` \u2014 never this conversation and never your reasoning \u2014 so put the facts they need into `context` in your own words, and expect anything you leave out to be invisible to them. With `reviewers` omitted (the default) the check runs
|
|
60861
|
+
[mcpToolNames.runDecisionConsensus]: 'Check a DECISION you are about to act on, before you act on it \u2014 not a document. Where run_spec_consensus reviews a spec page and run_code_reviewer_gate reviews a branch diff, this one reviews a judgement: "new API route or widen the existing accessor", "does this need a DB change", "is this task ready to start". Pass the `question` and the `position` you are leaning toward; the review tries to break that position. It is BLIND: reviewers see only `question`, `position` and `context` \u2014 never this conversation and never your reasoning \u2014 so put the facts they need into `context` in your own words, and expect anything you leave out to be invisible to them. With `reviewers` omitted (the default) only the blind check runs. Set `reviewers` to 1-3 to also run that many extra blind reviewers on your own provider, each in a different reviewer role, for the same question; they run once, in parallel, and are never re-asked. A reviewer run can time out or fail, in which case the result reports how many of the requested reviewers actually answered and the check falls back to the blind pass alone \u2014 read that number rather than assuming a full panel. All of them are the same model in different roles, so treat their agreement as less than independent confirmation. When the result objects to your position, do not quietly adopt a different answer and do not drop the objection: tell the operator what the objection is, in plain language, and let them decide. Never say "consensus", "converged", "anchor", or a verdict code like APPROVE or REQUEST_CHANGES to the operator; those are internal words.',
|
|
61458
60862
|
[mcpToolNames.appendExecutionArtifact]: "Append a durable artifact (plan, checkpoint, command output, test result, diff summary, self-review, error, deploy attempt, or handoff judgement) to an execution run.",
|
|
61459
60863
|
[mcpToolNames.recordProducedUrl]: 'Call this after publishing each web page produced by the task, so the UI link opens the page itself instead of the deployed site root. Pass the page\'s full https URL (for external pages, e.g. "https://dev.to/<slug>") OR a path starting with "/" for the deploy environment (e.g. "/blog/<slug>") \u2014 paths are resolved against the run\'s deployed env URL at render time. Optional `label` (\u226440 chars) is shown next to the link; omit and the UI defaults to the page title. Call once per page; multiple calls dedupe by resolved URL in the UI.',
|
|
61460
60864
|
[mcpToolNames.updateTaskState]: "Record where this task actually stands, in your own words, BEFORE you end your turn. This is the handoff the next run reads: it survives even when this conversation does not, because a thread is retired once it has accumulated too many runs and the next run then starts from this record plus the repository. Report what only you know \u2014 the goal as you now understand it, decisions you made AND WHY (a decision without its reason is the thing most often lost), problems still open, and the next concrete actions. Omit any field you learned nothing new about; an omitted field keeps its previous value rather than being cleared. Use one entry per line for decisions/next actions. Do not restate the spec or the file list \u2014 the next run gets those anyway.",
|
|
@@ -61644,15 +61048,24 @@ function makeReadTool(client, name, fallbackCode, fallbackMessage, handler, proj
|
|
|
61644
61048
|
}
|
|
61645
61049
|
var agentProviderCache = null;
|
|
61646
61050
|
var AGENT_PROVIDER_CACHE_TTL_MS = 3e4;
|
|
61051
|
+
var runDecisionConsensusImpl = runDecisionConsensus;
|
|
61052
|
+
var buildCodeGateDepsImpl = buildCodeGateDeps;
|
|
61053
|
+
function buildCodeGateDeps2(args) {
|
|
61054
|
+
return buildCodeGateDepsImpl(args);
|
|
61055
|
+
}
|
|
61056
|
+
async function mintCodeGateSeat(client) {
|
|
61057
|
+
const persistedProvider = await getAgentProviderForPanel(client);
|
|
61058
|
+
return persistedProvider ? await mintResolvedSeat(resolveProvider(process.env, persistedProvider)) : void 0;
|
|
61059
|
+
}
|
|
61647
61060
|
async function getAgentProviderForPanel(client, opts = {}) {
|
|
61648
61061
|
const now = (opts.now ?? (() => Date.now()))();
|
|
61649
61062
|
if (agentProviderCache !== null && now - agentProviderCache.fetchedAt < AGENT_PROVIDER_CACHE_TTL_MS) {
|
|
61650
61063
|
return agentProviderCache.value;
|
|
61651
61064
|
}
|
|
61652
61065
|
try {
|
|
61653
|
-
const
|
|
61654
|
-
agentProviderCache = { value:
|
|
61655
|
-
return
|
|
61066
|
+
const config2 = await client.getAgentProviderConfig();
|
|
61067
|
+
agentProviderCache = { value: config2.agentProvider, fetchedAt: now };
|
|
61068
|
+
return config2.agentProvider;
|
|
61656
61069
|
} catch (err) {
|
|
61657
61070
|
console.warn(
|
|
61658
61071
|
JSON.stringify({
|
|
@@ -62229,17 +61642,18 @@ function createMrrlinTools(options) {
|
|
|
62229
61642
|
// No client call: this review reads and writes no Mrrlin state. `projectSlug` is accepted for
|
|
62230
61643
|
// signature consistency with every other Director tool (see design.md D4a), not consumed here.
|
|
62231
61644
|
// tools.ts is an allowed provider mint site (eslint.config.mjs); decision-consensus.ts is
|
|
62232
|
-
// deliberately not, so the
|
|
62233
|
-
//
|
|
62234
|
-
|
|
61645
|
+
// deliberately not, so the persisted provider is read HERE and threaded down. It is resolved
|
|
61646
|
+
// through the allowlisted /operator/agent-provider read, not getSelectedProvider(): that store
|
|
61647
|
+
// is populated only in the bridge process, and this handler runs in `serve`, where it is
|
|
61648
|
+
// always null (which would silently pin every review to codex).
|
|
61649
|
+
async (c, input) => {
|
|
62235
61650
|
if (input.projectSlug) {
|
|
62236
61651
|
await checkTenantBoundary(input.projectSlug, "decision consensus");
|
|
62237
61652
|
}
|
|
62238
|
-
return
|
|
61653
|
+
return runDecisionConsensusImpl(
|
|
62239
61654
|
{ ...input, cwd: process.cwd() },
|
|
62240
61655
|
{
|
|
62241
|
-
persistedProvider:
|
|
62242
|
-
mintSeat: () => mintResolvedSeat(resolveProvider(process.env, getSelectedProvider()))
|
|
61656
|
+
persistedProvider: await getAgentProviderForPanel(c)
|
|
62243
61657
|
}
|
|
62244
61658
|
);
|
|
62245
61659
|
}
|
|
@@ -62251,8 +61665,9 @@ function createMrrlinTools(options) {
|
|
|
62251
61665
|
"Unable to run the code reviewer gate.",
|
|
62252
61666
|
async (c, { projectSlug, baseRef, extraHeads }) => {
|
|
62253
61667
|
await checkTenantBoundary(projectSlug, "code reviewer gate");
|
|
62254
|
-
const deps =
|
|
61668
|
+
const deps = buildCodeGateDeps2({
|
|
62255
61669
|
client: c,
|
|
61670
|
+
seat: await mintCodeGateSeat(c),
|
|
62256
61671
|
projectSlug,
|
|
62257
61672
|
baseRef,
|
|
62258
61673
|
cwd: process.cwd(),
|
|
@@ -62264,29 +61679,7 @@ function createMrrlinTools(options) {
|
|
|
62264
61679
|
// that fact now lives in one module instead of three copies.
|
|
62265
61680
|
stateDir: resolveStateDir()
|
|
62266
61681
|
});
|
|
62267
|
-
const persistedProvider = await getAgentProviderForPanel(c);
|
|
62268
|
-
let activeCodePanel = null;
|
|
62269
|
-
if (persistedProvider != null) {
|
|
62270
|
-
activeCodePanel = await resolveActivePanel({
|
|
62271
|
-
heads: ["code-reviewer", ...extraHeads ?? []],
|
|
62272
|
-
persistedProvider
|
|
62273
|
-
});
|
|
62274
|
-
}
|
|
62275
|
-
applyActivePanel(deps, activeCodePanel);
|
|
62276
61682
|
const codeGateResult = await runCodeGate({ projectSlug, baseRef }, deps);
|
|
62277
|
-
if (process.env[SHADOW_ENV_FLAG] && persistedProvider != null) {
|
|
62278
|
-
try {
|
|
62279
|
-
const diff = await readDiff({ cwd: process.cwd(), baseRef, run: defaultRunCmd });
|
|
62280
|
-
await maybeRunShadow({
|
|
62281
|
-
outcome: codeGateResult.outcome,
|
|
62282
|
-
artifact: diff,
|
|
62283
|
-
heads: ["code-reviewer", ...extraHeads ?? []],
|
|
62284
|
-
correlationId: `code:${baseRef}`,
|
|
62285
|
-
persistedProvider
|
|
62286
|
-
});
|
|
62287
|
-
} catch {
|
|
62288
|
-
}
|
|
62289
|
-
}
|
|
62290
61683
|
return codeGateResult;
|
|
62291
61684
|
}
|
|
62292
61685
|
),
|
|
@@ -62773,21 +62166,10 @@ var MRRLIN_BROWSER_TOOL_NAMES = [
|
|
|
62773
62166
|
"browser_type",
|
|
62774
62167
|
"browser_wait_for"
|
|
62775
62168
|
];
|
|
62776
|
-
var EXTERNAL_AGENTS_TOOL_NAMES = [
|
|
62777
|
-
"dispatch",
|
|
62778
|
-
"get_state",
|
|
62779
|
-
"get_stats",
|
|
62780
|
-
"list_agents",
|
|
62781
|
-
"pick_agents",
|
|
62782
|
-
"ping",
|
|
62783
|
-
"probe_agent",
|
|
62784
|
-
"set_credential"
|
|
62785
|
-
];
|
|
62786
62169
|
function allAgyGrantStrings() {
|
|
62787
62170
|
const mrrlinGrants = Object.values(mcpToolNames).map((tool) => `mcp(mrrlin/${tool})`);
|
|
62788
62171
|
const browserGrants = MRRLIN_BROWSER_TOOL_NAMES.map((tool) => `mcp(mrrlin-browser/${tool})`);
|
|
62789
|
-
|
|
62790
|
-
return Array.from(/* @__PURE__ */ new Set([...mrrlinGrants, ...browserGrants, ...externalAgentsGrants])).sort();
|
|
62172
|
+
return Array.from(/* @__PURE__ */ new Set([...mrrlinGrants, ...browserGrants])).sort();
|
|
62791
62173
|
}
|
|
62792
62174
|
function resolveAgyConfigPath(options) {
|
|
62793
62175
|
if (options.agyConfigPath) return options.agyConfigPath;
|
|
@@ -62817,10 +62199,6 @@ function mrrlinTable3(binPath, distribution, serveEnv) {
|
|
|
62817
62199
|
}
|
|
62818
62200
|
return base;
|
|
62819
62201
|
}
|
|
62820
|
-
function externalAgentsTable3(binPath, distribution) {
|
|
62821
|
-
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["external-agents-serve"] } : { command: "node", args: [binPath, "external-agents-serve"] };
|
|
62822
|
-
return base;
|
|
62823
|
-
}
|
|
62824
62202
|
function browserTable3(binPath, distribution, homeDir) {
|
|
62825
62203
|
const base = distribution === "npm" ? { command: "mrrlin-mcp", args: ["browser-serve"] } : { command: "node", args: [binPath, "browser-serve"] };
|
|
62826
62204
|
return { ...base, env: { PLAYWRIGHT_BROWSERS_PATH: browserPaths(homeDir).browsersPath } };
|
|
@@ -62829,8 +62207,7 @@ function managedEntries2(options, distribution) {
|
|
|
62829
62207
|
const homeDir = options.homeDir ?? import_node_os13.default.homedir();
|
|
62830
62208
|
return [
|
|
62831
62209
|
{ id: "mrrlin", expected: mrrlinTable3(options.binPath, distribution, options.serveEnv) },
|
|
62832
|
-
{ id: "mrrlin-browser", expected: browserTable3(options.binPath, distribution, homeDir) }
|
|
62833
|
-
{ id: "external-agents", expected: externalAgentsTable3(options.binPath, distribution) }
|
|
62210
|
+
{ id: "mrrlin-browser", expected: browserTable3(options.binPath, distribution, homeDir) }
|
|
62834
62211
|
];
|
|
62835
62212
|
}
|
|
62836
62213
|
async function pathExists4(target) {
|
|
@@ -62970,7 +62347,7 @@ var import_semver2 = __toESM(require_semver2(), 1);
|
|
|
62970
62347
|
var toml3 = __toESM(require_toml(), 1);
|
|
62971
62348
|
|
|
62972
62349
|
// src/agent-version.ts
|
|
62973
|
-
var
|
|
62350
|
+
var import_node_child_process16 = require("node:child_process");
|
|
62974
62351
|
var import_semver = __toESM(require_semver2(), 1);
|
|
62975
62352
|
var SEMVER_RE = /\b\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?\b/;
|
|
62976
62353
|
var CODEX_PACKAGE = process.env.MRRLIN_CODEX_PACKAGE?.trim() || "@openai/codex";
|
|
@@ -62980,7 +62357,7 @@ function parseCodexVersion(raw) {
|
|
|
62980
62357
|
return m ? m[0] : null;
|
|
62981
62358
|
}
|
|
62982
62359
|
var defaultRun = (args) => {
|
|
62983
|
-
const r = (0,
|
|
62360
|
+
const r = (0, import_node_child_process16.spawnSync)("codex", args, { encoding: "utf8", timeout: 8e3, shell: true });
|
|
62984
62361
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
62985
62362
|
};
|
|
62986
62363
|
function getInstalledAgentVersion(provider, run3) {
|
|
@@ -63064,14 +62441,6 @@ function resolveClaudeConfigPath2(opts) {
|
|
|
63064
62441
|
if (opts.claudeConfigPath) return opts.claudeConfigPath;
|
|
63065
62442
|
return import_node_path25.default.join(opts.homeDir ?? import_node_os14.default.homedir(), ".claude.json");
|
|
63066
62443
|
}
|
|
63067
|
-
function isExternalAgentsWrapper(table) {
|
|
63068
|
-
if (!table) return false;
|
|
63069
|
-
const command = typeof table.command === "string" ? table.command : "";
|
|
63070
|
-
const args = Array.isArray(table.args) ? table.args.map(String) : [];
|
|
63071
|
-
if (command === "mrrlin-mcp" && args.includes("external-agents-serve")) return true;
|
|
63072
|
-
if (command === "node" && args.some((a) => a.includes("external-agents-serve"))) return true;
|
|
63073
|
-
return false;
|
|
63074
|
-
}
|
|
63075
62444
|
async function verifyProviderReadiness(provider, run3, opts = {}) {
|
|
63076
62445
|
if (provider === "agy") {
|
|
63077
62446
|
let cliResult2;
|
|
@@ -63152,20 +62521,20 @@ async function verifyProviderReadiness(provider, run3, opts = {}) {
|
|
|
63152
62521
|
try {
|
|
63153
62522
|
const raw = await (0, import_promises11.readFile)(configPath, "utf8");
|
|
63154
62523
|
const parsed = toml3.parse(raw);
|
|
63155
|
-
checks.mcpReachable =
|
|
62524
|
+
checks.mcpReachable = isMrrlinServeEntryShape(parsed.mcp_servers?.["mrrlin"]);
|
|
63156
62525
|
} catch {
|
|
63157
62526
|
}
|
|
63158
|
-
if (!checks.mcpReachable) details.push("mcpReachable:
|
|
62527
|
+
if (!checks.mcpReachable) details.push("mcpReachable: Mrrlin MCP server entry (mrrlin) missing or invalid");
|
|
63159
62528
|
} else if (cliUnreachable) {
|
|
63160
62529
|
} else {
|
|
63161
62530
|
const configPath = resolveClaudeConfigPath2(opts);
|
|
63162
62531
|
try {
|
|
63163
62532
|
const raw = await (0, import_promises11.readFile)(configPath, "utf8");
|
|
63164
62533
|
const parsed = raw.trim() === "" ? {} : JSON.parse(raw);
|
|
63165
|
-
checks.mcpReachable =
|
|
62534
|
+
checks.mcpReachable = isMrrlinServeEntryShape(parsed.mcpServers?.["mrrlin"]);
|
|
63166
62535
|
} catch {
|
|
63167
62536
|
}
|
|
63168
|
-
if (!checks.mcpReachable) details.push("mcpReachable:
|
|
62537
|
+
if (!checks.mcpReachable) details.push("mcpReachable: Mrrlin MCP server entry (mrrlin) missing or invalid");
|
|
63169
62538
|
}
|
|
63170
62539
|
if (provider === "codex") {
|
|
63171
62540
|
checks.smoke = true;
|
|
@@ -63201,7 +62570,7 @@ async function verifyProviderReadiness(provider, run3, opts = {}) {
|
|
|
63201
62570
|
// src/browser-interceptor.ts
|
|
63202
62571
|
var import_node_os15 = __toESM(require("node:os"), 1);
|
|
63203
62572
|
var import_node_readline = __toESM(require("node:readline"), 1);
|
|
63204
|
-
var
|
|
62573
|
+
var import_node_child_process17 = require("node:child_process");
|
|
63205
62574
|
var INTERNAL_HOST_PATTERNS = [
|
|
63206
62575
|
/^(?:.*\.)?mrrlin\.(?:com|internal|local)$/i,
|
|
63207
62576
|
/^(?:localhost|127\.0\.0\.1)(?::\d+)?$/i
|
|
@@ -63382,7 +62751,7 @@ function signalToExitCode(signal) {
|
|
|
63382
62751
|
async function runBrowserServeProxy(opts) {
|
|
63383
62752
|
const input = opts.input ?? process.stdin;
|
|
63384
62753
|
const output3 = opts.output ?? process.stdout;
|
|
63385
|
-
const child = (0,
|
|
62754
|
+
const child = (0, import_node_child_process17.spawn)(opts.command, opts.args, {
|
|
63386
62755
|
stdio: ["pipe", "pipe", "inherit"],
|
|
63387
62756
|
env: { ...process.env, ...opts.env }
|
|
63388
62757
|
});
|
|
@@ -63433,7 +62802,7 @@ var import_node_fs29 = __toESM(require("node:fs"), 1);
|
|
|
63433
62802
|
var import_node_http3 = __toESM(require("node:http"), 1);
|
|
63434
62803
|
var import_node_os22 = __toESM(require("node:os"), 1);
|
|
63435
62804
|
var import_node_path43 = __toESM(require("node:path"), 1);
|
|
63436
|
-
var
|
|
62805
|
+
var import_node_child_process23 = require("node:child_process");
|
|
63437
62806
|
var import_node_crypto23 = __toESM(require("node:crypto"), 1);
|
|
63438
62807
|
|
|
63439
62808
|
// src/turn-replay-buffer.ts
|
|
@@ -63987,14 +63356,14 @@ function directorThreadEnv(projectSlug) {
|
|
|
63987
63356
|
}
|
|
63988
63357
|
|
|
63989
63358
|
// src/self-update.ts
|
|
63990
|
-
var
|
|
63359
|
+
var import_node_child_process19 = require("node:child_process");
|
|
63991
63360
|
var import_node_crypto16 = require("node:crypto");
|
|
63992
63361
|
var import_node_fs19 = require("node:fs");
|
|
63993
63362
|
var import_node_path27 = __toESM(require("node:path"), 1);
|
|
63994
63363
|
var import_semver3 = __toESM(require_semver2(), 1);
|
|
63995
63364
|
|
|
63996
63365
|
// src/codex-auth-preflight.ts
|
|
63997
|
-
var
|
|
63366
|
+
var import_node_child_process18 = require("node:child_process");
|
|
63998
63367
|
var import_node_fs18 = require("node:fs");
|
|
63999
63368
|
var import_node_os16 = __toESM(require("node:os"), 1);
|
|
64000
63369
|
var import_node_path26 = __toESM(require("node:path"), 1);
|
|
@@ -64088,7 +63457,7 @@ function runCodexAuthRefreshSmokeForBridgeUpdate(opts = {}) {
|
|
|
64088
63457
|
CODEX_AUTH_SMOKE_PROMPT
|
|
64089
63458
|
];
|
|
64090
63459
|
const command = commandForSmoke(executable, model);
|
|
64091
|
-
const execFileSync8 = opts.execFileSyncImpl ??
|
|
63460
|
+
const execFileSync8 = opts.execFileSyncImpl ?? import_node_child_process18.execFileSync;
|
|
64092
63461
|
try {
|
|
64093
63462
|
execFileSync8(executable, args, {
|
|
64094
63463
|
cwd,
|
|
@@ -64256,7 +63625,7 @@ function resolveBinPath(opts) {
|
|
|
64256
63625
|
}
|
|
64257
63626
|
const whichSync = opts.whichSync ?? ((name) => {
|
|
64258
63627
|
try {
|
|
64259
|
-
return (0,
|
|
63628
|
+
return (0, import_node_child_process19.execFileSync)("which", [name], { encoding: "utf8", timeout: 3e3 }).trim() || null;
|
|
64260
63629
|
} catch {
|
|
64261
63630
|
return null;
|
|
64262
63631
|
}
|
|
@@ -64592,7 +63961,7 @@ Do NOT derail the current task - if the operator has an in-flight question, answ
|
|
|
64592
63961
|
}
|
|
64593
63962
|
|
|
64594
63963
|
// src/_generated/version.ts
|
|
64595
|
-
var PKG_VERSION = "0.4.
|
|
63964
|
+
var PKG_VERSION = "0.4.161";
|
|
64596
63965
|
|
|
64597
63966
|
// src/bridge-allowed-origins.ts
|
|
64598
63967
|
var DEFAULT_DIRECTOR_BRIDGE_ALLOWED_ORIGINS = [
|
|
@@ -66805,270 +66174,15 @@ async function uploadPendingDays(stateDir, client, bridgeHealth, gateCtx) {
|
|
|
66805
66174
|
}
|
|
66806
66175
|
}
|
|
66807
66176
|
|
|
66808
|
-
// src/agent-pool-snapshot.ts
|
|
66809
|
-
function normalizeLastUsedAt(value) {
|
|
66810
|
-
if (value === void 0 || value === null) return null;
|
|
66811
|
-
if (typeof value === "number") {
|
|
66812
|
-
if (!Number.isFinite(value)) return null;
|
|
66813
|
-
const ms = value < 1e12 ? value * 1e3 : value;
|
|
66814
|
-
const date5 = new Date(ms);
|
|
66815
|
-
return Number.isNaN(date5.getTime()) ? null : date5.toISOString();
|
|
66816
|
-
}
|
|
66817
|
-
return value;
|
|
66818
|
-
}
|
|
66819
|
-
function buildAgentPoolSnapshot(statusRows, stats, opts) {
|
|
66820
|
-
if (!opts.available) {
|
|
66821
|
-
return {
|
|
66822
|
-
collected_at: opts.collectedAt,
|
|
66823
|
-
status: "unavailable",
|
|
66824
|
-
agents: [],
|
|
66825
|
-
totals: { calls: 0, tokens_in: 0, tokens_out: 0 },
|
|
66826
|
-
estimated_savings_usd: 0
|
|
66827
|
-
};
|
|
66828
|
-
}
|
|
66829
|
-
const costPer1M = opts.paidCostPer1MTokens ?? 3;
|
|
66830
|
-
const agents = statusRows.map((row) => {
|
|
66831
|
-
const agentStats = stats.by_agent[row.id];
|
|
66832
|
-
const count2 = agentStats?.count ?? 0;
|
|
66833
|
-
const tokensIn = agentStats?.tokens_in ?? 0;
|
|
66834
|
-
const tokensOut = agentStats?.tokens_out ?? 0;
|
|
66835
|
-
let successRate = 0;
|
|
66836
|
-
if (count2 > 0) {
|
|
66837
|
-
const successOutcomes = agentStats?.outcomes.success ?? 0;
|
|
66838
|
-
successRate = Number((successOutcomes / count2 * 100).toFixed(2)) / 100;
|
|
66839
|
-
}
|
|
66840
|
-
return {
|
|
66841
|
-
id: row.id,
|
|
66842
|
-
provider: row.provider,
|
|
66843
|
-
tier: row.tier,
|
|
66844
|
-
tags: row.tags,
|
|
66845
|
-
state: row.state ?? "unknown",
|
|
66846
|
-
calls: count2,
|
|
66847
|
-
tokens_in: tokensIn,
|
|
66848
|
-
tokens_out: tokensOut,
|
|
66849
|
-
success_rate: successRate,
|
|
66850
|
-
last_used_at: normalizeLastUsedAt(row.last_used_at)
|
|
66851
|
-
};
|
|
66852
|
-
});
|
|
66853
|
-
let totalCalls = 0;
|
|
66854
|
-
let totalTokensIn = 0;
|
|
66855
|
-
let totalTokensOut = 0;
|
|
66856
|
-
for (const entry of Object.values(stats.by_agent)) {
|
|
66857
|
-
totalCalls += entry.count;
|
|
66858
|
-
totalTokensIn += entry.tokens_in;
|
|
66859
|
-
totalTokensOut += entry.tokens_out;
|
|
66860
|
-
}
|
|
66861
|
-
let savedTokens = 0;
|
|
66862
|
-
for (const row of statusRows) {
|
|
66863
|
-
if (row.tags.includes("free")) {
|
|
66864
|
-
const agentStats = stats.by_agent[row.id];
|
|
66865
|
-
if (agentStats) {
|
|
66866
|
-
savedTokens += agentStats.tokens_in + agentStats.tokens_out;
|
|
66867
|
-
}
|
|
66868
|
-
}
|
|
66869
|
-
}
|
|
66870
|
-
const estimatedSavings = Number((savedTokens / 1e6 * costPer1M).toFixed(2));
|
|
66871
|
-
return {
|
|
66872
|
-
collected_at: opts.collectedAt,
|
|
66873
|
-
status: "ok",
|
|
66874
|
-
agents,
|
|
66875
|
-
totals: {
|
|
66876
|
-
calls: totalCalls,
|
|
66877
|
-
tokens_in: totalTokensIn,
|
|
66878
|
-
tokens_out: totalTokensOut
|
|
66879
|
-
},
|
|
66880
|
-
estimated_savings_usd: estimatedSavings
|
|
66881
|
-
};
|
|
66882
|
-
}
|
|
66883
|
-
|
|
66884
|
-
// src/agent-pool-collector.ts
|
|
66885
|
-
async function collectAgentPoolSnapshot(deps) {
|
|
66886
|
-
let statusRows;
|
|
66887
|
-
let stats;
|
|
66888
|
-
try {
|
|
66889
|
-
const statusResult = await deps.runCli(["status", "--json"]);
|
|
66890
|
-
if (statusResult.code !== 0) throw new Error("non-zero exit on status");
|
|
66891
|
-
let statusParsed;
|
|
66892
|
-
try {
|
|
66893
|
-
statusParsed = JSON.parse(statusResult.stdout);
|
|
66894
|
-
} catch {
|
|
66895
|
-
throw new Error("invalid status json");
|
|
66896
|
-
}
|
|
66897
|
-
if (!Array.isArray(statusParsed)) throw new Error("status not array");
|
|
66898
|
-
statusRows = statusParsed;
|
|
66899
|
-
const statsResult = await deps.runCli(["stats", "--json"]);
|
|
66900
|
-
if (statsResult.code !== 0) throw new Error("non-zero exit on stats");
|
|
66901
|
-
try {
|
|
66902
|
-
stats = JSON.parse(statsResult.stdout);
|
|
66903
|
-
} catch {
|
|
66904
|
-
throw new Error("invalid stats json");
|
|
66905
|
-
}
|
|
66906
|
-
} catch {
|
|
66907
|
-
return buildAgentPoolSnapshot(
|
|
66908
|
-
[],
|
|
66909
|
-
{},
|
|
66910
|
-
{ collectedAt: deps.now(), available: false }
|
|
66911
|
-
);
|
|
66912
|
-
}
|
|
66913
|
-
return buildAgentPoolSnapshot(
|
|
66914
|
-
statusRows,
|
|
66915
|
-
stats,
|
|
66916
|
-
{ collectedAt: deps.now(), paidCostPer1MTokens: deps.paidCostPer1MTokens, available: true }
|
|
66917
|
-
);
|
|
66918
|
-
}
|
|
66919
|
-
|
|
66920
|
-
// src/external-agents-spawn.ts
|
|
66921
|
-
var import_node_child_process22 = require("node:child_process");
|
|
66922
|
-
function runExternalAgentsCli(args, opts) {
|
|
66923
|
-
let command;
|
|
66924
|
-
let prefixArgs;
|
|
66925
|
-
let source;
|
|
66926
|
-
let triedPath;
|
|
66927
|
-
if (opts.envCliPath && opts.envCliPath.trim()) {
|
|
66928
|
-
command = "node";
|
|
66929
|
-
prefixArgs = [opts.envCliPath];
|
|
66930
|
-
source = "env";
|
|
66931
|
-
triedPath = opts.envCliPath;
|
|
66932
|
-
} else {
|
|
66933
|
-
({ command, prefixArgs } = resolveExternalAgentsCliInvocation());
|
|
66934
|
-
source = command === "node" && prefixArgs.length === 1 ? "bundled" : "path";
|
|
66935
|
-
triedPath = source === "bundled" ? prefixArgs[0] ?? "" : "external-agents (PATH)";
|
|
66936
|
-
}
|
|
66937
|
-
const useStdin = opts.stdinValue !== void 0;
|
|
66938
|
-
const stdioConfig = useStdin ? ["pipe", "pipe", "pipe"] : ["ignore", "pipe", "pipe"];
|
|
66939
|
-
return new Promise((resolve3) => {
|
|
66940
|
-
let stdout = "";
|
|
66941
|
-
let stderr = "";
|
|
66942
|
-
let settled = false;
|
|
66943
|
-
let timedOut = false;
|
|
66944
|
-
const done = (code) => {
|
|
66945
|
-
if (!settled) {
|
|
66946
|
-
settled = true;
|
|
66947
|
-
resolve3({ stdout, stderr, code, timedOut, source, triedPath });
|
|
66948
|
-
}
|
|
66949
|
-
};
|
|
66950
|
-
let spawned;
|
|
66951
|
-
try {
|
|
66952
|
-
spawned = (0, import_node_child_process22.spawn)(command, [...prefixArgs, ...args], { stdio: stdioConfig });
|
|
66953
|
-
} catch {
|
|
66954
|
-
done(1);
|
|
66955
|
-
return;
|
|
66956
|
-
}
|
|
66957
|
-
const child = spawned;
|
|
66958
|
-
let sigkillTimer = null;
|
|
66959
|
-
let budgetTimer = null;
|
|
66960
|
-
if (useStdin && child.stdin) {
|
|
66961
|
-
child.stdin.on("error", () => {
|
|
66962
|
-
});
|
|
66963
|
-
child.stdin.write(opts.stdinValue);
|
|
66964
|
-
child.stdin.end();
|
|
66965
|
-
}
|
|
66966
|
-
child.stdout?.on("data", (d) => {
|
|
66967
|
-
stdout += d.toString();
|
|
66968
|
-
if (stdout.length > 2e5) stdout = stdout.slice(-2e5);
|
|
66969
|
-
});
|
|
66970
|
-
child.stderr?.on("data", (d) => {
|
|
66971
|
-
stderr += d.toString();
|
|
66972
|
-
if (stderr.length > 2e5) stderr = stderr.slice(-2e5);
|
|
66973
|
-
});
|
|
66974
|
-
budgetTimer = setTimeout(() => {
|
|
66975
|
-
budgetTimer = null;
|
|
66976
|
-
timedOut = true;
|
|
66977
|
-
try {
|
|
66978
|
-
child.kill("SIGTERM");
|
|
66979
|
-
} catch {
|
|
66980
|
-
}
|
|
66981
|
-
sigkillTimer = setTimeout(() => {
|
|
66982
|
-
sigkillTimer = null;
|
|
66983
|
-
try {
|
|
66984
|
-
child.kill("SIGKILL");
|
|
66985
|
-
} catch {
|
|
66986
|
-
}
|
|
66987
|
-
}, 2e3);
|
|
66988
|
-
sigkillTimer.unref?.();
|
|
66989
|
-
done(1);
|
|
66990
|
-
}, opts.budgetMs);
|
|
66991
|
-
budgetTimer.unref?.();
|
|
66992
|
-
child.on("error", () => {
|
|
66993
|
-
if (budgetTimer) {
|
|
66994
|
-
clearTimeout(budgetTimer);
|
|
66995
|
-
budgetTimer = null;
|
|
66996
|
-
}
|
|
66997
|
-
if (sigkillTimer) {
|
|
66998
|
-
clearTimeout(sigkillTimer);
|
|
66999
|
-
sigkillTimer = null;
|
|
67000
|
-
}
|
|
67001
|
-
done(1);
|
|
67002
|
-
});
|
|
67003
|
-
child.on("close", (code) => {
|
|
67004
|
-
if (budgetTimer) {
|
|
67005
|
-
clearTimeout(budgetTimer);
|
|
67006
|
-
budgetTimer = null;
|
|
67007
|
-
}
|
|
67008
|
-
if (sigkillTimer) {
|
|
67009
|
-
clearTimeout(sigkillTimer);
|
|
67010
|
-
sigkillTimer = null;
|
|
67011
|
-
}
|
|
67012
|
-
done(code ?? 1);
|
|
67013
|
-
});
|
|
67014
|
-
});
|
|
67015
|
-
}
|
|
67016
|
-
|
|
67017
|
-
// src/agent-pool-loop.ts
|
|
67018
|
-
var DEFAULT_INTERVAL_MS2 = 6e4;
|
|
67019
|
-
function agentPoolLoopDisabled(env = process.env) {
|
|
67020
|
-
return env["MRRLIN_BRIDGE_AGENT_POOL_DISABLE"] === "1";
|
|
67021
|
-
}
|
|
67022
|
-
function defaultRunCli(args) {
|
|
67023
|
-
return runExternalAgentsCli(args, {
|
|
67024
|
-
budgetMs: 5e3,
|
|
67025
|
-
envCliPath: process.env["EXTERNAL_AGENTS_CLI"]
|
|
67026
|
-
}).then(({ stdout, code }) => ({ stdout, code }));
|
|
67027
|
-
}
|
|
67028
|
-
async function runAgentPoolCycle(deps) {
|
|
67029
|
-
try {
|
|
67030
|
-
const snapshot = await collectAgentPoolSnapshot({
|
|
67031
|
-
runCli: deps.runCli ?? defaultRunCli,
|
|
67032
|
-
now: deps.now ?? (() => (/* @__PURE__ */ new Date()).toISOString())
|
|
67033
|
-
});
|
|
67034
|
-
await deps.push(snapshot);
|
|
67035
|
-
} catch (err) {
|
|
67036
|
-
deps.onError?.(err);
|
|
67037
|
-
}
|
|
67038
|
-
}
|
|
67039
|
-
function startAgentPoolLoop(deps) {
|
|
67040
|
-
const env = deps.env ?? process.env;
|
|
67041
|
-
const intervalMs = deps.intervalMs ?? Number(env["MRRLIN_BRIDGE_AGENT_POOL_INTERVAL_MS"] ?? DEFAULT_INTERVAL_MS2);
|
|
67042
|
-
let stopped = false;
|
|
67043
|
-
let timer = null;
|
|
67044
|
-
const schedule = () => {
|
|
67045
|
-
if (stopped) return;
|
|
67046
|
-
timer = setTimeout(() => {
|
|
67047
|
-
void runAgentPoolCycle(deps).then(() => schedule());
|
|
67048
|
-
}, intervalMs);
|
|
67049
|
-
timer.unref?.();
|
|
67050
|
-
};
|
|
67051
|
-
timer = setTimeout(() => {
|
|
67052
|
-
void runAgentPoolCycle(deps).then(() => schedule());
|
|
67053
|
-
}, 1e3);
|
|
67054
|
-
timer.unref?.();
|
|
67055
|
-
return {
|
|
67056
|
-
stop() {
|
|
67057
|
-
stopped = true;
|
|
67058
|
-
if (timer) clearTimeout(timer);
|
|
67059
|
-
}
|
|
67060
|
-
};
|
|
67061
|
-
}
|
|
67062
|
-
|
|
67063
66177
|
// src/provider-readiness-loop.ts
|
|
67064
|
-
var
|
|
67065
|
-
var
|
|
66178
|
+
var import_node_child_process20 = require("node:child_process");
|
|
66179
|
+
var DEFAULT_INTERVAL_MS2 = 6e4;
|
|
67066
66180
|
function providerReadinessLoopDisabled(env = process.env) {
|
|
67067
66181
|
return env["MRRLIN_BRIDGE_PROVIDER_READINESS_DISABLE"] === "1";
|
|
67068
66182
|
}
|
|
67069
66183
|
function defaultRunnerFor(command) {
|
|
67070
66184
|
return (args) => {
|
|
67071
|
-
const r = (0,
|
|
66185
|
+
const r = (0, import_node_child_process20.spawnSync)(command, args, { encoding: "utf8", timeout: 8e3 });
|
|
67072
66186
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
67073
66187
|
};
|
|
67074
66188
|
}
|
|
@@ -67088,7 +66202,7 @@ async function runProviderReadinessCycle(deps) {
|
|
|
67088
66202
|
}
|
|
67089
66203
|
function startProviderReadinessLoop(deps) {
|
|
67090
66204
|
const env = deps.env ?? process.env;
|
|
67091
|
-
const intervalMs = deps.intervalMs ?? Number(env["MRRLIN_BRIDGE_PROVIDER_READINESS_INTERVAL_MS"] ??
|
|
66205
|
+
const intervalMs = deps.intervalMs ?? Number(env["MRRLIN_BRIDGE_PROVIDER_READINESS_INTERVAL_MS"] ?? DEFAULT_INTERVAL_MS2);
|
|
67092
66206
|
let stopped = false;
|
|
67093
66207
|
let timer = null;
|
|
67094
66208
|
const schedule = () => {
|
|
@@ -67110,8 +66224,17 @@ function startProviderReadinessLoop(deps) {
|
|
|
67110
66224
|
};
|
|
67111
66225
|
}
|
|
67112
66226
|
|
|
66227
|
+
// src/selected-provider-store.ts
|
|
66228
|
+
var current = null;
|
|
66229
|
+
function getSelectedProvider() {
|
|
66230
|
+
return current;
|
|
66231
|
+
}
|
|
66232
|
+
function setSelectedProvider(value) {
|
|
66233
|
+
current = value;
|
|
66234
|
+
}
|
|
66235
|
+
|
|
67113
66236
|
// src/execution-consumer.ts
|
|
67114
|
-
var
|
|
66237
|
+
var import_node_child_process21 = require("node:child_process");
|
|
67115
66238
|
var import_node_crypto20 = __toESM(require("node:crypto"), 1);
|
|
67116
66239
|
var import_node_path35 = __toESM(require("node:path"), 1);
|
|
67117
66240
|
var import_node_util2 = require("node:util");
|
|
@@ -68570,31 +67693,7 @@ var EXECUTOR_BASE_INSTRUCTIONS = [
|
|
|
68570
67693
|
"Fix the cause without removing or relaxing a security",
|
|
68571
67694
|
"check (origin, CSRF, authentication, authorization) just to make a check pass. Never hand the operator",
|
|
68572
67695
|
"a flow to verify that failed when you ran it unless you name the evidence that it will behave",
|
|
68573
|
-
"differently for them."
|
|
68574
|
-
// ADR 0022 Phase 3: the executor is the orchestrator, not the sole worker. It has the
|
|
68575
|
-
// external-agents `pick`/`dispatch` MCP tools (a pool of cheap/free models) and should
|
|
68576
|
-
// delegate judgment-requiring work to them, keeping itself as judge. If external-agents
|
|
68577
|
-
// isn't installed the tools are simply absent — these lines then read as advice the model
|
|
68578
|
-
// can't act on, and it does the work itself (graceful, no-op).
|
|
68579
|
-
"You are the ORCHESTRATOR and JUDGE, not the sole worker. If the external-agents `pick` and",
|
|
68580
|
-
"`dispatch` tools are available, use this rule to decide what to delegate:",
|
|
68581
|
-
"",
|
|
68582
|
-
"DISPATCH (judgment work): changes that require choosing an approach, understanding context",
|
|
68583
|
-
"across files, or making a non-obvious decision \u2014 feature code, tests, refactors, research.",
|
|
68584
|
-
"Gather context first, then write a focused prompt including what you already know (file contents,",
|
|
68585
|
-
"constraints, architecture decisions) so the worker skips re-discovery. That context distillation",
|
|
68586
|
-
"is where your tokens add value. Prefer `deepseek-reasoner` for hard/medium tasks; fall back to",
|
|
68587
|
-
"`openrouter-nemotron-ultra-free`, `openrouter-nemotron-super-free`, or `ollama-gpt-oss-120b`.",
|
|
68588
|
-
"Use `deepseek-chat` for quick parallel tasks. Dispatch several in parallel when subtasks are",
|
|
68589
|
-
"independent.",
|
|
68590
|
-
"",
|
|
68591
|
-
"SELF-EDIT (mechanical work): deterministic changes with no judgment \u2014 typo, import path, version",
|
|
68592
|
-
"bump, config plumbing. The prompt would cost more than the change itself. Just do it.",
|
|
68593
|
-
"",
|
|
68594
|
-
"You MUST verify every delegated result against the actual files and tests before it lands \u2014",
|
|
68595
|
-
"pool models are lower-reliability and a wrong delegated edit is YOUR responsibility; never",
|
|
68596
|
-
"commit unverified delegated output. If dispatch fails or the pool is unavailable, do the",
|
|
68597
|
-
"work yourself \u2014 never block the run on the pool."
|
|
67696
|
+
"differently for them."
|
|
68598
67697
|
].join("\n");
|
|
68599
67698
|
var LOCAL_GIT_EXECUTOR_INSTRUCTIONS = [
|
|
68600
67699
|
"",
|
|
@@ -68649,7 +67748,7 @@ var BLAST_RADIUS_FLOOR_PATTERNS = [/^supabase\/migrations\//, /^packages\/db\/sr
|
|
|
68649
67748
|
function isBlastRadiusFloorPath(path36) {
|
|
68650
67749
|
return BLAST_RADIUS_FLOOR_PATTERNS.some((re) => re.test(path36));
|
|
68651
67750
|
}
|
|
68652
|
-
var execFileAsync2 = (0, import_node_util2.promisify)(
|
|
67751
|
+
var execFileAsync2 = (0, import_node_util2.promisify)(import_node_child_process21.execFile);
|
|
68653
67752
|
async function gitOutput(cwd, args) {
|
|
68654
67753
|
const { stdout } = await execFileAsync2("git", ["-C", cwd, ...args], {
|
|
68655
67754
|
timeout: 3e4,
|
|
@@ -68658,21 +67757,21 @@ async function gitOutput(cwd, args) {
|
|
|
68658
67757
|
return String(stdout).trim();
|
|
68659
67758
|
}
|
|
68660
67759
|
async function defaultListRunDiffPaths(opts) {
|
|
68661
|
-
const
|
|
67760
|
+
const parse9 = (stdout) => stdout.split("\n").map((line) => line.trim()).filter((line) => line.length > 0);
|
|
68662
67761
|
try {
|
|
68663
67762
|
const { stdout } = await execFileAsync2(
|
|
68664
67763
|
"git",
|
|
68665
67764
|
["-C", opts.worktreePath, "diff", "--name-only", `origin/${opts.defaultBranch}...HEAD`],
|
|
68666
67765
|
{ timeout: 3e4 }
|
|
68667
67766
|
);
|
|
68668
|
-
return
|
|
67767
|
+
return parse9(stdout);
|
|
68669
67768
|
} catch {
|
|
68670
67769
|
const { stdout } = await execFileAsync2(
|
|
68671
67770
|
"git",
|
|
68672
67771
|
["-C", opts.worktreePath, "diff", "--name-only", `${opts.defaultBranch}...HEAD`],
|
|
68673
67772
|
{ timeout: 3e4 }
|
|
68674
67773
|
);
|
|
68675
|
-
return
|
|
67774
|
+
return parse9(stdout);
|
|
68676
67775
|
}
|
|
68677
67776
|
}
|
|
68678
67777
|
var BLAST_RADIUS_FLOOR_REASON = "migration or database schema files changed";
|
|
@@ -75744,14 +74843,14 @@ async function renderPairingQrSvg(payload) {
|
|
|
75744
74843
|
}
|
|
75745
74844
|
|
|
75746
74845
|
// src/executor-server.ts
|
|
75747
|
-
var
|
|
74846
|
+
var import_node_child_process22 = require("node:child_process");
|
|
75748
74847
|
function defaultReadinessRunner(provider) {
|
|
75749
74848
|
if (provider !== "codex" && provider !== "claude" && provider !== "agy") {
|
|
75750
74849
|
throw new Error(`unsupported executor provider: ${String(provider)}`);
|
|
75751
74850
|
}
|
|
75752
74851
|
const command = provider === "claude" ? "claude" : provider === "agy" ? "agy" : "codex";
|
|
75753
74852
|
return (args) => {
|
|
75754
|
-
const r = (0,
|
|
74853
|
+
const r = (0, import_node_child_process22.spawnSync)(command, args, { encoding: "utf8", timeout: 8e3, shell: true });
|
|
75755
74854
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
75756
74855
|
};
|
|
75757
74856
|
}
|
|
@@ -75840,7 +74939,7 @@ async function startExecutorServer(opts) {
|
|
|
75840
74939
|
const rawBaseEnv = opts.env ?? (isVerification ? buildVerificationEnv(process.env) : sanitizeExecutorEnv(process.env));
|
|
75841
74940
|
const baseEnv = isVerification ? buildVerificationEnv(rawBaseEnv) : sanitizeExecutorEnv(rawBaseEnv);
|
|
75842
74941
|
const childEnv = withDisabledGitHooksEnv(baseEnv, opts.disabledGitHooksDir);
|
|
75843
|
-
const baseSpawn = opts.spawn ??
|
|
74942
|
+
const baseSpawn = opts.spawn ?? import_node_child_process22.spawn;
|
|
75844
74943
|
const hasExtraFd = opts.brokerSocket != null || opts.brokerSocketFd != null;
|
|
75845
74944
|
const spawnFn = (cmd, args = [], spawnOpts = {}) => {
|
|
75846
74945
|
const argList = [...args];
|
|
@@ -77381,377 +76480,170 @@ async function readSessionRows(logsDir, files, sessionIds) {
|
|
|
77381
76480
|
return { lines: lines2, missingFiles };
|
|
77382
76481
|
}
|
|
77383
76482
|
|
|
77384
|
-
// src/external-agents-
|
|
77385
|
-
var import_node_fs28 =
|
|
76483
|
+
// src/external-agents-prune.ts
|
|
76484
|
+
var import_node_fs28 = require("node:fs");
|
|
76485
|
+
var import_promises17 = __toESM(require("node:fs/promises"), 1);
|
|
77386
76486
|
var import_node_os20 = __toESM(require("node:os"), 1);
|
|
77387
76487
|
var import_node_path41 = __toESM(require("node:path"), 1);
|
|
77388
|
-
var
|
|
77389
|
-
var
|
|
77390
|
-
|
|
77391
|
-
|
|
77392
|
-
|
|
77393
|
-
|
|
77394
|
-
|
|
77395
|
-
|
|
77396
|
-
|
|
77397
|
-
|
|
77398
|
-
|
|
77399
|
-
|
|
77400
|
-
|
|
77401
|
-
|
|
77402
|
-
|
|
77403
|
-
|
|
77404
|
-
|
|
77405
|
-
|
|
77406
|
-
|
|
77407
|
-
|
|
77408
|
-
|
|
77409
|
-
|
|
77410
|
-
|
|
77411
|
-
|
|
77412
|
-
|
|
77413
|
-
if (key === "") continue;
|
|
77414
|
-
map2.set(key, value);
|
|
77415
|
-
}
|
|
77416
|
-
} catch {
|
|
77417
|
-
}
|
|
77418
|
-
keysEnvCache = { mtimeMs, map: map2 };
|
|
77419
|
-
return map2;
|
|
77420
|
-
}
|
|
77421
|
-
function buildScrubSet(opts) {
|
|
77422
|
-
const result = /* @__PURE__ */ new Set();
|
|
77423
|
-
const fileMap = readKeysEnv();
|
|
77424
|
-
for (const name of opts.registryEnvNames) {
|
|
77425
|
-
const fromFile = fileMap.get(name);
|
|
77426
|
-
if (fromFile !== void 0 && fromFile !== "") {
|
|
77427
|
-
result.add(fromFile);
|
|
77428
|
-
}
|
|
77429
|
-
const fromEnv = process.env[name];
|
|
77430
|
-
if (fromEnv !== void 0 && fromEnv !== "") {
|
|
77431
|
-
result.add(fromEnv);
|
|
77432
|
-
}
|
|
77433
|
-
}
|
|
77434
|
-
for (const value of opts.inFlightValues ?? []) {
|
|
77435
|
-
result.add(value);
|
|
76488
|
+
var toml4 = __toESM(require_toml(), 1);
|
|
76489
|
+
var LEGACY_EXTERNAL_AGENTS_TOOL_NAMES = [
|
|
76490
|
+
"dispatch",
|
|
76491
|
+
"get_state",
|
|
76492
|
+
"get_stats",
|
|
76493
|
+
"list_agents",
|
|
76494
|
+
"pick_agents",
|
|
76495
|
+
"ping",
|
|
76496
|
+
"probe_agent",
|
|
76497
|
+
"set_credential"
|
|
76498
|
+
];
|
|
76499
|
+
var LEGACY_EXTERNAL_AGENTS_SERVER_ID = "external-agents";
|
|
76500
|
+
var SERVE_ARG = "external-agents-serve";
|
|
76501
|
+
var LEGACY_CODEX_COMMAND = "external-agents-mcp";
|
|
76502
|
+
var LEGACY_STARTUP_TIMEOUT_SEC = 30;
|
|
76503
|
+
function legacyGrantStrings() {
|
|
76504
|
+
return LEGACY_EXTERNAL_AGENTS_TOOL_NAMES.map((tool) => `mcp(${LEGACY_EXTERNAL_AGENTS_SERVER_ID}/${tool})`);
|
|
76505
|
+
}
|
|
76506
|
+
function isOurExternalAgentsEntry(entry, binPath, options = {}) {
|
|
76507
|
+
if (typeof entry !== "object" || entry === null || Array.isArray(entry)) return false;
|
|
76508
|
+
const table = entry;
|
|
76509
|
+
const allowedKeys = /* @__PURE__ */ new Set(["command", "args", "startup_timeout_sec"]);
|
|
76510
|
+
if (!Object.keys(table).every((key) => allowedKeys.has(key))) return false;
|
|
76511
|
+
if (table.startup_timeout_sec !== void 0 && table.startup_timeout_sec !== LEGACY_STARTUP_TIMEOUT_SEC) {
|
|
76512
|
+
return false;
|
|
77436
76513
|
}
|
|
77437
|
-
|
|
77438
|
-
|
|
77439
|
-
|
|
77440
|
-
|
|
77441
|
-
|
|
77442
|
-
|
|
77443
|
-
|
|
77444
|
-
return
|
|
76514
|
+
const { command, args } = table;
|
|
76515
|
+
if (typeof command !== "string") return false;
|
|
76516
|
+
if (args !== void 0 && !Array.isArray(args)) return false;
|
|
76517
|
+
const argv = args ?? [];
|
|
76518
|
+
if (!argv.every((a) => typeof a === "string")) return false;
|
|
76519
|
+
if (command === "mrrlin-mcp") return argv.length === 1 && argv[0] === SERVE_ARG;
|
|
76520
|
+
if (command === "node") return argv.length === 2 && [].concat(binPath).includes(argv[0]) && argv[1] === SERVE_ARG;
|
|
76521
|
+
if (options.allowCodexLegacy && command === LEGACY_CODEX_COMMAND) return argv.length === 0;
|
|
76522
|
+
return false;
|
|
77445
76523
|
}
|
|
77446
|
-
function
|
|
76524
|
+
async function readIfExists(file2) {
|
|
77447
76525
|
try {
|
|
77448
|
-
return
|
|
77449
|
-
} catch {
|
|
77450
|
-
return null;
|
|
77451
|
-
|
|
77452
|
-
}
|
|
77453
|
-
function collectVariants(scrubSet) {
|
|
77454
|
-
const variants = /* @__PURE__ */ new Set();
|
|
77455
|
-
for (const value of scrubSet) {
|
|
77456
|
-
if (value === "") continue;
|
|
77457
|
-
variants.add(value);
|
|
77458
|
-
const jsonForm = jsonEscapedVariant(value);
|
|
77459
|
-
if (jsonForm !== "") variants.add(jsonForm);
|
|
77460
|
-
const percentForm = percentEncodedVariant(value);
|
|
77461
|
-
if (percentForm !== null && percentForm !== "") variants.add(percentForm);
|
|
77462
|
-
}
|
|
77463
|
-
return [...variants];
|
|
77464
|
-
}
|
|
77465
|
-
function buildScrubRegex(scrubSet) {
|
|
77466
|
-
const variants = collectVariants(scrubSet);
|
|
77467
|
-
if (variants.length === 0) return null;
|
|
77468
|
-
variants.sort((a, b) => b.length - a.length);
|
|
77469
|
-
const alternatives = variants.map((variant) => {
|
|
77470
|
-
const escaped = escapeRegExp(variant);
|
|
77471
|
-
if (variant.length >= SHORT_VALUE_THRESHOLD) {
|
|
77472
|
-
return escaped;
|
|
77473
|
-
}
|
|
77474
|
-
return `(?<![A-Za-z0-9_])${escaped}(?![A-Za-z0-9_])`;
|
|
77475
|
-
});
|
|
77476
|
-
return new RegExp(alternatives.join("|"), "g");
|
|
77477
|
-
}
|
|
77478
|
-
function scrubString(input, regex) {
|
|
77479
|
-
return input.replace(regex, REDACTION);
|
|
77480
|
-
}
|
|
77481
|
-
function isPlainObject4(value) {
|
|
77482
|
-
if (typeof value !== "object" || value === null) return false;
|
|
77483
|
-
const proto = Object.getPrototypeOf(value);
|
|
77484
|
-
return proto === Object.prototype || proto === null;
|
|
77485
|
-
}
|
|
77486
|
-
function scrubValue(value, regex) {
|
|
77487
|
-
if (typeof value === "string") {
|
|
77488
|
-
return regex === null ? value : scrubString(value, regex);
|
|
77489
|
-
}
|
|
77490
|
-
if (Array.isArray(value)) {
|
|
77491
|
-
return value.map((item) => scrubValue(item, regex));
|
|
77492
|
-
}
|
|
77493
|
-
if (isPlainObject4(value)) {
|
|
77494
|
-
const out = {};
|
|
77495
|
-
for (const [key, child] of Object.entries(value)) {
|
|
77496
|
-
out[key] = scrubValue(child, regex);
|
|
77497
|
-
}
|
|
77498
|
-
return out;
|
|
76526
|
+
return await import_promises17.default.readFile(file2, "utf8");
|
|
76527
|
+
} catch (error51) {
|
|
76528
|
+
if (error51.code === "ENOENT") return null;
|
|
76529
|
+
throw error51;
|
|
77499
76530
|
}
|
|
77500
|
-
return value;
|
|
77501
76531
|
}
|
|
77502
|
-
function
|
|
77503
|
-
const regex = buildScrubRegex(scrubSet);
|
|
77504
|
-
return scrubValue(value, regex);
|
|
77505
|
-
}
|
|
77506
|
-
|
|
77507
|
-
// src/external-agents-handlers.ts
|
|
77508
|
-
var BUDGET_STATE_MS = 1e4;
|
|
77509
|
-
var BUDGET_PROBE_MS = 6e4;
|
|
77510
|
-
var BUDGET_VERIFY_READ_ONLY_MS = 6e4;
|
|
77511
|
-
var BUDGET_AUDIT_MS = 18e4;
|
|
77512
|
-
var BUDGET_TOGGLE_MS = 1e4;
|
|
77513
|
-
var BUDGET_ADD_MODEL_MS = 1e4;
|
|
77514
|
-
var BUDGET_SET_CREDENTIAL_MS = 1e4;
|
|
77515
|
-
var BUDGET_DISPATCH_MS = 3e5;
|
|
77516
|
-
var ENV_NAME_RE = /^[A-Z0-9_]+$/;
|
|
77517
|
-
var MAX_PROMPT_LEN = 8192;
|
|
77518
|
-
var TOGGLE_MIN_VERSION = "0.34.0";
|
|
77519
|
-
function invalidInput(field, reason) {
|
|
77520
|
-
return { ok: false, error: { code: "invalid_input", fields: { [field]: reason } } };
|
|
77521
|
-
}
|
|
77522
|
-
function tryParseJson(s) {
|
|
76532
|
+
async function realPathOr(file2) {
|
|
77523
76533
|
try {
|
|
77524
|
-
return
|
|
76534
|
+
return await import_promises17.default.realpath(file2);
|
|
77525
76535
|
} catch {
|
|
77526
|
-
return
|
|
77527
|
-
}
|
|
77528
|
-
}
|
|
77529
|
-
function
|
|
77530
|
-
|
|
77531
|
-
|
|
77532
|
-
|
|
77533
|
-
|
|
77534
|
-
|
|
77535
|
-
|
|
77536
|
-
|
|
77537
|
-
|
|
77538
|
-
|
|
77539
|
-
|
|
77540
|
-
|
|
77541
|
-
|
|
77542
|
-
}
|
|
77543
|
-
|
|
77544
|
-
|
|
77545
|
-
|
|
77546
|
-
|
|
77547
|
-
|
|
77548
|
-
|
|
77549
|
-
|
|
77550
|
-
|
|
77551
|
-
|
|
77552
|
-
return
|
|
76536
|
+
return file2;
|
|
76537
|
+
}
|
|
76538
|
+
}
|
|
76539
|
+
function resolveCodexConfigPath(options) {
|
|
76540
|
+
const codexHome = options.codexHome ?? (options.homeDir ? import_node_path41.default.join(options.homeDir, ".codex") : process.env.CODEX_HOME ?? import_node_path41.default.join(import_node_os20.default.homedir(), ".codex"));
|
|
76541
|
+
return import_node_path41.default.join(codexHome, "config.toml");
|
|
76542
|
+
}
|
|
76543
|
+
async function pruneCodexExternalAgents(options) {
|
|
76544
|
+
const configPath = await realPathOr(resolveCodexConfigPath(options));
|
|
76545
|
+
const absent = { client: "codex", file: configPath, status: "absent", grantsRemoved: 0 };
|
|
76546
|
+
const content = await readIfExists(configPath);
|
|
76547
|
+
if (content === null) return absent;
|
|
76548
|
+
const parsed = toml4.parse(content);
|
|
76549
|
+
const entry = parsed?.mcp_servers?.[LEGACY_EXTERNAL_AGENTS_SERVER_ID];
|
|
76550
|
+
if (entry === void 0) return absent;
|
|
76551
|
+
const blockRe = blockRegex(LEGACY_EXTERNAL_AGENTS_SERVER_ID);
|
|
76552
|
+
if (!isOurExternalAgentsEntry(entry, options.binPath, { allowCodexLegacy: true }) || !blockRe.test(content)) {
|
|
76553
|
+
return { ...absent, status: "kept-customized" };
|
|
76554
|
+
}
|
|
76555
|
+
const stripped = content.replace(blockRe, (match) => match.startsWith("\n") ? "\n" : "").replace(/\n{3,}/g, "\n\n").replace(/^\n+/, "");
|
|
76556
|
+
await import_promises17.default.writeFile(configPath, stripped, { mode: 384 });
|
|
76557
|
+
return { ...absent, status: "pruned" };
|
|
76558
|
+
}
|
|
76559
|
+
async function pruneJsonMcpEntry(client, file2, binPath) {
|
|
76560
|
+
const absent = { client, file: file2, status: "absent", grantsRemoved: 0 };
|
|
76561
|
+
const raw = await readIfExists(file2);
|
|
76562
|
+
if (raw === null) return absent;
|
|
76563
|
+
const parsed = raw.trim() === "" ? {} : JSON.parse(raw);
|
|
76564
|
+
const mcpServers = parsed.mcpServers ?? {};
|
|
76565
|
+
const entry = mcpServers[LEGACY_EXTERNAL_AGENTS_SERVER_ID];
|
|
76566
|
+
if (entry === void 0) return absent;
|
|
76567
|
+
if (!isOurExternalAgentsEntry(entry, binPath)) return { ...absent, status: "kept-customized" };
|
|
76568
|
+
delete mcpServers["external-agents"];
|
|
76569
|
+
parsed.mcpServers = mcpServers;
|
|
76570
|
+
await import_promises17.default.writeFile(file2, `${JSON.stringify(parsed, null, 2)}
|
|
76571
|
+
`, { mode: 384 });
|
|
76572
|
+
return { ...absent, status: "pruned" };
|
|
76573
|
+
}
|
|
76574
|
+
async function pruneClaudeExternalAgents(options) {
|
|
76575
|
+
const file2 = options.claudeConfigPath ?? import_node_path41.default.join(options.homeDir ?? import_node_os20.default.homedir(), ".claude.json");
|
|
76576
|
+
return pruneJsonMcpEntry("claude", file2, options.binPath);
|
|
76577
|
+
}
|
|
76578
|
+
async function pruneAgyExternalAgents(options) {
|
|
76579
|
+
const home = options.homeDir ?? import_node_os20.default.homedir();
|
|
76580
|
+
const mcpFile = options.agyConfigPath ?? import_node_path41.default.join(home, ".gemini", "config", "mcp_config.json");
|
|
76581
|
+
const configJsonPath = options.configJsonPath ?? import_node_path41.default.join(home, ".gemini", "config", "config.json");
|
|
76582
|
+
const result = await pruneJsonMcpEntry("agy", mcpFile, options.binPath);
|
|
76583
|
+
if (result.status !== "pruned") return result;
|
|
76584
|
+
const raw = await readIfExists(configJsonPath);
|
|
76585
|
+
if (raw === null) return result;
|
|
76586
|
+
const parsedConfig = raw.trim() === "" ? {} : JSON.parse(raw);
|
|
76587
|
+
const userSettings = parsedConfig.userSettings;
|
|
76588
|
+
const grants = userSettings?.globalPermissionGrants;
|
|
76589
|
+
if (!grants || !Array.isArray(grants.allow)) return result;
|
|
76590
|
+
const legacy = new Set(legacyGrantStrings());
|
|
76591
|
+
const before = grants.allow;
|
|
76592
|
+
const after = before.filter((g) => !(typeof g === "string" && legacy.has(g)));
|
|
76593
|
+
const removed = before.length - after.length;
|
|
76594
|
+
if (removed === 0) return result;
|
|
76595
|
+
grants.allow = after;
|
|
76596
|
+
await import_promises17.default.writeFile(configJsonPath, `${JSON.stringify(parsedConfig, null, 2)}
|
|
76597
|
+
`, { mode: 384 });
|
|
76598
|
+
return { ...result, grantsRemoved: removed, grantsFile: configJsonPath };
|
|
77553
76599
|
}
|
|
77554
|
-
async function
|
|
77555
|
-
|
|
77556
|
-
|
|
77557
|
-
|
|
76600
|
+
async function pruneAllExternalAgents(options) {
|
|
76601
|
+
const results = [];
|
|
76602
|
+
const errors = [];
|
|
76603
|
+
const steps = [
|
|
76604
|
+
["codex", () => pruneCodexExternalAgents(options)],
|
|
76605
|
+
["claude", () => pruneClaudeExternalAgents(options)],
|
|
76606
|
+
["agy", () => pruneAgyExternalAgents(options)]
|
|
76607
|
+
];
|
|
76608
|
+
for (const [client, run3] of steps) {
|
|
76609
|
+
try {
|
|
76610
|
+
results.push(await run3());
|
|
76611
|
+
} catch (error51) {
|
|
76612
|
+
errors.push({ client, message: error51 instanceof Error ? error51.message : String(error51) });
|
|
77558
76613
|
}
|
|
77559
76614
|
}
|
|
77560
|
-
|
|
77561
|
-
if (status.code !== 0) {
|
|
77562
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(status) }, defaultScrubSet(deps));
|
|
77563
|
-
}
|
|
77564
|
-
const statusParsed = tryParseJson(status.stdout);
|
|
77565
|
-
if (!statusParsed.ok || !Array.isArray(statusParsed.value)) {
|
|
77566
|
-
return finalizeReply(
|
|
77567
|
-
{ ok: false, error: { code: "cli_broken", detail: status.stderr || void 0 } },
|
|
77568
|
-
defaultScrubSet(deps)
|
|
77569
|
-
);
|
|
77570
|
-
}
|
|
77571
|
-
const agents = statusParsed.value;
|
|
77572
|
-
const stateScrubSet = buildScrubSet({
|
|
77573
|
-
registryEnvNames: [...deps.registryEnvNames, ...extractRegistryEnvNames(agents)]
|
|
77574
|
-
});
|
|
77575
|
-
const statsArgs = ["stats", "--json", ...request.since ? ["--since", request.since] : []];
|
|
77576
|
-
const stats = await deps.run(statsArgs, { budgetMs: BUDGET_STATE_MS });
|
|
77577
|
-
let totals = null;
|
|
77578
|
-
if (stats.code === 0) {
|
|
77579
|
-
const statsParsed = tryParseJson(stats.stdout);
|
|
77580
|
-
if (statsParsed.ok) totals = statsParsed.value;
|
|
77581
|
-
}
|
|
77582
|
-
return finalizeReply(
|
|
77583
|
-
{ ok: true, data: { agents, totals, cli: { path: null, version: null, source: status.source } } },
|
|
77584
|
-
stateScrubSet
|
|
77585
|
-
);
|
|
76615
|
+
return { results, errors };
|
|
77586
76616
|
}
|
|
77587
|
-
|
|
77588
|
-
const
|
|
77589
|
-
|
|
77590
|
-
|
|
77591
|
-
|
|
77592
|
-
|
|
77593
|
-
|
|
77594
|
-
|
|
77595
|
-
|
|
77596
|
-
const parsed = tryParseJson(result.stdout);
|
|
77597
|
-
if (!parsed.ok) {
|
|
77598
|
-
return finalizeReply({ ok: false, error: { code: "cli_broken", detail: result.stderr || void 0 } }, scrubSet);
|
|
77599
|
-
}
|
|
77600
|
-
return finalizeReply({ ok: true, data: parsed.value }, scrubSet);
|
|
77601
|
-
}
|
|
77602
|
-
async function handleAgentsVerifyReadOnly(deps, request) {
|
|
77603
|
-
const scrubSet = defaultScrubSet(deps);
|
|
77604
|
-
if (deps.lastKnownState === null || !deps.lastKnownState.agentIds.includes(request.id)) {
|
|
77605
|
-
return finalizeReply(invalidInput("id", "unknown agent id"), scrubSet);
|
|
77606
|
-
}
|
|
77607
|
-
const result = await deps.run(["verify-read-only", request.id], { budgetMs: BUDGET_VERIFY_READ_ONLY_MS });
|
|
77608
|
-
if (result.code !== 0) {
|
|
77609
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(result) }, scrubSet);
|
|
77610
|
-
}
|
|
77611
|
-
const parsed = tryParseJson(result.stdout);
|
|
77612
|
-
if (!parsed.ok) {
|
|
77613
|
-
return finalizeReply({ ok: false, error: { code: "cli_broken", detail: result.stderr || void 0 } }, scrubSet);
|
|
77614
|
-
}
|
|
77615
|
-
return finalizeReply({ ok: true, data: parsed.value }, scrubSet);
|
|
77616
|
-
}
|
|
77617
|
-
async function handleAgentsAudit(deps, request) {
|
|
77618
|
-
const scrubSet = defaultScrubSet(deps);
|
|
77619
|
-
if (deps.lastKnownState === null) {
|
|
77620
|
-
return finalizeReply(invalidInput("provider", "call agents-state before agents-audit"), scrubSet);
|
|
77621
|
-
}
|
|
77622
|
-
if (request.provider !== void 0 && !deps.lastKnownState.providers.includes(request.provider)) {
|
|
77623
|
-
return finalizeReply(invalidInput("provider", "unknown provider"), scrubSet);
|
|
77624
|
-
}
|
|
77625
|
-
const auditArgs = ["audit", "--json", ...request.provider ? ["--provider", request.provider] : []];
|
|
77626
|
-
const result = await deps.run(auditArgs, { budgetMs: BUDGET_AUDIT_MS });
|
|
77627
|
-
if (result.code !== 0) {
|
|
77628
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(result) }, scrubSet);
|
|
77629
|
-
}
|
|
77630
|
-
const parsed = tryParseJson(result.stdout);
|
|
77631
|
-
if (!parsed.ok) {
|
|
77632
|
-
return finalizeReply({ ok: false, error: { code: "cli_broken", detail: result.stderr || void 0 } }, scrubSet);
|
|
77633
|
-
}
|
|
77634
|
-
return finalizeReply({ ok: true, data: parsed.value }, scrubSet);
|
|
77635
|
-
}
|
|
77636
|
-
async function handleAgentsToggle(deps, request) {
|
|
77637
|
-
const scrubSet = defaultScrubSet(deps);
|
|
77638
|
-
if (deps.lastKnownState === null || !deps.lastKnownState.agentIds.includes(request.id)) {
|
|
77639
|
-
return finalizeReply(invalidInput("id", "unknown agent id"), scrubSet);
|
|
77640
|
-
}
|
|
77641
|
-
const result = await deps.run(
|
|
77642
|
-
["toggle", request.id, request.enabled ? "--enabled" : "--disabled"],
|
|
77643
|
-
{ budgetMs: BUDGET_TOGGLE_MS }
|
|
77644
|
-
);
|
|
77645
|
-
if (result.code !== 0) {
|
|
77646
|
-
const stderrLc = result.stderr.toLowerCase();
|
|
77647
|
-
if (stderrLc.includes("unknown subcommand") || stderrLc.includes("unknown command")) {
|
|
77648
|
-
return finalizeReply(
|
|
77649
|
-
{
|
|
77650
|
-
ok: false,
|
|
77651
|
-
error: {
|
|
77652
|
-
code: "cli_outdated",
|
|
77653
|
-
detail: `the toggle control requires external-agents >= ${TOGGLE_MIN_VERSION}`
|
|
77654
|
-
}
|
|
77655
|
-
},
|
|
77656
|
-
scrubSet
|
|
77657
|
-
);
|
|
76617
|
+
function runningBinPaths(argv1, resolveOpts) {
|
|
76618
|
+
const out = /* @__PURE__ */ new Set();
|
|
76619
|
+
const add2 = (p) => {
|
|
76620
|
+
if (!p) return;
|
|
76621
|
+
const resolved = import_node_path41.default.resolve(p);
|
|
76622
|
+
out.add(resolved);
|
|
76623
|
+
try {
|
|
76624
|
+
out.add((0, import_node_fs28.realpathSync)(resolved));
|
|
76625
|
+
} catch {
|
|
77658
76626
|
}
|
|
77659
|
-
|
|
77660
|
-
|
|
77661
|
-
|
|
76627
|
+
};
|
|
76628
|
+
add2(argv1);
|
|
76629
|
+
add2(resolveBinPath({ ...resolveOpts, argv1 }).path);
|
|
76630
|
+
return [...out];
|
|
77662
76631
|
}
|
|
77663
|
-
async function
|
|
77664
|
-
const
|
|
77665
|
-
if (!ENV_NAME_RE.test(request.env)) {
|
|
77666
|
-
return finalizeReply(invalidInput("env", "must match /^[A-Z0-9_]+$/"), scrubSet);
|
|
77667
|
-
}
|
|
76632
|
+
async function runExternalAgentsPruneAtStartup(deps) {
|
|
76633
|
+
const prefix = "[mrrlin-mcp director-bridge] info bridge.startup.external_agents_prune";
|
|
77668
76634
|
try {
|
|
77669
|
-
|
|
77670
|
-
|
|
77671
|
-
|
|
77672
|
-
|
|
77673
|
-
|
|
77674
|
-
return finalizeReply(invalidInput("id", "call agents-state before agents-add-model"), scrubSet);
|
|
77675
|
-
}
|
|
77676
|
-
if (deps.lastKnownState.agentIds.includes(request.id)) {
|
|
77677
|
-
return finalizeReply(invalidInput("id", "an agent with this id already exists"), scrubSet);
|
|
77678
|
-
}
|
|
77679
|
-
const args = [
|
|
77680
|
-
"add-model",
|
|
77681
|
-
"--id",
|
|
77682
|
-
request.id,
|
|
77683
|
-
"--provider",
|
|
77684
|
-
request.provider,
|
|
77685
|
-
"--url",
|
|
77686
|
-
request.url,
|
|
77687
|
-
"--model",
|
|
77688
|
-
request.model,
|
|
77689
|
-
"--env",
|
|
77690
|
-
request.env,
|
|
77691
|
-
...request.tier ? ["--tier", request.tier] : [],
|
|
77692
|
-
...request.tags?.length ? ["--tags", request.tags.join(",")] : []
|
|
77693
|
-
];
|
|
77694
|
-
const result = await deps.run(args, { budgetMs: BUDGET_ADD_MODEL_MS });
|
|
77695
|
-
if (result.code !== 0) {
|
|
77696
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(result) }, scrubSet);
|
|
77697
|
-
}
|
|
77698
|
-
return finalizeReply({ ok: true, data: { id: request.id } }, scrubSet);
|
|
77699
|
-
}
|
|
77700
|
-
async function handleAgentsSetCredential(deps, request) {
|
|
77701
|
-
const scrubSet = buildScrubSet({
|
|
77702
|
-
registryEnvNames: deps.registryEnvNames,
|
|
77703
|
-
inFlightValues: [request.value]
|
|
77704
|
-
});
|
|
77705
|
-
if (deps.lastKnownState === null) {
|
|
77706
|
-
return finalizeReply(invalidInput("env", "call agents-state before agents-set-credential"), scrubSet);
|
|
77707
|
-
}
|
|
77708
|
-
if (!ENV_NAME_RE.test(request.env)) {
|
|
77709
|
-
return finalizeReply(invalidInput("env", "must match /^[A-Z0-9_]+$/"), scrubSet);
|
|
77710
|
-
}
|
|
77711
|
-
if (request.value === "") {
|
|
77712
|
-
return finalizeReply(invalidInput("value", "must not be empty"), scrubSet);
|
|
77713
|
-
}
|
|
77714
|
-
const result = await deps.run(["set-credential", request.env, "-"], {
|
|
77715
|
-
stdinValue: request.value,
|
|
77716
|
-
budgetMs: BUDGET_SET_CREDENTIAL_MS
|
|
77717
|
-
});
|
|
77718
|
-
if (result.code !== 0) {
|
|
77719
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(result) }, scrubSet);
|
|
77720
|
-
}
|
|
77721
|
-
return finalizeReply({ ok: true, data: { env: request.env } }, scrubSet);
|
|
77722
|
-
}
|
|
77723
|
-
var DISPATCH_ALLOWED_KEYS = /* @__PURE__ */ new Set(["id", "prompt", "transport", "effort"]);
|
|
77724
|
-
async function handleAgentsDispatch(deps, request) {
|
|
77725
|
-
const scrubSet = defaultScrubSet(deps);
|
|
77726
|
-
for (const key of Object.keys(request)) {
|
|
77727
|
-
if (!DISPATCH_ALLOWED_KEYS.has(key)) {
|
|
77728
|
-
return finalizeReply(invalidInput(key, "unexpected field"), scrubSet);
|
|
76635
|
+
const binPath = deps.binPath ?? runningBinPaths(deps.argv1 ?? process.argv[1] ?? "", deps.resolveOpts);
|
|
76636
|
+
const report = await (deps.prune ?? ((resolved) => pruneAllExternalAgents({ binPath: resolved })))(binPath);
|
|
76637
|
+
for (const result of report.results) {
|
|
76638
|
+
if (result.status === "absent") continue;
|
|
76639
|
+
deps.log(`${prefix} ${JSON.stringify({ client: result.client, file: result.file, status: result.status, grantsRemoved: result.grantsRemoved, ...result.grantsFile ? { grantsFile: result.grantsFile } : {} })}`);
|
|
77729
76640
|
}
|
|
76641
|
+
for (const failure of report.errors) {
|
|
76642
|
+
deps.log(`${prefix}_failed ${JSON.stringify({ client: failure.client, message: failure.message })}`);
|
|
76643
|
+
}
|
|
76644
|
+
} catch (error51) {
|
|
76645
|
+
deps.log(`${prefix}_failed ${JSON.stringify({ message: error51 instanceof Error ? error51.message : String(error51) })}`);
|
|
77730
76646
|
}
|
|
77731
|
-
if (deps.lastKnownState === null || !deps.lastKnownState.agentIds.includes(request.id)) {
|
|
77732
|
-
return finalizeReply(invalidInput("id", "unknown agent id"), scrubSet);
|
|
77733
|
-
}
|
|
77734
|
-
if (request.prompt.length > MAX_PROMPT_LEN) {
|
|
77735
|
-
return finalizeReply(invalidInput("prompt", `must be at most ${MAX_PROMPT_LEN} characters`), scrubSet);
|
|
77736
|
-
}
|
|
77737
|
-
const outboundPrompt = scrubDeep(redactSecretFormats(request.prompt), scrubSet);
|
|
77738
|
-
const args = [
|
|
77739
|
-
"dispatch",
|
|
77740
|
-
request.id,
|
|
77741
|
-
"--json",
|
|
77742
|
-
...request.transport ? ["--transport", request.transport] : [],
|
|
77743
|
-
...request.effort ? ["--effort", request.effort] : [],
|
|
77744
|
-
outboundPrompt
|
|
77745
|
-
];
|
|
77746
|
-
const result = await deps.run(args, { budgetMs: BUDGET_DISPATCH_MS });
|
|
77747
|
-
if (result.code !== 0) {
|
|
77748
|
-
return finalizeReply({ ok: false, error: classifyCliFailure(result) }, scrubSet);
|
|
77749
|
-
}
|
|
77750
|
-
const parsed = tryParseJson(result.stdout);
|
|
77751
|
-
if (!parsed.ok) {
|
|
77752
|
-
return finalizeReply({ ok: false, error: { code: "cli_broken", detail: result.stderr || void 0 } }, scrubSet);
|
|
77753
|
-
}
|
|
77754
|
-
return finalizeReply({ ok: true, data: parsed.value }, scrubSet);
|
|
77755
76647
|
}
|
|
77756
76648
|
|
|
77757
76649
|
// src/director-bridge.ts
|
|
@@ -77920,7 +76812,7 @@ function neutralCheckoutCwd(stateDir) {
|
|
|
77920
76812
|
import_node_fs29.default.mkdirSync(dir, { recursive: true });
|
|
77921
76813
|
if (!import_node_fs29.default.existsSync(import_node_path43.default.join(dir, ".git"))) {
|
|
77922
76814
|
try {
|
|
77923
|
-
(0,
|
|
76815
|
+
(0, import_node_child_process23.spawnSync)("git", ["init", "-b", "main"], { cwd: dir, stdio: "ignore" });
|
|
77924
76816
|
} catch {
|
|
77925
76817
|
}
|
|
77926
76818
|
}
|
|
@@ -77992,9 +76884,11 @@ function buildThreadStartParams(msg, config2, desiredModel) {
|
|
|
77992
76884
|
" (d) the operator says they are unsure, or asks you to check with someone else.",
|
|
77993
76885
|
" In those cases pass `reviewers` between 1 and 3. Quota and latency are NOT a reason to skip",
|
|
77994
76886
|
" reviewers on a decision that meets one of those conditions.",
|
|
77995
|
-
"-
|
|
77996
|
-
"
|
|
77997
|
-
"
|
|
76887
|
+
"- Extra reviewers are separate blind runs on YOUR OWN provider, each in a different reviewer role",
|
|
76888
|
+
" \u2014 the same model wearing different hats, not independent outside models. Read what came back",
|
|
76889
|
+
" instead of assuming it: the result reports how many of the requested reviewers actually",
|
|
76890
|
+
" answered. Their agreement is weaker evidence than agreement between independent models, but an",
|
|
76891
|
+
" objection from any of them still counts.",
|
|
77998
76892
|
"- An objection is something you report, never something you route around. State the objection in",
|
|
77999
76893
|
" plain language and let the operator decide. Do not quietly adopt a different answer, and do not",
|
|
78000
76894
|
" drop the objection because you disagree with it.",
|
|
@@ -78449,7 +77343,7 @@ function resolveDefaultBranch(checkoutPath) {
|
|
|
78449
77343
|
if (!checkoutPath) return "main";
|
|
78450
77344
|
const runGit2 = (args) => {
|
|
78451
77345
|
try {
|
|
78452
|
-
return (0,
|
|
77346
|
+
return (0, import_node_child_process23.execFileSync)("git", ["-C", checkoutPath, ...args], {
|
|
78453
77347
|
encoding: "utf8",
|
|
78454
77348
|
stdio: ["ignore", "pipe", "ignore"],
|
|
78455
77349
|
timeout: 15e3,
|
|
@@ -78790,45 +77684,6 @@ function createBridgeMessageHandler(deps) {
|
|
|
78790
77684
|
for (const id of boundSessions) deps.unbindSessionSink?.(id, send);
|
|
78791
77685
|
boundSessions.clear();
|
|
78792
77686
|
});
|
|
78793
|
-
let externalAgentsRegistryEnvNames = [];
|
|
78794
|
-
let externalAgentsLastKnownState = null;
|
|
78795
|
-
function deriveLastKnownState(agents) {
|
|
78796
|
-
const agentIds = [];
|
|
78797
|
-
const providers = /* @__PURE__ */ new Set();
|
|
78798
|
-
for (const entry of agents) {
|
|
78799
|
-
if (typeof entry !== "object" || entry === null) continue;
|
|
78800
|
-
const rec = entry;
|
|
78801
|
-
if (typeof rec.id === "string") agentIds.push(rec.id);
|
|
78802
|
-
if (typeof rec.provider === "string") providers.add(rec.provider);
|
|
78803
|
-
}
|
|
78804
|
-
return { agentIds, providers: [...providers] };
|
|
78805
|
-
}
|
|
78806
|
-
async function probeAgentsUsingEnvVar(handlerDeps, envVar) {
|
|
78807
|
-
try {
|
|
78808
|
-
const before = await handleAgentsState(handlerDeps, {});
|
|
78809
|
-
if (!before.ok) return;
|
|
78810
|
-
const matchingIds = before.data.agents.filter((entry) => typeof entry === "object" && entry !== null).filter((entry) => entry.auth === `env:${envVar}`).map((entry) => entry.id).filter((id) => typeof id === "string");
|
|
78811
|
-
const lastKnownState = deriveLastKnownState(before.data.agents);
|
|
78812
|
-
await Promise.all(
|
|
78813
|
-
matchingIds.map((id) => handleAgentsProbe({ ...handlerDeps, lastKnownState }, { id }))
|
|
78814
|
-
);
|
|
78815
|
-
} catch {
|
|
78816
|
-
}
|
|
78817
|
-
}
|
|
78818
|
-
async function withPoolStateReread(handlerDeps, reply) {
|
|
78819
|
-
if (!reply.ok) return reply;
|
|
78820
|
-
try {
|
|
78821
|
-
const reRead = await handleAgentsState(handlerDeps, {});
|
|
78822
|
-
if (reRead.ok) {
|
|
78823
|
-
externalAgentsRegistryEnvNames = extractRegistryEnvNames(reRead.data.agents);
|
|
78824
|
-
externalAgentsLastKnownState = deriveLastKnownState(reRead.data.agents);
|
|
78825
|
-
return { ...reply, poolState: reRead.data };
|
|
78826
|
-
}
|
|
78827
|
-
return { ...reply, poolState: null };
|
|
78828
|
-
} catch {
|
|
78829
|
-
return { ...reply, poolState: null };
|
|
78830
|
-
}
|
|
78831
|
-
}
|
|
78832
77687
|
function logResumeRejected(sessionId, reason) {
|
|
78833
77688
|
logCtx?.logger.logOut({
|
|
78834
77689
|
spanId: logCtx.span.id,
|
|
@@ -79141,157 +77996,6 @@ function createBridgeMessageHandler(deps) {
|
|
|
79141
77996
|
}
|
|
79142
77997
|
return;
|
|
79143
77998
|
}
|
|
79144
|
-
if (msg.type === "agents-state") {
|
|
79145
|
-
if (!deps.runExternalAgentsCli) {
|
|
79146
|
-
sendForSpan({ type: "agents-state", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79147
|
-
return;
|
|
79148
|
-
}
|
|
79149
|
-
const handlerDeps = {
|
|
79150
|
-
run: deps.runExternalAgentsCli,
|
|
79151
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79152
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79153
|
-
};
|
|
79154
|
-
const req = msg;
|
|
79155
|
-
const reply = await handleAgentsState(handlerDeps, req.since !== void 0 ? { since: req.since } : {});
|
|
79156
|
-
if (reply.ok) {
|
|
79157
|
-
externalAgentsRegistryEnvNames = extractRegistryEnvNames(reply.data.agents);
|
|
79158
|
-
externalAgentsLastKnownState = deriveLastKnownState(reply.data.agents);
|
|
79159
|
-
}
|
|
79160
|
-
sendForSpan({ type: "agents-state", ...reply });
|
|
79161
|
-
return;
|
|
79162
|
-
}
|
|
79163
|
-
if (msg.type === "agents-probe") {
|
|
79164
|
-
if (!deps.runExternalAgentsCli) {
|
|
79165
|
-
sendForSpan({ type: "agents-probe", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79166
|
-
return;
|
|
79167
|
-
}
|
|
79168
|
-
const handlerDeps = {
|
|
79169
|
-
run: deps.runExternalAgentsCli,
|
|
79170
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79171
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79172
|
-
};
|
|
79173
|
-
const req = msg;
|
|
79174
|
-
const reply = await withPoolStateReread(handlerDeps, await handleAgentsProbe(handlerDeps, { id: req.id }));
|
|
79175
|
-
sendForSpan({ type: "agents-probe", ...reply });
|
|
79176
|
-
return;
|
|
79177
|
-
}
|
|
79178
|
-
if (msg.type === "agents-verify-read-only") {
|
|
79179
|
-
if (!deps.runExternalAgentsCli) {
|
|
79180
|
-
sendForSpan({ type: "agents-verify-read-only", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79181
|
-
return;
|
|
79182
|
-
}
|
|
79183
|
-
const handlerDeps = {
|
|
79184
|
-
run: deps.runExternalAgentsCli,
|
|
79185
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79186
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79187
|
-
};
|
|
79188
|
-
const req = msg;
|
|
79189
|
-
const reply = await withPoolStateReread(handlerDeps, await handleAgentsVerifyReadOnly(handlerDeps, { id: req.id }));
|
|
79190
|
-
sendForSpan({ type: "agents-verify-read-only", ...reply });
|
|
79191
|
-
return;
|
|
79192
|
-
}
|
|
79193
|
-
if (msg.type === "agents-audit") {
|
|
79194
|
-
if (!deps.runExternalAgentsCli) {
|
|
79195
|
-
sendForSpan({ type: "agents-audit", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79196
|
-
return;
|
|
79197
|
-
}
|
|
79198
|
-
const handlerDeps = {
|
|
79199
|
-
run: deps.runExternalAgentsCli,
|
|
79200
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79201
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79202
|
-
};
|
|
79203
|
-
const req = msg;
|
|
79204
|
-
const reply = await withPoolStateReread(
|
|
79205
|
-
handlerDeps,
|
|
79206
|
-
await handleAgentsAudit(handlerDeps, req.provider !== void 0 ? { provider: req.provider } : {})
|
|
79207
|
-
);
|
|
79208
|
-
sendForSpan({ type: "agents-audit", ...reply });
|
|
79209
|
-
return;
|
|
79210
|
-
}
|
|
79211
|
-
if (msg.type === "agents-toggle") {
|
|
79212
|
-
if (!deps.runExternalAgentsCli) {
|
|
79213
|
-
sendForSpan({ type: "agents-toggle", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79214
|
-
return;
|
|
79215
|
-
}
|
|
79216
|
-
const handlerDeps = {
|
|
79217
|
-
run: deps.runExternalAgentsCli,
|
|
79218
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79219
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79220
|
-
};
|
|
79221
|
-
const req = msg;
|
|
79222
|
-
const reply = await withPoolStateReread(
|
|
79223
|
-
handlerDeps,
|
|
79224
|
-
await handleAgentsToggle(handlerDeps, { id: req.id, enabled: req.enabled })
|
|
79225
|
-
);
|
|
79226
|
-
sendForSpan({ type: "agents-toggle", ...reply });
|
|
79227
|
-
return;
|
|
79228
|
-
}
|
|
79229
|
-
if (msg.type === "agents-add-model") {
|
|
79230
|
-
if (!deps.runExternalAgentsCli) {
|
|
79231
|
-
sendForSpan({ type: "agents-add-model", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79232
|
-
return;
|
|
79233
|
-
}
|
|
79234
|
-
const handlerDeps = {
|
|
79235
|
-
run: deps.runExternalAgentsCli,
|
|
79236
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79237
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79238
|
-
};
|
|
79239
|
-
const req = msg;
|
|
79240
|
-
const reply = await withPoolStateReread(
|
|
79241
|
-
handlerDeps,
|
|
79242
|
-
await handleAgentsAddModel(handlerDeps, {
|
|
79243
|
-
id: req.id,
|
|
79244
|
-
provider: req.provider,
|
|
79245
|
-
model: req.model,
|
|
79246
|
-
url: req.url,
|
|
79247
|
-
env: req.env,
|
|
79248
|
-
...req.tier !== void 0 ? { tier: req.tier } : {},
|
|
79249
|
-
...req.tags !== void 0 ? { tags: req.tags } : {}
|
|
79250
|
-
})
|
|
79251
|
-
);
|
|
79252
|
-
sendForSpan({ type: "agents-add-model", ...reply });
|
|
79253
|
-
return;
|
|
79254
|
-
}
|
|
79255
|
-
if (msg.type === "agents-set-credential") {
|
|
79256
|
-
if (!deps.runExternalAgentsCli) {
|
|
79257
|
-
sendForSpan({ type: "agents-set-credential", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79258
|
-
return;
|
|
79259
|
-
}
|
|
79260
|
-
const handlerDeps = {
|
|
79261
|
-
run: deps.runExternalAgentsCli,
|
|
79262
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79263
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79264
|
-
};
|
|
79265
|
-
const req = msg;
|
|
79266
|
-
const setCredResult = await handleAgentsSetCredential(handlerDeps, { env: req.env, value: req.value });
|
|
79267
|
-
if (setCredResult.ok) await probeAgentsUsingEnvVar(handlerDeps, req.env);
|
|
79268
|
-
const reply = await withPoolStateReread(handlerDeps, setCredResult);
|
|
79269
|
-
sendForSpan({ type: "agents-set-credential", ...reply });
|
|
79270
|
-
return;
|
|
79271
|
-
}
|
|
79272
|
-
if (msg.type === "agents-dispatch") {
|
|
79273
|
-
if (!deps.runExternalAgentsCli) {
|
|
79274
|
-
sendForSpan({ type: "agents-dispatch", ok: false, error: { code: "bridge_offline", detail: "external-agents is not configured on this bridge" } });
|
|
79275
|
-
return;
|
|
79276
|
-
}
|
|
79277
|
-
const handlerDeps = {
|
|
79278
|
-
run: deps.runExternalAgentsCli,
|
|
79279
|
-
registryEnvNames: externalAgentsRegistryEnvNames,
|
|
79280
|
-
lastKnownState: externalAgentsLastKnownState
|
|
79281
|
-
};
|
|
79282
|
-
const req = msg;
|
|
79283
|
-
const reply = await withPoolStateReread(
|
|
79284
|
-
handlerDeps,
|
|
79285
|
-
await handleAgentsDispatch(handlerDeps, {
|
|
79286
|
-
id: req.id,
|
|
79287
|
-
prompt: req.prompt,
|
|
79288
|
-
...req.transport !== void 0 ? { transport: req.transport } : {},
|
|
79289
|
-
...req.effort !== void 0 ? { effort: req.effort } : {}
|
|
79290
|
-
})
|
|
79291
|
-
);
|
|
79292
|
-
sendForSpan({ type: "agents-dispatch", ...reply });
|
|
79293
|
-
return;
|
|
79294
|
-
}
|
|
79295
77999
|
if (msg.type === "bootstrap") {
|
|
79296
78000
|
let models = null;
|
|
79297
78001
|
let rateLimits = null;
|
|
@@ -80237,7 +78941,7 @@ function parseConfig() {
|
|
|
80237
78941
|
}
|
|
80238
78942
|
function scanForOtherBridges() {
|
|
80239
78943
|
try {
|
|
80240
|
-
const result = (0,
|
|
78944
|
+
const result = (0, import_node_child_process23.spawnSync)("pgrep", ["-f", "mrrlin-mcp director-bridge"], {
|
|
80241
78945
|
encoding: "utf8"
|
|
80242
78946
|
});
|
|
80243
78947
|
if (result.status !== 0) return [];
|
|
@@ -80285,7 +78989,18 @@ function buildBridgeSigningProvider() {
|
|
|
80285
78989
|
}
|
|
80286
78990
|
return void 0;
|
|
80287
78991
|
}
|
|
80288
|
-
async function
|
|
78992
|
+
async function runStartupPruneSafely(prune2, log) {
|
|
78993
|
+
try {
|
|
78994
|
+
await prune2({ log });
|
|
78995
|
+
} catch (error51) {
|
|
78996
|
+
log(
|
|
78997
|
+
`[mrrlin-mcp director-bridge] info bridge.startup.external_agents_prune_failed ${JSON.stringify({
|
|
78998
|
+
message: error51 instanceof Error ? error51.message : String(error51)
|
|
78999
|
+
})}`
|
|
79000
|
+
);
|
|
79001
|
+
}
|
|
79002
|
+
}
|
|
79003
|
+
async function startDirectorBridge(startupDeps = {}) {
|
|
80289
79004
|
const signingProvider = buildBridgeSigningProvider();
|
|
80290
79005
|
const config2 = parseConfig();
|
|
80291
79006
|
const failureLog = createFailureLog();
|
|
@@ -80852,9 +79567,6 @@ async function startDirectorBridge() {
|
|
|
80852
79567
|
};
|
|
80853
79568
|
},
|
|
80854
79569
|
getProject: (projectSlug) => client.getProject(projectSlug),
|
|
80855
|
-
// External-agents control plane: the real spawn runner, with the EXTERNAL_AGENTS_CLI operator
|
|
80856
|
-
// escape hatch bound here (the handlers stay spawn-free and this is the only production seam).
|
|
80857
|
-
runExternalAgentsCli: (args, opts) => runExternalAgentsCli(args, { ...opts, envCliPath: process.env["EXTERNAL_AGENTS_CLI"] }),
|
|
80858
79570
|
// Compaction runner for `compact-request` (agent-seat-surfaces task 2.5). Closes over `config`
|
|
80859
79571
|
// (in scope here, unlike inside the handler) for cwd/executable, and the module-level budget +
|
|
80860
79572
|
// timeout constants. The handler supplies only the resolved seat's provider + default model.
|
|
@@ -81143,15 +79855,11 @@ async function startDirectorBridge() {
|
|
|
81143
79855
|
selectedProviderTimer = setInterval(() => void refresh(), 6e4);
|
|
81144
79856
|
selectedProviderTimer.unref?.();
|
|
81145
79857
|
}
|
|
81146
|
-
|
|
81147
|
-
|
|
81148
|
-
|
|
81149
|
-
|
|
81150
|
-
|
|
81151
|
-
suppressedPushLine("agent-pool snapshot push", err)
|
|
81152
|
-
)
|
|
81153
|
-
});
|
|
81154
|
-
}
|
|
79858
|
+
await runStartupPruneSafely(
|
|
79859
|
+
startupDeps.pruneExternalAgentsAtStartup ?? runExternalAgentsPruneAtStartup,
|
|
79860
|
+
(line) => process.stderr.write(`${line}
|
|
79861
|
+
`)
|
|
79862
|
+
);
|
|
81155
79863
|
let providerReadinessLoopHandle = null;
|
|
81156
79864
|
if (tokenProvider && !providerReadinessLoopDisabled(process.env)) {
|
|
81157
79865
|
providerReadinessLoopHandle = startProviderReadinessLoop({
|
|
@@ -81205,7 +79913,6 @@ async function startDirectorBridge() {
|
|
|
81205
79913
|
() => {
|
|
81206
79914
|
if (selectedProviderTimer) clearInterval(selectedProviderTimer);
|
|
81207
79915
|
},
|
|
81208
|
-
() => agentPoolLoopHandle?.stop(),
|
|
81209
79916
|
() => providerReadinessLoopHandle?.stop(),
|
|
81210
79917
|
() => agentKeepalive.dropNow(),
|
|
81211
79918
|
() => selfUpdateHandle.stop(),
|
|
@@ -83364,10 +82071,10 @@ function uninstallService(deps) {
|
|
|
83364
82071
|
}
|
|
83365
82072
|
|
|
83366
82073
|
// src/uninstall-codex.ts
|
|
83367
|
-
var
|
|
82074
|
+
var import_promises19 = __toESM(require("node:fs/promises"), 1);
|
|
83368
82075
|
var import_node_os24 = __toESM(require("node:os"), 1);
|
|
83369
82076
|
var import_node_path45 = __toESM(require("node:path"), 1);
|
|
83370
|
-
var
|
|
82077
|
+
var toml6 = __toESM(require_toml(), 1);
|
|
83371
82078
|
function resolveCodexHome3(options) {
|
|
83372
82079
|
if (options.codexHome) return options.codexHome;
|
|
83373
82080
|
if (options.homeDir) return import_node_path45.default.join(options.homeDir, ".codex");
|
|
@@ -83376,7 +82083,7 @@ function resolveCodexHome3(options) {
|
|
|
83376
82083
|
}
|
|
83377
82084
|
async function pathExists6(target) {
|
|
83378
82085
|
try {
|
|
83379
|
-
await
|
|
82086
|
+
await import_promises19.default.access(target);
|
|
83380
82087
|
return true;
|
|
83381
82088
|
} catch {
|
|
83382
82089
|
return false;
|
|
@@ -83390,11 +82097,11 @@ async function uninstallCodex(options = {}) {
|
|
|
83390
82097
|
if (!await pathExists6(configPath)) {
|
|
83391
82098
|
return { action: "missing", configPath, prompts: await removePrompts() };
|
|
83392
82099
|
}
|
|
83393
|
-
const realPath = await
|
|
83394
|
-
const existing = await
|
|
82100
|
+
const realPath = await import_promises19.default.realpath(configPath).catch(() => configPath);
|
|
82101
|
+
const existing = await import_promises19.default.readFile(realPath, "utf8");
|
|
83395
82102
|
let parsed = null;
|
|
83396
82103
|
try {
|
|
83397
|
-
parsed =
|
|
82104
|
+
parsed = toml6.parse(existing);
|
|
83398
82105
|
} catch (error51) {
|
|
83399
82106
|
const detail = error51 instanceof Error ? error51.message : String(error51);
|
|
83400
82107
|
const err = {
|
|
@@ -83408,7 +82115,7 @@ async function uninstallCodex(options = {}) {
|
|
|
83408
82115
|
return { action: "noop", configPath: realPath, prompts: await removePrompts() };
|
|
83409
82116
|
}
|
|
83410
82117
|
const stripped = existing.replace(MRRLIN_BLOCK_RE, (match) => match.startsWith("\n") ? "\n" : "").replace(/\n{3,}/g, "\n\n").replace(/^\n+/, "");
|
|
83411
|
-
await
|
|
82118
|
+
await import_promises19.default.writeFile(realPath, stripped, { mode: 384 });
|
|
83412
82119
|
return { action: "removed", configPath: realPath, prompts: await removePrompts() };
|
|
83413
82120
|
}
|
|
83414
82121
|
async function uninstallPrompts(codexHome, names) {
|
|
@@ -83418,7 +82125,7 @@ async function uninstallPrompts(codexHome, names) {
|
|
|
83418
82125
|
for (const name of names) {
|
|
83419
82126
|
const promptPath = import_node_path45.default.join(promptsDir, `${name}.md`);
|
|
83420
82127
|
try {
|
|
83421
|
-
await
|
|
82128
|
+
await import_promises19.default.unlink(promptPath);
|
|
83422
82129
|
out.push({ name, action: "removed", promptPath });
|
|
83423
82130
|
} catch (error51) {
|
|
83424
82131
|
const code = error51?.code;
|
|
@@ -83433,7 +82140,7 @@ async function uninstallPrompts(codexHome, names) {
|
|
|
83433
82140
|
}
|
|
83434
82141
|
|
|
83435
82142
|
// src/connect.ts
|
|
83436
|
-
var
|
|
82143
|
+
var import_node_child_process24 = require("node:child_process");
|
|
83437
82144
|
var CONNECT_EXIT = {
|
|
83438
82145
|
ok: 0,
|
|
83439
82146
|
codeRejected: 3,
|
|
@@ -83444,7 +82151,7 @@ var CONNECT_EXIT = {
|
|
|
83444
82151
|
};
|
|
83445
82152
|
function spawnRedacted(command, args, opts, sinks) {
|
|
83446
82153
|
return new Promise((resolve3) => {
|
|
83447
|
-
const child = (0,
|
|
82154
|
+
const child = (0, import_node_child_process24.spawn)(command, args, { cwd: opts.cwd, env: opts.env, stdio: ["ignore", "pipe", "pipe"] });
|
|
83448
82155
|
const buffers = { stdout: "", stderr: "" };
|
|
83449
82156
|
const feed = (stream, chunk) => {
|
|
83450
82157
|
buffers[stream] += chunk.toString("utf8");
|
|
@@ -83898,7 +82605,7 @@ function removeBridgeLaunchAgent(deps) {
|
|
|
83898
82605
|
}
|
|
83899
82606
|
|
|
83900
82607
|
// src/extract/command.ts
|
|
83901
|
-
var
|
|
82608
|
+
var import_promises20 = require("node:fs/promises");
|
|
83902
82609
|
var import_node_path48 = require("node:path");
|
|
83903
82610
|
function parseArgs(args) {
|
|
83904
82611
|
const map2 = /* @__PURE__ */ new Map();
|
|
@@ -83939,7 +82646,7 @@ Missing required flag(s): ${missing.join(
|
|
|
83939
82646
|
const logPath = (0, import_node_path48.join)(deps.stateDir, "logs", `bridge-${day}.jsonl`);
|
|
83940
82647
|
let raw;
|
|
83941
82648
|
try {
|
|
83942
|
-
raw = await (0,
|
|
82649
|
+
raw = await (0, import_promises20.readFile)(logPath, "utf8");
|
|
83943
82650
|
} catch {
|
|
83944
82651
|
continue;
|
|
83945
82652
|
}
|
|
@@ -83973,7 +82680,7 @@ Missing required flag(s): ${missing.join(
|
|
|
83973
82680
|
}
|
|
83974
82681
|
const outputText = cappedLines.join("\n");
|
|
83975
82682
|
if (outPath) {
|
|
83976
|
-
await (0,
|
|
82683
|
+
await (0, import_promises20.writeFile)(outPath, outputText, "utf8");
|
|
83977
82684
|
return {
|
|
83978
82685
|
ok: true,
|
|
83979
82686
|
message: `Wrote extract to ${outPath}`,
|
|
@@ -84040,13 +82747,13 @@ function augmentProcessPathWithCommonDirs() {
|
|
|
84040
82747
|
}
|
|
84041
82748
|
augmentProcessPathWithCommonDirs();
|
|
84042
82749
|
function pm2Runner(args) {
|
|
84043
|
-
const r = (0,
|
|
82750
|
+
const r = (0, import_node_child_process25.spawnSync)("pm2", args, { encoding: "utf8" });
|
|
84044
82751
|
process.stderr.write(r.stdout ?? "");
|
|
84045
82752
|
process.stderr.write(r.stderr ?? "");
|
|
84046
82753
|
return { code: r.status ?? 1, stdout: r.stdout ?? "" };
|
|
84047
82754
|
}
|
|
84048
82755
|
function whichBin(bin) {
|
|
84049
|
-
const r = (0,
|
|
82756
|
+
const r = (0, import_node_child_process25.spawnSync)("which", [bin], { encoding: "utf8" });
|
|
84050
82757
|
const out = (r.stdout ?? "").trim();
|
|
84051
82758
|
return r.status === 0 && out ? out.split("\n")[0] ?? null : null;
|
|
84052
82759
|
}
|
|
@@ -84061,7 +82768,7 @@ function bootHookStatus() {
|
|
|
84061
82768
|
{ label: "com.PM2", plist: import_node_path50.default.join(agents, `pm2.${(0, import_node_os25.userInfo)().username}.plist`) }
|
|
84062
82769
|
];
|
|
84063
82770
|
for (const candidate of candidates) {
|
|
84064
|
-
const printed = (0,
|
|
82771
|
+
const printed = (0, import_node_child_process25.spawnSync)("launchctl", ["print", `gui/${uid}/${candidate.label}`], { encoding: "utf8" });
|
|
84065
82772
|
if (printed.status !== 0) continue;
|
|
84066
82773
|
if (!(0, import_node_fs32.existsSync)(candidate.plist)) continue;
|
|
84067
82774
|
const out = printed.stdout ?? "";
|
|
@@ -84089,7 +82796,7 @@ function realLaunchAgentDeps() {
|
|
|
84089
82796
|
(0, import_node_fs32.chmodSync)(p, mode);
|
|
84090
82797
|
},
|
|
84091
82798
|
removeFile: (p) => (0, import_node_fs32.rmSync)(p, { force: true }),
|
|
84092
|
-
launchctl: (args) => ({ status: (0,
|
|
82799
|
+
launchctl: (args) => ({ status: (0, import_node_child_process25.spawnSync)("launchctl", args, { encoding: "utf8" }).status })
|
|
84093
82800
|
};
|
|
84094
82801
|
}
|
|
84095
82802
|
function bridgeHealthUrl() {
|
|
@@ -84167,7 +82874,7 @@ function realConnectDeps() {
|
|
|
84167
82874
|
function realDoctorDeps() {
|
|
84168
82875
|
const home = process.env.HOME ?? (0, import_node_os25.homedir)();
|
|
84169
82876
|
const runnerFor = (command) => (args) => {
|
|
84170
|
-
const r = (0,
|
|
82877
|
+
const r = (0, import_node_child_process25.spawnSync)(command, args, { encoding: "utf8", timeout: 8e3 });
|
|
84171
82878
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
84172
82879
|
};
|
|
84173
82880
|
return {
|
|
@@ -84177,12 +82884,12 @@ function realDoctorDeps() {
|
|
|
84177
82884
|
...process.env.CODEX_HOME ? { codexHome: process.env.CODEX_HOME } : {},
|
|
84178
82885
|
stateDir: resolveStateDir(),
|
|
84179
82886
|
npmLatest: async () => {
|
|
84180
|
-
const r = (0,
|
|
82887
|
+
const r = (0, import_node_child_process25.spawnSync)("npm", ["view", "@mrrlin-dev/mcp", "version"], { encoding: "utf8", timeout: 5e3 });
|
|
84181
82888
|
if (r.status !== 0 || !(r.stdout ?? "").trim()) throw new Error("npm view failed");
|
|
84182
82889
|
return (r.stdout ?? "").trim();
|
|
84183
82890
|
},
|
|
84184
82891
|
pm2Online: async () => {
|
|
84185
|
-
const r = (0,
|
|
82892
|
+
const r = (0, import_node_child_process25.spawnSync)("pm2", ["jlist"], { encoding: "utf8", timeout: 8e3 });
|
|
84186
82893
|
try {
|
|
84187
82894
|
const list = JSON.parse(r.stdout ?? "[]");
|
|
84188
82895
|
return list.some((a) => a.name === "mrrlin-bridge" && a.pm2_env?.status === "online");
|
|
@@ -84241,12 +82948,6 @@ Usage:
|
|
|
84241
82948
|
wired into the scheduler or Director turn-start
|
|
84242
82949
|
\u2014 this only answers the question).
|
|
84243
82950
|
|
|
84244
|
-
mrrlin-mcp external-agents-serve
|
|
84245
|
-
Launch the bundled @mrrlin-dev/external-agents
|
|
84246
|
-
MCP server (multi-LLM dispatch pool). This is the
|
|
84247
|
-
command configure bridge wires for the
|
|
84248
|
-
[mcp_servers.external-agents] block.
|
|
84249
|
-
|
|
84250
82951
|
mrrlin-mcp configure bridge Idempotently register Mrrlin in
|
|
84251
82952
|
[--force] ~/.codex/config.toml (or CODEX_HOME). Adds an
|
|
84252
82953
|
[mcp_servers.mrrlin] block. Development
|
|
@@ -84440,12 +83141,6 @@ async function main() {
|
|
|
84440
83141
|
`);
|
|
84441
83142
|
return;
|
|
84442
83143
|
}
|
|
84443
|
-
case "external-agents-serve": {
|
|
84444
|
-
const { command: command2, args } = externalAgentsServeArgs();
|
|
84445
|
-
const r = (0, import_node_child_process28.spawnSync)(command2, args, { stdio: "inherit", env: process.env });
|
|
84446
|
-
process.exitCode = r.status ?? 1;
|
|
84447
|
-
return;
|
|
84448
|
-
}
|
|
84449
83144
|
case "configure": {
|
|
84450
83145
|
const [target, ...configureRest] = rest;
|
|
84451
83146
|
if (target !== "bridge") {
|
|
@@ -84519,7 +83214,7 @@ async function main() {
|
|
|
84519
83214
|
);
|
|
84520
83215
|
}
|
|
84521
83216
|
const realProviderRunner = (command2) => (args) => {
|
|
84522
|
-
const r = (0,
|
|
83217
|
+
const r = (0, import_node_child_process25.spawnSync)(command2, args, { encoding: "utf8", timeout: 8e3 });
|
|
84523
83218
|
return { status: r.status, stdout: r.stdout ?? "", stderr: r.stderr ?? "" };
|
|
84524
83219
|
};
|
|
84525
83220
|
for (const provider of ["codex", "claude", "agy"]) {
|