@deeplake/hivemind 0.7.29 → 0.7.31

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.
@@ -19,6 +19,9 @@ function isAllowlistCoveringHivemind(alsoAllow) {
19
19
  }
20
20
  return false;
21
21
  }
22
+ function isPluginsAllowMissingHivemind(allow) {
23
+ return Array.isArray(allow) && allow.length > 0 && !allow.includes("hivemind");
24
+ }
22
25
  function ensureHivemindAllowlisted() {
23
26
  const configPath = getOpenclawConfigPath();
24
27
  if (!existsSync(configPath)) {
@@ -31,18 +34,33 @@ function ensureHivemindAllowlisted() {
31
34
  } catch (e) {
32
35
  return { status: "error", configPath, error: `could not read/parse config: ${e instanceof Error ? e.message : String(e)}` };
33
36
  }
37
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
38
+ return { status: "error", configPath, error: "openclaw config is not a JSON object" };
39
+ }
40
+ const plugins = parsed.plugins ?? {};
41
+ const pluginsAllowRaw = plugins.allow;
34
42
  const tools = parsed.tools ?? {};
35
- const alsoAllow = Array.isArray(tools.alsoAllow) ? tools.alsoAllow : [];
36
- if (isAllowlistCoveringHivemind(alsoAllow)) {
43
+ const alsoAllowRaw = tools.alsoAllow;
44
+ const pluginsAllowNeedsPatch = isPluginsAllowMissingHivemind(pluginsAllowRaw);
45
+ const toolsAlsoAllowNeedsPatch = Array.isArray(alsoAllowRaw) && alsoAllowRaw.length > 0 && !isAllowlistCoveringHivemind(alsoAllowRaw);
46
+ if (!pluginsAllowNeedsPatch && !toolsAlsoAllowNeedsPatch) {
37
47
  return { status: "already-set", configPath };
38
48
  }
39
- const updated = {
40
- ...parsed,
41
- tools: {
49
+ const updated = { ...parsed };
50
+ if (pluginsAllowNeedsPatch) {
51
+ updated.plugins = {
52
+ ...plugins,
53
+ // Cast safe — isPluginsAllowMissingHivemind guarantees Array.
54
+ allow: [...pluginsAllowRaw, "hivemind"]
55
+ };
56
+ }
57
+ if (toolsAlsoAllowNeedsPatch) {
58
+ updated.tools = {
42
59
  ...tools,
43
- alsoAllow: [...alsoAllow, "hivemind"]
44
- }
45
- };
60
+ // Cast safe — the needs-patch check above guarantees Array.
61
+ alsoAllow: [...alsoAllowRaw, "hivemind"]
62
+ };
63
+ }
46
64
  const backupPath = `${configPath}.bak-hivemind-${Date.now()}`;
47
65
  const tmpPath = `${configPath}.tmp-hivemind-${process.pid}`;
48
66
  try {
@@ -52,7 +70,15 @@ function ensureHivemindAllowlisted() {
52
70
  } catch (e) {
53
71
  return { status: "error", configPath, error: `could not write config: ${e instanceof Error ? e.message : String(e)}` };
54
72
  }
55
- return { status: "added", configPath, backupPath };
73
+ return {
74
+ status: "added",
75
+ configPath,
76
+ backupPath,
77
+ delta: {
78
+ pluginsAllow: pluginsAllowNeedsPatch,
79
+ toolsAlsoAllow: toolsAlsoAllowNeedsPatch
80
+ }
81
+ };
56
82
  }
57
83
  function toggleAutoUpdateConfig(setTo) {
58
84
  const configPath = getOpenclawConfigPath();
@@ -100,8 +126,12 @@ function detectAllowlistMissing() {
100
126
  if (!existsSync(configPath)) return false;
101
127
  try {
102
128
  const parsed = JSON.parse(readFileSync(configPath, "utf-8"));
129
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) return false;
130
+ const plugins = parsed.plugins ?? {};
103
131
  const tools = parsed.tools ?? {};
104
- return !isAllowlistCoveringHivemind(tools.alsoAllow);
132
+ const alsoAllow = tools.alsoAllow;
133
+ const toolsMissing = Array.isArray(alsoAllow) && alsoAllow.length > 0 && !isAllowlistCoveringHivemind(alsoAllow);
134
+ return isPluginsAllowMissingHivemind(plugins.allow) || toolsMissing;
105
135
  } catch {
106
136
  return false;
107
137
  }
@@ -112,5 +142,6 @@ export {
112
142
  ensureHivemindAllowlisted,
113
143
  getOpenclawConfigPath,
114
144
  isAllowlistCoveringHivemind,
145
+ isPluginsAllowMissingHivemind,
115
146
  toggleAutoUpdateConfig
116
147
  };
@@ -1036,7 +1036,10 @@ import {
1036
1036
  closeSync as fsClose,
1037
1037
  writeFileSync as fsWriteFile,
1038
1038
  constants as fsConstants,
1039
- renameSync as fsRename
1039
+ readFileSync as fsReadFile,
1040
+ renameSync as fsRename,
1041
+ unlinkSync as fsUnlink,
1042
+ statSync as fsStat
1040
1043
  } from "node:fs";
1041
1044
  import { createHash } from "node:crypto";
1042
1045
  import { createRequire } from "node:module";
@@ -1044,7 +1047,7 @@ function definePluginEntry(entry) {
1044
1047
  return entry;
1045
1048
  }
1046
1049
  function loadSetupConfig() {
1047
- return import("./chunks/setup-config-VI54GEUM.js");
1050
+ return import("./chunks/setup-config-ZYMCZQMJ.js");
1048
1051
  }
1049
1052
  var credsModulePromise = null;
1050
1053
  var configModulePromise = null;
@@ -1108,7 +1111,7 @@ function extractLatestVersion(body) {
1108
1111
  return typeof v === "string" && v.length > 0 ? v : null;
1109
1112
  }
1110
1113
  function getInstalledVersion() {
1111
- return "0.7.29".length > 0 ? "0.7.29" : null;
1114
+ return "0.7.31".length > 0 ? "0.7.31" : null;
1112
1115
  }
1113
1116
  function isNewer(latest, current) {
1114
1117
  const parse = (v) => v.replace(/-.*$/, "").split(".").map(Number);
@@ -1211,6 +1214,7 @@ var skillsTable = "skills";
1211
1214
  var captureEnabled = true;
1212
1215
  var capturedCounts = /* @__PURE__ */ new Map();
1213
1216
  var fallbackSessionId = crypto.randomUUID();
1217
+ var skillifySpawnedFor = /* @__PURE__ */ new Set();
1214
1218
  var __openclaw_filename = fileURLToPath(import.meta.url);
1215
1219
  var __openclaw_dirname = dirnamePath(__openclaw_filename);
1216
1220
  var OPENCLAW_SKILLIFY_WORKER_PATH = joinPath(__openclaw_dirname, "skillify-worker.js");
@@ -1235,14 +1239,51 @@ function deriveOpenclawProjectKey(channel) {
1235
1239
  const key = createHash("sha1").update(project).digest("hex").slice(0, 16);
1236
1240
  return { key, project };
1237
1241
  }
1242
+ var LOCK_MAX_AGE_MS = 10 * 60 * 1e3;
1238
1243
  function tryAcquireOpenclawSkillifyLock(projectKey) {
1239
1244
  try {
1240
1245
  migrateOpenclawSkillifyLegacyStateDir();
1241
1246
  fsMkdir(OPENCLAW_SKILLIFY_STATE_DIR, { recursive: true });
1242
1247
  const lockPath = joinPath(OPENCLAW_SKILLIFY_STATE_DIR, `${projectKey}.worker.lock`);
1243
- const fd = fsOpen(lockPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY);
1244
- fsClose(fd);
1245
- return true;
1248
+ const acquire = () => {
1249
+ const fd = fsOpen(lockPath, fsConstants.O_CREAT | fsConstants.O_EXCL | fsConstants.O_WRONLY);
1250
+ try {
1251
+ fsWriteFile(fd, String(Date.now()));
1252
+ } finally {
1253
+ fsClose(fd);
1254
+ }
1255
+ return true;
1256
+ };
1257
+ try {
1258
+ return acquire();
1259
+ } catch {
1260
+ try {
1261
+ const body = fsReadFile(lockPath, "utf-8");
1262
+ const ts = Number.parseInt(body.trim(), 10);
1263
+ const ageByBody = Number.isFinite(ts) ? Date.now() - ts : Number.POSITIVE_INFINITY;
1264
+ let ageByMtime = 0;
1265
+ try {
1266
+ ageByMtime = Date.now() - fsStat(lockPath).mtimeMs;
1267
+ } catch {
1268
+ ageByMtime = 0;
1269
+ }
1270
+ const effectiveAge = Number.isFinite(ts) ? ageByBody : ageByMtime;
1271
+ if (effectiveAge > LOCK_MAX_AGE_MS) {
1272
+ try {
1273
+ fsUnlink(lockPath);
1274
+ } catch {
1275
+ }
1276
+ try {
1277
+ return acquire();
1278
+ } catch {
1279
+ return false;
1280
+ }
1281
+ }
1282
+ return false;
1283
+ } catch {
1284
+ return false;
1285
+ }
1286
+ }
1246
1287
  } catch {
1247
1288
  return false;
1248
1289
  }
@@ -1267,23 +1308,23 @@ function detectOpenclawGateAgent() {
1267
1308
  function spawnOpenclawSkillifyWorker(a) {
1268
1309
  if (!fsExists(OPENCLAW_SKILLIFY_WORKER_PATH)) {
1269
1310
  a.loggerWarn?.(`skillify worker missing at ${OPENCLAW_SKILLIFY_WORKER_PATH} \u2014 reinstall openclaw plugin`);
1270
- return;
1311
+ return false;
1271
1312
  }
1272
1313
  const gateAgent = detectOpenclawGateAgent();
1273
1314
  if (!gateAgent) {
1274
1315
  a.loggerWarn?.(`skillify spawn: no delegate gate CLI found on PATH (need one of: claude, codex, cursor-agent, hermes, pi). Mining skipped.`);
1275
- return;
1316
+ return false;
1276
1317
  }
1277
1318
  const { key: projectKey, project } = deriveOpenclawProjectKey(a.channel);
1278
1319
  if (!tryAcquireOpenclawSkillifyLock(projectKey)) {
1279
- return;
1320
+ return false;
1280
1321
  }
1281
1322
  const tmpDir = joinPath(tmpdir(), `deeplake-skillify-openclaw-${projectKey}-${Date.now()}`);
1282
1323
  try {
1283
1324
  fsMkdir(tmpDir, { recursive: true, mode: 448 });
1284
1325
  } catch (e) {
1285
1326
  a.loggerWarn?.(`skillify spawn: mkdir failed: ${e?.message ?? e}`);
1286
- return;
1327
+ return false;
1287
1328
  }
1288
1329
  const configPath = joinPath(tmpDir, "config.json");
1289
1330
  const config = {
@@ -1326,7 +1367,7 @@ function spawnOpenclawSkillifyWorker(a) {
1326
1367
  fsWriteFile(configPath, JSON.stringify(config), { mode: 384 });
1327
1368
  } catch (e) {
1328
1369
  a.loggerWarn?.(`skillify spawn: config write failed: ${e?.message ?? e}`);
1329
- return;
1370
+ return false;
1330
1371
  }
1331
1372
  try {
1332
1373
  realSpawn(process.execPath, [OPENCLAW_SKILLIFY_WORKER_PATH, configPath], {
@@ -1334,69 +1375,15 @@ function spawnOpenclawSkillifyWorker(a) {
1334
1375
  stdio: "ignore",
1335
1376
  env: { ...inheritedEnv.env, HIVEMIND_SKILLIFY_WORKER: "1", HIVEMIND_CAPTURE: "false" }
1336
1377
  }).unref();
1378
+ return true;
1337
1379
  } catch (e) {
1338
1380
  a.loggerWarn?.(`skillify spawn: spawn failed: ${e?.message ?? e}`);
1381
+ return false;
1339
1382
  }
1340
1383
  }
1341
1384
  function buildSessionPath(config, sessionId) {
1342
1385
  return `/sessions/${config.userName}/${config.userName}_${config.orgName}_${config.workspaceId}_${sessionId}.jsonl`;
1343
1386
  }
1344
- var RECALL_STOPWORDS = /* @__PURE__ */ new Set([
1345
- "the",
1346
- "and",
1347
- "for",
1348
- "are",
1349
- "but",
1350
- "not",
1351
- "you",
1352
- "all",
1353
- "can",
1354
- "had",
1355
- "her",
1356
- "was",
1357
- "one",
1358
- "our",
1359
- "out",
1360
- "has",
1361
- "have",
1362
- "what",
1363
- "does",
1364
- "like",
1365
- "with",
1366
- "this",
1367
- "that",
1368
- "from",
1369
- "they",
1370
- "been",
1371
- "will",
1372
- "more",
1373
- "when",
1374
- "who",
1375
- "how",
1376
- "its",
1377
- "into",
1378
- "some",
1379
- "than",
1380
- "them",
1381
- "these",
1382
- "then",
1383
- "your",
1384
- "just",
1385
- "about",
1386
- "would",
1387
- "could",
1388
- "should",
1389
- "where",
1390
- "which",
1391
- "there",
1392
- "their",
1393
- "being",
1394
- "each",
1395
- "other"
1396
- ]);
1397
- function extractKeywords(prompt) {
1398
- return prompt.toLowerCase().replace(/[^a-z0-9\s]/g, " ").split(/\s+/).filter((w) => w.length >= 3 && !RECALL_STOPWORDS.has(w)).slice(0, 4);
1399
- }
1400
1387
  function normalizeVirtualPath(p) {
1401
1388
  if (!p || typeof p !== "string") return "/";
1402
1389
  const trimmed = p.trim();
@@ -1558,15 +1545,19 @@ Skill mining (skillify) runs in the background after each turn \u2014 your conve
1558
1545
  No changes needed \u2014 memory tools are available to the agent.${skillifyHint}` };
1559
1546
  }
1560
1547
  if (result.status === "added") {
1561
- return { text: `\u2705 Added "hivemind" to your tool allowlist.
1548
+ const touched = [];
1549
+ if (result.delta.pluginsAllow) touched.push(`"hivemind" \u2192 plugins.allow`);
1550
+ if (result.delta.toolsAlsoAllow) touched.push(`"hivemind" \u2192 tools.alsoAllow`);
1551
+ return { text: `\u2705 Added:
1552
+ \u2022 ${touched.join("\n \u2022 ")}
1562
1553
 
1563
- Openclaw will detect the config change and restart. On the next turn, the agent will have access to hivemind_search, hivemind_read, and hivemind_index.
1554
+ Openclaw will detect the config change and restart. On the next turn, the agent will have access to hivemind_search, hivemind_read, and hivemind_index. **Capture starts on the next turn \u2014 earlier turns are NOT backfilled.**
1564
1555
 
1565
1556
  Backup of previous config: ${result.backupPath}${skillifyHint}` };
1566
1557
  }
1567
1558
  return { text: `\u26A0\uFE0F Could not update allowlist: ${result.error}
1568
1559
 
1569
- Manual fix: open ${result.configPath} and add "hivemind" to the "alsoAllow" array under "tools".` };
1560
+ Manual fix: open ${result.configPath}. If \`plugins.allow\` exists as a non-empty array, add "hivemind" to it. If \`tools.alsoAllow\` exists as a non-empty array, add "hivemind" to it. If either is absent or empty, leave it as-is (openclaw treats that as default-allow).` };
1570
1561
  }
1571
1562
  });
1572
1563
  pluginApi.registerCommand({
@@ -1825,26 +1816,25 @@ A newer Hivemind version is available: ${pendingUpdate.current} \u2192 ${pending
1825
1816
  };
1826
1817
  });
1827
1818
  }
1828
- if (config.autoRecall !== false) {
1829
- hook("before_agent_start", async (event) => {
1830
- if (!event.prompt || event.prompt.length < 5) return;
1831
- try {
1832
- const dl = await getApi();
1833
- if (!dl && authUrl) {
1834
- return {
1835
- prependContext: `
1819
+ hook("before_agent_start", async (event) => {
1820
+ if (!event.prompt || event.prompt.length < 5) return;
1821
+ try {
1822
+ const dl = await getApi();
1823
+ if (!dl && authUrl) {
1824
+ return {
1825
+ prependContext: `
1836
1826
 
1837
1827
  IMPORTANT: The user needs to authenticate with Hivemind. Include this link in your reply: ${authUrl}
1838
1828
  Tell them to click it and sign in, then send another message.
1839
1829
  `
1840
- };
1841
- }
1842
- if (!dl) return;
1843
- if (justAuthenticated) {
1844
- justAuthenticated = false;
1845
- const creds2 = await loadCredentials2();
1846
- const orgName = creds2?.orgName ?? creds2?.orgId ?? "unknown";
1847
- return { prependContext: `
1830
+ };
1831
+ }
1832
+ if (!dl) return;
1833
+ if (justAuthenticated) {
1834
+ justAuthenticated = false;
1835
+ const creds2 = await loadCredentials2();
1836
+ const orgName = creds2?.orgName ?? creds2?.orgId ?? "unknown";
1837
+ return { prependContext: `
1848
1838
 
1849
1839
  \u{1F41D} Welcome to Hivemind!
1850
1840
 
@@ -1859,37 +1849,11 @@ Get started:
1859
1849
 
1860
1850
  One brain for every agent on your team.
1861
1851
  ` };
1862
- }
1863
- const keywords = extractKeywords(event.prompt);
1864
- if (!keywords.length) return;
1865
- const grepParams = {
1866
- pattern: keywords.join(" "),
1867
- ignoreCase: true,
1868
- wordMatch: false,
1869
- filesOnly: false,
1870
- countOnly: false,
1871
- lineNumber: false,
1872
- invertMatch: false,
1873
- fixedString: true
1874
- };
1875
- const searchOpts = buildGrepSearchOptions(grepParams, "/");
1876
- searchOpts.limit = 10;
1877
- const rows = await searchDeeplakeTables(dl, memoryTable, sessionsTable, searchOpts);
1878
- if (!rows.length) return;
1879
- const recalled = rows.map((r) => {
1880
- const body = normalizeContent(r.path, r.content);
1881
- return `[${r.path}] ${body.slice(0, 400)}`;
1882
- }).join("\n\n");
1883
- logger.info?.(`Auto-recalled ${rows.length} memories`);
1884
- const instruction = "These are raw Hivemind search hits from prior sessions. Each hit is prefixed with its path (e.g. `/summaries/<username>/...`). Different usernames are different people \u2014 do NOT merge, alias, or conflate them. If you need more detail, call `hivemind_search` with a more specific query or `hivemind_read` on a specific path. If these hits don't answer the question, say so rather than guessing.";
1885
- return {
1886
- prependContext: "\n\n<recalled-memories>\n" + instruction + "\n\n" + recalled + "\n</recalled-memories>\n"
1887
- };
1888
- } catch (err) {
1889
- logger.error(`Auto-recall failed: ${err instanceof Error ? err.message : String(err)}`);
1890
1852
  }
1891
- });
1892
- }
1853
+ } catch (err) {
1854
+ logger.error(`before_agent_start failed: ${err instanceof Error ? err.message : String(err)}`);
1855
+ }
1856
+ });
1893
1857
  if (config.autoCapture !== false) {
1894
1858
  hook("agent_end", async (event) => {
1895
1859
  const ev = event;
@@ -1939,23 +1903,27 @@ One brain for every agent on your team.
1939
1903
  }
1940
1904
  }
1941
1905
  logger.info?.(`Auto-captured ${newMessages.length} messages`);
1942
- try {
1943
- spawnOpenclawSkillifyWorker({
1944
- apiUrl: cfg.apiUrl,
1945
- token: cfg.token,
1946
- orgId: cfg.orgId,
1947
- workspaceId: cfg.workspaceId,
1948
- userName: cfg.userName,
1949
- channel: ev.channel || "openclaw",
1950
- sessionId: sid,
1951
- loggerWarn: (msg) => logger.error(`Skillify spawn: ${msg}`),
1952
- // Pass the same tuning dispatch the plugin populated at
1953
- // register-time. The worker will repopulate its own
1954
- // globalThis from this.
1955
- tuning: globalThis.__hivemind_tuning__
1956
- });
1957
- } catch (e) {
1958
- logger.error(`Skillify spawn threw: ${e?.message ?? e}`);
1906
+ if (!skillifySpawnedFor.has(sid)) {
1907
+ try {
1908
+ if (spawnOpenclawSkillifyWorker({
1909
+ apiUrl: cfg.apiUrl,
1910
+ token: cfg.token,
1911
+ orgId: cfg.orgId,
1912
+ workspaceId: cfg.workspaceId,
1913
+ userName: cfg.userName,
1914
+ channel: ev.channel || "openclaw",
1915
+ sessionId: sid,
1916
+ loggerWarn: (msg) => logger.error(`Skillify spawn: ${msg}`),
1917
+ // Pass the same tuning dispatch the plugin populated at
1918
+ // register-time. The worker will repopulate its own
1919
+ // globalThis from this.
1920
+ tuning: globalThis.__hivemind_tuning__
1921
+ })) {
1922
+ skillifySpawnedFor.add(sid);
1923
+ }
1924
+ } catch (e) {
1925
+ logger.error(`Skillify spawn threw: ${e?.message ?? e}`);
1926
+ }
1959
1927
  }
1960
1928
  } catch (err) {
1961
1929
  logger.error(`Auto-capture failed: ${err instanceof Error ? err.message : String(err)}`);
@@ -52,5 +52,5 @@
52
52
  }
53
53
  }
54
54
  },
55
- "version": "0.7.29"
55
+ "version": "0.7.31"
56
56
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hivemind",
3
- "version": "0.7.29",
3
+ "version": "0.7.31",
4
4
  "type": "module",
5
5
  "description": "Hivemind — cloud-backed persistent shared memory for AI agents, powered by DeepLake",
6
6
  "license": "Apache-2.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deeplake/hivemind",
3
- "version": "0.7.29",
3
+ "version": "0.7.31",
4
4
  "description": "Cloud-backed persistent shared memory for AI agents powered by Deeplake",
5
5
  "type": "module",
6
6
  "repository": {