refactor: manage monitor via gateway hooks
This commit is contained in:
@@ -40,6 +40,8 @@ const options = {
|
||||
uninstall: args.includes('--uninstall'),
|
||||
installOnly: args.includes('--install'),
|
||||
installCli: args.includes('--install-cli'),
|
||||
installMonitor: 'no',
|
||||
monitorBranch: 'main',
|
||||
};
|
||||
|
||||
const profileIdx = args.indexOf('--openclaw-profile-path');
|
||||
@@ -47,6 +49,16 @@ if (profileIdx !== -1 && args[profileIdx + 1]) {
|
||||
options.openclawProfilePath = resolve(args[profileIdx + 1]);
|
||||
}
|
||||
|
||||
const installMonitorIdx = args.indexOf('--install-monitor');
|
||||
if (installMonitorIdx !== -1 && args[installMonitorIdx + 1]) {
|
||||
options.installMonitor = String(args[installMonitorIdx + 1]).toLowerCase();
|
||||
}
|
||||
|
||||
const monitorBranchIdx = args.indexOf('--monitor-branch');
|
||||
if (monitorBranchIdx !== -1 && args[monitorBranchIdx + 1]) {
|
||||
options.monitorBranch = String(args[monitorBranchIdx + 1]);
|
||||
}
|
||||
|
||||
function resolveOpenclawPath() {
|
||||
if (options.openclawProfilePath) return options.openclawProfilePath;
|
||||
if (process.env.OPENCLAW_PATH) return resolve(process.env.OPENCLAW_PATH);
|
||||
@@ -164,6 +176,38 @@ 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 binaryPath = join(monitorDestDir, 'HarborForge.Monitor');
|
||||
try {
|
||||
exec(`go build -o ${binaryPath} .`, { cwd: monitorDestDir, 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;
|
||||
}
|
||||
}
|
||||
|
||||
function clearInstallTargets(openclawPath) {
|
||||
// Remove new plugin dir
|
||||
const destDir = join(openclawPath, 'plugins', PLUGIN_NAME);
|
||||
@@ -244,7 +288,7 @@ async function install() {
|
||||
|
||||
// Copy compiled plugin (no server directory — sidecar removed)
|
||||
mkdirSync(destDir, { recursive: true });
|
||||
copyDir(PLUGIN_SRC_DIR, destDir);
|
||||
copyDir(PLUGIN_SRC_DIR, destDir, { exclude: ['node_modules', '.git', '*.ts'] });
|
||||
logOk(`Plugin files → ${destDir}`);
|
||||
|
||||
// Copy skills (exclude hf/ unless --install-cli)
|
||||
@@ -263,7 +307,8 @@ async function install() {
|
||||
exec('npm install --omit=dev', { cwd: destDir, silent: !options.verbose });
|
||||
logOk('Runtime deps installed');
|
||||
|
||||
return { destDir };
|
||||
const managedMonitorPath = installManagedMonitor(openclawPath);
|
||||
return { destDir, managedMonitorPath };
|
||||
}
|
||||
|
||||
async function installCli() {
|
||||
@@ -329,6 +374,18 @@ async function configure() {
|
||||
setOpenclawConfig('plugins.allow', allow);
|
||||
}
|
||||
logOk(`plugins.allow includes ${PLUGIN_NAME}`);
|
||||
|
||||
if (options.installMonitor === 'yes') {
|
||||
const projectRoot = resolve(__dirname, '..');
|
||||
const binaryPath = join(openclawPath, 'managed', 'harborforge-monitor', 'HarborForge.Monitor');
|
||||
const entry = getOpenclawConfig(`plugins.entries.${PLUGIN_NAME}`, {}) || {};
|
||||
const config = entry.config || {};
|
||||
config.managedMonitor = binaryPath;
|
||||
entry.config = config;
|
||||
entry.enabled = true;
|
||||
setOpenclawConfig(`plugins.entries.${PLUGIN_NAME}`, entry);
|
||||
logOk(`managedMonitor configured → ${binaryPath}`);
|
||||
}
|
||||
|
||||
logOk('Plugin configured (remember to set apiKey in plugins.entries.harbor-forge.config)');
|
||||
|
||||
@@ -390,6 +447,12 @@ async function uninstall() {
|
||||
rmSync(hfBinary, { force: true });
|
||||
logOk('Removed hf CLI binary');
|
||||
}
|
||||
|
||||
const managedDir = join(openclawPath, 'managed', 'harborforge-monitor');
|
||||
if (existsSync(managedDir)) {
|
||||
rmSync(managedDir, { recursive: true, force: true });
|
||||
logOk('Removed managed HarborForge monitor');
|
||||
}
|
||||
|
||||
log('\nRun: openclaw gateway restart', 'yellow');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user