[Init] Initial commit - NetMesh terminal manager
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
This commit is contained in:
91
electron/bridges/mcpServerBridge/configAndCleanup.cjs
Normal file
91
electron/bridges/mcpServerBridge/configAndCleanup.cjs
Normal file
@@ -0,0 +1,91 @@
|
||||
/* eslint-disable no-undef */
|
||||
function createConfigAndCleanupApi(ctx) {
|
||||
with (ctx) {
|
||||
function resolveMcpServerRuntimeCommand() {
|
||||
const runtimeCommand = process.execPath;
|
||||
const runtimeEnv = [];
|
||||
|
||||
if (runtimeCommand && existsSync(runtimeCommand)) {
|
||||
const basename = path.basename(runtimeCommand).toLowerCase();
|
||||
const isNodeBinary = basename === "node" || basename.startsWith("node.");
|
||||
if (!isNodeBinary) {
|
||||
runtimeEnv.push({ name: "ELECTRON_RUN_AS_NODE", value: "1" });
|
||||
}
|
||||
return { command: runtimeCommand, env: runtimeEnv };
|
||||
}
|
||||
|
||||
return { command: "node", env: runtimeEnv };
|
||||
}
|
||||
|
||||
function buildMcpServerConfig(port, scopedSessionIds, chatSessionId) {
|
||||
// Use provided scoped IDs, or resolve them from chatSessionId.
|
||||
const effectiveIds = (scopedSessionIds && scopedSessionIds.length > 0)
|
||||
? scopedSessionIds
|
||||
: getScopedSessionIds(chatSessionId);
|
||||
|
||||
const runtimePath = toUnpackedAsarPath(
|
||||
path.join(__dirname, "..", "mcp", "netcatty-mcp-server.cjs"),
|
||||
);
|
||||
const runtime = resolveMcpServerRuntimeCommand();
|
||||
|
||||
const env = [
|
||||
...runtime.env,
|
||||
{ name: "NETCATTY_MCP_PORT", value: String(port) },
|
||||
];
|
||||
|
||||
if (authToken) {
|
||||
env.push({ name: "NETCATTY_MCP_TOKEN", value: authToken });
|
||||
}
|
||||
if (DEBUG_MCP) {
|
||||
env.push({ name: "NETCATTY_MCP_DEBUG", value: "1" });
|
||||
}
|
||||
|
||||
// When chatSessionId is present, the MCP subprocess resolves scope dynamically
|
||||
// through main-process metadata, so avoid freezing session IDs at spawn time.
|
||||
if (!chatSessionId && effectiveIds && effectiveIds.length > 0) {
|
||||
env.push({ name: "NETCATTY_MCP_SESSION_IDS", value: effectiveIds.join(",") });
|
||||
}
|
||||
|
||||
// Pass chatSessionId so MCP server can scope getContext responses
|
||||
if (chatSessionId) {
|
||||
env.push({ name: "NETCATTY_MCP_CHAT_SESSION_ID", value: chatSessionId });
|
||||
}
|
||||
|
||||
// Pass permission mode so MCP server can enforce it locally (defense-in-depth)
|
||||
env.push({ name: "NETCATTY_MCP_PERMISSION_MODE", value: permissionMode });
|
||||
|
||||
return {
|
||||
name: "netcatty-remote-hosts",
|
||||
type: "stdio",
|
||||
command: runtime.command,
|
||||
args: [runtimePath],
|
||||
env,
|
||||
};
|
||||
}
|
||||
|
||||
// ── Cleanup ──
|
||||
|
||||
async function cleanupScopedMetadata(chatSessionId) {
|
||||
if (chatSessionId) {
|
||||
scopedMetadata.delete(chatSessionId);
|
||||
scopedAttachments.delete(chatSessionId);
|
||||
preserveIdleSessionCleanup?.(chatSessionId);
|
||||
clearOpenedSessionScope?.(chatSessionId);
|
||||
cancelledChatSessions.delete(chatSessionId);
|
||||
cancelBackgroundJobsForSession(chatSessionId);
|
||||
cancelWorkerBackgroundJobsForSession(chatSessionId);
|
||||
// Resolve any in-flight approval requests so dispatch()'s finally block
|
||||
// releases its pendingSessionWriteApprovals entry. Without this, a chat
|
||||
// deleted while an approval was pending would leave the per-session
|
||||
// write lock held until the approval timeout expires.
|
||||
clearPendingApprovals(chatSessionId);
|
||||
await cancelSftpOpsForSession(chatSessionId);
|
||||
sftpBridge.clearSftpEncodingStateByPrefix?.(`chat:${chatSessionId}:session:`);
|
||||
}
|
||||
}
|
||||
|
||||
return { resolveMcpServerRuntimeCommand, buildMcpServerConfig, cleanupScopedMetadata };
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { createConfigAndCleanupApi };
|
||||
Reference in New Issue
Block a user