From 91e4a2d7495fb8f3eb40ac4aeb18f8bf18d751b6 Mon Sep 17 00:00:00 2001 From: TheAchiever6823 <61914223+ShawnMadadha@users.noreply.github.com> Date: Wed, 20 May 2026 03:28:05 -0700 Subject: [PATCH] [shawn] chore: drop dead Instagram MCP CLI bridge from electron/main.js getInstagramMcpPackageRoot, resolveNodeForMcpCli, and runInstagramBuddyCli were orphaned when Instagram MCP was vendored into backend/apps/instagram_mcp. runInstagramBuddyCli had zero callers and was the only caller of the other two. Removes 102 lines of dead code; node --check still passes. --- electron/main.js | 102 ----------------------------------------------- 1 file changed, 102 deletions(-) diff --git a/electron/main.js b/electron/main.js index 92cea9d0..0356f0fb 100644 --- a/electron/main.js +++ b/electron/main.js @@ -281,108 +281,6 @@ function getBundledNodePath() { return fs.existsSync(candidate) ? candidate : null; } -/** - * Directory containing package.json + dist/index.js + node_modules for - * instagram-mcp-buddy (dev: monorepo root; packaged: extraResources/instagram-mcp). - */ -function getInstagramMcpPackageRoot() { - const base = isPackaged ? process.resourcesPath : path.join(__dirname, '..'); - return path.join(base, 'instagram-mcp'); -} - -/** - * Resolve a Node binary for spawning instagram-mcp-buddy. Prefer the same - * bundled Node shipped for 9Router/MCP so Finder-launched Mac apps work - * without a user PATH; fall back to OPENSWARM_NODE_PATH, login-shell resolution - * (dev), then `node` on PATH. - */ -function resolveNodeForMcpCli() { - const bundled = getBundledNodePath(); - if (bundled && fs.existsSync(bundled)) return bundled; - const fromEnv = process.env.OPENSWARM_NODE_PATH; - if (fromEnv && fs.existsSync(fromEnv)) return fromEnv; - if (!isPackaged && process.platform !== 'win32') { - try { - const shell = process.env.SHELL || '/bin/zsh'; - const p = execFileSync(shell, ['-lc', 'command -v node'], { - encoding: 'utf8', - timeout: 8000, - env: { ...process.env, HOME: os.homedir() }, - }).trim().split(/\r?\n/).filter(Boolean).pop(); - if (p && fs.existsSync(p)) return p; - } catch (_) { /* fall through */ } - for (const c of ['/opt/homebrew/bin/node', '/usr/local/bin/node']) { - if (fs.existsSync(c)) return c; - } - } - if (!isPackaged && process.platform === 'win32') { - try { - const p = execFileSync('where', ['node'], { encoding: 'utf8', timeout: 8000 }).trim().split(/\r?\n/).filter(Boolean)[0]; - if (p && fs.existsSync(p)) return p; - } catch (_) { /* fall through */ } - } - return process.platform === 'win32' ? 'node.exe' : 'node'; -} - -/** - * Run instagram-mcp-buddy connect|logout non-interactively. Prefers the workspace - * build at ../instagram-mcp/dist/index.js when present (dev / source tree); - * otherwise `npx -y instagram-mcp-buddy` so packaged apps work without shipping - * the subfolder. Inherits a shell-expanded PATH on macOS (see getShellPath). - * - * @param {'connect'|'logout'} subcommand - * @param {Record} [extraEnv] merged into child env (e.g. INSTAGRAM_MCP_ENABLE_* from MCP config) - * @returns {Promise>} - */ -function runInstagramBuddyCli(subcommand, extraEnv = {}) { - return new Promise((resolve, reject) => { - const igPkgRoot = getInstagramMcpPackageRoot(); - const localScript = path.join(igPkgRoot, 'dist', 'index.js'); - const pathMerged = [getShellPath(), process.env.PATH || ''].filter(Boolean).join(path.delimiter); - const env = { ...process.env, ...extraEnv, PATH: pathMerged }; - - let cmd; - let args; - let shell = false; - /** cwd for module resolution (instagram-mcp-buddy needs package node_modules). */ - let cwd = isPackaged ? process.resourcesPath : path.join(__dirname, '..'); - - if (fs.existsSync(localScript)) { - cmd = resolveNodeForMcpCli(); - args = [localScript, subcommand]; - cwd = igPkgRoot; - } else { - cmd = 'npx'; - args = ['-y', 'instagram-mcp-buddy', subcommand]; - if (process.platform === 'win32') shell = true; - } - - const child = spawn(cmd, args, { env, cwd, windowsHide: true, shell }); - let out = ''; - let err = ''; - child.stdout.on('data', (d) => { out += d.toString(); }); - child.stderr.on('data', (d) => { err += d.toString(); }); - child.on('error', (e) => reject(e)); - child.on('close', (code) => { - if (code !== 0) { - const msg = (err || '').trim() || (out || '').trim() || `instagram-mcp-buddy ${subcommand} exited ${code}`; - reject(new Error(msg)); - return; - } - const line = out.trim().split(/\r?\n/).filter(Boolean).pop(); - if (!line) { - reject(new Error(`instagram-mcp-buddy ${subcommand}: empty stdout`)); - return; - } - try { - resolve(JSON.parse(line)); - } catch (e) { - reject(new Error(`instagram-mcp-buddy ${subcommand}: invalid JSON: ${line.slice(0, 200)}`)); - } - }); - }); -} - // Never wall-clock times out: cold-Defender Windows can take minutes. function waitForBackend(port, opts = {}) { const proc = opts.process || null;