@badgerclaw/connect 1.4.9 → 1.4.11

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
@@ -4,11 +4,12 @@ import { matrixPlugin } from "./src/channel.js";
4
4
  import { ensureMatrixCryptoRuntime } from "./src/matrix/deps.js";
5
5
  import { setMatrixRuntime } from "./src/runtime.js";
6
6
 
7
- let _pairWatcherStarted = false;
7
+ // Use global scope so the flag persists across module reloads (channel restarts)
8
+ const _g = global as any;
8
9
 
9
10
  async function startPairWatcher(logger: { info?: (msg: string) => void; warn?: (msg: string) => void }): Promise<void> {
10
- if (_pairWatcherStarted) return;
11
- _pairWatcherStarted = true;
11
+ if (_g._badgerclawPairWatcherStarted) return;
12
+ _g._badgerclawPairWatcherStarted = true;
12
13
  const log = logger.info ?? console.log;
13
14
  const warn = logger.warn ?? console.warn;
14
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@badgerclaw/connect",
3
- "version": "1.4.9",
3
+ "version": "1.4.11",
4
4
  "description": "BadgerClaw channel plugin for OpenClaw",
5
5
  "type": "module",
6
6
  "dependencies": {
@@ -1,71 +1,57 @@
1
1
  #!/usr/bin/env node
2
- const fs = require('fs');
3
- const path = require('path');
4
- const os = require('os');
5
-
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'),
2
+ const fs = require('fs'), path = require('path'), os = require('os');
3
+ const CANDIDATES = [
4
+ '/opt/homebrew/lib/node_modules/openclaw/package.json',
5
+ '/usr/local/lib/node_modules/openclaw/package.json',
6
+ path.join(os.homedir(), '.npm-global/lib/node_modules/openclaw/package.json'),
10
7
  ];
8
+ const pkgPath = CANDIDATES.find(p => fs.existsSync(p));
9
+ if (!pkgPath) { console.log('[badgerclaw] openclaw not found'); process.exit(0); }
11
10
 
12
- const MISSING_EXPORTS = {
13
- './plugin-sdk/compat': { types: './dist/plugin-sdk/compat.d.ts', default: './dist/plugin-sdk/compat.js' },
14
- './plugin-sdk/extension-shared': { types: './dist/plugin-sdk/extension-shared.d.ts', default: './dist/plugin-sdk/extension-shared.js' },
15
- './plugin-sdk/config-runtime': { types: './dist/plugin-sdk/config-runtime.d.ts', default: './dist/plugin-sdk/config-runtime.js' },
16
- };
17
-
18
- const openclawDir = OPENCLAW_PKG_CANDIDATES.find(p => fs.existsSync(path.join(p, 'package.json')));
19
-
20
- if (!openclawDir) {
21
- console.log('[badgerclaw] openclaw not found — skipping setup');
22
- process.exit(0);
23
- }
24
-
25
- // 1. Patch exports map
11
+ // Patch exports map
26
12
  try {
27
- const pkgPath = path.join(openclawDir, 'package.json');
28
13
  const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
29
14
  pkg.exports = pkg.exports || {};
15
+ const sdkDir = path.join(path.dirname(pkgPath), 'dist', 'plugin-sdk');
16
+ const needed = ['compat','extension-shared','config-runtime','matrix-runtime-heavy',
17
+ 'account-id','bluebubbles','channel-runtime','googlechat','allow-from','channel-inbound'];
30
18
  let patched = false;
31
- for (const [key, entry] of Object.entries(MISSING_EXPORTS)) {
32
- if (!pkg.exports[key]) { pkg.exports[key] = entry; console.log(`[badgerclaw] patched exports: ${key}`); patched = true; }
19
+ for (const sub of needed) {
20
+ const key = `./plugin-sdk/${sub}`;
21
+ const jsPath = path.join(sdkDir, `${sub}.js`);
22
+ if (!pkg.exports[key] && fs.existsSync(jsPath)) {
23
+ pkg.exports[key] = { types: `./dist/plugin-sdk/${sub}.d.ts`, default: `./dist/plugin-sdk/${sub}.js` };
24
+ console.log(`[badgerclaw] patched: ${key}`);
25
+ patched = true;
26
+ }
33
27
  }
34
28
  if (patched) fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
35
- else console.log('[badgerclaw] exports map already up to date');
36
- } catch (e) { console.log('[badgerclaw] exports patch warning:', e.message); }
29
+ else console.log('[badgerclaw] exports map up to date');
30
+ } catch (e) { console.log('[badgerclaw] patch warning:', e.message); }
37
31
 
38
- // 2. Symlink openclaw into plugin node_modules so imports resolve
32
+ // Symlink openclaw
39
33
  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');
34
+ const symlink = path.join(os.homedir(), '.openclaw', 'extensions', 'badgerclaw', 'node_modules', 'openclaw');
43
35
  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');
36
+ fs.mkdirSync(path.dirname(symlink), { recursive: true });
37
+ fs.symlinkSync(path.dirname(pkgPath), symlink);
38
+ console.log('[badgerclaw] symlinked openclaw');
49
39
  }
50
- } catch (e) { console.log('[badgerclaw] symlink warning:', e.message); }
40
+ } catch (e) { console.log('[badgerclaw] symlink:', e.message); }
51
41
 
