@bigbrain-work/mcp-connect 1.3.3 → 1.3.5
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/package.json +1 -1
- package/src/detection.js +12 -2
- package/src/keyring-worker.js +40 -0
- package/src/skill-refresh.js +19 -5
- package/src/token-store.js +72 -1
- package/src/updater.js +8 -1
package/package.json
CHANGED
package/src/detection.js
CHANGED
|
@@ -2,8 +2,18 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { access } from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
|
|
5
|
-
export function commandExists(
|
|
6
|
-
|
|
5
|
+
export function commandExists(
|
|
6
|
+
command,
|
|
7
|
+
spawn = spawnSync,
|
|
8
|
+
{ platform = process.platform, env = process.env } = {},
|
|
9
|
+
) {
|
|
10
|
+
if (!/^[a-z0-9_-]+$/iu.test(command)) return false;
|
|
11
|
+
const isWindows = platform === "win32";
|
|
12
|
+
const executable = isWindows ? env.ComSpec || "cmd.exe" : command;
|
|
13
|
+
const args = isWindows
|
|
14
|
+
? ["/d", "/s", "/c", `${command} --version`]
|
|
15
|
+
: ["--version"];
|
|
16
|
+
const result = spawn(executable, args, {
|
|
7
17
|
encoding: "utf8",
|
|
8
18
|
windowsHide: true,
|
|
9
19
|
shell: false,
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { stdin, stdout } from "node:process";
|
|
2
|
+
|
|
3
|
+
async function readRequest() {
|
|
4
|
+
let input = "";
|
|
5
|
+
stdin.setEncoding("utf8");
|
|
6
|
+
for await (const chunk of stdin) input += chunk;
|
|
7
|
+
return JSON.parse(input);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function validateRequest(request) {
|
|
11
|
+
if (
|
|
12
|
+
!request ||
|
|
13
|
+
!["get", "set", "delete"].includes(request.operation) ||
|
|
14
|
+
typeof request.service !== "string" ||
|
|
15
|
+
typeof request.account !== "string" ||
|
|
16
|
+
(request.operation === "set" && typeof request.password !== "string")
|
|
17
|
+
) {
|
|
18
|
+
throw new Error("凭据库请求无效");
|
|
19
|
+
}
|
|
20
|
+
return request;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
const request = validateRequest(await readRequest());
|
|
25
|
+
const { Entry } = await import("@napi-rs/keyring");
|
|
26
|
+
const entry = new Entry(request.service, request.account);
|
|
27
|
+
|
|
28
|
+
if (request.operation === "get") {
|
|
29
|
+
stdout.write(JSON.stringify({ value: await entry.getPassword() }));
|
|
30
|
+
} else if (request.operation === "set") {
|
|
31
|
+
await entry.setPassword(request.password);
|
|
32
|
+
stdout.write(JSON.stringify({ ok: true }));
|
|
33
|
+
} else {
|
|
34
|
+
await entry.deletePassword();
|
|
35
|
+
stdout.write(JSON.stringify({ ok: true }));
|
|
36
|
+
}
|
|
37
|
+
} catch (error) {
|
|
38
|
+
process.stderr.write(error?.message || String(error));
|
|
39
|
+
process.exitCode = 1;
|
|
40
|
+
}
|
package/src/skill-refresh.js
CHANGED
|
@@ -77,11 +77,25 @@ async function writeState(home, state) {
|
|
|
77
77
|
});
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
function
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
export function runSkillUpdate({
|
|
81
|
+
cwd,
|
|
82
|
+
platform = process.platform,
|
|
83
|
+
env = process.env,
|
|
84
|
+
spawnImpl = spawnSync,
|
|
85
|
+
}) {
|
|
86
|
+
const isWindows = platform === "win32";
|
|
87
|
+
const command = isWindows ? env.ComSpec || "cmd.exe" : "npx";
|
|
88
|
+
const args = isWindows
|
|
89
|
+
? [
|
|
90
|
+
"/d",
|
|
91
|
+
"/s",
|
|
92
|
+
"/c",
|
|
93
|
+
`npx.cmd -y skills update ${SHILIU_SKILL_NAME} -y`,
|
|
94
|
+
]
|
|
95
|
+
: ["-y", "skills", "update", SHILIU_SKILL_NAME, "-y"];
|
|
96
|
+
const result = spawnImpl(
|
|
83
97
|
command,
|
|
84
|
-
|
|
98
|
+
args,
|
|
85
99
|
{
|
|
86
100
|
cwd,
|
|
87
101
|
encoding: "utf8",
|
|
@@ -111,7 +125,7 @@ export async function refreshShiliuSkill({
|
|
|
111
125
|
now = Date.now(),
|
|
112
126
|
force = false,
|
|
113
127
|
intervalMs = SKILL_REFRESH_INTERVAL_MS,
|
|
114
|
-
runUpdate =
|
|
128
|
+
runUpdate = runSkillUpdate,
|
|
115
129
|
} = {}) {
|
|
116
130
|
if (!home) throw new Error("缺少用户目录,无法记录 Skill 检查时间");
|
|
117
131
|
const scope = path.resolve(cwd);
|
package/src/token-store.js
CHANGED
|
@@ -3,6 +3,12 @@ import {
|
|
|
3
3
|
KEYRING_SERVICE,
|
|
4
4
|
PENDING_KEYRING_ACCOUNT,
|
|
5
5
|
} from "./constants.js";
|
|
6
|
+
import { spawn } from "node:child_process";
|
|
7
|
+
import { fileURLToPath } from "node:url";
|
|
8
|
+
|
|
9
|
+
const KEYRING_WORKER_PATH = fileURLToPath(
|
|
10
|
+
new URL("./keyring-worker.js", import.meta.url),
|
|
11
|
+
);
|
|
6
12
|
|
|
7
13
|
function validateTokenSet(value) {
|
|
8
14
|
if (
|
|
@@ -17,7 +23,72 @@ function validateTokenSet(value) {
|
|
|
17
23
|
return value;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
|
-
|
|
26
|
+
export function runKeyringWorker(request, { spawnImpl = spawn } = {}) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const child = spawnImpl(process.execPath, [KEYRING_WORKER_PATH], {
|
|
29
|
+
windowsHide: true,
|
|
30
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
31
|
+
});
|
|
32
|
+
let stdout = "";
|
|
33
|
+
let stderr = "";
|
|
34
|
+
child.stdout.setEncoding("utf8");
|
|
35
|
+
child.stderr.setEncoding("utf8");
|
|
36
|
+
child.stdout.on("data", (chunk) => {
|
|
37
|
+
stdout += chunk;
|
|
38
|
+
});
|
|
39
|
+
child.stderr.on("data", (chunk) => {
|
|
40
|
+
stderr += chunk;
|
|
41
|
+
});
|
|
42
|
+
child.on("error", reject);
|
|
43
|
+
child.on("close", (code) => {
|
|
44
|
+
if (code !== 0) {
|
|
45
|
+
reject(new Error(stderr.trim() || `凭据库子进程返回退出码 ${code}`));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
resolve(JSON.parse(stdout));
|
|
50
|
+
} catch {
|
|
51
|
+
reject(new Error("凭据库子进程返回了无效响应"));
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
child.stdin.end(JSON.stringify(request));
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export async function createSystemEntry(
|
|
59
|
+
account,
|
|
60
|
+
{
|
|
61
|
+
platform = process.platform,
|
|
62
|
+
runWorker = runKeyringWorker,
|
|
63
|
+
} = {},
|
|
64
|
+
) {
|
|
65
|
+
if (platform === "win32") {
|
|
66
|
+
return {
|
|
67
|
+
async setPassword(password) {
|
|
68
|
+
await runWorker({
|
|
69
|
+
operation: "set",
|
|
70
|
+
service: KEYRING_SERVICE,
|
|
71
|
+
account,
|
|
72
|
+
password,
|
|
73
|
+
});
|
|
74
|
+
},
|
|
75
|
+
async getPassword() {
|
|
76
|
+
const result = await runWorker({
|
|
77
|
+
operation: "get",
|
|
78
|
+
service: KEYRING_SERVICE,
|
|
79
|
+
account,
|
|
80
|
+
});
|
|
81
|
+
return result.value;
|
|
82
|
+
},
|
|
83
|
+
async deletePassword() {
|
|
84
|
+
await runWorker({
|
|
85
|
+
operation: "delete",
|
|
86
|
+
service: KEYRING_SERVICE,
|
|
87
|
+
account,
|
|
88
|
+
});
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
21
92
|
let module;
|
|
22
93
|
try {
|
|
23
94
|
module = await import("@napi-rs/keyring");
|
package/src/updater.js
CHANGED
|
@@ -51,7 +51,14 @@ export async function printUpdateStatus(options = {}) {
|
|
|
51
51
|
const result = await checkForUpdates(options);
|
|
52
52
|
if (result.updateAvailable) {
|
|
53
53
|
console.log(`发现新版本:${result.current} → ${result.latest}`);
|
|
54
|
-
console.log(
|
|
54
|
+
console.log(
|
|
55
|
+
`更新命令:npm install -g ${PACKAGE_NAME}@latest --prefer-online`,
|
|
56
|
+
);
|
|
57
|
+
if (process.platform === "win32") {
|
|
58
|
+
console.log(
|
|
59
|
+
"Windows 覆盖升级前请关闭正在使用石榴 MCP 的 Agent,避免原生凭据库文件被占用。",
|
|
60
|
+
);
|
|
61
|
+
}
|
|
55
62
|
} else {
|
|
56
63
|
console.log(`当前版本:${result.current};npm latest:${result.latest}`);
|
|
57
64
|
}
|