@deeplake/hivemind 0.7.32 → 0.7.34

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.
Files changed (34) hide show
  1. package/.claude-plugin/marketplace.json +2 -2
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/bundle/cli.js +332 -189
  4. package/codex/bundle/capture.js +365 -332
  5. package/codex/bundle/commands/auth-login.js +163 -30
  6. package/codex/bundle/pre-tool-use.js +334 -301
  7. package/codex/bundle/session-start-setup.js +193 -60
  8. package/codex/bundle/session-start.js +229 -87
  9. package/codex/bundle/shell/deeplake-shell.js +328 -295
  10. package/codex/bundle/skillify-worker.js +26 -18
  11. package/codex/bundle/stop.js +450 -394
  12. package/codex/bundle/wiki-worker.js +174 -292
  13. package/cursor/bundle/capture.js +448 -392
  14. package/cursor/bundle/commands/auth-login.js +163 -30
  15. package/cursor/bundle/pre-tool-use.js +324 -291
  16. package/cursor/bundle/session-end.js +43 -20
  17. package/cursor/bundle/session-start.js +272 -130
  18. package/cursor/bundle/shell/deeplake-shell.js +328 -295
  19. package/cursor/bundle/skillify-worker.js +26 -18
  20. package/cursor/bundle/wiki-worker.js +174 -292
  21. package/hermes/bundle/capture.js +448 -392
  22. package/hermes/bundle/commands/auth-login.js +163 -30
  23. package/hermes/bundle/pre-tool-use.js +324 -291
  24. package/hermes/bundle/session-end.js +43 -20
  25. package/hermes/bundle/session-start.js +269 -127
  26. package/hermes/bundle/shell/deeplake-shell.js +328 -295
  27. package/hermes/bundle/skillify-worker.js +26 -18
  28. package/hermes/bundle/wiki-worker.js +174 -292
  29. package/mcp/bundle/server.js +190 -57
  30. package/openclaw/dist/index.js +160 -32
  31. package/openclaw/dist/skillify-worker.js +26 -18
  32. package/openclaw/openclaw.plugin.json +1 -1
  33. package/openclaw/package.json +1 -1
  34. package/package.json +1 -1
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // dist/src/hooks/codex/wiki-worker.js
4
- import { readFileSync as readFileSync5, writeFileSync as writeFileSync4, existsSync as existsSync4, appendFileSync as appendFileSync2, mkdirSync as mkdirSync4, rmSync } from "node:fs";
4
+ import { readFileSync as readFileSync4, writeFileSync as writeFileSync3, existsSync as existsSync4, appendFileSync as appendFileSync2, mkdirSync as mkdirSync3, rmSync } from "node:fs";
5
5
  import { execFileSync } from "node:child_process";
6
- import { dirname as dirname2, join as join7 } from "node:path";
6
+ import { dirname as dirname2, join as join6 } from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
8
 
9
9
  // dist/src/hooks/summary-state.js