52
- // 3. Config stash/restore for reinstalls
42
+ // Config stash/restore
53
43
  const configPath = path.join(os.homedir(), '.openclaw', 'openclaw.json');
54
44
  const stashPath = configPath + '.badgerclaw-stash';
55
-
56
- if (!fs.existsSync(configPath)) { process.exit(0); }
57
-
45
+ if (!fs.existsSync(configPath)) process.exit(0);
58
46
  try {
59
47
  const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
60
48
  const bcConfig = config.channels?.badgerclaw;
61
- if (!bcConfig) { process.exit(0); }
62
-
49
+ if (!bcConfig || Object.keys(bcConfig).length === 0) process.exit(0);
63
50
  delete config.channels.badgerclaw;
64
51
  if (config.plugins?.entries?.badgerclaw) delete config.plugins.entries.badgerclaw;
65
52
  fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
66
53
  fs.writeFileSync(stashPath, JSON.stringify(bcConfig, null, 2));
67
54
  console.log('[badgerclaw] stashed channels.badgerclaw config');
68
-
69
55
  setTimeout(() => {
70
56
  try {
71
57
  const cur = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
@@ -76,4 +62,4 @@ try {
76
62
  console.log('[badgerclaw] restored channels.badgerclaw config');
77
63
  } catch (e) { console.log('[badgerclaw] restore warning:', e.message); }
78
64
  }, 500);
79
- } catch (e) { console.log('[badgerclaw] config stash warning:', e.message); }
65
+ } catch (e) { console.log('[badgerclaw] stash warning:', e.message); }
@@ -1,10 +1,12 @@
1
1
  import {
2
2
  formatAllowlistMatchMeta,
3
3
  issuePairingChallenge,
4
- readStoreAllowFromForDmPolicy,
5
- resolveDmGroupAccessWithLists,
6
4
  resolveSenderScopedGroupPolicy,
7
5
  } from "openclaw/plugin-sdk/matrix";
6
+ import {
7
+ readStoreAllowFromForDmPolicy,
8
+ resolveDmGroupAccessWithLists,
9
+ } from "openclaw/plugin-sdk/compat";
8
10
  import {
9
11
  normalizeMatrixAllowList,
10
12
  resolveMatrixAllowListMatch,
@@ -1,20 +1,16 @@
1
1
  import type { LocationMessageEventContent, MatrixClient } from "@vector-im/matrix-bot-sdk";
2
2
  import {
3
- DEFAULT_ACCOUNT_ID,
4
- createChannelPairingController,
5
- createReplyPrefixOptions,
6
- createTypingCallbacks,
7
- dispatchReplyFromConfigWithSettledDispatcher,
8
- evaluateGroupRouteAccessForPolicy,
9
- formatAllowlistMatchMeta,
10
- logInboundDrop,
11
- logTypingFailure,
12
- resolveInboundSessionEnvelopeContext,
13
- resolveControlCommandGate,
14
3
  type PluginRuntime,
15
4
  type RuntimeEnv,
16
5
  type RuntimeLogger,
17
6
  } from "openclaw/plugin-sdk/matrix";
7
+ import { DEFAULT_ACCOUNT_ID } from "openclaw/plugin-sdk/account-id";
8
+ import { createChannelPairingController, logInboundDrop, logTypingFailure, resolveControlCommandGate } from "openclaw/plugin-sdk/bluebubbles";
9
+ import { createReplyPrefixOptions, createTypingCallbacks } from "openclaw/plugin-sdk/channel-runtime";
10
+ import { evaluateGroupRouteAccessForPolicy } from "openclaw/plugin-sdk/googlechat";
11
+ import { formatAllowlistMatchMeta } from "openclaw/plugin-sdk/allow-from";
12
+ import { resolveInboundSessionEnvelopeContext } from "openclaw/plugin-sdk/channel-inbound";
13
+ import { dispatchReplyFromConfigWithSettledDispatcher } from "openclaw/plugin-sdk/matrix-runtime-heavy";
18
14
  import type { CoreConfig, MatrixRoomConfig, ReplyToMode } from "../../types.js";
19
15
  import { fetchEventSummary } from "../actions/summary.js";
20
16
  import {