mindkeeper-openclaw 0.2.14 → 0.2.16

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/dist/index.js CHANGED
@@ -1188,11 +1188,39 @@ function createWatcherService(api, trackerRef) {
1188
1188
  }
1189
1189
 
1190
1190
  // src/index.ts
1191
+ var MINDKEEPER_TOOLS = [
1192
+ "mind_status",
1193
+ "mind_history",
1194
+ "mind_diff",
1195
+ "mind_rollback",
1196
+ "mind_snapshot"
1197
+ ];
1191
1198
  function mindkeeperPlugin(api) {
1192
1199
  const trackerRef = { current: null };
1193
1200
  registerTrackerTools(api, trackerRef);
1194
1201
  registerTrackerCli(api, trackerRef);
1195
1202
  const watcherService = createWatcherService(api, trackerRef);
1196
1203
  api.registerService?.(watcherService);
1204
+ ensureToolsInConfig(api);
1197
1205
  api.log?.info?.("[mindkeeper] Plugin loaded.");
1198
1206
  }
1207
+ function ensureToolsInConfig(api) {
1208
+ const cfg = api.config;
1209
+ const writeConfigFile = api.runtime?.config?.writeConfigFile;
1210
+ if (!cfg || !writeConfigFile) return;
1211
+ const allow = cfg.tools?.allow ?? [];
1212
+ const alsoAllow = cfg.tools?.alsoAllow ?? [];
1213
+ const target = allow.length > 0 ? allow : alsoAllow;
1214
+ const key = allow.length > 0 ? "allow" : "alsoAllow";
1215
+ const existing = new Set(
1216
+ target.map((e) => String(e).trim().toLowerCase()).filter(Boolean)
1217
+ );
1218
+ const needed = MINDKEEPER_TOOLS.filter((t) => !existing.has(t));
1219
+ if (needed.length === 0) return;
1220
+ for (const t of needed) existing.add(t);
1221
+ const merged = Array.from(existing);
1222
+ void writeConfigFile({
1223
+ ...cfg,
1224
+ tools: { ...cfg.tools, [key]: merged }
1225
+ }).catch((err) => api.log?.warn?.(`[mindkeeper] Failed to auto-update tools.${key}:`, String(err)));
1226
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mindkeeper-openclaw",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "OpenClaw plugin for mindkeeper: auto-snapshot, diff, and rollback for agent context files",
5
5
  "keywords": [
6
6
  "openclaw",
@@ -25,13 +25,15 @@
25
25
  "files": [
26
26
  "dist",
27
27
  "skills",
28
- "openclaw.plugin.json"
28
+ "openclaw.plugin.json",
29
+ "scripts/postinstall-merge-config.cjs"
29
30
  ],
30
31
  "scripts": {
31
32
  "build": "node build.mjs",
32
33
  "typecheck": "tsc --noEmit",
33
34
  "clean": "rm -rf dist",
34
- "prepublishOnly": "npm run clean && npm run build"
35
+ "prepublishOnly": "npm run clean && npm run build",
36
+ "postinstall": "node scripts/postinstall-merge-config.cjs"
35
37
  },
36
38
  "openclaw": {
37
39
  "extensions": [
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Postinstall: merge mindkeeper tools into OpenClaw config.
3
+ * - If tools.allow exists: merge into tools.allow (allow and alsoAllow are mutually exclusive).
4
+ * - Else: merge into tools.alsoAllow.
5
+ * Runs during plugin install so a single gateway restart is enough.
6
+ */
7
+ const fs = require("node:fs");
8
+ const path = require("node:path");
9
+ const os = require("node:os");
10
+
11
+ const TOOLS = [
12
+ "mind_status",
13
+ "mind_history",
14
+ "mind_diff",
15
+ "mind_rollback",
16
+ "mind_snapshot",
17
+ ];
18
+
19
+ function findConfigPath() {
20
+ const home = os.homedir();
21
+ if (!home) return null;
22
+
23
+ const candidates = [
24
+ process.env.OPENCLAW_CONFIG_PATH,
25
+ process.env.CLAWDBOT_CONFIG_PATH,
26
+ path.join(home, ".openclaw", "openclaw.json"),
27
+ path.join(home, ".openclaw", "clawdbot.json"),
28
+ path.join(home, ".clawdbot", "openclaw.json"),
29
+ path.join(home, ".clawdbot", "clawdbot.json"),
30
+ ].filter(Boolean);
31
+
32
+ for (const p of candidates) {
33
+ try {
34
+ const resolved = path.resolve(p.replace(/^~/, home));
35
+ if (fs.existsSync(resolved) && fs.statSync(resolved).isFile()) return resolved;
36
+ } catch {
37
+ /* skip */
38
+ }
39
+ }
40
+ const defaultPath = path.join(home, ".openclaw", "openclaw.json");
41
+ if (fs.existsSync(defaultPath)) return defaultPath;
42
+ return null;
43
+ }
44
+
45
+ function run() {
46
+ const configPath = findConfigPath();
47
+ if (!configPath) return;
48
+
49
+ let cfg;
50
+ try {
51
+ cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
52
+ } catch {
53
+ return;
54
+ }
55
+
56
+ const allow = cfg.tools?.allow ?? [];
57
+ const alsoAllow = cfg.tools?.alsoAllow ?? [];
58
+ const target = allow.length > 0 ? allow : alsoAllow;
59
+ const key = allow.length > 0 ? "allow" : "alsoAllow";
60
+
61
+ const existing = new Set(
62
+ target.map((e) => String(e).trim().toLowerCase()).filter(Boolean),
63
+ );
64
+ const needed = TOOLS.filter((t) => !existing.has(t));
65
+ if (needed.length === 0) return;
66
+
67
+ for (const t of needed) existing.add(t);
68
+ cfg.tools = { ...cfg.tools, [key]: Array.from(existing) };
69
+
70
+ try {
71
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2), "utf-8");
72
+ } catch {
73
+ /* ignore */
74
+ }
75
+ }
76
+
77
+ run();