fix: loadRouters preserves API-registered routers; install.mjs chowns root
Two related fixes: 1. core/router-loader.loadRouters() previously called map.clear() before scanning routersDir, which wiped routers registered via __prismFacet.addRouter (the cross-plugin API). Now: track which entries in the map came from a file vs API (filePath sentinel), only delete file-based ones that disappeared between loads. External routers are never touched. 2. scripts/install.mjs: chown installed plugin files to root when the installer is running as root. openclaw 2026.5+ blocks plugins whose files are owned by non-root; rsync/tar from a developer laptop silently broke prism-facet on the next gateway restart. Matches the Meridian + ClawPrompts install.mjs fix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -35,7 +35,16 @@ export async function loadRouters(
|
||||
log: { info(msg: string): void; warn(msg: string): void }
|
||||
): Promise<void> {
|
||||
const map = getRouterMap();
|
||||
map.clear();
|
||||
// Don't clear() — that would wipe externally-registered routers added
|
||||
// by other plugins via __prismFacet.addRouter. Instead, track which
|
||||
// routers came from the filesystem this run and remove only those
|
||||
// that disappeared. External routers (filePath sentinel) are never
|
||||
// touched here.
|
||||
const FILE_SENTINEL_PREFIX = "<external:";
|
||||
const fileRoutersBefore = new Set<string>();
|
||||
for (const [name, r] of map.entries()) {
|
||||
if (!r.filePath.startsWith(FILE_SENTINEL_PREFIX)) fileRoutersBefore.add(name);
|
||||
}
|
||||
|
||||
if (typeof _G[LOAD_COUNTER_KEY] !== "number") _G[LOAD_COUNTER_KEY] = 0;
|
||||
(_G[LOAD_COUNTER_KEY] as number)++;
|
||||
@@ -48,9 +57,12 @@ export async function loadRouters(
|
||||
);
|
||||
} catch {
|
||||
log.warn(`[prism-facet] routers directory not found: ${routersDir}`);
|
||||
// No file-based routers this run — drop any leftover file routers.
|
||||
for (const name of fileRoutersBefore) map.delete(name);
|
||||
return;
|
||||
}
|
||||
|
||||
const seenThisRun = new Set<string>();
|
||||
for (const file of files) {
|
||||
const name = routerNameFromFile(file);
|
||||
const filePath = path.resolve(routersDir, file);
|
||||
@@ -61,11 +73,17 @@ export async function loadRouters(
|
||||
continue;
|
||||
}
|
||||
map.set(name, { name, filePath, module: mod });
|
||||
seenThisRun.add(name);
|
||||
log.info(`[prism-facet] router loaded: ${name}`);
|
||||
} catch (err) {
|
||||
log.warn(`[prism-facet] router ${name}: failed to load — ${String(err)}`);
|
||||
}
|
||||
}
|
||||
// Drop file-based routers that disappeared between loads. Untouched
|
||||
// routers stay.
|
||||
for (const stale of fileRoutersBefore) {
|
||||
if (!seenThisRun.has(stale)) map.delete(stale);
|
||||
}
|
||||
}
|
||||
|
||||
export function getRouters(): LoadedRouter[] {
|
||||
|
||||
Reference in New Issue
Block a user