@@ -154,9 +154,9 @@ async function uploadSummary(query2, params) {
154
154
  // dist/src/embeddings/client.js
155
155
  import { connect } from "node:net";
156
156
  import { spawn } from "node:child_process";
157
- import { openSync as openSync3, closeSync as closeSync3, writeSync as writeSync2, unlinkSync as unlinkSync3, existsSync as existsSync3, readFileSync as readFileSync4 } from "node:fs";
158
- import { homedir as homedir6 } from "node:os";
159
- import { join as join6 } from "node:path";
157
+ import { openSync as openSync2, closeSync as closeSync2, writeSync as writeSync2, unlinkSync as unlinkSync2, existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
158
+ import { homedir as homedir3 } from "node:os";
159
+ import { join as join3 } from "node:path";
160
160
 
161
161
  // dist/src/embeddings/protocol.js
162
162
  var DEFAULT_SOCKET_DIR = "/tmp";
@@ -169,233 +169,13 @@ function pidPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
169
169
  return `${dir}/hivemind-embed-${uid}.pid`;
170
170
  }
171
171
 
172
- // dist/src/notifications/queue.js
173
- import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, renameSync as renameSync2, mkdirSync as mkdirSync2, openSync as openSync2, closeSync as closeSync2, unlinkSync as unlinkSync2, statSync } from "node:fs";
174
- import { join as join3, resolve } from "node:path";
175
- import { homedir as homedir3 } from "node:os";
176
- import { setTimeout as sleep } from "node:timers/promises";
177
- var log2 = (msg) => log("notifications-queue", msg);
178
- var LOCK_RETRY_MAX = 50;
179
- var LOCK_RETRY_BASE_MS = 5;
180
- var LOCK_STALE_MS = 5e3;
181
- function queuePath() {
182
- return join3(homedir3(), ".deeplake", "notifications-queue.json");
183
- }
184
- function lockPath2() {
185
- return `${queuePath()}.lock`;
186
- }
187
- function readQueue() {
188
- try {
189
- const raw = readFileSync2(queuePath(), "utf-8");
190
- const parsed = JSON.parse(raw);
191
- if (!parsed || !Array.isArray(parsed.queue)) {
192
- log2(`queue malformed \u2192 treating as empty`);
193
- return { queue: [] };
194
- }
195
- return { queue: parsed.queue };
196
- } catch {
197
- return { queue: [] };
198
- }
199
- }
200
- function _isQueuePathInsideHome(path, home) {
201
- const r = resolve(path);
202
- const h = resolve(home);
203
- return r.startsWith(h + "/") || r === h;
204
- }
205
- function writeQueue(q) {
206
- const path = queuePath();
207
- const home = resolve(homedir3());
208
- if (!_isQueuePathInsideHome(path, home)) {
209
- throw new Error(`notifications-queue write blocked: ${path} is outside ${home}`);
210
- }
211
- mkdirSync2(join3(home, ".deeplake"), { recursive: true, mode: 448 });
212
- const tmp = `${path}.${process.pid}.tmp`;
213
- writeFileSync2(tmp, JSON.stringify(q, null, 2), { mode: 384 });
214
- renameSync2(tmp, path);
215
- }
216
- async function withQueueLock(fn) {
217
- const path = lockPath2();
218
- mkdirSync2(join3(homedir3(), ".deeplake"), { recursive: true, mode: 448 });
219
- let fd = null;
220
- for (let attempt = 0; attempt < LOCK_RETRY_MAX; attempt++) {
221
- try {
222
- fd = openSync2(path, "wx", 384);
223
- break;
224
- } catch (e) {
225
- const code = e.code;
226
- if (code !== "EEXIST")
227
- throw e;
228
- try {
229
- const age = Date.now() - statSync(path).mtimeMs;
230
- if (age > LOCK_STALE_MS) {
231
- unlinkSync2(path);
232
- continue;
233
- }
234
- } catch {
235
- }
236
- const delay = LOCK_RETRY_BASE_MS * (attempt + 1);
237
- await sleep(delay);
238
- }
239
- }
240
- if (fd === null) {
241
- log2(`lock acquisition gave up after ${LOCK_RETRY_MAX} attempts \u2014 proceeding unlocked (last-writer-wins)`);
242
- return fn();
243
- }
244
- try {
245
- return fn();
246
- } finally {
247
- try {
248
- closeSync2(fd);
249
- } catch {
250
- }
251
- try {
252
- unlinkSync2(path);
253
- } catch {
254
- }
255
- }
256
- }
257
- function sameDedupKey(a, b) {
258
- if (a.id !== b.id)
259
- return false;
260
- return JSON.stringify(a.dedupKey) === JSON.stringify(b.dedupKey);
261
- }
262
- async function enqueueNotification(n) {
263
- await withQueueLock(() => {
264
- const q = readQueue();
265
- if (q.queue.some((existing) => sameDedupKey(existing, n))) {
266
- return;
267
- }
268
- q.queue.push(n);
269
- writeQueue(q);
270
- });
271
- }
272
-
273
- // dist/src/embeddings/disable.js
274
- import { createRequire } from "node:module";
275
- import { homedir as homedir5 } from "node:os";
276
- import { join as join5 } from "node:path";
277
- import { pathToFileURL } from "node:url";
278
-
279
- // dist/src/user-config.js
280
- import { existsSync as existsSync2, mkdirSync as mkdirSync3, readFileSync as readFileSync3, renameSync as renameSync3, writeFileSync as writeFileSync3 } from "node:fs";
281
- import { homedir as homedir4 } from "node:os";
282
- import { dirname, join as join4 } from "node:path";
283
- var _configPath = () => process.env.HIVEMIND_CONFIG_PATH ?? join4(homedir4(), ".deeplake", "config.json");
284
- var _cache = null;
285
- var _migrated = false;
286
- function readUserConfig() {
287
- if (_cache !== null)
288
- return _cache;
289
- const path = _configPath();
290
- if (!existsSync2(path)) {
291
- _cache = {};
292
- return _cache;
293
- }
294
- try {
295
- const raw = readFileSync3(path, "utf-8");
296
- const parsed = JSON.parse(raw);
297
- _cache = isPlainObject(parsed) ? parsed : {};
298
- } catch {
299
- _cache = {};
300
- }
301
- return _cache;
302
- }
303
- function writeUserConfig(patch) {
304
- const current = readUserConfig();
305
- const merged = deepMerge(current, patch);
306
- const path = _configPath();
307
- const dir = dirname(path);
308
- if (!existsSync2(dir))
309
- mkdirSync3(dir, { recursive: true });
310
- const tmp = `${path}.tmp.${process.pid}`;
311
- writeFileSync3(tmp, JSON.stringify(merged, null, 2) + "\n", "utf-8");
312
- renameSync3(tmp, path);
313
- _cache = merged;
314
- return merged;
315
- }
316
- function getEmbeddingsEnabled() {
317
- const cfg2 = readUserConfig();
318
- if (cfg2.embeddings && typeof cfg2.embeddings.enabled === "boolean") {
319
- return cfg2.embeddings.enabled;
320
- }
321
- if (_migrated) {
322
- return migrationValueFromEnv();
323
- }
324
- _migrated = true;
325
- const enabled = migrationValueFromEnv();
326
- try {
327
- writeUserConfig({ embeddings: { enabled } });
328
- } catch {
329
- _cache = { ...cfg2 ?? {}, embeddings: { ...cfg2?.embeddings ?? {}, enabled } };
330
- }
331
- return enabled;
332
- }
333
- function migrationValueFromEnv() {
334
- const raw = process.env.HIVEMIND_EMBEDDINGS;
335
- if (raw === void 0)
336
- return false;
337
- if (raw === "false")
338
- return false;
339
- return true;
340
- }
341
- function isPlainObject(value) {
342
- return typeof value === "object" && value !== null && !Array.isArray(value);
343
- }
344
- function deepMerge(base, patch) {
345
- const out = { ...base };
346
- for (const key of Object.keys(patch)) {
347
- const patchVal = patch[key];
348
- const baseVal = base[key];
349
- if (isPlainObject(patchVal) && isPlainObject(baseVal)) {
350
- out[key] = { ...baseVal, ...patchVal };
351
- } else if (patchVal !== void 0) {
352
- out[key] = patchVal;
353
- }
354
- }
355
- return out;
356
- }
357
-
358
- // dist/src/embeddings/disable.js
359
- var cachedStatus = null;
360
- function defaultResolveTransformers() {
361
- const sharedDir = join5(homedir5(), ".hivemind", "embed-deps");
362
- try {
363
- createRequire(pathToFileURL(`${sharedDir}/`).href).resolve("@huggingface/transformers");
364
- return;
365
- } catch {
366
- }
367
- createRequire(import.meta.url).resolve("@huggingface/transformers");
368
- }
369
- var _resolve = defaultResolveTransformers;
370
- var _readEnabled = getEmbeddingsEnabled;
371
- function detectStatus() {
372
- if (!_readEnabled())
373
- return "user-disabled";
374
- try {
375
- _resolve();
376
- return "enabled";
377
- } catch {
378
- return "no-transformers";
379
- }
380
- }
381
- function embeddingsStatus() {
382
- if (cachedStatus !== null)
383
- return cachedStatus;
384
- cachedStatus = detectStatus();
385
- return cachedStatus;
386
- }
387
- function embeddingsDisabled() {
388
- return embeddingsStatus() !== "enabled";
389
- }
390
-
391
172
  // dist/src/embeddings/client.js
