metheus-governance-mcp-cli 0.2.54 → 0.2.57
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 +24 -3
- package/package.json +1 -1
- package/scripts/local-bot-ai-bridge.mjs +53 -6
package/cli.mjs
CHANGED
|
@@ -1858,14 +1858,34 @@ async function deliverLocalProviderMessage({
|
|
|
1858
1858
|
if (replyToMessageID > 0) {
|
|
1859
1859
|
payload.reply_to_message_id = replyToMessageID;
|
|
1860
1860
|
}
|
|
1861
|
-
|
|
1862
|
-
|
|
1861
|
+
let response = await postJSONWithoutAuth(requestURL, timeoutSeconds, payload);
|
|
1862
|
+
let responseJSON = parseJSONText(response.bodyText);
|
|
1863
|
+
let effectiveReplyToMessageID = replyToMessageID > 0 ? replyToMessageID : 0;
|
|
1864
|
+
let replyFallbackUsed = false;
|
|
1865
|
+
const responseDescription = String(safeObject(responseJSON).description || "").trim().toLowerCase();
|
|
1866
|
+
if (
|
|
1867
|
+
replyToMessageID > 0
|
|
1868
|
+
&& !(response.statusCode >= 200 && response.statusCode < 300 && Boolean(responseJSON?.ok ?? true))
|
|
1869
|
+
&& responseDescription.includes("message to be replied not found")
|
|
1870
|
+
) {
|
|
1871
|
+
const fallbackPayload = {
|
|
1872
|
+
chat_id: destination.chatID,
|
|
1873
|
+
text,
|
|
1874
|
+
disable_web_page_preview: disableWebPagePreview,
|
|
1875
|
+
};
|
|
1876
|
+
response = await postJSONWithoutAuth(requestURL, timeoutSeconds, fallbackPayload);
|
|
1877
|
+
responseJSON = parseJSONText(response.bodyText);
|
|
1878
|
+
effectiveReplyToMessageID = 0;
|
|
1879
|
+
replyFallbackUsed = true;
|
|
1880
|
+
}
|
|
1863
1881
|
return {
|
|
1864
1882
|
statusCode: response.statusCode,
|
|
1865
1883
|
body: responseJSON || response.bodyText,
|
|
1866
1884
|
ok: response.statusCode >= 200 && response.statusCode < 300 && Boolean(responseJSON?.ok ?? true),
|
|
1867
1885
|
url: sanitizeTelegramAPIURL(requestURL),
|
|
1868
1886
|
replySupported: true,
|
|
1887
|
+
effectiveReplyToMessageID,
|
|
1888
|
+
replyFallbackUsed,
|
|
1869
1889
|
};
|
|
1870
1890
|
}
|
|
1871
1891
|
if (normalizedProvider === "slack") {
|
|
@@ -5576,13 +5596,14 @@ async function performLocalBotDelivery({
|
|
|
5576
5596
|
deliveredResult.message_id ?? deliveredBody.message_id ?? deliveredBody.ts,
|
|
5577
5597
|
0,
|
|
5578
5598
|
);
|
|
5599
|
+
const archiveReplyToMessageID = intFromRawAllowZero(delivery.effectiveReplyToMessageID, replyToMessageID);
|
|
5579
5600
|
const archiveBody = formatBotReplyArchiveComment({
|
|
5580
5601
|
provider: normalizedProvider,
|
|
5581
5602
|
bot,
|
|
5582
5603
|
destination,
|
|
5583
5604
|
replyText: text,
|
|
5584
5605
|
messageID: deliveredMessageID,
|
|
5585
|
-
replyToMessageID,
|
|
5606
|
+
replyToMessageID: archiveReplyToMessageID,
|
|
5586
5607
|
});
|
|
5587
5608
|
const createdComment = await createThreadComment({
|
|
5588
5609
|
siteBaseURL,
|
package/package.json
CHANGED
|
@@ -56,6 +56,50 @@ function resolveWorkspaceDir(rawValue) {
|
|
|
56
56
|
return process.cwd();
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
function resolveLocalCliCommand(commandName) {
|
|
60
|
+
const name = String(commandName || "").trim();
|
|
61
|
+
if (!name) {
|
|
62
|
+
throw new Error("command name is required");
|
|
63
|
+
}
|
|
64
|
+
if (process.platform === "win32") {
|
|
65
|
+
const candidates = [
|
|
66
|
+
path.join(process.env.APPDATA || "", "npm", `${name}.cmd`),
|
|
67
|
+
path.join(process.env.APPDATA || "", "npm", `${name}.ps1`),
|
|
68
|
+
path.join(process.env.APPDATA || "", "npm", name),
|
|
69
|
+
].filter(Boolean);
|
|
70
|
+
for (const candidate of candidates) {
|
|
71
|
+
if (candidate && fs.existsSync(candidate)) {
|
|
72
|
+
return candidate;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return name;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function quoteWindowsShellArg(value) {
|
|
80
|
+
const text = String(value ?? "");
|
|
81
|
+
if (!text) return '""';
|
|
82
|
+
if (!/[\s"&|<>^()]/.test(text)) return text;
|
|
83
|
+
return `"${text.replace(/"/g, '""')}"`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function spawnCli(commandPath, args, options) {
|
|
87
|
+
const executable = String(commandPath || "").trim();
|
|
88
|
+
if (!executable) {
|
|
89
|
+
throw new Error("command path is required");
|
|
90
|
+
}
|
|
91
|
+
const normalizedArgs = Array.isArray(args) ? args.map((item) => String(item)) : [];
|
|
92
|
+
if (process.platform === "win32" && /\.(cmd|bat)$/i.test(executable)) {
|
|
93
|
+
const commandLine = [quoteWindowsShellArg(executable), ...normalizedArgs.map(quoteWindowsShellArg)].join(" ");
|
|
94
|
+
return spawnSync(
|
|
95
|
+
process.env.ComSpec || "cmd.exe",
|
|
96
|
+
["/d", "/s", "/c", commandLine],
|
|
97
|
+
options,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
return spawnSync(executable, normalizedArgs, options);
|
|
101
|
+
}
|
|
102
|
+
|
|
59
103
|
function buildPrompt(payload, { terse = true } = {}) {
|
|
60
104
|
const safePayload = payload && typeof payload === "object" ? payload : {};
|
|
61
105
|
const trigger = safePayload.trigger && typeof safePayload.trigger === "object" ? safePayload.trigger : {};
|
|
@@ -117,8 +161,9 @@ function normalizeCliResponse(rawText) {
|
|
|
117
161
|
|
|
118
162
|
function runCodex(promptText, workspaceDir) {
|
|
119
163
|
const outputPath = path.join(os.tmpdir(), `metheus-runner-codex-${Date.now()}.txt`);
|
|
120
|
-
const
|
|
121
|
-
|
|
164
|
+
const codexCommand = resolveLocalCliCommand("codex");
|
|
165
|
+
const result = spawnCli(
|
|
166
|
+
codexCommand,
|
|
122
167
|
[
|
|
123
168
|
"exec",
|
|
124
169
|
"-",
|
|
@@ -148,8 +193,9 @@ function runCodex(promptText, workspaceDir) {
|
|
|
148
193
|
}
|
|
149
194
|
|
|
150
195
|
function runClaude(promptText) {
|
|
151
|
-
const
|
|
152
|
-
|
|
196
|
+
const claudeCommand = resolveLocalCliCommand("claude");
|
|
197
|
+
const result = spawnCli(
|
|
198
|
+
claudeCommand,
|
|
153
199
|
[
|
|
154
200
|
"-p",
|
|
155
201
|
promptText,
|
|
@@ -175,8 +221,9 @@ function runClaude(promptText) {
|
|
|
175
221
|
}
|
|
176
222
|
|
|
177
223
|
function runGemini(promptText) {
|
|
178
|
-
const
|
|
179
|
-
|
|
224
|
+
const geminiCommand = resolveLocalCliCommand("gemini");
|
|
225
|
+
const result = spawnCli(
|
|
226
|
+
geminiCommand,
|
|
180
227
|
[
|
|
181
228
|
"-p",
|
|
182
229
|
promptText,
|