diff --git a/plugin/index.ts b/plugin/index.ts index 350fe85..a137357 100644 --- a/plugin/index.ts +++ b/plugin/index.ts @@ -10,17 +10,23 @@ import { startModeratorPresence, stopModeratorPresence } from "./moderator-prese let noReplyProcess: ChildProcess | null = null; function startNoReplyApi(logger: { info: (m: string) => void; warn: (m: string) => void }, pluginDir: string, port = 8787): void { + logger.info(`dirigent: startNoReplyApi called, pluginDir=${pluginDir}`); + if (noReplyProcess) { logger.info("dirigent: no-reply API already running, skipping"); return; } const serverPath = path.resolve(pluginDir, "..", "no-reply-api", "server.mjs"); + logger.info(`dirigent: resolved serverPath=${serverPath}`); + if (!fs.existsSync(serverPath)) { logger.warn(`dirigent: no-reply API server not found at ${serverPath}, skipping`); return; } + logger.info(`dirigent: no-reply API server found, spawning process...`); + noReplyProcess = spawn(process.execPath, [serverPath], { env: { ...process.env, PORT: String(port) }, stdio: ["ignore", "pipe", "pipe"], @@ -508,17 +514,38 @@ export default { ensurePolicyStateLoaded(api, liveAtRegister); // Resolve plugin directory for locating sibling modules (no-reply-api/) - // Use api.resolvePath to get the actual plugin directory in OpenClaw environment - const pluginDir = api.resolvePath("."); + // Note: api.resolvePath(".") returns cwd, not script directory. Use import.meta.url instead. + const pluginDir = path.dirname(new URL(import.meta.url).pathname); + api.logger.info(`dirigent: pluginDir resolved from import.meta.url: ${pluginDir}`); // Gateway lifecycle: start/stop no-reply API and moderator bot with the gateway api.on("gateway_start", () => { + api.logger.info(`dirigent: gateway_start event received`); + + // Check no-reply-api server file exists + const serverPath = path.resolve(pluginDir, "..", "no-reply-api", "server.mjs"); + api.logger.info(`dirigent: checking no-reply-api server at ${serverPath}, exists=${fs.existsSync(serverPath)}`); + + // Additional debug: list what's in the parent directory + const parentDir = path.resolve(pluginDir, ".."); + try { + const entries = fs.readdirSync(parentDir); + api.logger.info(`dirigent: parent dir (${parentDir}) entries: ${JSON.stringify(entries)}`); + } catch (e) { + api.logger.warn(`dirigent: cannot read parent dir: ${String(e)}`); + } + startNoReplyApi(api.logger, pluginDir); const live = getLivePluginConfig(api, baseConfig as DirigentConfig); + api.logger.info(`dirigent: config loaded, moderatorBotToken=${live.moderatorBotToken ? "[set]" : "[not set]"}`); + if (live.moderatorBotToken) { + api.logger.info("dirigent: starting moderator bot presence..."); startModeratorPresence(live.moderatorBotToken, api.logger); - api.logger.info("dirigent: moderator bot presence starting"); + api.logger.info("dirigent: moderator bot presence started"); + } else { + api.logger.info("dirigent: moderator bot not starting - no moderatorBotToken in config"); } }); diff --git a/scripts/install-dirigent-openclaw.mjs b/scripts/install-dirigent-openclaw.mjs index d5fb9c5..3dfec54 100755 --- a/scripts/install-dirigent-openclaw.mjs +++ b/scripts/install-dirigent-openclaw.mjs @@ -22,11 +22,26 @@ const __dirname = path.dirname(new URL(import.meta.url).pathname); // Ensure dist/dirigent exists (handles git clone without npm prepare) const DIST_DIR = path.resolve(__dirname, "..", "dist", "dirigent"); const PLUGIN_SRC_DIR = path.resolve(__dirname, "..", "plugin"); -if (mode === "install" && !fs.existsSync(DIST_DIR)) { - console.log("[dirigent] dist/ not found, syncing from plugin/..."); - fs.mkdirSync(DIST_DIR, { recursive: true }); - for (const f of fs.readdirSync(PLUGIN_SRC_DIR)) { - fs.copyFileSync(path.join(PLUGIN_SRC_DIR, f), path.join(DIST_DIR, f)); +const NO_REPLY_API_SRC_DIR = path.resolve(__dirname, "..", "no-reply-api"); +const NO_REPLY_API_DIST_DIR = path.resolve(__dirname, "..", "dist", "no-reply-api"); + +if (mode === "install") { + // Copy plugin files to dist/dirigent + if (!fs.existsSync(DIST_DIR)) { + console.log("[dirigent] dist/dirigent/ not found, syncing from plugin/..."); + fs.mkdirSync(DIST_DIR, { recursive: true }); + for (const f of fs.readdirSync(PLUGIN_SRC_DIR)) { + fs.copyFileSync(path.join(PLUGIN_SRC_DIR, f), path.join(DIST_DIR, f)); + } + } + + // Copy no-reply-api files to dist/no-reply-api + if (!fs.existsSync(NO_REPLY_API_DIST_DIR)) { + console.log("[dirigent] dist/no-reply-api/ not found, syncing from no-reply-api/..."); + fs.mkdirSync(NO_REPLY_API_DIST_DIR, { recursive: true }); + for (const f of fs.readdirSync(NO_REPLY_API_SRC_DIR)) { + fs.copyFileSync(path.join(NO_REPLY_API_SRC_DIR, f), path.join(NO_REPLY_API_DIST_DIR, f)); + } } }