feat: rename plugin to harbor-forge, remove sidecar, add --install-cli
Major changes: - Renamed plugin id from harborforge-monitor to harbor-forge (TODO 4.1) - Removed sidecar server/ directory and spawn logic (TODO 4.2) - Added monitorPort to plugin config schema (TODO 4.3) - Added --install-cli flag to installer for building hf CLI (TODO 4.4) - skills/hf/ only deployed when --install-cli is present (TODO 4.5) - Plugin now serves telemetry data directly via tools - Installer handles migration from old plugin name - Bumped version to 0.2.0
This commit is contained in:
@@ -1,7 +1,13 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* HarborForge Monitor Plugin Installer v0.1.0
|
||||
* HarborForge Plugin Installer v0.2.0
|
||||
*
|
||||
* Changes from v0.1.0:
|
||||
* - Plugin renamed from harborforge-monitor to harbor-forge
|
||||
* - Sidecar server removed (telemetry served directly by plugin)
|
||||
* - Added --install-cli flag for building and installing the hf CLI
|
||||
* - skills/hf/ only installed when --install-cli is present
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
@@ -11,8 +17,7 @@ import {
|
||||
copyFileSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
readFileSync,
|
||||
writeFileSync,
|
||||
chmodSync,
|
||||
} from 'fs';
|
||||
import { dirname, join, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
@@ -21,9 +26,9 @@ import { homedir, platform } from 'os';
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = resolve(dirname(__filename), '..');
|
||||
|
||||
const PLUGIN_NAME = 'harborforge-monitor';
|
||||
const PLUGIN_NAME = 'harbor-forge';
|
||||
const OLD_PLUGIN_NAME = 'harborforge-monitor';
|
||||
const PLUGIN_SRC_DIR = join(__dirname, 'plugin');
|
||||
const SERVER_SRC_DIR = join(__dirname, 'server');
|
||||
const SKILLS_SRC_DIR = join(__dirname, 'skills');
|
||||
|
||||
const args = process.argv.slice(2);
|
||||
@@ -34,6 +39,7 @@ const options = {
|
||||
verbose: args.includes('--verbose') || args.includes('-v'),
|
||||
uninstall: args.includes('--uninstall'),
|
||||
installOnly: args.includes('--install'),
|
||||
installCli: args.includes('--install-cli'),
|
||||
};
|
||||
|
||||
const profileIdx = args.indexOf('--openclaw-profile-path');
|
||||
@@ -83,19 +89,21 @@ function unsetOpenclawConfig(key) {
|
||||
try { exec(`openclaw config unset ${key}`, { silent: true }); } catch {}
|
||||
}
|
||||
|
||||
function copyDir(src, dest) {
|
||||
function copyDir(src, dest, { exclude = [] } = {}) {
|
||||
mkdirSync(dest, { recursive: true });
|
||||
for (const entry of readdirSync(src, { withFileTypes: true })) {
|
||||
const s = join(src, entry.name);
|
||||
const d = join(dest, entry.name);
|
||||
if (entry.name === 'node_modules') continue;
|
||||
entry.isDirectory() ? copyDir(s, d) : copyFileSync(s, d);
|
||||
if (exclude.includes(entry.name)) continue;
|
||||
entry.isDirectory() ? copyDir(s, d, { exclude }) : copyFileSync(s, d);
|
||||
}
|
||||
}
|
||||
|
||||
function detectEnvironment() {
|
||||
logStep(1, 5, 'Detecting environment...');
|
||||
const env = { platform: platform(), nodeVersion: null };
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
logStep(1, totalSteps, 'Detecting environment...');
|
||||
const env = { platform: platform(), nodeVersion: null, goVersion: null };
|
||||
|
||||
try {
|
||||
env.nodeVersion = exec('node --version', { silent: true }).trim();
|
||||
@@ -109,19 +117,34 @@ function detectEnvironment() {
|
||||
} catch {
|
||||
logWarn('openclaw CLI not in PATH');
|
||||
}
|
||||
|
||||
if (options.installCli) {
|
||||
try {
|
||||
env.goVersion = exec('go version', { silent: true }).trim();
|
||||
logOk(env.goVersion);
|
||||
} catch {
|
||||
logWarn('Go not found (needed for --install-cli)');
|
||||
}
|
||||
}
|
||||
|
||||
return env;
|
||||
}
|
||||
|
||||
function checkDeps(env) {
|
||||
if (options.skipCheck) { logStep(2, 5, 'Skipping dep checks'); return; }
|
||||
logStep(2, 5, 'Checking dependencies...');
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
if (options.skipCheck) { logStep(2, totalSteps, 'Skipping dep checks'); return; }
|
||||
logStep(2, totalSteps, 'Checking dependencies...');
|
||||
|
||||
let fail = false;
|
||||
if (!env.nodeVersion || parseInt(env.nodeVersion.slice(1)) < 18) {
|
||||
logErr('Node.js 18+ required');
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if (options.installCli && !env.goVersion) {
|
||||
logErr('Go is required for --install-cli');
|
||||
fail = true;
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
log('\nInstall missing deps and retry.', 'red');
|
||||
@@ -132,7 +155,8 @@ function checkDeps(env) {
|
||||
}
|
||||
|
||||
async function build() {
|
||||
logStep(3, 5, 'Building plugin...');
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
logStep(3, totalSteps, 'Building plugin...');
|
||||
|
||||
log(' Building TypeScript plugin...', 'blue');
|
||||
exec('npm install', { cwd: PLUGIN_SRC_DIR, silent: !options.verbose });
|
||||
@@ -141,11 +165,18 @@ async function build() {
|
||||
}
|
||||
|
||||
function clearInstallTargets(openclawPath) {
|
||||
// Remove new plugin dir
|
||||
const destDir = join(openclawPath, 'plugins', PLUGIN_NAME);
|
||||
if (existsSync(destDir)) {
|
||||
rmSync(destDir, { recursive: true, force: true });
|
||||
logOk(`Removed ${destDir}`);
|
||||
}
|
||||
// Remove old plugin dir if it exists
|
||||
const oldDestDir = join(openclawPath, 'plugins', OLD_PLUGIN_NAME);
|
||||
if (existsSync(oldDestDir)) {
|
||||
rmSync(oldDestDir, { recursive: true, force: true });
|
||||
logOk(`Removed old plugin dir ${oldDestDir}`);
|
||||
}
|
||||
}
|
||||
|
||||
function cleanupConfig(openclawPath) {
|
||||
@@ -153,20 +184,31 @@ function cleanupConfig(openclawPath) {
|
||||
|
||||
try {
|
||||
const allow = getOpenclawConfig('plugins.allow', []);
|
||||
const idx = allow.indexOf(PLUGIN_NAME);
|
||||
if (idx !== -1) {
|
||||
allow.splice(idx, 1);
|
||||
setOpenclawConfig('plugins.allow', allow);
|
||||
logOk('Removed from allow list');
|
||||
// Remove both old and new names
|
||||
for (const name of [PLUGIN_NAME, OLD_PLUGIN_NAME]) {
|
||||
const idx = allow.indexOf(name);
|
||||
if (idx !== -1) {
|
||||
allow.splice(idx, 1);
|
||||
logOk(`Removed ${name} from allow list`);
|
||||
}
|
||||
}
|
||||
setOpenclawConfig('plugins.allow', allow);
|
||||
|
||||
unsetOpenclawConfig(`plugins.entries.${PLUGIN_NAME}`);
|
||||
logOk('Removed plugin entry');
|
||||
unsetOpenclawConfig(`plugins.entries.${OLD_PLUGIN_NAME}`);
|
||||
logOk('Removed plugin entries');
|
||||
|
||||
const paths = getOpenclawConfig('plugins.load.paths', []);
|
||||
const pidx = paths.indexOf(destDir);
|
||||
if (pidx !== -1) {
|
||||
paths.splice(pidx, 1);
|
||||
const oldDestDir = join(openclawPath, 'plugins', OLD_PLUGIN_NAME);
|
||||
let changed = false;
|
||||
for (const p of [destDir, oldDestDir]) {
|
||||
const pidx = paths.indexOf(p);
|
||||
if (pidx !== -1) {
|
||||
paths.splice(pidx, 1);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
setOpenclawConfig('plugins.load.paths', paths);
|
||||
logOk('Removed from load paths');
|
||||
}
|
||||
@@ -176,8 +218,9 @@ function cleanupConfig(openclawPath) {
|
||||
}
|
||||
|
||||
async function install() {
|
||||
if (options.buildOnly) { logStep(4, 5, 'Skipping install (--build-only)'); return null; }
|
||||
logStep(4, 5, 'Installing...');
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
if (options.buildOnly) { logStep(4, totalSteps, 'Skipping install (--build-only)'); return null; }
|
||||
logStep(4, totalSteps, 'Installing...');
|
||||
|
||||
const openclawPath = resolveOpenclawPath();
|
||||
const pluginsDir = join(openclawPath, 'plugins');
|
||||
@@ -186,29 +229,34 @@ async function install() {
|
||||
log(` OpenClaw path: ${openclawPath}`, 'blue');
|
||||
|
||||
if (existsSync(destDir)) {
|
||||
logWarn('Existing install detected, uninstalling before install...');
|
||||
logWarn('Existing install detected, cleaning up...');
|
||||
clearInstallTargets(openclawPath);
|
||||
cleanupConfig(openclawPath);
|
||||
}
|
||||
|
||||
if (existsSync(destDir)) rmSync(destDir, { recursive: true, force: true });
|
||||
// Clean up old plugin name if present
|
||||
const oldDestDir = join(pluginsDir, OLD_PLUGIN_NAME);
|
||||
if (existsSync(oldDestDir)) {
|
||||
logWarn('Old plugin (harborforge-monitor) detected, removing...');
|
||||
rmSync(oldDestDir, { recursive: true, force: true });
|
||||
cleanupConfig(openclawPath);
|
||||
}
|
||||
|
||||
// Copy compiled plugin
|
||||
// Copy compiled plugin (no server directory — sidecar removed)
|
||||
mkdirSync(destDir, { recursive: true });
|
||||
copyDir(PLUGIN_SRC_DIR, destDir);
|
||||
logOk(`Plugin files → ${destDir}`);
|
||||
|
||||
// Copy telemetry server
|
||||
const serverDestDir = join(destDir, 'server');
|
||||
mkdirSync(serverDestDir, { recursive: true });
|
||||
copyDir(SERVER_SRC_DIR, serverDestDir);
|
||||
logOk(`Server files → ${serverDestDir}`);
|
||||
|
||||
// Copy skills
|
||||
// Copy skills (exclude hf/ unless --install-cli)
|
||||
if (existsSync(SKILLS_SRC_DIR)) {
|
||||
const skillsDestDir = join(openclawPath, 'skills');
|
||||
mkdirSync(skillsDestDir, { recursive: true });
|
||||
copyDir(SKILLS_SRC_DIR, skillsDestDir);
|
||||
logOk(`Skills → ${skillsDestDir}`);
|
||||
const excludeSkills = options.installCli ? [] : ['hf'];
|
||||
copyDir(SKILLS_SRC_DIR, skillsDestDir, { exclude: excludeSkills });
|
||||
if (options.installCli) {
|
||||
logOk(`Skills (including hf) → ${skillsDestDir}`);
|
||||
} else {
|
||||
logOk(`Skills (hf skipped, use --install-cli) → ${skillsDestDir}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Install runtime deps
|
||||
@@ -218,9 +266,51 @@ async function install() {
|
||||
return { destDir };
|
||||
}
|
||||
|
||||
async function installCli() {
|
||||
if (!options.installCli) return;
|
||||
const totalSteps = 6;
|
||||
logStep(5, totalSteps, 'Building and installing hf CLI...');
|
||||
|
||||
const openclawPath = resolveOpenclawPath();
|
||||
const binDir = join(openclawPath, 'bin');
|
||||
mkdirSync(binDir, { recursive: true });
|
||||
|
||||
// Find CLI source — look for HarborForge.Cli relative to project root
|
||||
const projectRoot = resolve(__dirname, '..');
|
||||
const cliDir = join(projectRoot, 'HarborForge.Cli');
|
||||
|
||||
if (!existsSync(cliDir)) {
|
||||
// Try parent directory (monorepo layout)
|
||||
const monoCliDir = resolve(projectRoot, '..', 'HarborForge.Cli');
|
||||
if (!existsSync(monoCliDir)) {
|
||||
logErr(`Cannot find HarborForge.Cli at ${cliDir} or ${monoCliDir}`);
|
||||
logWarn('Skipping CLI installation');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const effectiveCliDir = existsSync(cliDir)
|
||||
? cliDir
|
||||
: resolve(projectRoot, '..', 'HarborForge.Cli');
|
||||
|
||||
log(` Building hf from ${effectiveCliDir}...`, 'blue');
|
||||
|
||||
try {
|
||||
const hfBinary = join(binDir, 'hf');
|
||||
exec(`go build -o ${hfBinary} ./cmd/hf`, { cwd: effectiveCliDir, silent: !options.verbose });
|
||||
chmodSync(hfBinary, 0o755);
|
||||
logOk(`hf binary → ${hfBinary}`);
|
||||
} catch (err) {
|
||||
logErr(`Failed to build hf CLI: ${err.message}`);
|
||||
logWarn('CLI installation failed, plugin still installed');
|
||||
}
|
||||
}
|
||||
|
||||
async function configure() {
|
||||
if (options.buildOnly) { logStep(5, 5, 'Skipping config'); return; }
|
||||
logStep(5, 5, 'Configuring OpenClaw...');
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
const step = options.installCli ? 6 : 5;
|
||||
if (options.buildOnly) { logStep(step, totalSteps, 'Skipping config'); return; }
|
||||
logStep(step, totalSteps, 'Configuring OpenClaw...');
|
||||
|
||||
const openclawPath = resolveOpenclawPath();
|
||||
const destDir = join(openclawPath, 'plugins', PLUGIN_NAME);
|
||||
@@ -240,8 +330,7 @@ async function configure() {
|
||||
}
|
||||
logOk(`plugins.allow includes ${PLUGIN_NAME}`);
|
||||
|
||||
// Note: apiKey must be configured manually by user
|
||||
logOk('Plugin configured (remember to set apiKey in plugins.entries.harborforge-monitor.config)');
|
||||
logOk('Plugin configured (remember to set apiKey in plugins.entries.harbor-forge.config)');
|
||||
|
||||
} catch (err) {
|
||||
logWarn(`Config failed: ${err.message}`);
|
||||
@@ -249,11 +338,12 @@ async function configure() {
|
||||
}
|
||||
|
||||
function summary() {
|
||||
logStep(5, 5, 'Done!');
|
||||
const totalSteps = options.installCli ? 6 : 5;
|
||||
logStep(totalSteps, totalSteps, 'Done!');
|
||||
console.log('');
|
||||
log('╔══════════════════════════════════════════════╗', 'cyan');
|
||||
log('║ HarborForge Monitor v0.1.0 Install Complete ║', 'cyan');
|
||||
log('╚══════════════════════════════════════════════╝', 'cyan');
|
||||
log('╔════════════════════════════════════════════╗', 'cyan');
|
||||
log('║ HarborForge v0.2.0 Install Complete ║', 'cyan');
|
||||
log('╚════════════════════════════════════════════╝', 'cyan');
|
||||
|
||||
if (options.buildOnly) {
|
||||
log('\nBuild-only — plugin not installed.', 'yellow');
|
||||
@@ -263,11 +353,11 @@ function summary() {
|
||||
console.log('');
|
||||
log('Next steps:', 'blue');
|
||||
log(' 1. Register server in HarborForge Monitor to get apiKey', 'cyan');
|
||||
log(' 2. Edit ~/.openclaw/openclaw.json under plugins.entries.harborforge-monitor.config:', 'cyan');
|
||||
log(' 2. Edit ~/.openclaw/openclaw.json under plugins.entries.harbor-forge.config:', 'cyan');
|
||||
log(' {', 'cyan');
|
||||
log(' "plugins": {', 'cyan');
|
||||
log(' "entries": {', 'cyan');
|
||||
log(' "harborforge-monitor": {', 'cyan');
|
||||
log(' "harbor-forge": {', 'cyan');
|
||||
log(' "enabled": true,', 'cyan');
|
||||
log(' "config": {', 'cyan');
|
||||
log(' "enabled": true,', 'cyan');
|
||||
@@ -278,22 +368,36 @@ function summary() {
|
||||
log(' }', 'cyan');
|
||||
log(' }', 'cyan');
|
||||
log(' 3. openclaw gateway restart', 'cyan');
|
||||
|
||||
if (options.installCli) {
|
||||
console.log('');
|
||||
log(' hf CLI installed to ~/.openclaw/bin/hf', 'green');
|
||||
log(' Ensure ~/.openclaw/bin is in your PATH', 'cyan');
|
||||
}
|
||||
console.log('');
|
||||
}
|
||||
|
||||
async function uninstall() {
|
||||
log('Uninstalling HarborForge Monitor...', 'cyan');
|
||||
log('Uninstalling HarborForge...', 'cyan');
|
||||
const openclawPath = resolveOpenclawPath();
|
||||
clearInstallTargets(openclawPath);
|
||||
cleanupConfig(openclawPath);
|
||||
|
||||
// Remove CLI binary if present
|
||||
const hfBinary = join(openclawPath, 'bin', 'hf');
|
||||
if (existsSync(hfBinary)) {
|
||||
rmSync(hfBinary, { force: true });
|
||||
logOk('Removed hf CLI binary');
|
||||
}
|
||||
|
||||
log('\nRun: openclaw gateway restart', 'yellow');
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('');
|
||||
log('╔══════════════════════════════════════════════╗', 'cyan');
|
||||
log('║ HarborForge Monitor Plugin Installer v0.1.0 ║', 'cyan');
|
||||
log('╚══════════════════════════════════════════════╝', 'cyan');
|
||||
log('╔════════════════════════════════════════════╗', 'cyan');
|
||||
log('║ HarborForge Plugin Installer v0.2.0 ║', 'cyan');
|
||||
log('╚════════════════════════════════════════════╝', 'cyan');
|
||||
console.log('');
|
||||
|
||||
try {
|
||||
@@ -309,6 +413,9 @@ async function main() {
|
||||
|
||||
if (!options.buildOnly) {
|
||||
await install();
|
||||
if (options.installCli) {
|
||||
await installCli();
|
||||
}
|
||||
await configure();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user