392
- var SHARED_DAEMON_PATH = join6(homedir6(), ".hivemind", "embed-deps", "embed-daemon.js");
393
- var log3 = (m) => log("embed-client", m);
173
+ var SHARED_DAEMON_PATH = join3(homedir3(), ".hivemind", "embed-deps", "embed-daemon.js");
174
+ var log2 = (m) => log("embed-client", m);
394
175
  function getUid() {
395
176
  const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
396
177
  return uid !== void 0 ? String(uid) : process.env.USER ?? "default";
397
178
  }
398
- var _signalledMissingDeps = false;
399
179
  var _recycledStuckDaemon = false;
400
180
  var EmbedClient = class {
401
181
  socketPath;
@@ -412,7 +192,7 @@ var EmbedClient = class {
412
192
  this.socketPath = socketPathFor(uid, dir);
413
193
  this.pidPath = pidPathFor(uid, dir);
414
194
  this.timeoutMs = opts.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;
415
- this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (existsSync3(SHARED_DAEMON_PATH) ? SHARED_DAEMON_PATH : void 0);
195
+ this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (existsSync2(SHARED_DAEMON_PATH) ? SHARED_DAEMON_PATH : void 0);
416
196
  this.autoSpawn = opts.autoSpawn ?? true;
417
197
  this.spawnWaitMs = opts.spawnWaitMs ?? 5e3;
418
198
  }
@@ -467,7 +247,7 @@ var EmbedClient = class {
467
247
  const resp = await this.sendAndWait(sock, req);
468
248
  if (resp.error || !("embedding" in resp) || !resp.embedding) {
469
249
  const err = resp.error ?? "no embedding";
470
- log3(`embed err: ${err}`);
250
+ log2(`embed err: ${err}`);
471
251
  if (isTransformersMissingError(err)) {
472
252
  this.handleTransformersMissing(err);
473
253
  }
@@ -476,7 +256,7 @@ var EmbedClient = class {
476
256
  return resp.embedding;
477
257
  } catch (e) {
478
258
  const err = e instanceof Error ? e.message : String(e);
479
- log3(`embed failed: ${err}`);
259
+ log2(`embed failed: ${err}`);
480
260
  return null;
481
261
  } finally {
482
262
  try {
@@ -493,7 +273,7 @@ var EmbedClient = class {
493
273
  async waitForDaemonReady() {
494
274
  const deadline = Date.now() + this.spawnWaitMs;
495
275
  while (Date.now() < deadline) {
496
- if (existsSync3(this.socketPath))
276
+ if (existsSync2(this.socketPath))
497
277
  return;
498
278
  await new Promise((r) => setTimeout(r, 50));
499
279
  }
@@ -523,7 +303,7 @@ var EmbedClient = class {
523
303
  try {
524
304
  resp = await this.sendAndWait(sock, req);
525
305
  } catch (e) {
526
- log3(`hello probe failed (inconclusive, will retry next connect): ${e instanceof Error ? e.message : String(e)}`);
306
+ log2(`hello probe failed (inconclusive, will retry next connect): ${e instanceof Error ? e.message : String(e)}`);
527
307
  return false;
528
308
  }
529
309
  const hello = resp;
@@ -532,13 +312,13 @@ var EmbedClient = class {
532
312
  }
533
313
  if (!hello.daemonPath) {
534
314
  _recycledStuckDaemon = true;
535
- log3(`daemon does not implement hello (older protocol); recycling`);
315
+ log2(`daemon does not implement hello (older protocol); recycling`);
536
316
  this.recycleDaemon(hello.pid);
537
317
  return true;
538
318
  }
539
- if (hello.daemonPath !== this.daemonEntry && !existsSync3(hello.daemonPath)) {
319
+ if (hello.daemonPath !== this.daemonEntry && !existsSync2(hello.daemonPath)) {
540
320
  _recycledStuckDaemon = true;
541
- log3(`daemon path no longer on disk \u2014 running=${hello.daemonPath} (gone) expected=${this.daemonEntry}; recycling`);
321
+ log2(`daemon path no longer on disk \u2014 running=${hello.daemonPath} (gone) expected=${this.daemonEntry}; recycling`);
542
322
  this.recycleDaemon(hello.pid);
543
323
  return true;
544
324
  }
@@ -548,37 +328,21 @@ var EmbedClient = class {
548
328
  /**
549
329
  * On a transformers-missing error from the daemon, SIGTERM the stuck
550
330
  * daemon (the bundle daemon that can't find its deps) and clear
551
- * sock/pid so the next call spawns fresh. Also enqueue a one-time
552
- * notification telling the user to run `hivemind embeddings install`
553
- * but only when the user has opted in. Suppressed when
554
- * embeddingsStatus() === "user-disabled" so we don't nag users who
555
- * explicitly chose to turn embeddings off.
331
+ * sock/pid so the next call spawns fresh.
332
+ *
333
+ * Previously this also enqueued a user-visible "Hivemind embeddings
334
+ * disabled deps missing" notification telling the user to run
335
+ * `hivemind embeddings install`. The notification was removed because
336
+ * (a) the recycle alone often fixes the issue silently, and (b) the
337
+ * warning kept stacking on top of the primary session-start banner
338
+ * which clashed with the single-slot priority model. The `detail`
339
+ * argument is retained for future telemetry / debug logging.
556
340
  */
557
- handleTransformersMissing(detail) {
341
+ handleTransformersMissing(_detail) {
558
342
  if (!_recycledStuckDaemon) {
559
343
  _recycledStuckDaemon = true;
560
344
  this.recycleDaemon(null);
561
345
  }
562
- if (_signalledMissingDeps)
563
- return;
564
- _signalledMissingDeps = true;
565
- let status;
566
- try {
567
- status = embeddingsStatus();
568
- } catch {
569
- status = "enabled";
570
- }
571
- if (status === "user-disabled")
572
- return;
573
- enqueueNotification({
574
- id: "embed-deps-missing",
575
- severity: "warn",
576
- title: "Hivemind embeddings disabled \u2014 deps missing",
577
- body: `Semantic memory search is off because @huggingface/transformers is not installed where the daemon can find it. Run \`hivemind embeddings install\` to enable.`,
578
- dedupKey: { reason: "transformers-missing", detail: detail.slice(0, 200) }
579
- }).catch((e) => {
580
- log3(`enqueue embed-deps-missing failed: ${e instanceof Error ? e.message : String(e)}`);
581
- });
582
346
  }
583
347
  /**
584
348
  * Best-effort SIGTERM + sock/pid cleanup. Tolerant of every missing-file
@@ -597,24 +361,24 @@ var EmbedClient = class {
597
361
  let pid = reportedPid;
598
362
  if (pid === null) {
599
363
  try {
600
- pid = Number.parseInt(readFileSync4(this.pidPath, "utf-8").trim(), 10);
364
+ pid = Number.parseInt(readFileSync2(this.pidPath, "utf-8").trim(), 10);
601
365
  } catch {
602
366
  }
603
367
  }
604
- if (Number.isFinite(pid) && pid !== null && pid > 0 && existsSync3(this.socketPath)) {
368
+ if (Number.isFinite(pid) && pid !== null && pid > 0 && existsSync2(this.socketPath)) {
605
369
  try {
606
370
  process.kill(pid, "SIGTERM");
607
371
  } catch {
608
372
  }
609
373
  } else if (pid !== null) {
610
- log3(`recycle: socket gone, skipping SIGTERM on possibly-stale pid ${pid}`);
374
+ log2(`recycle: socket gone, skipping SIGTERM on possibly-stale pid ${pid}`);
611
375
  }
612
376
  try {
613
- unlinkSync3(this.socketPath);
377
+ unlinkSync2(this.socketPath);
614
378
  } catch {
615
379
  }
616
380
  try {
617
- unlinkSync3(this.pidPath);
381
+ unlinkSync2(this.pidPath);
618
382
  } catch {
619
383
  }
620
384
  }
@@ -641,7 +405,7 @@ var EmbedClient = class {
641
405
  }
642
406
  }
643
407
  connectOnce() {
644
- return new Promise((resolve2, reject) => {
408
+ return new Promise((resolve, reject) => {
645
409
  const sock = connect(this.socketPath);
646
410
  const to = setTimeout(() => {
647
411
  sock.destroy();
@@ -649,7 +413,7 @@ var EmbedClient = class {
649
413
  }, this.timeoutMs);
650
414
  sock.once("connect", () => {
651
415
  clearTimeout(to);
652
- resolve2(sock);
416
+ resolve(sock);
653
417
  });
654
418
  sock.once("error", (e) => {
655
419
  clearTimeout(to);
@@ -660,16 +424,16 @@ var EmbedClient = class {
660
424
  trySpawnDaemon() {
661
425
  let fd;
662
426
  try {
663
- fd = openSync3(this.pidPath, "wx", 384);
427
+ fd = openSync2(this.pidPath, "wx", 384);
664
428
  writeSync2(fd, String(process.pid));
665
429
  } catch (e) {
666
430
  if (this.isPidFileStale()) {
667
431
  try {
668
- unlinkSync3(this.pidPath);
432
+ unlinkSync2(this.pidPath);
669
433
  } catch {
670
434
  }
671
435
  try {
672
- fd = openSync3(this.pidPath, "wx", 384);
436
+ fd = openSync2(this.pidPath, "wx", 384);
673
437
  writeSync2(fd, String(process.pid));
674
438
  } catch {
675
439
  return;
@@ -678,11 +442,11 @@ var EmbedClient = class {
678
442
  return;
679
443
  }
680
444
  }
681
- if (!this.daemonEntry || !existsSync3(this.daemonEntry)) {
682
- log3(`daemonEntry not configured or missing: ${this.daemonEntry}`);
445
+ if (!this.daemonEntry || !existsSync2(this.daemonEntry)) {
446
+ log2(`daemonEntry not configured or missing: ${this.daemonEntry}`);
683
447
  try {
684
- closeSync3(fd);
685
- unlinkSync3(this.pidPath);
448
+ closeSync2(fd);
449
+ unlinkSync2(this.pidPath);
686
450
  } catch {
687
451
  }
688
452
  return;
@@ -694,14 +458,14 @@ var EmbedClient = class {
694
458
  env: process.env
695
459
  });
696
460
  child.unref();
697
- log3(`spawned daemon pid=${child.pid}`);
461
+ log2(`spawned daemon pid=${child.pid}`);
698
462
  } finally {
699
- closeSync3(fd);
463
+ closeSync2(fd);
700
464
  }
701
465
  }
702
466
  isPidFileStale() {
703
467
  try {
704
- const raw = readFileSync4(this.pidPath, "utf-8").trim();
468
+ const raw = readFileSync2(this.pidPath, "utf-8").trim();
705
469
  const pid = Number(raw);
706
470
  if (!pid || Number.isNaN(pid))
707
471
  return true;
@@ -719,9 +483,9 @@ var EmbedClient = class {
719
483
  const deadline = Date.now() + this.spawnWaitMs;
720
484
  let delay = 30;
721
485
  while (Date.now() < deadline) {
722
- await sleep2(delay);
486
+ await sleep(delay);
723
487
  delay = Math.min(delay * 1.5, 300);
724
- if (!existsSync3(this.socketPath))
488
+ if (!existsSync2(this.socketPath))
725
489
  continue;
726
490
  try {
727
491
  return await this.connectOnce();
@@ -731,7 +495,7 @@ var EmbedClient = class {
731
495
  throw new Error("daemon did not become ready within spawnWaitMs");
732
496
  }
733
497
  sendAndWait(sock, req) {
734
- return new Promise((resolve2, reject) => {
498
+ return new Promise((resolve, reject) => {
735
499
  let buf = "";
736
500
  const to = setTimeout(() => {
737
501
  sock.destroy();
@@ -746,7 +510,7 @@ var EmbedClient = class {
746
510
  const line = buf.slice(0, nl);
747
511
  clearTimeout(to);
748
512
  try {
749
- resolve2(JSON.parse(line));
513
+ resolve(JSON.parse(line));
750
514
  } catch (e) {
751
515
  reject(e);
752
516
  }
@@ -763,7 +527,7 @@ var EmbedClient = class {
763
527
  });
764
528
  }
765
529
  };
766
- function sleep2(ms) {
530
+ function sleep(ms) {
767
531
  return new Promise((r) => setTimeout(r, ms));
768
532
  }
769
533
  function isTransformersMissingError(err) {
@@ -772,6 +536,124 @@ function isTransformersMissingError(err) {
772
536
  return /@huggingface\/transformers/i.test(err);
773
537
  }
774
538
 
539
+ // dist/src/embeddings/disable.js
540
+ import { createRequire } from "node:module";
541
+ import { homedir as homedir5 } from "node:os";
542
+ import { join as join5 } from "node:path";
543
+ import { pathToFileURL } from "node:url";
544
+
545
+ // dist/src/user-config.js
546
+ import { existsSync as existsSync3, mkdirSync as mkdirSync2, readFileSync as readFileSync3, renameSync as renameSync2, writeFileSync as writeFileSync2 } from "node:fs";
547
+ import { homedir as homedir4 } from "node:os";
548
+ import { dirname, join as join4 } from "node:path";
549
+ var _configPath = () => process.env.HIVEMIND_CONFIG_PATH ?? join4(homedir4(), ".deeplake", "config.json");
550
+ var _cache = null;
551
+ var _migrated = false;
552
+ function readUserConfig() {
553
+ if (_cache !== null)
554
+ return _cache;
555
+ const path = _configPath();
556
+ if (!existsSync3(path)) {
557
+ _cache = {};
558
+ return _cache;
559
+ }
560
+ try {
561
+ const raw = readFileSync3(path, "utf-8");
562
+ const parsed = JSON.parse(raw);
563
+ _cache = isPlainObject(parsed) ? parsed : {};
564
+ } catch {
565
+ _cache = {};
566
+ }
567
+ return _cache;
568
+ }
569
+ function writeUserConfig(patch) {
570
+ const current = readUserConfig();
571
+ const merged = deepMerge(current, patch);
572
+ const path = _configPath();
573
+ const dir = dirname(path);
574
+ if (!existsSync3(dir))
575
+ mkdirSync2(dir, { recursive: true });
576
+ const tmp = `${path}.tmp.${process.pid}`;
577
+ writeFileSync2(tmp, JSON.stringify(merged, null, 2) + "\n", "utf-8");
578
+ renameSync2(tmp, path);
579
+ _cache = merged;
580
+ return merged;
581
+ }
582
+ function getEmbeddingsEnabled() {
583
+ const cfg2 = readUserConfig();
584
+ if (cfg2.embeddings && typeof cfg2.embeddings.enabled === "boolean") {
585
+ return cfg2.embeddings.enabled;
586
+ }
587
+ if (_migrated) {
588
+ return migrationValueFromEnv();
589
+ }
590
+ _migrated = true;
591
+ const enabled = migrationValueFromEnv();
592
+ try {
593
+ writeUserConfig({ embeddings: { enabled } });
594
+ } catch {
595
+ _cache = { ...cfg2 ?? {}, embeddings: { ...cfg2?.embeddings ?? {}, enabled } };
596
+ }
597
+ return enabled;
598
+ }
599
+ function migrationValueFromEnv() {
600
+ const raw = process.env.HIVEMIND_EMBEDDINGS;
601
+ if (raw === void 0)
602
+ return false;
603
+ if (raw === "false")
604
+ return false;
605
+ return true;
606
+ }
607
+ function isPlainObject(value) {
608
+ return typeof value === "object" && value !== null && !Array.isArray(value);
609
+ }
610
+ function deepMerge(base, patch) {
611
+ const out = { ...base };
612
+ for (const key of Object.keys(patch)) {
613
+ const patchVal = patch[key];
614
+ const baseVal = base[key];
615
+ if (isPlainObject(patchVal) && isPlainObject(baseVal)) {
616
+ out[key] = { ...baseVal, ...patchVal };
617
+ } else if (patchVal !== void 0) {
618
+ out[key] = patchVal;
619
+ }
620
+ }
621
+ return out;
622
+ }
623
+
624
+ // dist/src/embeddings/disable.js
625
+ var cachedStatus = null;
626
+ function defaultResolveTransformers() {
627
+ const sharedDir = join5(homedir5(), ".hivemind", "embed-deps");
628
+ try {
629
+ createRequire(pathToFileURL(`${sharedDir}/`).href).resolve("@huggingface/transformers");
630
+ return;
631
+ } catch {
632
+ }
633
+ createRequire(import.meta.url).resolve("@huggingface/transformers");
634
+ }
635
+ var _resolve = defaultResolveTransformers;
636
+ var _readEnabled = getEmbeddingsEnabled;
637
+ function detectStatus() {
638
+ if (!_readEnabled())
639
+ return "user-disabled";
640
+ try {
641
+ _resolve();
642
+ return "enabled";
643
+ } catch {
644
+ return "no-transformers";
645
+ }
646
+ }
647
+ function embeddingsStatus() {
648
+ if (cachedStatus !== null)
649
+ return cachedStatus;
650
+ cachedStatus = detectStatus();
651
+ return cachedStatus;
652
+ }
653
+ function embeddingsDisabled() {
654
+ return embeddingsStatus() !== "enabled";
655
+ }
656
+
775
657
  // dist/src/utils/client-header.js
776
658
  var DEEPLAKE_CLIENT_HEADER = "X-Deeplake-Client";
777
659
  function deeplakeClientValue() {
@@ -783,13 +665,13 @@ function deeplakeClientHeader() {
783
665
 
784
666
  // dist/src/hooks/codex/wiki-worker.js
785
667
  var dlog2 = (msg) => log("codex-wiki-worker", msg);
786
- var cfg = JSON.parse(readFileSync5(process.argv[2], "utf-8"));
668
+ var cfg = JSON.parse(readFileSync4(process.argv[2], "utf-8"));
787
669
  var tmpDir = cfg.tmpDir;
788
- var tmpJsonl = join7(tmpDir, "session.jsonl");
789
- var tmpSummary = join7(tmpDir, "summary.md");
670
+ var tmpJsonl = join6(tmpDir, "session.jsonl");
671
+ var tmpSummary = join6(tmpDir, "summary.md");
790
672
  function wlog(msg) {
791
673
  try {
792
- mkdirSync4(cfg.hooksDir, { recursive: true });
674
+ mkdirSync3(cfg.hooksDir, { recursive: true });
793
675
  appendFileSync2(cfg.wikiLog, `[${(/* @__PURE__ */ new Date()).toISOString().replace("T", " ").slice(0, 19)}] wiki-worker(${cfg.sessionId}): ${msg}
794
676
  `);
795
677
  } catch {
@@ -821,7 +703,7 @@ async function query(sql, retries = 4) {
821
703
  const base = Math.min(3e4, 2e3 * Math.pow(2, attempt));
822
704
  const delay = base + Math.floor(Math.random() * 1e3);
823
705
  wlog(`API ${r.status}, retrying in ${delay}ms (attempt ${attempt + 1}/${retries})`);
824
- await new Promise((resolve2) => setTimeout(resolve2, delay));
706
+ await new Promise((resolve) => setTimeout(resolve, delay));
825
707
  continue;
826
708
  }
827
709
  throw new Error(`API ${r.status}: ${(await r.text()).slice(0, 200)}`);
@@ -847,7 +729,7 @@ async function main() {
847
729
  const jsonlLines = rows.length;
848
730
  const pathRows = await query(`SELECT DISTINCT path FROM "${cfg.sessionsTable}" WHERE path LIKE '${esc2(`/sessions/%${cfg.sessionId}%`)}' LIMIT 1`);
849
731
  const jsonlServerPath = pathRows.length > 0 ? pathRows[0].path : `/sessions/unknown/${cfg.sessionId}.jsonl`;
850
- writeFileSync4(tmpJsonl, jsonlContent);
732
+ writeFileSync3(tmpJsonl, jsonlContent);
851
733
  wlog(`found ${jsonlLines} events at ${jsonlServerPath}`);
852
734
  let prevOffset = 0;
853
735
  try {
@@ -857,7 +739,7 @@ async function main() {
857
739
  const match = existing.match(/\*\*JSONL offset\*\*:\s*(\d+)/);
858
740
  if (match)
859
741
  prevOffset = parseInt(match[1], 10);
860
- writeFileSync4(tmpSummary, existing);
742
+ writeFileSync3(tmpSummary, existing);
861
743
  wlog(`existing summary found, offset=${prevOffset}`);
862
744
  }
863
745
  } catch {
@@ -879,14 +761,14 @@ async function main() {
879
761
  wlog(`codex exec failed: ${e.status ?? e.message}`);
880
762
  }
881
763
  if (existsSync4(tmpSummary)) {
882
- const text = readFileSync5(tmpSummary, "utf-8");
764
+ const text = readFileSync4(tmpSummary, "utf-8");
883
765
  if (text.trim()) {
884
766
  const fname = `${cfg.sessionId}.md`;
885
767
  const vpath = `/summaries/${cfg.userName}/${fname}`;
886
768
  let embedding = null;
887
769
  if (!embeddingsDisabled()) {
888
770
  try {
889
- const daemonEntry = join7(dirname2(fileURLToPath(import.meta.url)), "embeddings", "embed-daemon.js");
771
+ const daemonEntry = join6(dirname2(fileURLToPath(import.meta.url)), "embeddings", "embed-daemon.js");
890
772
  embedding = await new EmbedClient({ daemonEntry }).embed(text, "document");
891
773
  } catch (e) {
892
774
  wlog(`summary embedding failed, writing NULL: ${e.message}`);