diff --git a/scripts/install-whispergate-openclaw.mjs b/scripts/install-whispergate-openclaw.mjs index ec0da4d..111ad8f 100755 --- a/scripts/install-whispergate-openclaw.mjs +++ b/scripts/install-whispergate-openclaw.mjs @@ -77,6 +77,25 @@ function readRecord(file) { return JSON.parse(fs.readFileSync(file, "utf8")); } +function findLatestInstallRecord() { + if (!fs.existsSync(STATE_DIR)) return ""; + const files = fs + .readdirSync(STATE_DIR) + .filter((f) => /^whispergate-\d+\.json$/.test(f)) + .sort() + .reverse(); + for (const f of files) { + const p = path.join(STATE_DIR, f); + try { + const rec = readRecord(p); + if (rec?.mode === "install") return p; + } catch { + // ignore broken records + } + } + return ""; +} + if (!fs.existsSync(OPENCLAW_CONFIG_PATH)) { console.error(`[whispergate] config not found: ${OPENCLAW_CONFIG_PATH}`); process.exit(1); @@ -153,9 +172,9 @@ if (mode === "install") { process.exit(1); } } else { - const recFile = env.RECORD_FILE || (fs.existsSync(LATEST_RECORD_LINK) ? LATEST_RECORD_LINK : ""); + const recFile = env.RECORD_FILE || findLatestInstallRecord(); if (!recFile || !fs.existsSync(recFile)) { - console.error("[whispergate] no record found. set RECORD_FILE= or install first."); + console.error("[whispergate] no install record found. set RECORD_FILE= to an install record."); process.exit(1); }