baseline: dsh 工作区基线快照(2026-09-10,全新历史起点)
本提交为 dsh_mcn_workshop 仓库的首个提交(旧仓 dsh_MCNProject 已停用), 完整固化 C:/Users/Administrator/.dsh 当前磁盘状态。 1) 临时数据清理:移出 sessions/(81M)、logs/、skill-backup-20260906/(14M)、 scripts/__pycache__、storages/workspace.json.bak —— 合计 94M(.dsh 162M → 68M) 2) 凭据脱敏:.credentials.yaml(含明文 DEEPSEEK_API_KEY)移出 git 跟踪并加入 .gitignore;mcn-data-insight/scripts/setup_redfox_key.py 中真实 key 示例改为占位符 3) .gitignore 增补 logs/、skill-backup-*/ 规则 4) 技能结构以当前磁盘状态为准:skills/ = mcn-short-video / impeccable / taste-skill / dsh-multi-user-migration;旧技能目录(mcn-dou-analysis、storyboard-prompt、 short-video-script、browser-harness、mcn-data-insight)与 profiles/web/node_modules/dsh-vision-router 本地已不存在,本提交记为删除
This commit is contained in:
commit
856e632807
880 files changed
+225426
No files matched your search
+61
@@ -0,0 +1,61 @@
|
||||
// dsh-plugin-mcn MCP stdio 客户端(复用已验证方案;拆分自 index.js)
|
||||
import { homedir } from "node:os";
|
||||
import { join, isAbsolute, resolve } from "node:path";
|
||||
import { spawn } from "node:child_process";
|
||||
import { NPX_CMD, MCP_PACKAGE, MCP_ENV } from "./config.js";
|
||||
|
||||
function dshHome() {
|
||||
const configured = process.env.DSH_HOME?.trim();
|
||||
if (!configured) return join(homedir(), ".dsh");
|
||||
return isAbsolute(configured) ? configured : resolve(configured);
|
||||
}
|
||||
|
||||
function callMcpTool(toolName, args = {}) {
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
const reqs = [
|
||||
JSON.stringify({ jsonrpc: "2.0", id: 1, method: "initialize", params: { protocolVersion: "2024-11-05", capabilities: {}, clientInfo: { name: "dsh-plugin-mcn", version: "0.1.0" } } }),
|
||||
JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }),
|
||||
JSON.stringify({ jsonrpc: "2.0", id: 2, method: "tools/call", params: { name: toolName, arguments: args } }),
|
||||
].join("\n") + "\n";
|
||||
|
||||
const child = spawn(NPX_CMD, ["-y", MCP_PACKAGE], {
|
||||
env: { ...process.env, ...MCP_ENV },
|
||||
shell: true,
|
||||
stdio: ["pipe", "pipe", "inherit"],
|
||||
});
|
||||
let stdout = "";
|
||||
let settled = false;
|
||||
const timer = setTimeout(() => {
|
||||
if (!settled) { settled = true; child.kill(); reject(new Error("MCP 调用超时")); }
|
||||
}, 120000);
|
||||
|
||||
child.stdout.on("data", (chunk) => { stdout += chunk.toString("utf8"); });
|
||||
child.on("close", (code) => {
|
||||
if (settled) return;
|
||||
settled = true;
|
||||
clearTimeout(timer);
|
||||
try {
|
||||
// 找到 id=2 的响应
|
||||
const lines = stdout.split("\n");
|
||||
for (const line of lines) {
|
||||
if (!line.includes('"id":2')) continue;
|
||||
const msg = JSON.parse(line);
|
||||
if (msg.result?.isError) { reject(new Error(msg.result.content?.[0]?.text || "MCP 工具报错")); return; }
|
||||
// 优先 structuredContent(结构化数据);无则回退 text(格式化文本)
|
||||
const sc = msg.result?.structuredContent;
|
||||
const text = msg.result?.content?.[0]?.text ?? "";
|
||||
resolvePromise({ structured: sc ?? null, text });
|
||||
return;
|
||||
}
|
||||
reject(new Error("未找到 MCP 工具响应"));
|
||||
} catch (e) {
|
||||
reject(new Error("解析 MCP 响应失败: " + e.message));
|
||||
}
|
||||
});
|
||||
child.stdin.write(reqs);
|
||||
child.stdin.end();
|
||||
child.on("error", (e) => { if (!settled) { settled = true; clearTimeout(timer); reject(new Error("MCP 进程启动失败: " + e.message)); } });
|
||||
});
|
||||
}
|
||||
|
||||
export { dshHome, callMcpTool };
|
||||
Reference in new issue
Block a user