@drakon-systems/multi-clawd 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -165,10 +165,15 @@ second Claude subscription you own.
165
165
  **Upgrading:**
166
166
 
167
167
  ```bash
168
- # Registry install (npm / ClawHub):
169
- openclaw plugins install @drakon-systems/multi-clawd@latest --force
170
- openclaw gateway restart
168
+ npx @drakon-systems/multi-clawd update
169
+ ```
171
170
 
171
+ One command: checks the registry, installs the new version with the right
172
+ flags, offers the gateway restart, and finishes with a doctor health check.
173
+ (`npm i -g @drakon-systems/multi-clawd` once, and it's just `multi-clawd
174
+ update` — with `multi-clawd setup` and `multi-clawd doctor` alongside.)
175
+
176
+ ```bash
172
177
  # From source:
173
178
  cd multi-clawd && git pull && npm install && npm run build && npm run doctor
174
179
  ```
@@ -0,0 +1,30 @@
1
+ export function compareVersions(a, b) {
2
+ const pa = a.split(".").map((n) => parseInt(n, 10) || 0);
3
+ const pb = b.split(".").map((n) => parseInt(n, 10) || 0);
4
+ for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
5
+ const d = (pa[i] ?? 0) - (pb[i] ?? 0);
6
+ if (d !== 0)
7
+ return d;
8
+ }
9
+ return 0;
10
+ }
11
+ export function decideUpdateAction(opts) {
12
+ if (opts.installed === undefined)
13
+ return "install";
14
+ if (opts.latest === undefined)
15
+ return "unknown";
16
+ return compareVersions(opts.installed, opts.latest) < 0 ? "update" : "up-to-date";
17
+ }
18
+ export function formatUpdateBanner(opts) {
19
+ const action = decideUpdateAction(opts);
20
+ switch (action) {
21
+ case "install":
22
+ return `not installed — latest is v${opts.latest}`;
23
+ case "update":
24
+ return `update available: v${opts.installed} → v${opts.latest}`;
25
+ case "up-to-date":
26
+ return `up to date (v${opts.installed})`;
27
+ case "unknown":
28
+ return `installed v${opts.installed} — could not reach the registry to check for updates`;
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drakon-systems/multi-clawd",
3
- "version": "1.1.0",
3
+ "version": "1.2.1",
4
4
  "description": "Multi-account Claude Code failover for OpenClaw — register additional Claude (Max/Pro) logins as first-class CLI backends and keep the full skills/MCP harness across every account.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -35,6 +35,9 @@
35
35
  }
36
36
  },
37
37
  "main": "./dist/index.js",
38
+ "bin": {
39
+ "multi-clawd": "./scripts/cli.mjs"
40
+ },
38
41
  "publishConfig": {
39
42
  "access": "public"
40
43
  },
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Shared helpers for the CLI scripts (cli.mjs, setup.mjs).
3
+ *
4
+ * resolveWatchdogScript exists because of a real footgun: run via `npx`, a
5
+ * script's __dirname is the EPHEMERAL npx cache — pointing a scheduled unit
6
+ * there breaks on the next cache clean. The watchdog target must be the
7
+ * INSTALLED plugin's copy whenever one exists; the __dirname sibling is only
8
+ * correct for a source checkout with no install.
9
+ */
10
+ import { existsSync, readdirSync, statSync } from "node:fs";
11
+ import { homedir } from "node:os";
12
+ import { join } from "node:path";
13
+
14
+ /** Where the plugin is installed: path install wins, else newest npm-project install. */
15
+ export function resolveInstallDir() {
16
+ const HOME = homedir();
17
+ const extDir = join(HOME, ".openclaw", "extensions", "multi-clawd");
18
+ if (existsSync(join(extDir, "openclaw.plugin.json"))) return extDir;
19
+ const projects = join(HOME, ".openclaw", "npm", "projects");
20
+ let best;
21
+ let bestM = -1;
22
+ try {
23
+ for (const p of readdirSync(projects)) {
24
+ if (!p.startsWith("drakon-systems-multi-clawd-")) continue;
25
+ const dir = join(projects, p, "node_modules", "@drakon-systems", "multi-clawd");
26
+ const manifest = join(dir, "openclaw.plugin.json");
27
+ if (!existsSync(manifest)) continue;
28
+ const m = statSync(manifest).mtimeMs;
29
+ if (m > bestM) {
30
+ bestM = m;
31
+ best = dir;
32
+ }
33
+ }
34
+ } catch {
35
+ /* no npm projects dir */
36
+ }
37
+ return best;
38
+ }
39
+
40
+ /** The watchdog script a scheduled unit should point at. */
41
+ export function resolveWatchdogScript(fallbackDir) {
42
+ const inst = resolveInstallDir();
43
+ if (inst) {
44
+ const p = join(inst, "scripts", "eviction-watchdog.mjs");
45
+ if (existsSync(p)) return p;
46
+ }
47
+ return join(fallbackDir, "eviction-watchdog.mjs");
48
+ }
@@ -0,0 +1,162 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * multi-clawd CLI — the friendly front door.
4
+ *
5
+ * npx @drakon-systems/multi-clawd setup guided setup wizard
6
+ * npx @drakon-systems/multi-clawd update update to the latest version
7
+ * npx @drakon-systems/multi-clawd doctor health check
8
+ * npx @drakon-systems/multi-clawd version versions (CLI + installed plugin)
9
+ *
10
+ * (Installed globally via `npm i -g @drakon-systems/multi-clawd`, the same
11
+ * commands are just `multi-clawd setup` / `multi-clawd update` / …)
12
+ *
13
+ * `update` wraps the whole upgrade dance — registry version check, the
14
+ * openclaw install with the right flags, gateway restart, doctor — so nobody
15
+ * has to remember `--pin --force`.
16
+ */
17
+ import { execFileSync, spawnSync } from "node:child_process";
18
+ import { readFileSync } from "node:fs";
19
+ import { dirname, join, resolve } from "node:path";
20
+ import { fileURLToPath } from "node:url";
21
+ import readline from "node:readline/promises";
22
+
23
+ const __dirname = dirname(fileURLToPath(import.meta.url));
24
+ const PKG = "@drakon-systems/multi-clawd";
25
+ const BOLD = process.stdout.isTTY ? "\x1b[1m" : "";
26
+ const DIM = process.stdout.isTTY ? "\x1b[2m" : "";
27
+ const RESET = process.stdout.isTTY ? "\x1b[0m" : "";
28
+
29
+ const [cmd, ...rest] = process.argv.slice(2);
30
+
31
+ function usage() {
32
+ console.log(`
33
+ ${BOLD}🦞 multi-clawd${RESET} — multi-account Claude failover for OpenClaw
34
+
35
+ ${BOLD}setup${RESET} guided setup wizard (accounts, pool, watchdog)
36
+ ${BOLD}update${RESET} update the plugin to the latest version
37
+ ${BOLD}doctor${RESET} health check (add --probe for a live turn)
38
+ ${BOLD}version${RESET} show CLI + installed plugin versions
39
+
40
+ Run via npx (${DIM}npx ${PKG} <command>${RESET}) or install globally
41
+ (${DIM}npm i -g ${PKG}${RESET}) for a bare ${DIM}multi-clawd <command>${RESET}.
42
+ `);
43
+ }
44
+
45
+ const { resolveInstallDir } = await import(join(__dirname, "_shared.mjs"));
46
+
47
+ function installedVersion() {
48
+ const dir = resolveInstallDir();
49
+ if (!dir) return undefined;
50
+ try {
51
+ return JSON.parse(readFileSync(join(dir, "package.json"), "utf8")).version;
52
+ } catch {
53
+ return undefined;
54
+ }
55
+ }
56
+
57
+ function latestVersion() {
58
+ try {
59
+ return execFileSync("npm", ["view", PKG, "version"], { encoding: "utf8", timeout: 15000 })
60
+ .trim();
61
+ } catch {
62
+ return undefined;
63
+ }
64
+ }
65
+
66
+ function haveOpenclaw() {
67
+ try {
68
+ execFileSync("openclaw", ["--version"], { stdio: "pipe", timeout: 15000 });
69
+ return true;
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+
75
+ function runSibling(script, args) {
76
+ const r = spawnSync(process.execPath, [join(__dirname, script), ...args], { stdio: "inherit" });
77
+ process.exit(r.status ?? 1);
78
+ }
79
+
80
+ async function askYes(question, dflt = true) {
81
+ if (!process.stdin.isTTY) return dflt;
82
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
83
+ const a = (await rl.question(`${question} ${dflt ? "[Y/n]" : "[y/N]"} `)).trim().toLowerCase();
84
+ rl.close();
85
+ if (!a) return dflt;
86
+ return a.startsWith("y");
87
+ }
88
+
89
+ async function update() {
90
+ let uc;
91
+ try {
92
+ uc = await import(resolve(__dirname, "..", "dist", "update-core.js"));
93
+ } catch {
94
+ console.error("update: built dist/ is missing — reinstall the package.");
95
+ process.exit(1);
96
+ }
97
+ console.log(`\n${BOLD}🦞 multi-clawd update${RESET}\n`);
98
+ if (!haveOpenclaw()) {
99
+ console.error(" ❌ the `openclaw` CLI is not on PATH — install OpenClaw first.");
100
+ process.exit(1);
101
+ }
102
+ const installed = installedVersion();
103
+ process.stdout.write(` checking registry… `);
104
+ const latest = latestVersion();
105
+ console.log(latest ? `latest is v${latest}` : "unreachable");
106
+ const banner = uc.formatUpdateBanner({ installed, latest });
107
+ const action = uc.decideUpdateAction({ installed, latest });
108
+ console.log(` ${action === "up-to-date" ? "✅" : action === "unknown" ? "⚠️ " : "⬆️ "} ${banner}\n`);
109
+ if (action === "up-to-date") return;
110
+ if (action === "unknown") {
111
+ console.log(" Check your network and try again.");
112
+ process.exit(1);
113
+ }
114
+ if (!(await askYes(` ${action === "install" ? "Install" : "Update"} now?`))) return;
115
+
116
+ console.log(`\n ${DIM}openclaw plugins install ${PKG} --pin --force${RESET}`);
117
+ const inst = spawnSync("openclaw", ["plugins", "install", PKG, "--pin", "--force"], {
118
+ stdio: "inherit",
119
+ });
120
+ if (inst.status !== 0) {
121
+ console.error("\n ❌ install failed — see output above.");
122
+ process.exit(1);
123
+ }
124
+ if (await askYes("\n Restart the gateway to load it? (briefly interrupts running turns)")) {
125
+ const r = spawnSync("openclaw", ["gateway", "restart"], { stdio: "inherit" });
126
+ if (r.status !== 0) console.log(" ⚠ restart failed — run `openclaw gateway restart` yourself.");
127
+ } else {
128
+ console.log(" ⏳ remember: the new version loads on the next gateway restart.");
129
+ }
130
+ console.log(`\n${BOLD} health check${RESET}`);
131
+ const doc = spawnSync(process.execPath, [join(__dirname, "doctor.mjs")], { stdio: "inherit" });
132
+ if (doc.status !== 0) {
133
+ console.log(`\n ⚠ doctor found problems — if it flagged the watchdog, run ${BOLD}npx ${PKG} setup${RESET} to repair it.`);
134
+ process.exit(doc.status ?? 1);
135
+ }
136
+ console.log(`\n ✅ done — now on v${installedVersion() ?? "?"}`);
137
+ }
138
+
139
+ switch (cmd) {
140
+ case "setup":
141
+ runSibling("setup.mjs", rest);
142
+ break;
143
+ case "doctor":
144
+ runSibling("doctor.mjs", rest);
145
+ break;
146
+ case "update":
147
+ await update();
148
+ break;
149
+ case "version":
150
+ case "--version":
151
+ case "-v": {
152
+ const cliVersion = JSON.parse(
153
+ readFileSync(resolve(__dirname, "..", "package.json"), "utf8"),
154
+ ).version;
155
+ console.log(`cli: v${cliVersion}`);
156
+ console.log(`installed plugin: ${installedVersion() ? `v${installedVersion()}` : "(not installed)"}`);
157
+ break;
158
+ }
159
+ default:
160
+ usage();
161
+ process.exit(cmd === undefined || cmd === "help" || cmd === "--help" ? 0 : 1);
162
+ }
package/scripts/setup.mjs CHANGED
@@ -229,7 +229,10 @@ async function watchdogStep() {
229
229
  console.log(" (auto-scheduling not supported on this platform — see README for manual setup)");
230
230
  return;
231
231
  }
232
- const scriptPath = join(__dirname, "eviction-watchdog.mjs");
232
+ // Install-aware: under npx, __dirname is the EPHEMERAL npx cache — the unit
233
+ // must point at the installed plugin's copy whenever one exists.
234
+ const { resolveWatchdogScript } = await import(resolve(__dirname, "_shared.mjs"));
235
+ const scriptPath = resolveWatchdogScript(__dirname);
233
236
  const scanDir =
234
237
  platform === "darwin"
235
238
  ? join(homedir(), "Library", "LaunchAgents")