fix: install managed monitor from temp clone

This commit is contained in:
2026-04-04 06:54:18 +00:00
parent 038862ef8c
commit e6e1c5395b

View File

@@ -112,6 +112,10 @@ function copyDir(src, dest, { exclude = [] } = {}) {
}
}
function shellEscape(value) {
return `'${String(value).replace(/'/g, `'"'"'`)}'`;
}
function detectEnvironment() {
const totalSteps = options.installCli ? 6 : 5;
logStep(1, totalSteps, 'Detecting environment...');
@@ -176,35 +180,26 @@ async function build() {
logOk('plugin compiled');
}
function findMonitorSource(projectRoot) {
const candidates = [
join(projectRoot, 'HarborForge.Monitor'),
resolve(projectRoot, '..', 'HarborForge.Monitor'),
];
return candidates.find((p) => existsSync(p)) || null;
}
function installManagedMonitor(openclawPath) {
if (options.installMonitor !== 'yes') return null;
const projectRoot = resolve(__dirname, '..');
const monitorSrc = findMonitorSource(projectRoot);
if (!monitorSrc) {
logWarn('HarborForge.Monitor source not found; skipping managed monitor install');
return null;
}
const monitorDestDir = join(openclawPath, 'managed', 'harborforge-monitor');
rmSync(monitorDestDir, { recursive: true, force: true });
mkdirSync(monitorDestDir, { recursive: true });
copyDir(monitorSrc, monitorDestDir, { exclude: ['.git', 'node_modules', 'bin', 'obj'] });
const gitRoot = exec('git config --get remote.origin.url', { cwd: projectRoot, silent: true }).trim();
const monitorRepo = gitRoot.replace(/HarborForge\.OpenclawPlugin(\.git)?$/, 'HarborForge.Monitor.git');
const tmpDir = join('/tmp', `harborforge-monitor-${Date.now()}`);
const monitorDestDir = join(openclawPath, 'plugins', PLUGIN_NAME, 'bin');
const binaryPath = join(monitorDestDir, 'HarborForge.Monitor');
mkdirSync(monitorDestDir, { recursive: true });
try {
exec(`go build -o ${binaryPath} .`, { cwd: monitorDestDir, silent: !options.verbose });
exec(`git clone --branch ${shellEscape(options.monitorBranch)} ${shellEscape(monitorRepo)} ${shellEscape(tmpDir)}`, { silent: !options.verbose });
exec(`go build -o ${shellEscape(binaryPath)} .`, { cwd: tmpDir, silent: !options.verbose });
chmodSync(binaryPath, 0o755);
logOk(`Managed monitor installed → ${binaryPath} (branch hint: ${options.monitorBranch})`);
return binaryPath;
} catch (err) {
logWarn(`Managed monitor build failed: ${err.message}`);
return null;
} finally {
rmSync(tmpDir, { recursive: true, force: true });
}
}
@@ -288,7 +283,7 @@ async function install() {
// Copy compiled plugin (no server directory — sidecar removed)
mkdirSync(destDir, { recursive: true });
copyDir(PLUGIN_SRC_DIR, destDir, { exclude: ['node_modules', '.git', '*.ts'] });
copyDir(PLUGIN_SRC_DIR, destDir, { exclude: ['node_modules', '.git'] });
logOk(`Plugin files → ${destDir}`);
// Copy skills (exclude hf/ unless --install-cli)
@@ -376,8 +371,7 @@ async function configure() {
logOk(`plugins.allow includes ${PLUGIN_NAME}`);
if (options.installMonitor === 'yes') {
const projectRoot = resolve(__dirname, '..');
const binaryPath = join(openclawPath, 'managed', 'harborforge-monitor', 'HarborForge.Monitor');
const binaryPath = join(openclawPath, 'plugins', PLUGIN_NAME, 'bin', 'HarborForge.Monitor');
const entry = getOpenclawConfig(`plugins.entries.${PLUGIN_NAME}`, {}) || {};
const config = entry.config || {};
config.managedMonitor = binaryPath;
@@ -448,7 +442,7 @@ async function uninstall() {
logOk('Removed hf CLI binary');
}
const managedDir = join(openclawPath, 'managed', 'harborforge-monitor');
const managedDir = join(openclawPath, 'plugins', PLUGIN_NAME, 'bin');
if (existsSync(managedDir)) {
rmSync(managedDir, { recursive: true, force: true });
logOk('Removed managed HarborForge monitor');