@maind-dev/mcp-bridge 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/index.js +407 -235
- package/build/meta.json +1 -1
- package/package.json +18 -17
package/build/index.js
CHANGED
|
@@ -172,6 +172,13 @@ function clearApiKey() {
|
|
|
172
172
|
if (!existsSync(file)) return;
|
|
173
173
|
writeFileSync2(file, "", { encoding: "utf8", mode: 384 });
|
|
174
174
|
}
|
|
175
|
+
function bridgeLabel() {
|
|
176
|
+
try {
|
|
177
|
+
return `mcp-bridge-${hostname()}`;
|
|
178
|
+
} catch {
|
|
179
|
+
return "mcp-bridge";
|
|
180
|
+
}
|
|
181
|
+
}
|
|
175
182
|
function clientMeta(version) {
|
|
176
183
|
return {
|
|
177
184
|
os: `${platform()} ${release()}`,
|
|
@@ -195,7 +202,7 @@ var BRIDGE_VERSION;
|
|
|
195
202
|
var init_version = __esm({
|
|
196
203
|
"src/version.ts"() {
|
|
197
204
|
"use strict";
|
|
198
|
-
BRIDGE_VERSION = "0.
|
|
205
|
+
BRIDGE_VERSION = "0.23.0";
|
|
199
206
|
}
|
|
200
207
|
});
|
|
201
208
|
|
|
@@ -625,16 +632,16 @@ function toPosix(p) {
|
|
|
625
632
|
return sep === "/" ? p : p.split(sep).join("/");
|
|
626
633
|
}
|
|
627
634
|
function classify(paths) {
|
|
628
|
-
const
|
|
635
|
+
const out2 = [];
|
|
629
636
|
for (const raw of paths) {
|
|
630
637
|
const path8 = toPosix(raw).trim();
|
|
631
638
|
if (!path8 || isSkippablePath(path8))
|
|
632
639
|
continue;
|
|
633
640
|
const language = languageForPath(path8);
|
|
634
641
|
if (language)
|
|
635
|
-
|
|
642
|
+
out2.push({ path: path8, language });
|
|
636
643
|
}
|
|
637
|
-
return
|
|
644
|
+
return out2;
|
|
638
645
|
}
|
|
639
646
|
function classifyPaths(paths) {
|
|
640
647
|
return classify(paths);
|
|
@@ -1063,12 +1070,12 @@ import { execFileSync as execFileSync4 } from "node:child_process";
|
|
|
1063
1070
|
import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
|
|
1064
1071
|
import { posix as posix3 } from "node:path";
|
|
1065
1072
|
function computeDivergence(facts) {
|
|
1066
|
-
const
|
|
1073
|
+
const out2 = [];
|
|
1067
1074
|
if (!facts.isRepo)
|
|
1068
|
-
return
|
|
1075
|
+
return out2;
|
|
1069
1076
|
const onFeatureBranch = facts.branch != null && facts.defaultBranch != null && facts.branch !== facts.defaultBranch && !facts.detachedHead;
|
|
1070
1077
|
if (facts.detachedHead) {
|
|
1071
|
-
|
|
1078
|
+
out2.push({
|
|
1072
1079
|
id: "worktree.detached-head",
|
|
1073
1080
|
status: "warn",
|
|
1074
1081
|
scope: "worktree",
|
|
@@ -1079,7 +1086,7 @@ function computeDivergence(facts) {
|
|
|
1079
1086
|
}
|
|
1080
1087
|
if (onFeatureBranch) {
|
|
1081
1088
|
if (facts.upstream == null) {
|
|
1082
|
-
|
|
1089
|
+
out2.push({
|
|
1083
1090
|
id: "branch.no-upstream",
|
|
1084
1091
|
status: "open",
|
|
1085
1092
|
scope: "branch",
|
|
@@ -1090,7 +1097,7 @@ function computeDivergence(facts) {
|
|
|
1090
1097
|
} else {
|
|
1091
1098
|
const upstreamBranch = facts.upstream.split("/").slice(1).join("/");
|
|
1092
1099
|
if (upstreamBranch && upstreamBranch !== facts.branch) {
|
|
1093
|
-
|
|
1100
|
+
out2.push({
|
|
1094
1101
|
id: "branch.upstream-mismatch",
|
|
1095
1102
|
status: "open",
|
|
1096
1103
|
scope: "branch",
|
|
@@ -1100,7 +1107,7 @@ function computeDivergence(facts) {
|
|
|
1100
1107
|
});
|
|
1101
1108
|
}
|
|
1102
1109
|
if (facts.remoteTrackingExists === false) {
|
|
1103
|
-
|
|
1110
|
+
out2.push({
|
|
1104
1111
|
id: "branch.unpushed-missing-remote",
|
|
1105
1112
|
status: "open",
|
|
1106
1113
|
scope: "branch",
|
|
@@ -1114,7 +1121,7 @@ function computeDivergence(facts) {
|
|
|
1114
1121
|
const behind = facts.behind ?? 0;
|
|
1115
1122
|
const ahead = facts.ahead ?? 0;
|
|
1116
1123
|
if (behind > 0) {
|
|
1117
|
-
|
|
1124
|
+
out2.push({
|
|
1118
1125
|
id: "branch.behind",
|
|
1119
1126
|
status: "info",
|
|
1120
1127
|
scope: "branch",
|
|
@@ -1124,7 +1131,7 @@ function computeDivergence(facts) {
|
|
|
1124
1131
|
});
|
|
1125
1132
|
}
|
|
1126
1133
|
if (facts.upstream != null && facts.headMatchesUpstream === false) {
|
|
1127
|
-
|
|
1134
|
+
out2.push({
|
|
1128
1135
|
id: "branch.unpushed-commits",
|
|
1129
1136
|
status: "warn",
|
|
1130
1137
|
scope: "branch",
|
|
@@ -1135,7 +1142,7 @@ function computeDivergence(facts) {
|
|
|
1135
1142
|
}
|
|
1136
1143
|
if (facts.unmergedMigrations.length > 0) {
|
|
1137
1144
|
const n = facts.unmergedMigrations.length;
|
|
1138
|
-
|
|
1145
|
+
out2.push({
|
|
1139
1146
|
id: "branch.unmerged-migrations",
|
|
1140
1147
|
status: "info",
|
|
1141
1148
|
scope: "branch",
|
|
@@ -1145,7 +1152,7 @@ function computeDivergence(facts) {
|
|
|
1145
1152
|
});
|
|
1146
1153
|
}
|
|
1147
1154
|
if (facts.isSharedMainTree && facts.otherWorktrees > 0 && facts.uncommitted > 0 && !onFeatureBranch) {
|
|
1148
|
-
|
|
1155
|
+
out2.push({
|
|
1149
1156
|
id: "worktree.direct-on-shared-base",
|
|
1150
1157
|
status: "warn",
|
|
1151
1158
|
scope: "worktree",
|
|
@@ -1155,7 +1162,7 @@ function computeDivergence(facts) {
|
|
|
1155
1162
|
});
|
|
1156
1163
|
}
|
|
1157
1164
|
if (facts.inProgressOp) {
|
|
1158
|
-
|
|
1165
|
+
out2.push({
|
|
1159
1166
|
id: "worktree.in-progress-op",
|
|
1160
1167
|
status: "warn",
|
|
1161
1168
|
scope: "worktree",
|
|
@@ -1166,7 +1173,7 @@ function computeDivergence(facts) {
|
|
|
1166
1173
|
}
|
|
1167
1174
|
if (facts.worktreeParity && facts.worktreeParity.missing.length > 0) {
|
|
1168
1175
|
const miss = facts.worktreeParity.missing;
|
|
1169
|
-
|
|
1176
|
+
out2.push({
|
|
1170
1177
|
id: "worktree.parity-missing",
|
|
1171
1178
|
status: "open",
|
|
1172
1179
|
scope: "worktree",
|
|
@@ -1176,7 +1183,7 @@ function computeDivergence(facts) {
|
|
|
1176
1183
|
});
|
|
1177
1184
|
}
|
|
1178
1185
|
if (facts.release?.allRed) {
|
|
1179
|
-
|
|
1186
|
+
out2.push({
|
|
1180
1187
|
id: "release.all-checks-red",
|
|
1181
1188
|
status: "warn",
|
|
1182
1189
|
scope: "release",
|
|
@@ -1185,7 +1192,7 @@ function computeDivergence(facts) {
|
|
|
1185
1192
|
hint: "Check the CI provider's billing/spending status before debugging code."
|
|
1186
1193
|
});
|
|
1187
1194
|
}
|
|
1188
|
-
return sortFindings(
|
|
1195
|
+
return sortFindings(out2);
|
|
1189
1196
|
}
|
|
1190
1197
|
function sortFindings(f) {
|
|
1191
1198
|
return [...f].sort((a, b) => STATUS_ORDER[a.status] - STATUS_ORDER[b.status] || a.id.localeCompare(b.id));
|
|
@@ -1225,11 +1232,11 @@ function detectInProgressOp(repoRoot) {
|
|
|
1225
1232
|
return null;
|
|
1226
1233
|
}
|
|
1227
1234
|
function parseWorktrees(raw) {
|
|
1228
|
-
const
|
|
1235
|
+
const out2 = [];
|
|
1229
1236
|
let cur = null;
|
|
1230
1237
|
const flush = () => {
|
|
1231
1238
|
if (cur?.path)
|
|
1232
|
-
|
|
1239
|
+
out2.push({ path: cur.path, branch: cur.branch, detached: cur.detached ?? false });
|
|
1233
1240
|
};
|
|
1234
1241
|
for (const line of raw.split("\n")) {
|
|
1235
1242
|
if (line.startsWith("worktree ")) {
|
|
@@ -1244,7 +1251,7 @@ function parseWorktrees(raw) {
|
|
|
1244
1251
|
}
|
|
1245
1252
|
}
|
|
1246
1253
|
flush();
|
|
1247
|
-
return
|
|
1254
|
+
return out2;
|
|
1248
1255
|
}
|
|
1249
1256
|
function readWorktreeRequirements(repoRoot) {
|
|
1250
1257
|
const p = posix3.join(repoRoot, WORKTREE_REQUIREMENTS_RELPATH);
|
|
@@ -1436,9 +1443,9 @@ function parseNumbered(fileName) {
|
|
|
1436
1443
|
return { prefix: m.groups.prefix ?? "", number: m.groups.num };
|
|
1437
1444
|
}
|
|
1438
1445
|
function computeNumberCollisions(facts) {
|
|
1439
|
-
const
|
|
1446
|
+
const out2 = [];
|
|
1440
1447
|
if (!facts.isRepo)
|
|
1441
|
-
return
|
|
1448
|
+
return out2;
|
|
1442
1449
|
const added = new Set(facts.addedPaths);
|
|
1443
1450
|
for (const ns of facts.namespaces) {
|
|
1444
1451
|
const key = namespaceKey(ns);
|
|
@@ -1453,7 +1460,7 @@ function computeNumberCollisions(facts) {
|
|
|
1453
1460
|
const ownPath = paths.find((p) => added.has(p));
|
|
1454
1461
|
const others = paths.filter((p) => p !== ownPath);
|
|
1455
1462
|
const label = `${ns.prefix}${number}`;
|
|
1456
|
-
|
|
1463
|
+
out2.push(ownPath ? {
|
|
1457
1464
|
id: `number.collision:${key}#${number}`,
|
|
1458
1465
|
status: "open",
|
|
1459
1466
|
namespace: ns,
|
|
@@ -1477,7 +1484,7 @@ function computeNumberCollisions(facts) {
|
|
|
1477
1484
|
}
|
|
1478
1485
|
}
|
|
1479
1486
|
const order = { open: 0, warn: 1, info: 2, passed: 3 };
|
|
1480
|
-
return
|
|
1487
|
+
return out2.sort((a, b) => order[a.status] - order[b.status] || a.id.localeCompare(b.id));
|
|
1481
1488
|
}
|
|
1482
1489
|
function isCollisionFree(findings) {
|
|
1483
1490
|
return !findings.some((f) => f.status === "open");
|
|
@@ -1533,8 +1540,8 @@ function trimOrNull2(s) {
|
|
|
1533
1540
|
const t = s?.trim();
|
|
1534
1541
|
return t ? t : null;
|
|
1535
1542
|
}
|
|
1536
|
-
function lines(
|
|
1537
|
-
return
|
|
1543
|
+
function lines(out2) {
|
|
1544
|
+
return out2 ? out2.split("\n").filter(Boolean) : [];
|
|
1538
1545
|
}
|
|
1539
1546
|
function resolveDefaultBranch2(repoRoot) {
|
|
1540
1547
|
const sym = trimOrNull2(runGit(repoRoot, ["symbolic-ref", "--quiet", "refs/remotes/origin/HEAD"]));
|
|
@@ -1611,12 +1618,12 @@ async function gatherNumberCollisionFacts(repoRoot, opts = {}) {
|
|
|
1611
1618
|
const scanTree = (ref, kind, where) => {
|
|
1612
1619
|
if (dirs.length === 0)
|
|
1613
1620
|
return;
|
|
1614
|
-
const
|
|
1615
|
-
if (
|
|
1621
|
+
const out2 = runGit(repoRoot, ["ls-tree", "-r", "--name-only", ref, "--", ...dirs]);
|
|
1622
|
+
if (out2 === null) {
|
|
1616
1623
|
skipped.push(`could not read ${where}`);
|
|
1617
1624
|
return;
|
|
1618
1625
|
}
|
|
1619
|
-
for (const path8 of lines(
|
|
1626
|
+
for (const path8 of lines(out2))
|
|
1620
1627
|
record(path8, kind, where);
|
|
1621
1628
|
};
|
|
1622
1629
|
for (const dir of dirs) {
|
|
@@ -2143,13 +2150,13 @@ var init_engine = __esm({
|
|
|
2143
2150
|
await this.store.init();
|
|
2144
2151
|
const limit = clampLimit(opts.limit, 20, 100);
|
|
2145
2152
|
const hits = await this.store.searchFts(query, opts.kind ?? null, limit);
|
|
2146
|
-
const
|
|
2153
|
+
const out2 = [];
|
|
2147
2154
|
for (const h of hits) {
|
|
2148
2155
|
const n = await this.store.getNode(h.nodeKey);
|
|
2149
2156
|
if (n)
|
|
2150
|
-
|
|
2157
|
+
out2.push({ ...toHit(n), score: h.score });
|
|
2151
2158
|
}
|
|
2152
|
-
return
|
|
2159
|
+
return out2;
|
|
2153
2160
|
}
|
|
2154
2161
|
async semanticQuery(query, opts = {}) {
|
|
2155
2162
|
await this.store.init();
|
|
@@ -2159,13 +2166,13 @@ var init_engine = __esm({
|
|
|
2159
2166
|
const qvec = await this.embedder.embedQuery(query);
|
|
2160
2167
|
const all = await this.store.allEmbeddings();
|
|
2161
2168
|
const scored = all.map((e) => ({ nodeKey: e.nodeKey, score: cosineSimilarity(qvec, e.vec) })).sort((a, b) => b.score - a.score).slice(0, limit);
|
|
2162
|
-
const
|
|
2169
|
+
const out2 = [];
|
|
2163
2170
|
for (const s of scored) {
|
|
2164
2171
|
const n = await this.store.getNode(s.nodeKey);
|
|
2165
2172
|
if (n)
|
|
2166
|
-
|
|
2173
|
+
out2.push({ ...toHit(n), score: s.score });
|
|
2167
2174
|
}
|
|
2168
|
-
return
|
|
2175
|
+
return out2;
|
|
2169
2176
|
}
|
|
2170
2177
|
async tracePath(nodeKey, opts = {}) {
|
|
2171
2178
|
await this.store.init();
|
|
@@ -3737,8 +3744,8 @@ var Forwarder = class {
|
|
|
3737
3744
|
this.presence?.onActivity();
|
|
3738
3745
|
}
|
|
3739
3746
|
if (this.localRouter && this.localRouter.handlesToolCall(parsed?.method, parsed?.params)) {
|
|
3740
|
-
const
|
|
3741
|
-
process.stdout.write(
|
|
3747
|
+
const out2 = await this.localRouter.handleToolCall(parsed?.id ?? null, parsed?.params);
|
|
3748
|
+
process.stdout.write(out2 + "\n");
|
|
3742
3749
|
return;
|
|
3743
3750
|
}
|
|
3744
3751
|
const isToolsList = this.localRouter !== null && parsed?.method === "tools/list";
|
|
@@ -4141,7 +4148,7 @@ function functionsOrigin() {
|
|
|
4141
4148
|
const v = process.env.MAIND_FUNCTIONS_ORIGIN;
|
|
4142
4149
|
return v && v.length > 0 ? v.replace(/\/+$/, "") : DEFAULT_FUNCTIONS_ORIGIN;
|
|
4143
4150
|
}
|
|
4144
|
-
async function runDeviceFlow(version) {
|
|
4151
|
+
async function runDeviceFlow(version, out2 = process.stderr) {
|
|
4145
4152
|
const origin = functionsOrigin();
|
|
4146
4153
|
const startUrl = `${origin}/device-authorization-start`;
|
|
4147
4154
|
const pollUrl = `${origin}/device-authorization-poll`;
|
|
@@ -4159,36 +4166,36 @@ async function runDeviceFlow(version) {
|
|
|
4159
4166
|
const start = await startRes.json();
|
|
4160
4167
|
await openExternalBrowser(start.verification_uri_complete).catch(() => {
|
|
4161
4168
|
});
|
|
4162
|
-
printAuthInstructions(start);
|
|
4169
|
+
printAuthInstructions(start, out2);
|
|
4163
4170
|
const deadline = Date.now() + start.expires_in * 1e3;
|
|
4164
4171
|
const intervalMs = Math.max(start.interval, 3) * 1e3;
|
|
4165
4172
|
while (Date.now() < deadline) {
|
|
4166
4173
|
await sleep(intervalMs);
|
|
4167
4174
|
const poll = await pollOnce(pollUrl, start.device_code).catch((e) => {
|
|
4168
|
-
|
|
4175
|
+
out2.write(`[maind-mcp-bridge] poll error (will retry): ${String(e)}
|
|
4169
4176
|
`);
|
|
4170
4177
|
return null;
|
|
4171
4178
|
});
|
|
4172
4179
|
if (!poll) continue;
|
|
4173
4180
|
if (poll.status === "approved") {
|
|
4174
4181
|
writeApiKey(poll.api_key);
|
|
4175
|
-
|
|
4182
|
+
out2.write(
|
|
4176
4183
|
`[maind-mcp-bridge] signed in (plan: ${poll.plan}). API key saved to ~/.config/maind/api-key
|
|
4177
4184
|
`
|
|
4178
4185
|
);
|
|
4179
4186
|
return { apiKey: poll.api_key, plan: poll.plan };
|
|
4180
4187
|
}
|
|
4181
4188
|
if (poll.status === "denied") {
|
|
4182
|
-
|
|
4189
|
+
out2.write("[maind-mcp-bridge] sign-in denied by user\n");
|
|
4183
4190
|
return null;
|
|
4184
4191
|
}
|
|
4185
4192
|
if (poll.status === "expired" || poll.status === "consumed") {
|
|
4186
|
-
|
|
4193
|
+
out2.write(`[maind-mcp-bridge] sign-in ${poll.status}
|
|
4187
4194
|
`);
|
|
4188
4195
|
return null;
|
|
4189
4196
|
}
|
|
4190
4197
|
}
|
|
4191
|
-
|
|
4198
|
+
out2.write("[maind-mcp-bridge] sign-in timed out\n");
|
|
4192
4199
|
return null;
|
|
4193
4200
|
}
|
|
4194
4201
|
async function pollOnce(url, deviceCode) {
|
|
@@ -4206,7 +4213,7 @@ async function pollOnce(url, deviceCode) {
|
|
|
4206
4213
|
function sleep(ms) {
|
|
4207
4214
|
return new Promise((resolve2) => setTimeout(resolve2, ms));
|
|
4208
4215
|
}
|
|
4209
|
-
function printAuthInstructions(start) {
|
|
4216
|
+
function printAuthInstructions(start, out2) {
|
|
4210
4217
|
const lines2 = [
|
|
4211
4218
|
"",
|
|
4212
4219
|
" \u250C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510",
|
|
@@ -4223,7 +4230,7 @@ function printAuthInstructions(start) {
|
|
|
4223
4230
|
" \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518",
|
|
4224
4231
|
""
|
|
4225
4232
|
];
|
|
4226
|
-
|
|
4233
|
+
out2.write(lines2.join("\n") + "\n");
|
|
4227
4234
|
}
|
|
4228
4235
|
function pad(s, width) {
|
|
4229
4236
|
if (s.length >= width) return s.slice(0, width);
|
|
@@ -4321,6 +4328,8 @@ function parseInstallFlags(argv) {
|
|
|
4321
4328
|
noHook: false,
|
|
4322
4329
|
nonInteractive: false,
|
|
4323
4330
|
token: null,
|
|
4331
|
+
oneClickToken: null,
|
|
4332
|
+
oneClickExchangeUrl: null,
|
|
4324
4333
|
telemetry: false,
|
|
4325
4334
|
client: null,
|
|
4326
4335
|
skipCodex: false,
|
|
@@ -4373,6 +4382,24 @@ function parseInstallFlags(argv) {
|
|
|
4373
4382
|
i++;
|
|
4374
4383
|
break;
|
|
4375
4384
|
}
|
|
4385
|
+
case "--one-click-token": {
|
|
4386
|
+
const next = argv[i + 1];
|
|
4387
|
+
if (next === void 0 || next.startsWith("--")) {
|
|
4388
|
+
throw new InstallFlagError("--one-click-token requires a token argument");
|
|
4389
|
+
}
|
|
4390
|
+
flags.oneClickToken = next;
|
|
4391
|
+
i++;
|
|
4392
|
+
break;
|
|
4393
|
+
}
|
|
4394
|
+
case "--one-click-exchange-url": {
|
|
4395
|
+
const next = argv[i + 1];
|
|
4396
|
+
if (next === void 0 || next.startsWith("--")) {
|
|
4397
|
+
throw new InstallFlagError("--one-click-exchange-url requires a URL argument");
|
|
4398
|
+
}
|
|
4399
|
+
flags.oneClickExchangeUrl = next;
|
|
4400
|
+
i++;
|
|
4401
|
+
break;
|
|
4402
|
+
}
|
|
4376
4403
|
case "--client": {
|
|
4377
4404
|
const next = argv[i + 1];
|
|
4378
4405
|
if (next === void 0 || next.startsWith("--")) {
|
|
@@ -4414,7 +4441,10 @@ function printInstallHelp() {
|
|
|
4414
4441
|
" --no-preamble Skip the 5 preamble files (MCP-config + pairing only)",
|
|
4415
4442
|
" --no-hook Never write the Claude Code hooks (overrides --full for hooks)",
|
|
4416
4443
|
" --non-interactive Skip every TTY prompt (used by CI / Dashboard-One-Click)",
|
|
4417
|
-
" --token <
|
|
4444
|
+
" --token <key> Use a pre-issued mnd_ api-key instead of browser pairing",
|
|
4445
|
+
" --one-click-token <jwt> Exchange the dashboard one-click token for a device-bound",
|
|
4446
|
+
" key \u2014 no browser (needs --one-click-exchange-url; ADR-267)",
|
|
4447
|
+
" --one-click-exchange-url <url> Exchange endpoint (set by the launcher scripts)",
|
|
4418
4448
|
" --client <family> Install only for one client family (claude-code, cursor, ...)",
|
|
4419
4449
|
" --skip-codex Skip the Codex ~/.codex/config.toml target",
|
|
4420
4450
|
' --dry-run Compute the plan but do not write anything (status "would-\u2026")',
|
|
@@ -4727,6 +4757,9 @@ function nonEmpty(v) {
|
|
|
4727
4757
|
return trimmed.length > 0 ? trimmed : null;
|
|
4728
4758
|
}
|
|
4729
4759
|
|
|
4760
|
+
// src/install/index.ts
|
|
4761
|
+
init_bridge_entry();
|
|
4762
|
+
|
|
4730
4763
|
// src/install/atomic-write.ts
|
|
4731
4764
|
import * as fs2 from "node:fs/promises";
|
|
4732
4765
|
import * as path4 from "node:path";
|
|
@@ -4836,7 +4869,7 @@ async function mergeJsonConfig(target, serverEntry, dryRun = false) {
|
|
|
4836
4869
|
if (isObject(existing) && serverEntriesEqual(existing, serverEntry)) {
|
|
4837
4870
|
alreadyConsistent = true;
|
|
4838
4871
|
}
|
|
4839
|
-
nextConfig = { ...parsed, [MAIND_SERVER_KEY]: serverEntry };
|
|
4872
|
+
nextConfig = { ...parsed, [MAIND_SERVER_KEY]: mergeEntry(existing, serverEntry) };
|
|
4840
4873
|
} else {
|
|
4841
4874
|
const mcpServers = isObject(parsed.mcpServers) ? parsed.mcpServers : {};
|
|
4842
4875
|
const existing = mcpServers[MAIND_SERVER_KEY];
|
|
@@ -4845,7 +4878,7 @@ async function mergeJsonConfig(target, serverEntry, dryRun = false) {
|
|
|
4845
4878
|
}
|
|
4846
4879
|
nextConfig = {
|
|
4847
4880
|
...parsed,
|
|
4848
|
-
mcpServers: { ...mcpServers, [MAIND_SERVER_KEY]: serverEntry }
|
|
4881
|
+
mcpServers: { ...mcpServers, [MAIND_SERVER_KEY]: mergeEntry(existing, serverEntry) }
|
|
4849
4882
|
};
|
|
4850
4883
|
}
|
|
4851
4884
|
if (alreadyConsistent && raw !== null) {
|
|
@@ -4877,6 +4910,14 @@ async function mergeJsonConfig(target, serverEntry, dryRun = false) {
|
|
|
4877
4910
|
detail: target.path
|
|
4878
4911
|
};
|
|
4879
4912
|
}
|
|
4913
|
+
function mergeEntry(existing, serverEntry) {
|
|
4914
|
+
const existingEnv = isObject(existing) && isObject(existing.env) ? existing.env : {};
|
|
4915
|
+
const env = { ...serverEntry.env };
|
|
4916
|
+
for (const [key, value] of Object.entries(existingEnv)) {
|
|
4917
|
+
if (!(key in env) && typeof value === "string") env[key] = value;
|
|
4918
|
+
}
|
|
4919
|
+
return { command: serverEntry.command, args: [...serverEntry.args], env };
|
|
4920
|
+
}
|
|
4880
4921
|
function hasRootShape(parsed) {
|
|
4881
4922
|
if ("mcpServers" in parsed) return false;
|
|
4882
4923
|
if (!(MAIND_SERVER_KEY in parsed)) return false;
|
|
@@ -4961,10 +5002,15 @@ async function mergeTomlConfig(target, serverEntry, dryRun = false) {
|
|
|
4961
5002
|
detail: "maind entry already up-to-date"
|
|
4962
5003
|
};
|
|
4963
5004
|
}
|
|
5005
|
+
const existingEnv = isObject2(existing) && isObject2(existing.env) ? existing.env : {};
|
|
5006
|
+
const mergedEnv = { ...serverEntry.env };
|
|
5007
|
+
for (const [key, value] of Object.entries(existingEnv)) {
|
|
5008
|
+
if (!(key in mergedEnv) && typeof value === "string") mergedEnv[key] = value;
|
|
5009
|
+
}
|
|
4964
5010
|
const maindBlock = {
|
|
4965
5011
|
command: serverEntry.command,
|
|
4966
5012
|
args: [...serverEntry.args],
|
|
4967
|
-
env:
|
|
5013
|
+
env: mergedEnv
|
|
4968
5014
|
};
|
|
4969
5015
|
const nextConfig = {
|
|
4970
5016
|
...parsed,
|
|
@@ -6006,11 +6052,11 @@ function findExistingHookCommand(settings, event, pattern) {
|
|
|
6006
6052
|
}
|
|
6007
6053
|
return null;
|
|
6008
6054
|
}
|
|
6009
|
-
async function promptYesNo(
|
|
6010
|
-
|
|
6055
|
+
async function promptYesNo(out2, prompt) {
|
|
6056
|
+
out2.write(prompt);
|
|
6011
6057
|
const rl = readline2.createInterface({
|
|
6012
6058
|
input: process.stdin,
|
|
6013
|
-
output:
|
|
6059
|
+
output: out2,
|
|
6014
6060
|
terminal: true
|
|
6015
6061
|
});
|
|
6016
6062
|
const answer = await new Promise((resolve2) => {
|
|
@@ -6029,6 +6075,47 @@ function errMessage(err) {
|
|
|
6029
6075
|
|
|
6030
6076
|
// src/install/browser-pair.ts
|
|
6031
6077
|
init_device_id();
|
|
6078
|
+
|
|
6079
|
+
// src/install/one-click-exchange.ts
|
|
6080
|
+
async function exchangeOneClickToken(args) {
|
|
6081
|
+
const fetchImpl = args.fetchImpl ?? fetch;
|
|
6082
|
+
const controller = new AbortController();
|
|
6083
|
+
const timer = setTimeout(() => controller.abort(), args.timeoutMs ?? 1e4);
|
|
6084
|
+
try {
|
|
6085
|
+
const res = await fetchImpl(args.url, {
|
|
6086
|
+
method: "POST",
|
|
6087
|
+
headers: { "content-type": "application/json" },
|
|
6088
|
+
body: JSON.stringify({
|
|
6089
|
+
token: args.token,
|
|
6090
|
+
device_id: args.deviceId,
|
|
6091
|
+
label: args.label,
|
|
6092
|
+
client_meta: args.clientMeta
|
|
6093
|
+
}),
|
|
6094
|
+
signal: controller.signal
|
|
6095
|
+
});
|
|
6096
|
+
let body = {};
|
|
6097
|
+
try {
|
|
6098
|
+
body = await res.json();
|
|
6099
|
+
} catch {
|
|
6100
|
+
}
|
|
6101
|
+
if (!res.ok) {
|
|
6102
|
+
return { ok: false, reason: body.error ?? `http_${res.status}` };
|
|
6103
|
+
}
|
|
6104
|
+
if (body.status !== "exchanged" || typeof body.api_key !== "string" || !body.api_key.startsWith("mnd_")) {
|
|
6105
|
+
return { ok: false, reason: "unexpected_response" };
|
|
6106
|
+
}
|
|
6107
|
+
return { ok: true, apiKey: body.api_key, plan: body.plan ?? "unknown" };
|
|
6108
|
+
} catch (err) {
|
|
6109
|
+
if (err instanceof Error && err.name === "AbortError") {
|
|
6110
|
+
return { ok: false, reason: "timeout" };
|
|
6111
|
+
}
|
|
6112
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
6113
|
+
} finally {
|
|
6114
|
+
clearTimeout(timer);
|
|
6115
|
+
}
|
|
6116
|
+
}
|
|
6117
|
+
|
|
6118
|
+
// src/install/browser-pair.ts
|
|
6032
6119
|
async function pairOrUseToken(opts) {
|
|
6033
6120
|
const targetKey = "browser-pair";
|
|
6034
6121
|
if (opts.token !== null) {
|
|
@@ -6068,6 +6155,47 @@ async function pairOrUseToken(opts) {
|
|
|
6068
6155
|
};
|
|
6069
6156
|
}
|
|
6070
6157
|
}
|
|
6158
|
+
let exchangeFailure = null;
|
|
6159
|
+
if (opts.oneClickToken !== null && opts.oneClickExchangeUrl !== null) {
|
|
6160
|
+
if (opts.dryRun) {
|
|
6161
|
+
return {
|
|
6162
|
+
apiKey: null,
|
|
6163
|
+
result: {
|
|
6164
|
+
target: targetKey,
|
|
6165
|
+
action: "exchange",
|
|
6166
|
+
status: "would-pair",
|
|
6167
|
+
detail: "would exchange one-click token for a device-bound key (no browser)"
|
|
6168
|
+
}
|
|
6169
|
+
};
|
|
6170
|
+
}
|
|
6171
|
+
const meta = clientMeta(opts.bridgeVersion);
|
|
6172
|
+
const exchanged = await exchangeOneClickToken({
|
|
6173
|
+
token: opts.oneClickToken,
|
|
6174
|
+
url: opts.oneClickExchangeUrl,
|
|
6175
|
+
deviceId: meta.device_id,
|
|
6176
|
+
label: bridgeLabel(),
|
|
6177
|
+
clientMeta: { ...meta }
|
|
6178
|
+
});
|
|
6179
|
+
if (exchanged.ok) {
|
|
6180
|
+
clearApiKey();
|
|
6181
|
+
writeApiKey(exchanged.apiKey);
|
|
6182
|
+
return {
|
|
6183
|
+
apiKey: exchanged.apiKey,
|
|
6184
|
+
result: {
|
|
6185
|
+
target: targetKey,
|
|
6186
|
+
action: "exchange",
|
|
6187
|
+
status: "created",
|
|
6188
|
+
detail: `device-bound api-key via one-click exchange (plan: ${exchanged.plan})`
|
|
6189
|
+
}
|
|
6190
|
+
};
|
|
6191
|
+
}
|
|
6192
|
+
exchangeFailure = exchanged.reason;
|
|
6193
|
+
out(opts).write(
|
|
6194
|
+
`[maind-mcp-bridge] one-click exchange failed (${exchanged.reason}) \u2014 falling back to browser pairing.
|
|
6195
|
+
`
|
|
6196
|
+
);
|
|
6197
|
+
}
|
|
6198
|
+
const fallbackNote = exchangeFailure === null ? "" : ` (after exchange failure: ${exchangeFailure})`;
|
|
6071
6199
|
const cached = readApiKey();
|
|
6072
6200
|
if (cached !== null) {
|
|
6073
6201
|
return {
|
|
@@ -6076,7 +6204,7 @@ async function pairOrUseToken(opts) {
|
|
|
6076
6204
|
target: targetKey,
|
|
6077
6205
|
action: "skip",
|
|
6078
6206
|
status: "skipped",
|
|
6079
|
-
detail:
|
|
6207
|
+
detail: `device already paired \u2014 use --reauth to force a fresh pairing${fallbackNote}`
|
|
6080
6208
|
}
|
|
6081
6209
|
};
|
|
6082
6210
|
}
|
|
@@ -6092,7 +6220,7 @@ async function pairOrUseToken(opts) {
|
|
|
6092
6220
|
};
|
|
6093
6221
|
}
|
|
6094
6222
|
try {
|
|
6095
|
-
const flow = await runDeviceFlow(opts.bridgeVersion);
|
|
6223
|
+
const flow = await runDeviceFlow(opts.bridgeVersion, out(opts));
|
|
6096
6224
|
if (flow === null) {
|
|
6097
6225
|
return {
|
|
6098
6226
|
apiKey: null,
|
|
@@ -6100,7 +6228,7 @@ async function pairOrUseToken(opts) {
|
|
|
6100
6228
|
target: targetKey,
|
|
6101
6229
|
action: "pair",
|
|
6102
6230
|
status: "failed",
|
|
6103
|
-
detail:
|
|
6231
|
+
detail: `device-authorization flow did not complete (denied / expired / timeout)${fallbackNote}`
|
|
6104
6232
|
}
|
|
6105
6233
|
};
|
|
6106
6234
|
}
|
|
@@ -6110,7 +6238,7 @@ async function pairOrUseToken(opts) {
|
|
|
6110
6238
|
target: targetKey,
|
|
6111
6239
|
action: "pair",
|
|
6112
6240
|
status: "created",
|
|
6113
|
-
detail: `device-bound api-key written (plan: ${flow.plan})`
|
|
6241
|
+
detail: `device-bound api-key written (plan: ${flow.plan})${fallbackNote}`
|
|
6114
6242
|
}
|
|
6115
6243
|
};
|
|
6116
6244
|
} catch (err) {
|
|
@@ -6140,6 +6268,9 @@ function validateTokenShape(token) {
|
|
|
6140
6268
|
function errMessage2(err) {
|
|
6141
6269
|
return err instanceof Error ? err.message : String(err);
|
|
6142
6270
|
}
|
|
6271
|
+
function out(opts) {
|
|
6272
|
+
return opts.out ?? process.stdout;
|
|
6273
|
+
}
|
|
6143
6274
|
|
|
6144
6275
|
// src/install/telemetry.ts
|
|
6145
6276
|
var DEFAULT_FUNCTIONS_ORIGIN2 = "https://vsddmiosisvfrairepxv.supabase.co/functions/v1";
|
|
@@ -6201,179 +6332,9 @@ function parseNodeMajor(version) {
|
|
|
6201
6332
|
return Number.parseInt(m[1], 10);
|
|
6202
6333
|
}
|
|
6203
6334
|
|
|
6204
|
-
// src/install/index.ts
|
|
6205
|
-
var DEFAULT_MCP_URL2 = "https://mcp.maind.dev/mcp";
|
|
6206
|
-
async function runInstall(argv) {
|
|
6207
|
-
const startTime = Date.now();
|
|
6208
|
-
let flags;
|
|
6209
|
-
try {
|
|
6210
|
-
flags = parseInstallFlags(argv);
|
|
6211
|
-
} catch (err) {
|
|
6212
|
-
if (err instanceof InstallFlagError) {
|
|
6213
|
-
process.stderr.write(`error: ${err.message}
|
|
6214
|
-
`);
|
|
6215
|
-
process.stderr.write("Run `npx -y @maind-dev/mcp-bridge install --help` for usage.\n");
|
|
6216
|
-
return 2;
|
|
6217
|
-
}
|
|
6218
|
-
throw err;
|
|
6219
|
-
}
|
|
6220
|
-
if (flags.help) {
|
|
6221
|
-
printInstallHelp();
|
|
6222
|
-
return 0;
|
|
6223
|
-
}
|
|
6224
|
-
const isTtyStdin = Boolean(process.stdin.isTTY);
|
|
6225
|
-
const isInteractive = isTtyStdin && !flags.nonInteractive;
|
|
6226
|
-
const homeDir = os.homedir();
|
|
6227
|
-
if (homeDir.trim().length === 0) {
|
|
6228
|
-
process.stderr.write("error: could not resolve home directory (os.homedir() returned empty)\n");
|
|
6229
|
-
return 2;
|
|
6230
|
-
}
|
|
6231
|
-
let projectRoot;
|
|
6232
|
-
if (flags.projectRoot !== null) {
|
|
6233
|
-
projectRoot = flags.projectRoot;
|
|
6234
|
-
} else {
|
|
6235
|
-
const candidates = await findAllProjectRoots(process.cwd());
|
|
6236
|
-
if (candidates.length === 0) {
|
|
6237
|
-
projectRoot = await detectProjectRoot(process.cwd());
|
|
6238
|
-
} else if (candidates.length === 1) {
|
|
6239
|
-
projectRoot = candidates[0];
|
|
6240
|
-
} else {
|
|
6241
|
-
const chosen = await disambiguateProjectRoot(candidates, isInteractive);
|
|
6242
|
-
if (chosen === null) {
|
|
6243
|
-
process.stderr.write(
|
|
6244
|
-
"error: multiple project roots found and we cannot prompt (non-interactive). Pass --project-root <path> to pick one explicitly.\n"
|
|
6245
|
-
);
|
|
6246
|
-
for (const c of candidates) process.stderr.write(` candidate: ${c}
|
|
6247
|
-
`);
|
|
6248
|
-
return 2;
|
|
6249
|
-
}
|
|
6250
|
-
projectRoot = chosen;
|
|
6251
|
-
}
|
|
6252
|
-
}
|
|
6253
|
-
const report = new InstallReport();
|
|
6254
|
-
const mcpUrl = (process.env.MAIND_MCP_URL ?? "").trim() || DEFAULT_MCP_URL2;
|
|
6255
|
-
if (flags.dryRun) {
|
|
6256
|
-
process.stdout.write(
|
|
6257
|
-
"DRY RUN \u2014 computing the plan, no files will be modified.\n"
|
|
6258
|
-
);
|
|
6259
|
-
}
|
|
6260
|
-
process.stdout.write(`maind install \u2014 project root: ${projectRoot}
|
|
6261
|
-
`);
|
|
6262
|
-
process.stdout.write(` \u2014 mcp endpoint: ${mcpUrl}
|
|
6263
|
-
|
|
6264
|
-
`);
|
|
6265
|
-
const pairOutcome = await pairOrUseToken({
|
|
6266
|
-
bridgeVersion: BRIDGE_VERSION,
|
|
6267
|
-
token: flags.token,
|
|
6268
|
-
dryRun: flags.dryRun
|
|
6269
|
-
});
|
|
6270
|
-
report.add(pairOutcome.result);
|
|
6271
|
-
if (pairOutcome.result.status === "failed") {
|
|
6272
|
-
process.stderr.write(
|
|
6273
|
-
`
|
|
6274
|
-
pairing failed: ${pairOutcome.result.detail ?? "unknown"}
|
|
6275
|
-
Skipping remaining steps.
|
|
6276
|
-
`
|
|
6277
|
-
);
|
|
6278
|
-
report.print(process.stdout);
|
|
6279
|
-
return 2;
|
|
6280
|
-
}
|
|
6281
|
-
const ctx = makeDefaultContext({
|
|
6282
|
-
projectRoot,
|
|
6283
|
-
homeDir,
|
|
6284
|
-
platform: process.platform,
|
|
6285
|
-
env: process.env
|
|
6286
|
-
});
|
|
6287
|
-
let targets = getClientTargets(ctx);
|
|
6288
|
-
targets = filterTargetsByFamily(targets, flags.client);
|
|
6289
|
-
if (flags.skipCodex) {
|
|
6290
|
-
targets = targets.filter((t) => t.key !== "codex-cli");
|
|
6291
|
-
}
|
|
6292
|
-
if (targets.length === 0) {
|
|
6293
|
-
process.stderr.write(
|
|
6294
|
-
flags.client !== null ? `error: --client "${flags.client}" matched no known target. Run --help for the list.
|
|
6295
|
-
` : "error: no client targets selected (did you skip all of them?)\n"
|
|
6296
|
-
);
|
|
6297
|
-
report.print(process.stdout);
|
|
6298
|
-
return 2;
|
|
6299
|
-
}
|
|
6300
|
-
for (const target of targets) {
|
|
6301
|
-
const serverEntry = buildMaindServerEntry({
|
|
6302
|
-
mcpUrl,
|
|
6303
|
-
clientFamily: target.clientFamilyEnv
|
|
6304
|
-
});
|
|
6305
|
-
let result;
|
|
6306
|
-
if (target.kind === "json") {
|
|
6307
|
-
result = await mergeJsonConfig(target, serverEntry, flags.dryRun);
|
|
6308
|
-
} else {
|
|
6309
|
-
result = await mergeTomlConfig(target, serverEntry, flags.dryRun);
|
|
6310
|
-
}
|
|
6311
|
-
report.add(result);
|
|
6312
|
-
}
|
|
6313
|
-
if (!flags.noPreamble) {
|
|
6314
|
-
const preambleResults = await writePreambleFiles(
|
|
6315
|
-
{ projectRoot, homeDir },
|
|
6316
|
-
flags.dryRun
|
|
6317
|
-
);
|
|
6318
|
-
for (const r of preambleResults) report.add(r);
|
|
6319
|
-
} else {
|
|
6320
|
-
report.add({
|
|
6321
|
-
target: "preamble:*",
|
|
6322
|
-
action: "skip",
|
|
6323
|
-
status: "skipped",
|
|
6324
|
-
detail: "--no-preamble"
|
|
6325
|
-
});
|
|
6326
|
-
}
|
|
6327
|
-
const hookOpts = {
|
|
6328
|
-
homeDir,
|
|
6329
|
-
isInteractive,
|
|
6330
|
-
full: flags.full,
|
|
6331
|
-
skip: flags.noHook,
|
|
6332
|
-
dryRun: flags.dryRun,
|
|
6333
|
-
out: process.stdout
|
|
6334
|
-
};
|
|
6335
|
-
report.add(await mergeSessionStartHook(hookOpts));
|
|
6336
|
-
report.add(await mergeSessionStartMetricsHook(hookOpts));
|
|
6337
|
-
report.add(await mergeToolUseHook(hookOpts));
|
|
6338
|
-
report.add(await mergeFileWriteHook(hookOpts));
|
|
6339
|
-
report.add(await mergeStopHook(hookOpts));
|
|
6340
|
-
if (!flags.dryRun) {
|
|
6341
|
-
await postInstallTelemetry({
|
|
6342
|
-
enabled: flags.telemetry || flags.full,
|
|
6343
|
-
installerVersion: BRIDGE_VERSION,
|
|
6344
|
-
summary: report.summary(),
|
|
6345
|
-
steps: report.results_(),
|
|
6346
|
-
wallClockMs: Date.now() - startTime,
|
|
6347
|
-
apiKey: pairOutcome.apiKey,
|
|
6348
|
-
clientFamilyFilter: flags.client
|
|
6349
|
-
});
|
|
6350
|
-
}
|
|
6351
|
-
report.print(process.stdout);
|
|
6352
|
-
const exitCode = report.exitCode();
|
|
6353
|
-
const wallClockSec = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
6354
|
-
if (flags.dryRun) {
|
|
6355
|
-
process.stdout.write(
|
|
6356
|
-
`
|
|
6357
|
-
DRY RUN finished in ${wallClockSec}s. No files were modified. Re-run without --dry-run to apply.
|
|
6358
|
-
`
|
|
6359
|
-
);
|
|
6360
|
-
} else {
|
|
6361
|
-
process.stdout.write(
|
|
6362
|
-
`
|
|
6363
|
-
Finished in ${wallClockSec}s. Restart your MCP client so it picks up the new server entry.
|
|
6364
|
-
`
|
|
6365
|
-
);
|
|
6366
|
-
}
|
|
6367
|
-
if (exitCode === 1) {
|
|
6368
|
-
process.stdout.write(
|
|
6369
|
-
"Note: some steps were skipped or failed \u2014 review the table above. The MCP setup is usable as long as 'browser-pair' and at least one JSON/TOML target succeeded.\n"
|
|
6370
|
-
);
|
|
6371
|
-
}
|
|
6372
|
-
return exitCode;
|
|
6373
|
-
}
|
|
6374
|
-
|
|
6375
6335
|
// src/local-tools/engine.ts
|
|
6376
6336
|
import { execFileSync as execFileSync5 } from "node:child_process";
|
|
6337
|
+
import { createRequire as createRequire3 } from "node:module";
|
|
6377
6338
|
|
|
6378
6339
|
// ../../packages/code-index/build/node.js
|
|
6379
6340
|
import { mkdirSync as mkdirSync3 } from "node:fs";
|
|
@@ -6770,7 +6731,11 @@ init_engine();
|
|
|
6770
6731
|
// ../../packages/code-index/build/store/node-sqlite.js
|
|
6771
6732
|
init_schema();
|
|
6772
6733
|
init_identifiers();
|
|
6773
|
-
import
|
|
6734
|
+
import { createRequire as createRequire2 } from "node:module";
|
|
6735
|
+
var requireNative = createRequire2(import.meta.url);
|
|
6736
|
+
function loadDatabase() {
|
|
6737
|
+
return requireNative("better-sqlite3");
|
|
6738
|
+
}
|
|
6774
6739
|
function toNodeRow(r) {
|
|
6775
6740
|
return {
|
|
6776
6741
|
nodeKey: r.node_key,
|
|
@@ -6791,6 +6756,7 @@ var CHUNK = 400;
|
|
|
6791
6756
|
var NodeSqliteStore = class {
|
|
6792
6757
|
db;
|
|
6793
6758
|
constructor(dbPath) {
|
|
6759
|
+
const Database = loadDatabase();
|
|
6794
6760
|
this.db = new Database(dbPath);
|
|
6795
6761
|
this.db.pragma("journal_mode = WAL");
|
|
6796
6762
|
this.db.pragma("foreign_keys = ON");
|
|
@@ -7060,6 +7026,20 @@ function createNodeCodeIndex(opts) {
|
|
|
7060
7026
|
}
|
|
7061
7027
|
|
|
7062
7028
|
// src/local-tools/engine.ts
|
|
7029
|
+
function probeNativeStore() {
|
|
7030
|
+
try {
|
|
7031
|
+
createRequire3(import.meta.url)("better-sqlite3");
|
|
7032
|
+
return { ok: true };
|
|
7033
|
+
} catch (err) {
|
|
7034
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) };
|
|
7035
|
+
}
|
|
7036
|
+
}
|
|
7037
|
+
function isNativeStoreUnavailable(err) {
|
|
7038
|
+
const code = err?.code ?? "";
|
|
7039
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
7040
|
+
return /better.sqlite3|better_sqlite3|bindings file/i.test(`${code} ${msg}`) || code === "ERR_DLOPEN_FAILED" || /NODE_MODULE_VERSION/.test(msg);
|
|
7041
|
+
}
|
|
7042
|
+
var NATIVE_STORE_UNAVAILABLE_HINT = "codebase_* tools are unavailable on this machine: the native module better-sqlite3 could not be loaded. The MCP bridge itself is unaffected. To enable the local codebase tools, reinstall the bridge with build scripts enabled or run `npm rebuild better-sqlite3` in its install prefix.";
|
|
7063
7043
|
function resolveRepoRoot2(cwd = process.cwd()) {
|
|
7064
7044
|
try {
|
|
7065
7045
|
const top = execFileSync5("git", ["rev-parse", "--show-toplevel"], {
|
|
@@ -7077,6 +7057,197 @@ function defaultEngineFactory() {
|
|
|
7077
7057
|
return createNodeCodeIndex({ repoRoot: resolveRepoRoot2() });
|
|
7078
7058
|
}
|
|
7079
7059
|
|
|
7060
|
+
// src/install/index.ts
|
|
7061
|
+
var DEFAULT_MCP_URL2 = "https://mcp.maind.dev/mcp";
|
|
7062
|
+
async function runInstall(argv) {
|
|
7063
|
+
const startTime = Date.now();
|
|
7064
|
+
let flags;
|
|
7065
|
+
try {
|
|
7066
|
+
flags = parseInstallFlags(argv);
|
|
7067
|
+
} catch (err) {
|
|
7068
|
+
if (err instanceof InstallFlagError) {
|
|
7069
|
+
process.stderr.write(`error: ${err.message}
|
|
7070
|
+
`);
|
|
7071
|
+
process.stderr.write("Run `npx -y @maind-dev/mcp-bridge install --help` for usage.\n");
|
|
7072
|
+
return 2;
|
|
7073
|
+
}
|
|
7074
|
+
throw err;
|
|
7075
|
+
}
|
|
7076
|
+
if (flags.help) {
|
|
7077
|
+
printInstallHelp();
|
|
7078
|
+
return 0;
|
|
7079
|
+
}
|
|
7080
|
+
const isTtyStdin = Boolean(process.stdin.isTTY);
|
|
7081
|
+
const isInteractive = isTtyStdin && !flags.nonInteractive;
|
|
7082
|
+
const homeDir = os.homedir();
|
|
7083
|
+
if (homeDir.trim().length === 0) {
|
|
7084
|
+
process.stderr.write("error: could not resolve home directory (os.homedir() returned empty)\n");
|
|
7085
|
+
return 2;
|
|
7086
|
+
}
|
|
7087
|
+
let projectRoot;
|
|
7088
|
+
if (flags.projectRoot !== null) {
|
|
7089
|
+
projectRoot = flags.projectRoot;
|
|
7090
|
+
} else {
|
|
7091
|
+
const candidates = await findAllProjectRoots(process.cwd());
|
|
7092
|
+
if (candidates.length === 0) {
|
|
7093
|
+
projectRoot = await detectProjectRoot(process.cwd());
|
|
7094
|
+
} else if (candidates.length === 1) {
|
|
7095
|
+
projectRoot = candidates[0];
|
|
7096
|
+
} else {
|
|
7097
|
+
const chosen = await disambiguateProjectRoot(candidates, isInteractive);
|
|
7098
|
+
if (chosen === null) {
|
|
7099
|
+
process.stderr.write(
|
|
7100
|
+
"error: multiple project roots found and we cannot prompt (non-interactive). Pass --project-root <path> to pick one explicitly.\n"
|
|
7101
|
+
);
|
|
7102
|
+
for (const c of candidates) process.stderr.write(` candidate: ${c}
|
|
7103
|
+
`);
|
|
7104
|
+
return 2;
|
|
7105
|
+
}
|
|
7106
|
+
projectRoot = chosen;
|
|
7107
|
+
}
|
|
7108
|
+
}
|
|
7109
|
+
const report = new InstallReport();
|
|
7110
|
+
const mcpUrl = (process.env.MAIND_MCP_URL ?? "").trim() || DEFAULT_MCP_URL2;
|
|
7111
|
+
if (flags.dryRun) {
|
|
7112
|
+
process.stdout.write(
|
|
7113
|
+
"DRY RUN \u2014 computing the plan, no files will be modified.\n"
|
|
7114
|
+
);
|
|
7115
|
+
}
|
|
7116
|
+
process.stdout.write(`maind install \u2014 project root: ${projectRoot}
|
|
7117
|
+
`);
|
|
7118
|
+
process.stdout.write(` \u2014 mcp endpoint: ${mcpUrl}
|
|
7119
|
+
|
|
7120
|
+
`);
|
|
7121
|
+
const pairOutcome = await pairOrUseToken({
|
|
7122
|
+
bridgeVersion: BRIDGE_VERSION,
|
|
7123
|
+
token: flags.token,
|
|
7124
|
+
oneClickToken: flags.oneClickToken,
|
|
7125
|
+
oneClickExchangeUrl: flags.oneClickExchangeUrl,
|
|
7126
|
+
dryRun: flags.dryRun,
|
|
7127
|
+
out: process.stdout
|
|
7128
|
+
});
|
|
7129
|
+
report.add(pairOutcome.result);
|
|
7130
|
+
if (pairOutcome.result.status === "failed") {
|
|
7131
|
+
process.stderr.write(
|
|
7132
|
+
`
|
|
7133
|
+
pairing failed: ${pairOutcome.result.detail ?? "unknown"}
|
|
7134
|
+
Skipping remaining steps.
|
|
7135
|
+
`
|
|
7136
|
+
);
|
|
7137
|
+
report.print(process.stdout);
|
|
7138
|
+
return 2;
|
|
7139
|
+
}
|
|
7140
|
+
const ctx = makeDefaultContext({
|
|
7141
|
+
projectRoot,
|
|
7142
|
+
homeDir,
|
|
7143
|
+
platform: process.platform,
|
|
7144
|
+
env: process.env
|
|
7145
|
+
});
|
|
7146
|
+
let targets = getClientTargets(ctx);
|
|
7147
|
+
targets = filterTargetsByFamily(targets, flags.client);
|
|
7148
|
+
if (flags.skipCodex) {
|
|
7149
|
+
targets = targets.filter((t) => t.key !== "codex-cli");
|
|
7150
|
+
}
|
|
7151
|
+
if (targets.length === 0) {
|
|
7152
|
+
process.stderr.write(
|
|
7153
|
+
flags.client !== null ? `error: --client "${flags.client}" matched no known target. Run --help for the list.
|
|
7154
|
+
` : "error: no client targets selected (did you skip all of them?)\n"
|
|
7155
|
+
);
|
|
7156
|
+
report.print(process.stdout);
|
|
7157
|
+
return 2;
|
|
7158
|
+
}
|
|
7159
|
+
for (const target of targets) {
|
|
7160
|
+
const serverEntry = buildMaindServerEntry({
|
|
7161
|
+
mcpUrl,
|
|
7162
|
+
clientFamily: target.clientFamilyEnv
|
|
7163
|
+
});
|
|
7164
|
+
let result;
|
|
7165
|
+
if (target.kind === "json") {
|
|
7166
|
+
result = await mergeJsonConfig(target, serverEntry, flags.dryRun);
|
|
7167
|
+
} else {
|
|
7168
|
+
result = await mergeTomlConfig(target, serverEntry, flags.dryRun);
|
|
7169
|
+
}
|
|
7170
|
+
report.add(result);
|
|
7171
|
+
}
|
|
7172
|
+
if (!flags.noPreamble) {
|
|
7173
|
+
const preambleResults = await writePreambleFiles(
|
|
7174
|
+
{ projectRoot, homeDir },
|
|
7175
|
+
flags.dryRun
|
|
7176
|
+
);
|
|
7177
|
+
for (const r of preambleResults) report.add(r);
|
|
7178
|
+
} else {
|
|
7179
|
+
report.add({
|
|
7180
|
+
target: "preamble:*",
|
|
7181
|
+
action: "skip",
|
|
7182
|
+
status: "skipped",
|
|
7183
|
+
detail: "--no-preamble"
|
|
7184
|
+
});
|
|
7185
|
+
}
|
|
7186
|
+
const hookOpts = {
|
|
7187
|
+
homeDir,
|
|
7188
|
+
isInteractive,
|
|
7189
|
+
full: flags.full,
|
|
7190
|
+
skip: flags.noHook,
|
|
7191
|
+
dryRun: flags.dryRun,
|
|
7192
|
+
out: process.stdout
|
|
7193
|
+
};
|
|
7194
|
+
report.add(await mergeSessionStartHook(hookOpts));
|
|
7195
|
+
report.add(await mergeSessionStartMetricsHook(hookOpts));
|
|
7196
|
+
report.add(await mergeToolUseHook(hookOpts));
|
|
7197
|
+
report.add(await mergeFileWriteHook(hookOpts));
|
|
7198
|
+
report.add(await mergeStopHook(hookOpts));
|
|
7199
|
+
const nativeProbe = probeNativeStore();
|
|
7200
|
+
if (!nativeProbe.ok) {
|
|
7201
|
+
report.add({
|
|
7202
|
+
target: "codebase-tools",
|
|
7203
|
+
action: "probe",
|
|
7204
|
+
status: "skipped",
|
|
7205
|
+
detail: `codebase_* tools disabled \u2014 better-sqlite3 unavailable (${nativeProbe.reason}). Bridge works; fix: npm rebuild better-sqlite3`
|
|
7206
|
+
});
|
|
7207
|
+
}
|
|
7208
|
+
if (!flags.dryRun) {
|
|
7209
|
+
await postInstallTelemetry({
|
|
7210
|
+
enabled: flags.telemetry || flags.full,
|
|
7211
|
+
installerVersion: BRIDGE_VERSION,
|
|
7212
|
+
summary: report.summary(),
|
|
7213
|
+
steps: report.results_(),
|
|
7214
|
+
wallClockMs: Date.now() - startTime,
|
|
7215
|
+
apiKey: pairOutcome.apiKey,
|
|
7216
|
+
clientFamilyFilter: flags.client
|
|
7217
|
+
});
|
|
7218
|
+
}
|
|
7219
|
+
report.print(process.stdout);
|
|
7220
|
+
const exitCode = report.exitCode();
|
|
7221
|
+
const wallClockSec = ((Date.now() - startTime) / 1e3).toFixed(1);
|
|
7222
|
+
if (flags.dryRun) {
|
|
7223
|
+
process.stdout.write(
|
|
7224
|
+
`
|
|
7225
|
+
DRY RUN finished in ${wallClockSec}s. No files were modified. Re-run without --dry-run to apply.
|
|
7226
|
+
`
|
|
7227
|
+
);
|
|
7228
|
+
} else {
|
|
7229
|
+
process.stdout.write(
|
|
7230
|
+
`
|
|
7231
|
+
Finished in ${wallClockSec}s. Restart your MCP client so it picks up the new server entry.
|
|
7232
|
+
`
|
|
7233
|
+
);
|
|
7234
|
+
}
|
|
7235
|
+
const launch = resolveBridgeLaunch({
|
|
7236
|
+
entryPath: currentBridgeEntry(),
|
|
7237
|
+
nodePath: process.execPath,
|
|
7238
|
+
isElectron: process.versions.electron !== void 0
|
|
7239
|
+
});
|
|
7240
|
+
const reauthCmd = launch.fallbackReason === null ? `${launchToShellCommand(launch)} --reauth` : "npx -y @maind-dev/mcp-bridge --reauth";
|
|
7241
|
+
process.stdout.write(`Re-pair this device later with: ${reauthCmd}
|
|
7242
|
+
`);
|
|
7243
|
+
if (exitCode === 1) {
|
|
7244
|
+
process.stdout.write(
|
|
7245
|
+
"Note: some steps were skipped or failed \u2014 review the table above. The MCP setup is usable as long as 'browser-pair' and at least one JSON/TOML target succeeded.\n"
|
|
7246
|
+
);
|
|
7247
|
+
}
|
|
7248
|
+
return exitCode;
|
|
7249
|
+
}
|
|
7250
|
+
|
|
7080
7251
|
// src/local-tools/savings.ts
|
|
7081
7252
|
import { readFileSync as readFileSync5 } from "node:fs";
|
|
7082
7253
|
import { join as join10 } from "node:path";
|
|
@@ -7103,10 +7274,10 @@ var SavingsAggregator = class {
|
|
|
7103
7274
|
}
|
|
7104
7275
|
/** Return the pending delta and reset the accumulator. */
|
|
7105
7276
|
takePending() {
|
|
7106
|
-
const
|
|
7277
|
+
const out2 = { tokens: this.pendingTokens, calls: this.pendingCalls };
|
|
7107
7278
|
this.pendingTokens = 0;
|
|
7108
7279
|
this.pendingCalls = 0;
|
|
7109
|
-
return
|
|
7280
|
+
return out2;
|
|
7110
7281
|
}
|
|
7111
7282
|
};
|
|
7112
7283
|
function readFileCapped(absPath) {
|
|
@@ -7670,11 +7841,12 @@ var LocalToolRouter = class {
|
|
|
7670
7841
|
});
|
|
7671
7842
|
} catch (err) {
|
|
7672
7843
|
const message = err instanceof Error ? err.message : String(err);
|
|
7844
|
+
const text = isNativeStoreUnavailable(err) ? `${NATIVE_STORE_UNAVAILABLE_HINT} (${message})` : `codebase tool error: ${message}`;
|
|
7673
7845
|
return JSON.stringify({
|
|
7674
7846
|
jsonrpc: "2.0",
|
|
7675
7847
|
id,
|
|
7676
7848
|
result: {
|
|
7677
|
-
content: [{ type: "text", text
|
|
7849
|
+
content: [{ type: "text", text }],
|
|
7678
7850
|
isError: true
|
|
7679
7851
|
}
|
|
7680
7852
|
});
|
|
@@ -8033,9 +8205,9 @@ async function main() {
|
|
|
8033
8205
|
}
|
|
8034
8206
|
if (process.argv.includes("--reauth")) {
|
|
8035
8207
|
clearApiKey();
|
|
8036
|
-
const result = await runDeviceFlow(BRIDGE_VERSION);
|
|
8208
|
+
const result = await runDeviceFlow(BRIDGE_VERSION, process.stdout);
|
|
8037
8209
|
if (result === null) process.exit(1);
|
|
8038
|
-
process.
|
|
8210
|
+
process.stdout.write("[maind-mcp-bridge] re-authorization complete.\n");
|
|
8039
8211
|
process.exit(0);
|
|
8040
8212
|
}
|
|
8041
8213
|
const deviceId = ensureDeviceId();
|