@badgerclaw/connect 1.4.4 → 1.4.6

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/index.ts CHANGED
@@ -6,7 +6,7 @@ import { setMatrixRuntime } from "./src/runtime.js";
6
6
 
7
7
  async function checkPluginUpdate(log: (msg: string) => void): Promise<void> {
8
8
  try {
9
- const CURRENT = "1.4.3";
9
+ const CURRENT = "1.4.4";
10
10
  const controller = new AbortController();
11
11
  setTimeout(() => controller.abort(), 3000);
12
12
  const resp = await fetch("https://registry.npmjs.org/@badgerclaw/connect/latest", { signal: controller.signal });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badgerclaw/connect",
3
- "version": "1.4.4",
3
+ "version": "1.4.6",
4
4
  "description": "BadgerClaw channel plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -1,11 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
+ const os = require('os');
4
5
 
5
- const CANDIDATES = [
6
- '/opt/homebrew/lib/node_modules/openclaw/package.json',
7
- '/usr/local/lib/node_modules/openclaw/package.json',
8
- path.join(process.env.HOME || '', '.npm-global/lib/node_modules/openclaw/package.json'),
6
+ const OPENCLAW_PKG_CANDIDATES = [
7
+ '/opt/homebrew/lib/node_modules/openclaw',
8
+ '/usr/local/lib/node_modules/openclaw',
9
+ path.join(os.homedir(), '.npm-global/lib/node_modules/openclaw'),
9
10
  ];
10
11
 
11
12
  const MISSING_EXPORTS = {
@@ -14,16 +15,65 @@ const MISSING_EXPORTS = {
14
15
  './plugin-sdk/config-runtime': { types: './dist/plugin-sdk/config-runtime.d.ts', default: './dist/plugin-sdk/config-runtime.js' },
15
16
  };
16
17
 
17
- const pkgPath = CANDIDATES.find(p => fs.existsSync(p));
18
- if (!pkgPath) { console.log('[badgerclaw] postinstall: openclaw not found, skipping'); process.exit(0); }
18
+ const openclawDir = OPENCLAW_PKG_CANDIDATES.find(p => fs.existsSync(path.join(p, 'package.json')));
19
19
 
20
+ if (!openclawDir) {
21
+ console.log('[badgerclaw] openclaw not found — skipping setup');
22
+ process.exit(0);
23
+ }
24
+
25
+ // 1. Patch exports map
20
26
  try {
27
+ const pkgPath = path.join(openclawDir, 'package.json');
21
28
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
22
29
  pkg.exports = pkg.exports || {};
23
30
  let patched = false;
24
31
  for (const [key, entry] of Object.entries(MISSING_EXPORTS)) {
25
- if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched: ${key}`); patched = true; }
32
+ if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched exports: ${key}`); patched = true; }
26
33
  }
27
34
  if (patched) fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
28
- else console.log('[badgerclaw] openclaw exports map already up to date');
29
- } catch (e) { console.log('[badgerclaw] postinstall warning:', e.message); }
35
+ else console.log('[badgerclaw] exports map already up to date');
36
+ } catch (e) { console.log('[badgerclaw] exports patch warning:', e.message); }
37
+
38
+ // 2. Symlink openclaw into plugin node_modules so imports resolve
39
+ try {
40
+ const pluginDir = path.join(os.homedir(), '.openclaw', 'extensions', 'badgerclaw');
41
+ const pluginNodeModules = path.join(pluginDir, 'node_modules');
42
+ const symlink = path.join(pluginNodeModules, 'openclaw');
43
+ if (!fs.existsSync(symlink)) {
44
+ fs.mkdirSync(pluginNodeModules, { recursive: true });
45
+ fs.symlinkSync(openclawDir, symlink);
46
+ console.log(`[badgerclaw] symlinked openclaw → ${openclawDir}`);
47
+ } else {
48
+ console.log('[badgerclaw] openclaw symlink already exists');
49
+ }
50
+ } catch (e) { console.log('[badgerclaw] symlink warning:', e.message); }
51
+
52
+ // 3. Config stash/restore for reinstalls
53
+ const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
54
+ const stashPath = configPath + '.badgerclaw-stash';
55
+
56
+ if (!fs.existsSync(configPath)) { process.exit(0); }
57
+
58
+ try {
59
+ const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
60
+ const bcConfig = config.channels?.badgerclaw;
61
+ if (!bcConfig) { process.exit(0); }
62
+
63
+ delete config.channels.badgerclaw;
64
+ if (config.plugins?.entries?.badgerclaw) delete config.plugins.entries.badgerclaw;
65
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
66
+ fs.writeFileSync(stashPath, JSON.stringify(bcConfig, null, 2));
67
+ console.log('[badgerclaw] stashed channels.badgerclaw config');
68
+
69
+ setTimeout(() => {
70
+ try {
71
+ const cur = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
72
+ cur.channels = cur.channels || {};
73
+ cur.channels.badgerclaw = JSON.parse(fs.readFileSync(stashPath, 'utf-8'));
74
+ fs.writeFileSync(configPath, JSON.stringify(cur, null, 2));
75
+ fs.unlinkSync(stashPath);
76
+ console.log('[badgerclaw] restored channels.badgerclaw config');
77
+ } catch (e) { console.log('[badgerclaw] restore warning:', e.message); }
78
+ }, 500);
79
+ } catch (e) { console.log('[badgerclaw] config stash warning:', e.message); }