metheus-governance-mcp-cli 0.2.76 → 0.2.78
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/cli.mjs +87 -8
- package/lib/bot-commands.mjs +24 -14
- package/lib/selftest-bot-commands.mjs +12 -4
- package/package.json +1 -1
package/cli.mjs
CHANGED
|
@@ -5029,6 +5029,7 @@ async function runProxy(flags) {
|
|
|
5029
5029
|
}
|
|
5030
5030
|
|
|
5031
5031
|
function runSetupInternal(flags, options = {}) {
|
|
5032
|
+
const printOutput = options.printOutput !== false;
|
|
5032
5033
|
const setupRegistrationDeps = buildSetupRegistrationDeps();
|
|
5033
5034
|
const summary = runSetupInternalFlow(
|
|
5034
5035
|
{
|
|
@@ -5039,7 +5040,10 @@ function runSetupInternal(flags, options = {}) {
|
|
|
5039
5040
|
setupRegistrationDeps,
|
|
5040
5041
|
);
|
|
5041
5042
|
const lines = buildSetupOutputLines(summary, setupRegistrationDeps);
|
|
5042
|
-
|
|
5043
|
+
if (printOutput) {
|
|
5044
|
+
process.stdout.write(`\n${lines.join("\n")}\n`);
|
|
5045
|
+
}
|
|
5046
|
+
return { summary, lines };
|
|
5043
5047
|
}
|
|
5044
5048
|
|
|
5045
5049
|
function runSetup(flags) {
|
|
@@ -5213,25 +5217,100 @@ TELEGRAM_BOT_REVIEW_TOKEN=review-token
|
|
|
5213
5217
|
}
|
|
5214
5218
|
}
|
|
5215
5219
|
|
|
5220
|
+
function bootstrapSupportsANSIColors() {
|
|
5221
|
+
if (!process.stdout?.isTTY) return false;
|
|
5222
|
+
if (process.env.NO_COLOR) return false;
|
|
5223
|
+
const term = String(process.env.TERM || "").toLowerCase();
|
|
5224
|
+
return term && term !== "dumb";
|
|
5225
|
+
}
|
|
5226
|
+
|
|
5227
|
+
function bootstrapColorText(value, colorCode) {
|
|
5228
|
+
if (!value || !bootstrapSupportsANSIColors()) return value;
|
|
5229
|
+
return `\u001b[${colorCode}m${value}\u001b[0m`;
|
|
5230
|
+
}
|
|
5231
|
+
|
|
5232
|
+
function bootstrapPadRight(value, width) {
|
|
5233
|
+
const text = String(value || "");
|
|
5234
|
+
if (text.length >= width) return text;
|
|
5235
|
+
return `${text}${" ".repeat(width - text.length)}`;
|
|
5236
|
+
}
|
|
5237
|
+
|
|
5238
|
+
function bootstrapWrapAsciiLine(value, width) {
|
|
5239
|
+
const text = String(value || "");
|
|
5240
|
+
if (!text) return [""];
|
|
5241
|
+
const lines = [];
|
|
5242
|
+
for (const rawLine of text.split(/\r?\n/)) {
|
|
5243
|
+
if (!rawLine) {
|
|
5244
|
+
lines.push("");
|
|
5245
|
+
continue;
|
|
5246
|
+
}
|
|
5247
|
+
let remaining = rawLine;
|
|
5248
|
+
while (remaining.length > width) {
|
|
5249
|
+
let breakAt = remaining.lastIndexOf(" ", width);
|
|
5250
|
+
if (breakAt <= 0) breakAt = width;
|
|
5251
|
+
lines.push(remaining.slice(0, breakAt).trimEnd());
|
|
5252
|
+
remaining = remaining.slice(breakAt).trimStart();
|
|
5253
|
+
}
|
|
5254
|
+
lines.push(remaining);
|
|
5255
|
+
}
|
|
5256
|
+
return lines;
|
|
5257
|
+
}
|
|
5258
|
+
|
|
5259
|
+
function formatBootstrapBlock(title, lines = [], { accentColor = "36" } = {}) {
|
|
5260
|
+
const innerWidth = 64;
|
|
5261
|
+
const border = `+${"-".repeat(innerWidth + 2)}+`;
|
|
5262
|
+
const output = [bootstrapColorText(border, accentColor)];
|
|
5263
|
+
const renderedTitle = `| ${bootstrapPadRight(String(title || ""), innerWidth)} |`;
|
|
5264
|
+
output.push(bootstrapColorText(renderedTitle, accentColor));
|
|
5265
|
+
for (const line of Array.isArray(lines) ? lines : [lines]) {
|
|
5266
|
+
for (const wrapped of bootstrapWrapAsciiLine(line, innerWidth)) {
|
|
5267
|
+
output.push(`| ${bootstrapPadRight(wrapped, innerWidth)} |`);
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
output.push(bootstrapColorText(border, accentColor));
|
|
5271
|
+
return output.join("\n");
|
|
5272
|
+
}
|
|
5273
|
+
|
|
5216
5274
|
async function runBootstrap(flags) {
|
|
5217
|
-
process.stdout.write(
|
|
5275
|
+
process.stdout.write(
|
|
5276
|
+
`\n${formatBootstrapBlock("BOOTSTRAP", [
|
|
5277
|
+
"Check auth, ensure local templates, and keep CLI registrations in sync",
|
|
5278
|
+
], { accentColor: "35" })}\n`,
|
|
5279
|
+
);
|
|
5218
5280
|
const authFlowDeps = buildAuthFlowDeps();
|
|
5219
5281
|
let resolved = resolveCurrentAccessToken(authFlowDeps);
|
|
5220
5282
|
if (!resolved.token) {
|
|
5221
|
-
process.stdout.write(
|
|
5283
|
+
process.stdout.write(
|
|
5284
|
+
`\n${formatBootstrapBlock("BOOTSTRAP | AUTH", [
|
|
5285
|
+
"Auth token missing or expired",
|
|
5286
|
+
"Starting login flow",
|
|
5287
|
+
], { accentColor: "33" })}\n`,
|
|
5288
|
+
);
|
|
5222
5289
|
await runAuthLogin(flags, authFlowDeps);
|
|
5223
5290
|
resolved = resolveCurrentAccessToken(authFlowDeps);
|
|
5224
5291
|
if (!resolved.token) {
|
|
5225
|
-
process.stderr.write(
|
|
5292
|
+
process.stderr.write(
|
|
5293
|
+
`\n${formatBootstrapBlock("BOOTSTRAP | ERROR", [
|
|
5294
|
+
"Auth login finished but token is still unavailable.",
|
|
5295
|
+
], { accentColor: "31" })}\n`,
|
|
5296
|
+
);
|
|
5226
5297
|
process.exitCode = 1;
|
|
5227
5298
|
return;
|
|
5228
5299
|
}
|
|
5229
|
-
} else {
|
|
5230
|
-
process.stdout.write(`Auth token OK (${resolved.source}).\n`);
|
|
5231
5300
|
}
|
|
5301
|
+
process.stdout.write(
|
|
5302
|
+
`\n${formatBootstrapBlock("BOOTSTRAP | AUTH", [
|
|
5303
|
+
`Auth token OK (${resolved.source}).`,
|
|
5304
|
+
], { accentColor: "32" })}\n`,
|
|
5305
|
+
);
|
|
5232
5306
|
|
|
5233
|
-
runSetupInternal(flags, { ensureOnly: true });
|
|
5234
|
-
process.stdout.write("
|
|
5307
|
+
const { lines } = runSetupInternal(flags, { ensureOnly: true, printOutput: false });
|
|
5308
|
+
process.stdout.write(`\n${formatBootstrapBlock("BOOTSTRAP | SUMMARY", lines, { accentColor: "36" })}\n`);
|
|
5309
|
+
process.stdout.write(
|
|
5310
|
+
`\n${formatBootstrapBlock("BOOTSTRAP | DONE", [
|
|
5311
|
+
"Bootstrap complete.",
|
|
5312
|
+
], { accentColor: "32" })}\n`,
|
|
5313
|
+
);
|
|
5235
5314
|
}
|
|
5236
5315
|
|
|
5237
5316
|
async function runBot(argv) {
|
package/lib/bot-commands.mjs
CHANGED
|
@@ -711,22 +711,32 @@ async function editTelegramBotGuided(ui, parsed, selected, current, flags, deps)
|
|
|
711
711
|
let serverRoleAutoResolved = "";
|
|
712
712
|
let groupedServerRoles = [];
|
|
713
713
|
let groupedServerName = "";
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
714
|
+
let serverManagedIdentity = Boolean(current.serverBotID || current.__preferServerIdentity);
|
|
715
|
+
if (!serverManagedIdentity) {
|
|
716
|
+
const initialServerBot = await autoResolveTelegramServerBot(current, flags, deps);
|
|
717
|
+
if (String(initialServerBot.botID || "").trim() || initialServerBot.matchMode === "group") {
|
|
718
|
+
serverManagedIdentity = true;
|
|
719
|
+
}
|
|
717
720
|
}
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
defaultValue: current.username ? "keep" : "change",
|
|
722
|
-
});
|
|
723
|
-
if (usernameAction === "change") {
|
|
724
|
-
current.username = requireDependency(deps, "normalizeTelegramBotUsername")(
|
|
725
|
-
await promptRequiredLine(ui, "Telegram username (without @)", current.username),
|
|
726
|
-
"",
|
|
727
|
-
);
|
|
728
|
-
} else if (usernameAction === "clear") {
|
|
721
|
+
let usernameAction = "keep";
|
|
722
|
+
if (serverManagedIdentity) {
|
|
723
|
+
current.__preferServerIdentity = true;
|
|
729
724
|
current.username = "";
|
|
725
|
+
serverRoleAutoResolved = String(current.roleProfile || "").trim() || "__server_binding__";
|
|
726
|
+
process.stdout.write("Telegram username is managed from server bot info and cannot be edited here.\n");
|
|
727
|
+
} else {
|
|
728
|
+
usernameAction = await promptKeepChangeClear(ui, "Telegram username", {
|
|
729
|
+
allowClear: true,
|
|
730
|
+
defaultValue: current.username ? "keep" : "change",
|
|
731
|
+
});
|
|
732
|
+
if (usernameAction === "change") {
|
|
733
|
+
current.username = requireDependency(deps, "normalizeTelegramBotUsername")(
|
|
734
|
+
await promptRequiredLine(ui, "Telegram username (without @)", current.username),
|
|
735
|
+
"",
|
|
736
|
+
);
|
|
737
|
+
} else if (usernameAction === "clear") {
|
|
738
|
+
current.username = "";
|
|
739
|
+
}
|
|
730
740
|
}
|
|
731
741
|
|
|
732
742
|
const tokenAction = await promptKeepChangeClear(ui, "Telegram token", {
|
|
@@ -347,7 +347,7 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
347
347
|
`username=${String(groupedState.TELEGRAM_BOT_RYOAI_BOT_USERNAME || "")} server_bot_id=${String(groupedState.TELEGRAM_BOT_RYOAI_BOT_SERVER_BOT_ID || "")} role=${String(groupedState.TELEGRAM_BOT_RYOAI_BOT_ROLE_PROFILE || "")}`,
|
|
348
348
|
);
|
|
349
349
|
|
|
350
|
-
await runCLI({
|
|
350
|
+
const groupedEditResult = await runCLI({
|
|
351
351
|
cliPath,
|
|
352
352
|
args: [
|
|
353
353
|
"bot", "edit",
|
|
@@ -359,7 +359,6 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
359
359
|
METHEUS_SCRIPTED_PROMPT_ANSWERS: JSON.stringify([
|
|
360
360
|
"1", // provider: telegram
|
|
361
361
|
"2", // bot entry: ryoai_bot
|
|
362
|
-
"1", // keep username
|
|
363
362
|
"1", // keep token
|
|
364
363
|
"2", // grouped role settings: edit one role
|
|
365
364
|
"3", // select role to edit: worker
|
|
@@ -381,6 +380,11 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
381
380
|
]),
|
|
382
381
|
},
|
|
383
382
|
});
|
|
383
|
+
push(
|
|
384
|
+
"bot_edit_grouped_server_roles_skips_local_username_prompt",
|
|
385
|
+
!String(groupedEditResult.stdout || "").includes("Telegram username (without @)"),
|
|
386
|
+
String(groupedEditResult.stdout || "").split(/\r?\n/).filter((line) => line.includes("Telegram username")).join(" | ") || "username prompt skipped",
|
|
387
|
+
);
|
|
384
388
|
const groupedRunnerConfigPath = path.join(tempHome, ".metheus", "bot-runner.json");
|
|
385
389
|
const groupedRunnerConfig = readJSON(fs.readFileSync(groupedRunnerConfigPath, "utf8"));
|
|
386
390
|
push(
|
|
@@ -487,7 +491,7 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
487
491
|
`routes=${JSON.stringify(safeObject(showWithRoutesPayload.routeLinks))}`,
|
|
488
492
|
);
|
|
489
493
|
|
|
490
|
-
await runCLI({
|
|
494
|
+
const guidedEditResult = await runCLI({
|
|
491
495
|
cliPath,
|
|
492
496
|
args: ["bot", "edit"],
|
|
493
497
|
env: {
|
|
@@ -495,7 +499,6 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
495
499
|
METHEUS_SCRIPTED_PROMPT_ANSWERS: JSON.stringify([
|
|
496
500
|
"1", // provider: telegram
|
|
497
501
|
"1", // bot entry: @monitorselftestbot
|
|
498
|
-
"1", // keep username
|
|
499
502
|
"1", // keep token
|
|
500
503
|
"2", // change AI client
|
|
501
504
|
"4", // gemini
|
|
@@ -510,6 +513,11 @@ export async function runSelftestBotCommands(push, deps) {
|
|
|
510
513
|
]),
|
|
511
514
|
},
|
|
512
515
|
});
|
|
516
|
+
push(
|
|
517
|
+
"bot_edit_single_server_binding_skips_local_username_prompt",
|
|
518
|
+
!String(guidedEditResult.stdout || "").includes("Telegram username (without @)"),
|
|
519
|
+
String(guidedEditResult.stdout || "").split(/\r?\n/).filter((line) => line.includes("Telegram username")).join(" | ") || "username prompt skipped",
|
|
520
|
+
);
|
|
513
521
|
const guidedState = parseSimpleEnvText(fs.readFileSync(telegramEnvPath, "utf8"));
|
|
514
522
|
push(
|
|
515
523
|
"bot_edit_guided_prompts_update_ai_binding_fields",
|