[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:
108
electron/bridges/externalMcp/desktopCliResolver.cjs
Normal file
108
electron/bridges/externalMcp/desktopCliResolver.cjs
Normal file
@@ -0,0 +1,108 @@
|
||||
"use strict";
|
||||
|
||||
const fs = require("node:fs");
|
||||
const os = require("node:os");
|
||||
const path = require("node:path");
|
||||
|
||||
function isExecutableFile(filePath, deps) {
|
||||
try {
|
||||
if (!deps.existsSync(filePath)) return false;
|
||||
const stat = deps.statSync(filePath);
|
||||
if (!stat.isFile()) return false;
|
||||
// Prefer runtime access check so we skip candidates the process cannot
|
||||
// execute (mode bits alone miss ACL/ownership cases). Fall back to mode
|
||||
// bits when accessSync is not provided (tests can inject either).
|
||||
if (typeof deps.accessSync === "function") {
|
||||
deps.accessSync(filePath, deps.X_OK);
|
||||
return true;
|
||||
}
|
||||
return (stat.mode & 0o111) !== 0;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function findFirstExecutable(candidates, deps) {
|
||||
for (const candidate of candidates) {
|
||||
if (isExecutableFile(candidate, deps)) return candidate;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function compareVersionDirectoryNames(left, right) {
|
||||
return String(right).localeCompare(String(left), "en", {
|
||||
numeric: true,
|
||||
sensitivity: "base",
|
||||
});
|
||||
}
|
||||
|
||||
function resolveCodexDesktopCli(homeDir, deps) {
|
||||
const appRoots = [
|
||||
"/Applications/ChatGPT.app",
|
||||
"/Applications/Codex.app",
|
||||
path.join(homeDir, "Applications", "ChatGPT.app"),
|
||||
path.join(homeDir, "Applications", "Codex.app"),
|
||||
];
|
||||
return findFirstExecutable(
|
||||
appRoots.map((appRoot) => path.join(appRoot, "Contents", "Resources", "codex")),
|
||||
deps,
|
||||
);
|
||||
}
|
||||
|
||||
function resolveClaudeDesktopCli(homeDir, deps) {
|
||||
const versionsRoot = path.join(
|
||||
homeDir,
|
||||
"Library",
|
||||
"Application Support",
|
||||
"Claude",
|
||||
"claude-code",
|
||||
);
|
||||
|
||||
let versionDirectories;
|
||||
try {
|
||||
versionDirectories = deps.readdirSync(versionsRoot, { withFileTypes: true })
|
||||
.filter((entry) => entry.isDirectory())
|
||||
.map((entry) => entry.name)
|
||||
.sort(compareVersionDirectoryNames);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Only the native macOS app-bundle CLI. A sibling `<version>/claude` binary
|
||||
// may exist but is a Linux VM helper on current Claude Desktop installs, so
|
||||
// accepting it would break spawn and block falling back to an older good version.
|
||||
return findFirstExecutable(
|
||||
versionDirectories.map((version) => path.join(
|
||||
versionsRoot,
|
||||
version,
|
||||
"claude.app",
|
||||
"Contents",
|
||||
"MacOS",
|
||||
"claude",
|
||||
)),
|
||||
deps,
|
||||
);
|
||||
}
|
||||
|
||||
function resolveDesktopManagedCli(name, options = {}) {
|
||||
const platform = options.platform || process.platform;
|
||||
if (platform !== "darwin") return null;
|
||||
|
||||
const deps = {
|
||||
existsSync: options.existsSync || fs.existsSync,
|
||||
statSync: options.statSync || fs.statSync,
|
||||
readdirSync: options.readdirSync || fs.readdirSync,
|
||||
accessSync: options.accessSync || fs.accessSync,
|
||||
X_OK: options.X_OK != null ? options.X_OK : fs.constants.X_OK,
|
||||
};
|
||||
const homeDir = options.homeDir || os.homedir();
|
||||
|
||||
if (name === "codex") return resolveCodexDesktopCli(homeDir, deps);
|
||||
if (name === "claude") return resolveClaudeDesktopCli(homeDir, deps);
|
||||
return null;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
compareVersionDirectoryNames,
|
||||
resolveDesktopManagedCli,
|
||||
};
|
||||
Reference in New Issue
Block a user