@2501-ai/cli
Version:
[](https://www.npmjs.com/package/@2501-ai/cli) [](https://www.2501.ai/research/full-humaneval-benchmark) [); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getRemoteSystemInfo = getRemoteSystemInfo;
const logger_1 = __importDefault(require("../utils/logger"));
const systemInfo_1 = require("../utils/systemInfo");
const remoteExecutor_1 = require("./remoteExecutor");
const windowsHelper_1 = require("./windowsHelper");
function getRemoteGlobalNpmPackages(platform) {
return __awaiter(this, void 0, void 0, function* () {
if (platform === 'fortigate') {
return [];
}
try {
const command = platform === 'windows'
? 'npm list -g --depth=0 | findstr /R "^[├└]" | findstr "@"'
: 'npm list -g --depth=0 | awk "{print $2}" | grep @';
const executor = remoteExecutor_1.RemoteExecutor.instance;
const output = yield executor.executeCommand(command);
const packageLines = output.trim().split('\n').filter(Boolean);
if (platform === 'windows') {
if ((0, windowsHelper_1.isCommandNotFound)(output)) {
return [];
}
return packageLines
.map((line) => line.replace(/^[+--\s]+/, '').split('@')[0] +
'@' +
line.split('@')[1])
.filter((pkg) => pkg.includes('@'))
.map(windowsHelper_1.sanitizeWindowsOutput);
}
else {
return packageLines.filter((pkg) => pkg.includes('@'));
}
}
catch (error) {
logger_1.default.debug('Error executing npm list command on remote:', error.message);
if (error instanceof Error && (0, windowsHelper_1.isCommandNotFound)(error.message)) {
return [];
}
return [];
}
});
}
function getRemoteVersion(command) {
return __awaiter(this, void 0, void 0, function* () {
try {
const executor = remoteExecutor_1.RemoteExecutor.instance;
const result = yield executor.executeCommand(command);
if ((0, windowsHelper_1.isCommandNotFound)(result)) {
return '(not found)';
}
return (0, windowsHelper_1.sanitizeWindowsOutput)(result.trim());
}
catch (error) {
logger_1.default.debug(`Failed to get remote version for command "${command}":`, error);
if (error instanceof Error && (0, windowsHelper_1.isCommandNotFound)(error.message)) {
return '(not found)';
}
return '(error)';
}
});
}
function getRemotePythonVersion(platform) {
return __awaiter(this, void 0, void 0, function* () {
if (platform === 'fortigate') {
return '(not applicable)';
}
if (platform === 'unix') {
const py3Version = yield getRemoteVersion('python3 --version');
if (py3Version !== '(error)') {
return py3Version;
}
}
const output = yield getRemoteVersion('python --version');
return (0, windowsHelper_1.sanitizeWindowsOutput)(output);
});
}
function parseFortigateSystemInfo(output) {
var _a, _b, _c, _d, _e, _f;
try {
const lines = output.split('\n').map((line) => line.trim());
let version = '';
let model = '';
let serialNumber = '';
let hostname = '';
let licenseStatus = '';
let operationMode = '';
let haMode = '';
let resources = '';
for (const line of lines) {
if (line.includes('Version:')) {
const versionMatch = line.match(/Version:\s*([^,]+)/);
if (versionMatch) {
const fullVersion = versionMatch[1].trim();
const modelMatch = fullVersion.match(/(FortiGate[^\s]*)/i);
if (modelMatch) {
model = modelMatch[1];
}
const versionNumMatch = fullVersion.match(/v?(\d+\.\d+\.\d+)/);
if (versionNumMatch) {
version = `v${versionNumMatch[1]}`;
}
const buildMatch = line.match(/build(\d+)/i);
if (buildMatch) {
version += ` (build ${buildMatch[1]})`;
}
}
}
if (line.includes('Serial-Number:')) {
serialNumber = ((_a = line.split(':')[1]) === null || _a === void 0 ? void 0 : _a.trim()) || '';
}
if (line.includes('Hostname:')) {
hostname = ((_b = line.split(':')[1]) === null || _b === void 0 ? void 0 : _b.trim()) || '';
}
if (line.includes('License Status:')) {
licenseStatus = ((_c = line.split(':')[1]) === null || _c === void 0 ? void 0 : _c.trim()) || '';
}
if (line.includes('Operation Mode:')) {
operationMode = ((_d = line.split(':')[1]) === null || _d === void 0 ? void 0 : _d.trim()) || '';
}
if (line.includes('Current HA mode:')) {
haMode = ((_e = line.split(':')[1]) === null || _e === void 0 ? void 0 : _e.trim()) || '';
}
if (line.includes('VM Resources:')) {
resources = ((_f = line.split(':')[1]) === null || _f === void 0 ? void 0 : _f.trim()) || '';
}
}
const parts = [];
if (model && version) {
parts.push(`${model} FortiOS ${version}`);
}
else if (version) {
parts.push(`FortiGate FortiOS ${version}`);
}
else {
parts.push('FortiGate FortiOS');
}
if (hostname) {
parts.push(`Hostname: ${hostname}`);
}
if (serialNumber) {
parts.push(`S/N: ${serialNumber}`);
}
if (operationMode) {
parts.push(`Mode: ${operationMode}`);
}
if (haMode && haMode !== 'standalone') {
parts.push(`HA: ${haMode}`);
}
if (licenseStatus) {
parts.push(`License: ${licenseStatus}`);
}
if (resources) {
parts.push(`Resources: ${resources}`);
}
return parts.join(' | ');
}
catch (error) {
logger_1.default.debug('Error parsing FortiGate system info:', error);
return 'FortiGate FortiOS';
}
}
function getRemoteOSInfo(platform) {
return __awaiter(this, void 0, void 0, function* () {
const executor = remoteExecutor_1.RemoteExecutor.instance;
if (platform === 'windows') {
try {
const result = yield executor.executeCommand('systeminfo');
return (0, windowsHelper_1.sanitizeWindowsOutput)(result.trim());
}
catch (error) {
logger_1.default.debug('Failed to get remote Windows OS info:', error);
return '(windows - OS info unavailable)';
}
}
if (platform === 'fortigate') {
logger_1.default.debug('Attempting FortiGate detection with "get system status" command');
const fortigateResult = yield executor.executeCommand('get system status', undefined, true);
return parseFortigateSystemInfo(fortigateResult);
}
try {
logger_1.default.debug('Attempting standard Linux detection with "uname -a" command');
const result = yield executor.executeCommand('uname -a');
return (0, windowsHelper_1.sanitizeWindowsOutput)(result.trim());
}
catch (error) {
logger_1.default.debug('Failed to get remote Unix OS info:', error);
return '(unix - OS info unavailable)';
}
});
}
function getUnixRemotePackages() {
return __awaiter(this, void 0, void 0, function* () {
const executor = remoteExecutor_1.RemoteExecutor.instance;
let platformPms = [];
try {
const uname = yield executor.executeCommand('uname -s');
if (uname.toLowerCase().includes('linux')) {
platformPms = systemInfo_1.LINUX_PACKAGE_MANAGERS;
logger_1.default.debug('Detected remote OS: Linux');
}
else if (uname.toLowerCase().includes('darwin')) {
platformPms = systemInfo_1.MACOS_PACKAGE_MANAGERS;
logger_1.default.debug('Detected remote OS: macOS');
}
else {
logger_1.default.debug(`Unsupported Unix variant: ${uname}`);
return {};
}
}
catch (e) {
logger_1.default.error('Could not determine remote Unix OS type.', e);
return {};
}
const detectedPms = (yield Promise.all(platformPms.map((pm) => __awaiter(this, void 0, void 0, function* () {
try {
yield executor.executeCommand(`command -v ${pm.cmd}`);
return pm;
}
catch (_a) {
return null;
}
})))).filter(Boolean);
if (!detectedPms.length) {
logger_1.default.debug('No package managers found on remote Unix host.');
return {};
}
logger_1.default.debug('Detected remote package managers:', detectedPms.map((p) => p.cmd));
const exclusionPattern = systemInfo_1.DEFAULT_PACKAGE_EXCLUSIONS.join('|');
const allPackages = yield Promise.all(detectedPms.map((pm) => __awaiter(this, void 0, void 0, function* () {
try {
const listCmd = pm.listCmd(exclusionPattern);
const stdout = yield executor.executeCommand(listCmd);
const packages = stdout.split('\n').filter(Boolean).sort();
if (packages.length > 0) {
return { [`packages installed via ${pm.cmd}`]: packages.join(',') };
}
return { [pm.cmd]: '' };
}
catch (error) {
logger_1.default.error(`Remote error executing ${pm.cmd} list command:`, error);
return { [pm.cmd]: '' };
}
})));
return allPackages.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {});
});
}
function getFortigateRemotePackages() {
return __awaiter(this, void 0, void 0, function* () {
const executor = remoteExecutor_1.RemoteExecutor.instance;
const result = yield executor.executeCommand('get system global', undefined, true);
return { FortiGate: result };
});
}
function getWindowsRemotePackages() {
return __awaiter(this, void 0, void 0, function* () {
const executor = remoteExecutor_1.RemoteExecutor.instance;
const platformPms = systemInfo_1.WINDOWS_PACKAGE_MANAGERS;
const detectedPms = (yield Promise.all(platformPms.map((pm) => __awaiter(this, void 0, void 0, function* () {
try {
const output = yield executor.executeCommand(`where ${pm.cmd}`);
if ((0, windowsHelper_1.isCommandNotFound)(output)) {
return null;
}
return pm;
}
catch (_a) {
return null;
}
})))).filter(Boolean);
if (!detectedPms.length) {
logger_1.default.debug('No package managers found on remote Windows host.');
return {};
}
logger_1.default.debug('Detected remote package managers:', detectedPms.map((p) => p.cmd));
const exclusionPattern = systemInfo_1.DEFAULT_PACKAGE_EXCLUSIONS.join('|');
const allPackages = yield Promise.all(detectedPms.map((pm) => __awaiter(this, void 0, void 0, function* () {
try {
const listCmd = pm.listCmd(exclusionPattern);
const stdout = yield executor.executeCommand(listCmd);
const packages = (0, windowsHelper_1.sanitizeWindowsOutput)(stdout)
.split('\n')
.filter(Boolean)
.sort();
if (packages.length > 0) {
return { [`packages installed via ${pm.cmd}`]: packages.join(',') };
}
return { [pm.cmd]: '' };
}
catch (error) {
logger_1.default.debug(`Error executing remote ${pm.cmd} list command:`, error);
return { [pm.cmd]: '' };
}
})));
return allPackages.reduce((acc, curr) => (Object.assign(Object.assign({}, acc), curr)), {});
});
}
function getRemoteInstalledPackages(platform) {
return __awaiter(this, void 0, void 0, function* () {
logger_1.default.debug(`Getting remote packages for platform: ${platform}`);
if (platform === 'windows') {
return getWindowsRemotePackages();
}
else if (platform === 'fortigate') {
return getFortigateRemotePackages();
}
else {
return getUnixRemotePackages();
}
});
}
function getPhpInfo(platform) {
return __awaiter(this, void 0, void 0, function* () {
if (platform === 'fortigate') {
return '(not applicable)';
}
return getRemoteVersion('php --version');
});
}
function getNodeInfo(platform) {
return __awaiter(this, void 0, void 0, function* () {
if (platform === 'fortigate') {
return '(not applicable)';
}
return getRemoteVersion('node --version');
});
}
function getRemoteSystemInfo() {
return __awaiter(this, void 0, void 0, function* () {
const config = remoteExecutor_1.RemoteExecutor.instance.getConfig();
const { target, platform } = config;
logger_1.default.debug(`Getting remote system info for host: ${target} (${platform})`);
if (!remoteExecutor_1.RemoteExecutor.instance.isConnected) {
yield remoteExecutor_1.RemoteExecutor.instance.connect();
}
const [installed_packages, os_info, pythonVersion, phpVersion, globalNpmPackages, nodeVersion,] = yield Promise.all([
getRemoteInstalledPackages(platform),
getRemoteOSInfo(platform),
getRemotePythonVersion(platform),
getPhpInfo(platform),
getRemoteGlobalNpmPackages(platform),
getNodeInfo(platform),
]);
const sysInfo = {
platform: platform,
os_info,
installed_packages,
};
return {
sysInfo,
nodeInfo: {
version: nodeVersion,
global_packages: globalNpmPackages,
},
pythonInfo: {
version: pythonVersion,
},
phpInfo: {
version: phpVersion,
},
};
});
}