From 2ea4f59a1e406ba1f3dcd52dcbba2164ac33c6e6 Mon Sep 17 00:00:00 2001 From: zhi Date: Tue, 3 Mar 2026 16:24:05 +0000 Subject: [PATCH] build: support both registry publish and git clone install - Add root package.json with files[] for registry publishing - Add prepare script to sync dist/ from plugin/ - Add postinstall to auto-run install script - Modify install script: auto-create dist/ if missing (git clone case) - Plugin works in both scenarios: * npm install @hangman-lab/dirigent -> uses bundled dist/ * git clone + node scripts/install-dirigent-openclaw.mjs -> auto-creates dist/ --- package.json | 39 +++++++++++++++++++++++++++ scripts/install-dirigent-openclaw.mjs | 14 +++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..44692d6 --- /dev/null +++ b/package.json @@ -0,0 +1,39 @@ +{ + "name": "@hangman-lab/dirigent", + "version": "0.2.0", + "description": "Dirigent - Rule-based no-reply gate with provider/model override and turn management for OpenClaw", + "type": "module", + "files": [ + "dist/", + "plugin/", + "no-reply-api/", + "discord-control-api/", + "docs/", + "scripts/install-dirigent-openclaw.mjs", + "docker-compose.yml", + "Makefile", + "README.md", + "CHANGELOG.md", + "TASKLIST.md" + ], + "scripts": { + "prepare": "mkdir -p dist/dirigent && cp plugin/* dist/dirigent/", + "postinstall": "node scripts/install-dirigent-openclaw.mjs --install", + "uninstall": "node scripts/install-dirigent-openclaw.mjs --uninstall" + }, + "keywords": [ + "openclaw", + "plugin", + "discord", + "moderation", + "turn-management" + ], + "license": "MIT", + "repository": { + "type": "git", + "url": "https://git.hangman-lab.top/nav/Dirigent.git" + }, + "engines": { + "node": ">=20" + } +} diff --git a/scripts/install-dirigent-openclaw.mjs b/scripts/install-dirigent-openclaw.mjs index 550188f..05d81bb 100755 --- a/scripts/install-dirigent-openclaw.mjs +++ b/scripts/install-dirigent-openclaw.mjs @@ -14,7 +14,19 @@ const mode = modeArg === "--install" ? "install" : "uninstall"; const env = process.env; const OPENCLAW_CONFIG_PATH = env.OPENCLAW_CONFIG_PATH || path.join(os.homedir(), ".openclaw", "openclaw.json"); const __dirname = path.dirname(new URL(import.meta.url).pathname); -const PLUGIN_PATH = env.PLUGIN_PATH || path.resolve(__dirname, "..", "dist", "dirigent"); + +// 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 PLUGIN_PATH = env.PLUGIN_PATH || DIST_DIR; const NO_REPLY_PROVIDER_ID = env.NO_REPLY_PROVIDER_ID || "dirigentway"; const NO_REPLY_MODEL_ID = env.NO_REPLY_MODEL_ID || "no-reply"; const NO_REPLY_BASE_URL = env.NO_REPLY_BASE_URL || "http://127.0.0.1:8787/v1";