refactor(installer): detect existing install via plugins.entries.dirigent registration

This commit is contained in:
2026-03-08 06:25:07 +00:00
parent 6124ceec7a
commit 7640e80373

View File

@@ -232,14 +232,21 @@ function clone(v) {
return JSON.parse(JSON.stringify(v)); return JSON.parse(JSON.stringify(v));
} }
function isDirigentRegistered() {
const entry = getJson(PATH_PLUGIN_ENTRY);
return !!(entry && typeof entry === "object");
}
// ═══════════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════════
// INSTALL // INSTALL
// ═══════════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════════
if (mode === "install") { if (mode === "install") {
// Check if already installed - if so, uninstall first // Check if plugin is already registered in config.
// Prefer record-based uninstall when record exists; otherwise continue with in-place overwrite.
const registered = isDirigentRegistered();
const existingRecord = findLatestInstallRecord(); const existingRecord = findLatestInstallRecord();
if (existingRecord) { if (registered && existingRecord) {
console.log("[dirigent] existing installation detected, uninstalling first..."); console.log("[dirigent] existing plugin registration detected (with install record), uninstalling first...");
process.env.RECORD_FILE = existingRecord; process.env.RECORD_FILE = existingRecord;
const result = spawnSync(process.execPath, [import.meta.filename, "--uninstall"], { const result = spawnSync(process.execPath, [import.meta.filename, "--uninstall"], {
env: { ...process.env, OPENCLAW_DIR }, env: { ...process.env, OPENCLAW_DIR },
@@ -250,6 +257,8 @@ if (mode === "install") {
process.exit(1); process.exit(1);
} }
console.log("[dirigent] previous installation removed, proceeding with fresh install..."); console.log("[dirigent] previous installation removed, proceeding with fresh install...");
} else if (registered) {
console.log("[dirigent] existing plugin registration detected (no install record). Proceeding with in-place reinstall...");
} }
// 1. Build dist // 1. Build dist