@deeplake/hivemind 0.7.32 → 0.7.33

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.
@@ -46081,14 +46081,14 @@ var require_turndown_cjs = __commonJS({
46081
46081
  } else if (node.nodeType === 1) {
46082
46082
  replacement = replacementForNode.call(self2, node);
46083
46083
  }
46084
- return join13(output, replacement);
46084
+ return join14(output, replacement);
46085
46085
  }, "");
46086
46086
  }
46087
46087
  function postProcess(output) {
46088
46088
  var self2 = this;
46089
46089
  this.rules.forEach(function(rule) {
46090
46090
  if (typeof rule.append === "function") {
46091
- output = join13(output, rule.append(self2.options));
46091
+ output = join14(output, rule.append(self2.options));
46092
46092
  }
46093
46093
  });
46094
46094
  return output.replace(/^[\t\r\n]+/, "").replace(/[\t\r\n\s]+$/, "");
@@ -46100,7 +46100,7 @@ var require_turndown_cjs = __commonJS({
46100
46100
  if (whitespace.leading || whitespace.trailing) content = content.trim();
46101
46101
  return whitespace.leading + rule.replacement(content, node, this.options) + whitespace.trailing;
46102
46102
  }
46103
- function join13(output, replacement) {
46103
+ function join14(output, replacement) {
46104
46104
  var s12 = trimTrailingNewlines(output);
46105
46105
  var s22 = trimLeadingNewlines(replacement);
46106
46106
  var nls = Math.max(output.length - s12.length, replacement.length - s22.length);
@@ -59941,21 +59941,21 @@ __export(index_marker_store_exports, {
59941
59941
  hasFreshIndexMarker: () => hasFreshIndexMarker,
59942
59942
  writeIndexMarker: () => writeIndexMarker
59943
59943
  });
59944
- import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
59945
- import { join as join6 } from "node:path";
59944
+ import { existsSync as existsSync3, mkdirSync as mkdirSync3, readFileSync as readFileSync4, writeFileSync as writeFileSync3 } from "node:fs";
59945
+ import { join as join8 } from "node:path";
59946
59946
  import { tmpdir } from "node:os";
59947
59947
  function getIndexMarkerDir() {
59948
- return process.env.HIVEMIND_INDEX_MARKER_DIR ?? join6(tmpdir(), "hivemind-deeplake-indexes");
59948
+ return process.env.HIVEMIND_INDEX_MARKER_DIR ?? join8(tmpdir(), "hivemind-deeplake-indexes");
59949
59949
  }
59950
59950
  function buildIndexMarkerPath(workspaceId, orgId, table, suffix) {
59951
59951
  const markerKey = [workspaceId, orgId, table, suffix].join("__").replace(/[^a-zA-Z0-9_.-]/g, "_");
59952
- return join6(getIndexMarkerDir(), `${markerKey}.json`);
59952
+ return join8(getIndexMarkerDir(), `${markerKey}.json`);
59953
59953
  }
59954
59954
  function hasFreshIndexMarker(markerPath) {
59955
59955
  if (!existsSync3(markerPath))
59956
59956
  return false;
59957
59957
  try {
59958
- const raw = JSON.parse(readFileSync2(markerPath, "utf-8"));
59958
+ const raw = JSON.parse(readFileSync4(markerPath, "utf-8"));
59959
59959
  const updatedAt = raw.updatedAt ? new Date(raw.updatedAt).getTime() : NaN;
59960
59960
  if (!Number.isFinite(updatedAt) || Date.now() - updatedAt > INDEX_MARKER_TTL_MS)
59961
59961
  return false;
@@ -59965,8 +59965,8 @@ function hasFreshIndexMarker(markerPath) {
59965
59965
  }
59966
59966
  }
59967
59967
  function writeIndexMarker(markerPath) {
59968
- mkdirSync(getIndexMarkerDir(), { recursive: true });
59969
- writeFileSync(markerPath, JSON.stringify({ updatedAt: (/* @__PURE__ */ new Date()).toISOString() }), "utf-8");
59968
+ mkdirSync3(getIndexMarkerDir(), { recursive: true });
59969
+ writeFileSync3(markerPath, JSON.stringify({ updatedAt: (/* @__PURE__ */ new Date()).toISOString() }), "utf-8");
59970
59970
  }
59971
59971
  var INDEX_MARKER_TTL_MS;
59972
59972
  var init_index_marker_store = __esm({
@@ -66841,6 +66841,125 @@ function deeplakeClientHeader() {
66841
66841
  return { [DEEPLAKE_CLIENT_HEADER]: deeplakeClientValue() };
66842
66842
  }
66843
66843
 
66844
+ // dist/src/notifications/queue.js
66845
+ import { readFileSync as readFileSync2, writeFileSync, renameSync, mkdirSync, openSync, closeSync, unlinkSync, statSync as statSync2 } from "node:fs";
66846
+ import { join as join6, resolve as resolve4 } from "node:path";
66847
+ import { homedir as homedir3 } from "node:os";
66848
+ import { setTimeout as sleep } from "node:timers/promises";
66849
+ var log2 = (msg) => log("notifications-queue", msg);
66850
+ var LOCK_RETRY_MAX = 50;
66851
+ var LOCK_RETRY_BASE_MS = 5;
66852
+ var LOCK_STALE_MS = 5e3;
66853
+ function queuePath() {
66854
+ return join6(homedir3(), ".deeplake", "notifications-queue.json");
66855
+ }
66856
+ function lockPath() {
66857
+ return `${queuePath()}.lock`;
66858
+ }
66859
+ function readQueue() {
66860
+ try {
66861
+ const raw = readFileSync2(queuePath(), "utf-8");
66862
+ const parsed = JSON.parse(raw);
66863
+ if (!parsed || !Array.isArray(parsed.queue)) {
66864
+ log2(`queue malformed \u2192 treating as empty`);
66865
+ return { queue: [] };
66866
+ }
66867
+ return { queue: parsed.queue };
66868
+ } catch {
66869
+ return { queue: [] };
66870
+ }
66871
+ }
66872
+ function _isQueuePathInsideHome(path2, home) {
66873
+ const r10 = resolve4(path2);
66874
+ const h18 = resolve4(home);
66875
+ return r10.startsWith(h18 + "/") || r10 === h18;
66876
+ }
66877
+ function writeQueue(q17) {
66878
+ const path2 = queuePath();
66879
+ const home = resolve4(homedir3());
66880
+ if (!_isQueuePathInsideHome(path2, home)) {
66881
+ throw new Error(`notifications-queue write blocked: ${path2} is outside ${home}`);
66882
+ }
66883
+ mkdirSync(join6(home, ".deeplake"), { recursive: true, mode: 448 });
66884
+ const tmp = `${path2}.${process.pid}.tmp`;
66885
+ writeFileSync(tmp, JSON.stringify(q17, null, 2), { mode: 384 });
66886
+ renameSync(tmp, path2);
66887
+ }
66888
+ async function withQueueLock(fn4) {
66889
+ const path2 = lockPath();
66890
+ mkdirSync(join6(homedir3(), ".deeplake"), { recursive: true, mode: 448 });
66891
+ let fd = null;
66892
+ for (let attempt = 0; attempt < LOCK_RETRY_MAX; attempt++) {
66893
+ try {
66894
+ fd = openSync(path2, "wx", 384);
66895
+ break;
66896
+ } catch (e6) {
66897
+ const code = e6.code;
66898
+ if (code !== "EEXIST")
66899
+ throw e6;
66900
+ try {
66901
+ const age = Date.now() - statSync2(path2).mtimeMs;
66902
+ if (age > LOCK_STALE_MS) {
66903
+ unlinkSync(path2);
66904
+ continue;
66905
+ }
66906
+ } catch {
66907
+ }
66908
+ const delay = LOCK_RETRY_BASE_MS * (attempt + 1);
66909
+ await sleep(delay);
66910
+ }
66911
+ }
66912
+ if (fd === null) {
66913
+ log2(`lock acquisition gave up after ${LOCK_RETRY_MAX} attempts \u2014 proceeding unlocked (last-writer-wins)`);
66914
+ return fn4();
66915
+ }
66916
+ try {
66917
+ return fn4();
66918
+ } finally {
66919
+ try {
66920
+ closeSync(fd);
66921
+ } catch {
66922
+ }
66923
+ try {
66924
+ unlinkSync(path2);
66925
+ } catch {
66926
+ }
66927
+ }
66928
+ }
66929
+ function sameDedupKey(a15, b26) {
66930
+ if (a15.id !== b26.id)
66931
+ return false;
66932
+ return JSON.stringify(a15.dedupKey) === JSON.stringify(b26.dedupKey);
66933
+ }
66934
+ async function enqueueNotification(n24) {
66935
+ await withQueueLock(() => {
66936
+ const q17 = readQueue();
66937
+ if (q17.queue.some((existing) => sameDedupKey(existing, n24))) {
66938
+ return;
66939
+ }
66940
+ q17.queue.push(n24);
66941
+ writeQueue(q17);
66942
+ });
66943
+ }
66944
+
66945
+ // dist/src/commands/auth-creds.js
66946
+ import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, mkdirSync as mkdirSync2, unlinkSync as unlinkSync2 } from "node:fs";
66947
+ import { join as join7 } from "node:path";
66948
+ import { homedir as homedir4 } from "node:os";
66949
+ function configDir() {
66950
+ return join7(homedir4(), ".deeplake");
66951
+ }
66952
+ function credsPath() {
66953
+ return join7(configDir(), "credentials.json");
66954
+ }
66955
+ function loadCredentials() {
66956
+ try {
66957
+ return JSON.parse(readFileSync3(credsPath(), "utf-8"));
66958
+ } catch {
66959
+ return null;
66960
+ }
66961
+ }
66962
+
66844
66963
  // dist/src/deeplake-api.js
66845
66964
  var indexMarkerStorePromise = null;
66846
66965
  function getIndexMarkerStore() {
@@ -66848,7 +66967,7 @@ function getIndexMarkerStore() {
66848
66967
  indexMarkerStorePromise = Promise.resolve().then(() => (init_index_marker_store(), index_marker_store_exports));
66849
66968
  return indexMarkerStorePromise;
66850
66969
  }
66851
- var log2 = (msg) => log("sdk", msg);
66970
+ var log3 = (msg) => log("sdk", msg);
66852
66971
  function summarizeSql(sql, maxLen = 220) {
66853
66972
  const compact = sql.replace(/\s+/g, " ").trim();
66854
66973
  return compact.length > maxLen ? `${compact.slice(0, maxLen)}...` : compact;
@@ -66860,7 +66979,38 @@ function traceSql(msg) {
66860
66979
  process.stderr.write(`[deeplake-sql] ${msg}
66861
66980
  `);
66862
66981
  if (process.env.HIVEMIND_DEBUG === "1")
66863
- log2(msg);
66982
+ log3(msg);
66983
+ }
66984
+ var _signalledBalanceExhausted = false;
66985
+ function maybeSignalBalanceExhausted(status, bodyText) {
66986
+ if (status !== 402)
66987
+ return;
66988
+ if (!bodyText.includes("balance_cents"))
66989
+ return;
66990
+ if (_signalledBalanceExhausted)
66991
+ return;
66992
+ _signalledBalanceExhausted = true;
66993
+ log3(`balance exhausted \u2014 enqueuing session-start banner (body=${bodyText.slice(0, 120)})`);
66994
+ enqueueNotification({
66995
+ id: "balance-exhausted",
66996
+ severity: "warn",
66997
+ transient: true,
66998
+ title: "Hivemind credits exhausted \u2014 top up to keep capturing",
66999
+ body: `Sessions are not being saved and memory recall is returning empty. Top up at ${billingUrl()} to restore capture and recall.`,
67000
+ dedupKey: { reason: "balance-zero" }
67001
+ }).catch((e6) => {
67002
+ log3(`enqueue balance-exhausted failed: ${e6 instanceof Error ? e6.message : String(e6)}`);
67003
+ });
67004
+ }
67005
+ function billingUrl() {
67006
+ try {
67007
+ const c15 = loadCredentials();
67008
+ if (c15?.orgName && c15?.workspaceId) {
67009
+ return `https://deeplake.ai/${encodeURIComponent(c15.orgName)}/workspace/${encodeURIComponent(c15.workspaceId)}/billing`;
67010
+ }
67011
+ } catch {
67012
+ }
67013
+ return "https://deeplake.ai";
66864
67014
  }
66865
67015
  var RETRYABLE_CODES = /* @__PURE__ */ new Set([429, 500, 502, 503, 504]);
66866
67016
  var MAX_RETRIES = 3;
@@ -66869,7 +67019,7 @@ var MAX_CONCURRENCY = 5;
66869
67019
  function getQueryTimeoutMs() {
66870
67020
  return Number(process.env.HIVEMIND_QUERY_TIMEOUT_MS ?? 1e4);
66871
67021
  }
66872
- function sleep(ms3) {
67022
+ function sleep2(ms3) {
66873
67023
  return new Promise((resolve6) => setTimeout(resolve6, ms3));
66874
67024
  }
66875
67025
  function isTimeoutError(error) {
@@ -66971,8 +67121,8 @@ var DeeplakeApi = class {
66971
67121
  lastError = e6 instanceof Error ? e6 : new Error(String(e6));
66972
67122
  if (attempt < MAX_RETRIES) {
66973
67123
  const delay = BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200;
66974
- log2(`query retry ${attempt + 1}/${MAX_RETRIES} (fetch error: ${lastError.message}) in ${delay.toFixed(0)}ms`);
66975
- await sleep(delay);
67124
+ log3(`query retry ${attempt + 1}/${MAX_RETRIES} (fetch error: ${lastError.message}) in ${delay.toFixed(0)}ms`);
67125
+ await sleep2(delay);
66976
67126
  continue;
66977
67127
  }
66978
67128
  throw lastError;
@@ -66988,10 +67138,11 @@ var DeeplakeApi = class {
66988
67138
  const alreadyExists = resp.status === 500 && isDuplicateIndexError(text);
66989
67139
  if (!alreadyExists && attempt < MAX_RETRIES && (RETRYABLE_CODES.has(resp.status) || retryable403)) {
66990
67140
  const delay = BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200;
66991
- log2(`query retry ${attempt + 1}/${MAX_RETRIES} (${resp.status}) in ${delay.toFixed(0)}ms`);
66992
- await sleep(delay);
67141
+ log3(`query retry ${attempt + 1}/${MAX_RETRIES} (${resp.status}) in ${delay.toFixed(0)}ms`);
67142
+ await sleep2(delay);
66993
67143
  continue;
66994
67144
  }
67145
+ maybeSignalBalanceExhausted(resp.status, text);
66995
67146
  throw new Error(`Query failed: ${resp.status}: ${text.slice(0, 200)}`);
66996
67147
  }
66997
67148
  throw lastError ?? new Error("Query failed: max retries exceeded");
@@ -67012,7 +67163,7 @@ var DeeplakeApi = class {
67012
67163
  const chunk = rows.slice(i11, i11 + CONCURRENCY);
67013
67164
  await Promise.allSettled(chunk.map((r10) => this.upsertRowSql(r10)));
67014
67165
  }
67015
- log2(`commit: ${rows.length} rows`);
67166
+ log3(`commit: ${rows.length} rows`);
67016
67167
  }
67017
67168
  async upsertRowSql(row) {
67018
67169
  const ts3 = (/* @__PURE__ */ new Date()).toISOString();
@@ -67068,7 +67219,7 @@ var DeeplakeApi = class {
67068
67219
  markers.writeIndexMarker(markerPath);
67069
67220
  return;
67070
67221
  }
67071
- log2(`index "${indexName}" skipped: ${e6.message}`);
67222
+ log3(`index "${indexName}" skipped: ${e6.message}`);
67072
67223
  }
67073
67224
  }
67074
67225
  /**
@@ -67158,13 +67309,13 @@ var DeeplakeApi = class {
67158
67309
  };
67159
67310
  }
67160
67311
  if (attempt < MAX_RETRIES && RETRYABLE_CODES.has(resp.status)) {
67161
- await sleep(BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200);
67312
+ await sleep2(BASE_DELAY_MS * Math.pow(2, attempt) + Math.random() * 200);
67162
67313
  continue;
67163
67314
  }
67164
67315
  return { tables: [], cacheable: false };
67165
67316
  } catch {
67166
67317
  if (attempt < MAX_RETRIES) {
67167
- await sleep(BASE_DELAY_MS * Math.pow(2, attempt));
67318
+ await sleep2(BASE_DELAY_MS * Math.pow(2, attempt));
67168
67319
  continue;
67169
67320
  }
67170
67321
  return { tables: [], cacheable: false };
@@ -67192,9 +67343,9 @@ var DeeplakeApi = class {
67192
67343
  } catch (err) {
67193
67344
  lastErr = err;
67194
67345
  const msg = err instanceof Error ? err.message : String(err);
67195
- log2(`CREATE TABLE "${label}" attempt ${attempt + 1}/${OUTER_BACKOFFS_MS.length + 1} failed: ${msg}`);
67346
+ log3(`CREATE TABLE "${label}" attempt ${attempt + 1}/${OUTER_BACKOFFS_MS.length + 1} failed: ${msg}`);
67196
67347
  if (attempt < OUTER_BACKOFFS_MS.length) {
67197
- await sleep(OUTER_BACKOFFS_MS[attempt]);
67348
+ await sleep2(OUTER_BACKOFFS_MS[attempt]);
67198
67349
  }
67199
67350
  }
67200
67351
  }
@@ -67205,9 +67356,9 @@ var DeeplakeApi = class {
67205
67356
  const tbl = sqlIdent(name ?? this.tableName);
67206
67357
  const tables = await this.listTables();
67207
67358
  if (!tables.includes(tbl)) {
67208
- log2(`table "${tbl}" not found, creating`);
67359
+ log3(`table "${tbl}" not found, creating`);
67209
67360
  await this.createTableWithRetry(`CREATE TABLE IF NOT EXISTS "${tbl}" (id TEXT NOT NULL DEFAULT '', path TEXT NOT NULL DEFAULT '', filename TEXT NOT NULL DEFAULT '', summary TEXT NOT NULL DEFAULT '', summary_embedding FLOAT4[], author TEXT NOT NULL DEFAULT '', mime_type TEXT NOT NULL DEFAULT 'text/plain', size_bytes BIGINT NOT NULL DEFAULT 0, project TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', agent TEXT NOT NULL DEFAULT '', plugin_version TEXT NOT NULL DEFAULT '', creation_date TEXT NOT NULL DEFAULT '', last_update_date TEXT NOT NULL DEFAULT '') USING deeplake`, tbl);
67210
- log2(`table "${tbl}" created`);
67361
+ log3(`table "${tbl}" created`);
67211
67362
  if (!tables.includes(tbl))
67212
67363
  this._tablesCache = [...tables, tbl];
67213
67364
  }
@@ -67220,9 +67371,9 @@ var DeeplakeApi = class {
67220
67371
  const safe = sqlIdent(name);
67221
67372
  const tables = await this.listTables();
67222
67373
  if (!tables.includes(safe)) {
67223
- log2(`table "${safe}" not found, creating`);
67374
+ log3(`table "${safe}" not found, creating`);
67224
67375
  await this.createTableWithRetry(`CREATE TABLE IF NOT EXISTS "${safe}" (id TEXT NOT NULL DEFAULT '', path TEXT NOT NULL DEFAULT '', filename TEXT NOT NULL DEFAULT '', message JSONB, message_embedding FLOAT4[], author TEXT NOT NULL DEFAULT '', mime_type TEXT NOT NULL DEFAULT 'application/json', size_bytes BIGINT NOT NULL DEFAULT 0, project TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', agent TEXT NOT NULL DEFAULT '', plugin_version TEXT NOT NULL DEFAULT '', creation_date TEXT NOT NULL DEFAULT '', last_update_date TEXT NOT NULL DEFAULT '') USING deeplake`, safe);
67225
- log2(`table "${safe}" created`);
67376
+ log3(`table "${safe}" created`);
67226
67377
  if (!tables.includes(safe))
67227
67378
  this._tablesCache = [...tables, safe];
67228
67379
  }
@@ -67245,9 +67396,9 @@ var DeeplakeApi = class {
67245
67396
  const safe = sqlIdent(name);
67246
67397
  const tables = await this.listTables();
67247
67398
  if (!tables.includes(safe)) {
67248
- log2(`table "${safe}" not found, creating`);
67399
+ log3(`table "${safe}" not found, creating`);
67249
67400
  await this.createTableWithRetry(`CREATE TABLE IF NOT EXISTS "${safe}" (id TEXT NOT NULL DEFAULT '', name TEXT NOT NULL DEFAULT '', project TEXT NOT NULL DEFAULT '', project_key TEXT NOT NULL DEFAULT '', local_path TEXT NOT NULL DEFAULT '', install TEXT NOT NULL DEFAULT 'project', source_sessions TEXT NOT NULL DEFAULT '[]', source_agent TEXT NOT NULL DEFAULT '', scope TEXT NOT NULL DEFAULT 'me', author TEXT NOT NULL DEFAULT '', description TEXT NOT NULL DEFAULT '', trigger_text TEXT NOT NULL DEFAULT '', body TEXT NOT NULL DEFAULT '', version BIGINT NOT NULL DEFAULT 1, created_at TEXT NOT NULL DEFAULT '', updated_at TEXT NOT NULL DEFAULT '') USING deeplake`, safe);
67250
- log2(`table "${safe}" created`);
67401
+ log3(`table "${safe}" created`);
67251
67402
  if (!tables.includes(safe))
67252
67403
  this._tablesCache = [...tables, safe];
67253
67404
  }
@@ -67259,7 +67410,7 @@ var DeeplakeApi = class {
67259
67410
  import { basename as basename4, posix } from "node:path";
67260
67411
  import { randomUUID as randomUUID2 } from "node:crypto";
67261
67412
  import { fileURLToPath } from "node:url";
67262
- import { dirname as dirname5, join as join11 } from "node:path";
67413
+ import { dirname as dirname5, join as join12 } from "node:path";
67263
67414
 
67264
67415
  // dist/src/shell/grep-core.js
67265
67416
  var TOOL_INPUT_FIELDS = [
@@ -67689,9 +67840,9 @@ function refineGrepMatches(rows, params, forceMultiFilePrefix) {
67689
67840
  // dist/src/embeddings/client.js
67690
67841
  import { connect } from "node:net";
67691
67842
  import { spawn } from "node:child_process";
67692
- import { openSync as openSync2, closeSync as closeSync2, writeSync, unlinkSync as unlinkSync2, existsSync as existsSync5, readFileSync as readFileSync5 } from "node:fs";
67693
- import { homedir as homedir6 } from "node:os";
67694
- import { join as join10 } from "node:path";
67843
+ import { openSync as openSync2, closeSync as closeSync2, writeSync, unlinkSync as unlinkSync3, existsSync as existsSync4, readFileSync as readFileSync5 } from "node:fs";
67844
+ import { homedir as homedir5 } from "node:os";
67845
+ import { join as join9 } from "node:path";
67695
67846
 
67696
67847
  // dist/src/embeddings/protocol.js
67697
67848
  var DEFAULT_SOCKET_DIR = "/tmp";
@@ -67704,233 +67855,13 @@ function pidPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
67704
67855
  return `${dir}/hivemind-embed-${uid}.pid`;
67705
67856
  }
67706
67857
 
67707
- // dist/src/notifications/queue.js
67708
- import { readFileSync as readFileSync3, writeFileSync as writeFileSync2, renameSync, mkdirSync as mkdirSync2, openSync, closeSync, unlinkSync, statSync as statSync2 } from "node:fs";
67709
- import { join as join7, resolve as resolve4 } from "node:path";
67710
- import { homedir as homedir3 } from "node:os";
67711
- import { setTimeout as sleep2 } from "node:timers/promises";
67712
- var log3 = (msg) => log("notifications-queue", msg);
67713
- var LOCK_RETRY_MAX = 50;
67714
- var LOCK_RETRY_BASE_MS = 5;
67715
- var LOCK_STALE_MS = 5e3;
67716
- function queuePath() {
67717
- return join7(homedir3(), ".deeplake", "notifications-queue.json");
67718
- }
67719
- function lockPath() {
67720
- return `${queuePath()}.lock`;
67721
- }
67722
- function readQueue() {
67723
- try {
67724
- const raw = readFileSync3(queuePath(), "utf-8");
67725
- const parsed = JSON.parse(raw);
67726
- if (!parsed || !Array.isArray(parsed.queue)) {
67727
- log3(`queue malformed \u2192 treating as empty`);
67728
- return { queue: [] };
67729
- }
67730
- return { queue: parsed.queue };
67731
- } catch {
67732
- return { queue: [] };
67733
- }
67734
- }
67735
- function _isQueuePathInsideHome(path2, home) {
67736
- const r10 = resolve4(path2);
67737
- const h18 = resolve4(home);
67738
- return r10.startsWith(h18 + "/") || r10 === h18;
67739
- }
67740
- function writeQueue(q17) {
67741
- const path2 = queuePath();
67742
- const home = resolve4(homedir3());
67743
- if (!_isQueuePathInsideHome(path2, home)) {
67744
- throw new Error(`notifications-queue write blocked: ${path2} is outside ${home}`);
67745
- }
67746
- mkdirSync2(join7(home, ".deeplake"), { recursive: true, mode: 448 });
67747
- const tmp = `${path2}.${process.pid}.tmp`;
67748
- writeFileSync2(tmp, JSON.stringify(q17, null, 2), { mode: 384 });
67749
- renameSync(tmp, path2);
67750
- }
67751
- async function withQueueLock(fn4) {
67752
- const path2 = lockPath();
67753
- mkdirSync2(join7(homedir3(), ".deeplake"), { recursive: true, mode: 448 });
67754
- let fd = null;
67755
- for (let attempt = 0; attempt < LOCK_RETRY_MAX; attempt++) {
67756
- try {
67757
- fd = openSync(path2, "wx", 384);
67758
- break;
67759
- } catch (e6) {
67760
- const code = e6.code;
67761
- if (code !== "EEXIST")
67762
- throw e6;
67763
- try {
67764
- const age = Date.now() - statSync2(path2).mtimeMs;
67765
- if (age > LOCK_STALE_MS) {
67766
- unlinkSync(path2);
67767
- continue;
67768
- }
67769
- } catch {
67770
- }
67771
- const delay = LOCK_RETRY_BASE_MS * (attempt + 1);
67772
- await sleep2(delay);
67773
- }
67774
- }
67775
- if (fd === null) {
67776
- log3(`lock acquisition gave up after ${LOCK_RETRY_MAX} attempts \u2014 proceeding unlocked (last-writer-wins)`);
67777
- return fn4();
67778
- }
67779
- try {
67780
- return fn4();
67781
- } finally {
67782
- try {
67783
- closeSync(fd);
67784
- } catch {
67785
- }
67786
- try {
67787
- unlinkSync(path2);
67788
- } catch {
67789
- }
67790
- }
67791
- }
67792
- function sameDedupKey(a15, b26) {
67793
- if (a15.id !== b26.id)
67794
- return false;
67795
- return JSON.stringify(a15.dedupKey) === JSON.stringify(b26.dedupKey);
67796
- }
67797
- async function enqueueNotification(n24) {
67798
- await withQueueLock(() => {
67799
- const q17 = readQueue();
67800
- if (q17.queue.some((existing) => sameDedupKey(existing, n24))) {
67801
- return;
67802
- }
67803
- q17.queue.push(n24);
67804
- writeQueue(q17);
67805
- });
67806
- }
67807
-
67808
- // dist/src/embeddings/disable.js
67809
- import { createRequire } from "node:module";
67810
- import { homedir as homedir5 } from "node:os";
67811
- import { join as join9 } from "node:path";
67812
- import { pathToFileURL } from "node:url";
67813
-
67814
- // dist/src/user-config.js
67815
- import { existsSync as existsSync4, mkdirSync as mkdirSync3, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync3 } from "node:fs";
67816
- import { homedir as homedir4 } from "node:os";
67817
- import { dirname as dirname4, join as join8 } from "node:path";
67818
- var _configPath = () => process.env.HIVEMIND_CONFIG_PATH ?? join8(homedir4(), ".deeplake", "config.json");
67819
- var _cache = null;
67820
- var _migrated = false;
67821
- function readUserConfig() {
67822
- if (_cache !== null)
67823
- return _cache;
67824
- const path2 = _configPath();
67825
- if (!existsSync4(path2)) {
67826
- _cache = {};
67827
- return _cache;
67828
- }
67829
- try {
67830
- const raw = readFileSync4(path2, "utf-8");
67831
- const parsed = JSON.parse(raw);
67832
- _cache = isPlainObject(parsed) ? parsed : {};
67833
- } catch {
67834
- _cache = {};
67835
- }
67836
- return _cache;
67837
- }
67838
- function writeUserConfig(patch) {
67839
- const current = readUserConfig();
67840
- const merged = deepMerge(current, patch);
67841
- const path2 = _configPath();
67842
- const dir = dirname4(path2);
67843
- if (!existsSync4(dir))
67844
- mkdirSync3(dir, { recursive: true });
67845
- const tmp = `${path2}.tmp.${process.pid}`;
67846
- writeFileSync3(tmp, JSON.stringify(merged, null, 2) + "\n", "utf-8");
67847
- renameSync2(tmp, path2);
67848
- _cache = merged;
67849
- return merged;
67850
- }
67851
- function getEmbeddingsEnabled() {
67852
- const cfg = readUserConfig();
67853
- if (cfg.embeddings && typeof cfg.embeddings.enabled === "boolean") {
67854
- return cfg.embeddings.enabled;
67855
- }
67856
- if (_migrated) {
67857
- return migrationValueFromEnv();
67858
- }
67859
- _migrated = true;
67860
- const enabled = migrationValueFromEnv();
67861
- try {
67862
- writeUserConfig({ embeddings: { enabled } });
67863
- } catch {
67864
- _cache = { ...cfg ?? {}, embeddings: { ...cfg?.embeddings ?? {}, enabled } };
67865
- }
67866
- return enabled;
67867
- }
67868
- function migrationValueFromEnv() {
67869
- const raw = process.env.HIVEMIND_EMBEDDINGS;
67870
- if (raw === void 0)
67871
- return false;
67872
- if (raw === "false")
67873
- return false;
67874
- return true;
67875
- }
67876
- function isPlainObject(value) {
67877
- return typeof value === "object" && value !== null && !Array.isArray(value);
67878
- }
67879
- function deepMerge(base, patch) {
67880
- const out = { ...base };
67881
- for (const key of Object.keys(patch)) {
67882
- const patchVal = patch[key];
67883
- const baseVal = base[key];
67884
- if (isPlainObject(patchVal) && isPlainObject(baseVal)) {
67885
- out[key] = { ...baseVal, ...patchVal };
67886
- } else if (patchVal !== void 0) {
67887
- out[key] = patchVal;
67888
- }
67889
- }
67890
- return out;
67891
- }
67892
-
67893
- // dist/src/embeddings/disable.js
67894
- var cachedStatus = null;
67895
- function defaultResolveTransformers() {
67896
- const sharedDir = join9(homedir5(), ".hivemind", "embed-deps");
67897
- try {
67898
- createRequire(pathToFileURL(`${sharedDir}/`).href).resolve("@huggingface/transformers");
67899
- return;
67900
- } catch {
67901
- }
67902
- createRequire(import.meta.url).resolve("@huggingface/transformers");
67903
- }
67904
- var _resolve = defaultResolveTransformers;
67905
- var _readEnabled = getEmbeddingsEnabled;
67906
- function detectStatus() {
67907
- if (!_readEnabled())
67908
- return "user-disabled";
67909
- try {
67910
- _resolve();
67911
- return "enabled";
67912
- } catch {
67913
- return "no-transformers";
67914
- }
67915
- }
67916
- function embeddingsStatus() {
67917
- if (cachedStatus !== null)
67918
- return cachedStatus;
67919
- cachedStatus = detectStatus();
67920
- return cachedStatus;
67921
- }
67922
- function embeddingsDisabled() {
67923
- return embeddingsStatus() !== "enabled";
67924
- }
67925
-
67926
67858
  // dist/src/embeddings/client.js
67927
- var SHARED_DAEMON_PATH = join10(homedir6(), ".hivemind", "embed-deps", "embed-daemon.js");
67859
+ var SHARED_DAEMON_PATH = join9(homedir5(), ".hivemind", "embed-deps", "embed-daemon.js");
67928
67860
  var log4 = (m26) => log("embed-client", m26);
67929
67861
  function getUid() {
67930
67862
  const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
67931
67863
  return uid !== void 0 ? String(uid) : process.env.USER ?? "default";
67932
67864
  }
67933
- var _signalledMissingDeps = false;
67934
67865
  var _recycledStuckDaemon = false;
67935
67866
  var EmbedClient = class {
67936
67867
  socketPath;
@@ -67947,7 +67878,7 @@ var EmbedClient = class {
67947
67878
  this.socketPath = socketPathFor(uid, dir);
67948
67879
  this.pidPath = pidPathFor(uid, dir);
67949
67880
  this.timeoutMs = opts.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;
67950
- this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (existsSync5(SHARED_DAEMON_PATH) ? SHARED_DAEMON_PATH : void 0);
67881
+ this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (existsSync4(SHARED_DAEMON_PATH) ? SHARED_DAEMON_PATH : void 0);
67951
67882
  this.autoSpawn = opts.autoSpawn ?? true;
67952
67883
  this.spawnWaitMs = opts.spawnWaitMs ?? 5e3;
67953
67884
  }
@@ -68028,7 +67959,7 @@ var EmbedClient = class {
68028
67959
  async waitForDaemonReady() {
68029
67960
  const deadline = Date.now() + this.spawnWaitMs;
68030
67961
  while (Date.now() < deadline) {
68031
- if (existsSync5(this.socketPath))
67962
+ if (existsSync4(this.socketPath))
68032
67963
  return;
68033
67964
  await new Promise((r10) => setTimeout(r10, 50));
68034
67965
  }
@@ -68071,7 +68002,7 @@ var EmbedClient = class {
68071
68002
  this.recycleDaemon(hello.pid);
68072
68003
  return true;
68073
68004
  }
68074
- if (hello.daemonPath !== this.daemonEntry && !existsSync5(hello.daemonPath)) {
68005
+ if (hello.daemonPath !== this.daemonEntry && !existsSync4(hello.daemonPath)) {
68075
68006
  _recycledStuckDaemon = true;
68076
68007
  log4(`daemon path no longer on disk \u2014 running=${hello.daemonPath} (gone) expected=${this.daemonEntry}; recycling`);
68077
68008
  this.recycleDaemon(hello.pid);
@@ -68083,37 +68014,21 @@ var EmbedClient = class {
68083
68014
  /**
68084
68015
  * On a transformers-missing error from the daemon, SIGTERM the stuck
68085
68016
  * daemon (the bundle daemon that can't find its deps) and clear
68086
- * sock/pid so the next call spawns fresh. Also enqueue a one-time
68087
- * notification telling the user to run `hivemind embeddings install`
68088
- * but only when the user has opted in. Suppressed when
68089
- * embeddingsStatus() === "user-disabled" so we don't nag users who
68090
- * explicitly chose to turn embeddings off.
68017
+ * sock/pid so the next call spawns fresh.
68018
+ *
68019
+ * Previously this also enqueued a user-visible "Hivemind embeddings
68020
+ * disabled deps missing" notification telling the user to run
68021
+ * `hivemind embeddings install`. The notification was removed because
68022
+ * (a) the recycle alone often fixes the issue silently, and (b) the
68023
+ * warning kept stacking on top of the primary session-start banner
68024
+ * which clashed with the single-slot priority model. The `detail`
68025
+ * argument is retained for future telemetry / debug logging.
68091
68026
  */
68092
- handleTransformersMissing(detail) {
68027
+ handleTransformersMissing(_detail) {
68093
68028
  if (!_recycledStuckDaemon) {
68094
68029
  _recycledStuckDaemon = true;
68095
68030
  this.recycleDaemon(null);
68096
68031
  }
68097
- if (_signalledMissingDeps)
68098
- return;
68099
- _signalledMissingDeps = true;
68100
- let status;
68101
- try {
68102
- status = embeddingsStatus();
68103
- } catch {
68104
- status = "enabled";
68105
- }
68106
- if (status === "user-disabled")
68107
- return;
68108
- enqueueNotification({
68109
- id: "embed-deps-missing",
68110
- severity: "warn",
68111
- title: "Hivemind embeddings disabled \u2014 deps missing",
68112
- body: `Semantic memory search is off because @huggingface/transformers is not installed where the daemon can find it. Run \`hivemind embeddings install\` to enable.`,
68113
- dedupKey: { reason: "transformers-missing", detail: detail.slice(0, 200) }
68114
- }).catch((e6) => {
68115
- log4(`enqueue embed-deps-missing failed: ${e6 instanceof Error ? e6.message : String(e6)}`);
68116
- });
68117
68032
  }
68118
68033
  /**
68119
68034
  * Best-effort SIGTERM + sock/pid cleanup. Tolerant of every missing-file
@@ -68136,7 +68051,7 @@ var EmbedClient = class {
68136
68051
  } catch {
68137
68052
  }
68138
68053
  }
68139
- if (Number.isFinite(pid) && pid !== null && pid > 0 && existsSync5(this.socketPath)) {
68054
+ if (Number.isFinite(pid) && pid !== null && pid > 0 && existsSync4(this.socketPath)) {
68140
68055
  try {
68141
68056
  process.kill(pid, "SIGTERM");
68142
68057
  } catch {
@@ -68145,11 +68060,11 @@ var EmbedClient = class {
68145
68060
  log4(`recycle: socket gone, skipping SIGTERM on possibly-stale pid ${pid}`);
68146
68061
  }
68147
68062
  try {
68148
- unlinkSync2(this.socketPath);
68063
+ unlinkSync3(this.socketPath);
68149
68064
  } catch {
68150
68065
  }
68151
68066
  try {
68152
- unlinkSync2(this.pidPath);
68067
+ unlinkSync3(this.pidPath);
68153
68068
  } catch {
68154
68069
  }
68155
68070
  }
@@ -68200,7 +68115,7 @@ var EmbedClient = class {
68200
68115
  } catch (e6) {
68201
68116
  if (this.isPidFileStale()) {
68202
68117
  try {
68203
- unlinkSync2(this.pidPath);
68118
+ unlinkSync3(this.pidPath);
68204
68119
  } catch {
68205
68120
  }
68206
68121
  try {
@@ -68213,11 +68128,11 @@ var EmbedClient = class {
68213
68128
  return;
68214
68129
  }
68215
68130
  }
68216
- if (!this.daemonEntry || !existsSync5(this.daemonEntry)) {
68131
+ if (!this.daemonEntry || !existsSync4(this.daemonEntry)) {
68217
68132
  log4(`daemonEntry not configured or missing: ${this.daemonEntry}`);
68218
68133
  try {
68219
68134
  closeSync2(fd);
68220
- unlinkSync2(this.pidPath);
68135
+ unlinkSync3(this.pidPath);
68221
68136
  } catch {
68222
68137
  }
68223
68138
  return;
@@ -68256,7 +68171,7 @@ var EmbedClient = class {
68256
68171
  while (Date.now() < deadline) {
68257
68172
  await sleep3(delay);
68258
68173
  delay = Math.min(delay * 1.5, 300);
68259
- if (!existsSync5(this.socketPath))
68174
+ if (!existsSync4(this.socketPath))
68260
68175
  continue;
68261
68176
  try {
68262
68177
  return await this.connectOnce();
@@ -68320,6 +68235,124 @@ function embeddingSqlLiteral(vec) {
68320
68235
  return `ARRAY[${parts.join(",")}]::float4[]`;
68321
68236
  }
68322
68237
 
68238
+ // dist/src/embeddings/disable.js
68239
+ import { createRequire } from "node:module";
68240
+ import { homedir as homedir7 } from "node:os";
68241
+ import { join as join11 } from "node:path";
68242
+ import { pathToFileURL } from "node:url";
68243
+
68244
+ // dist/src/user-config.js
68245
+ import { existsSync as existsSync5, mkdirSync as mkdirSync4, readFileSync as readFileSync6, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "node:fs";
68246
+ import { homedir as homedir6 } from "node:os";
68247
+ import { dirname as dirname4, join as join10 } from "node:path";
68248
+ var _configPath = () => process.env.HIVEMIND_CONFIG_PATH ?? join10(homedir6(), ".deeplake", "config.json");
68249
+ var _cache = null;
68250
+ var _migrated = false;
68251
+ function readUserConfig() {
68252
+ if (_cache !== null)
68253
+ return _cache;
68254
+ const path2 = _configPath();
68255
+ if (!existsSync5(path2)) {
68256
+ _cache = {};
68257
+ return _cache;
68258
+ }
68259
+ try {
68260
+ const raw = readFileSync6(path2, "utf-8");
68261
+ const parsed = JSON.parse(raw);
68262
+ _cache = isPlainObject(parsed) ? parsed : {};
68263
+ } catch {
68264
+ _cache = {};
68265
+ }
68266
+ return _cache;
68267
+ }
68268
+ function writeUserConfig(patch) {
68269
+ const current = readUserConfig();
68270
+ const merged = deepMerge(current, patch);
68271
+ const path2 = _configPath();
68272
+ const dir = dirname4(path2);
68273
+ if (!existsSync5(dir))
68274
+ mkdirSync4(dir, { recursive: true });
68275
+ const tmp = `${path2}.tmp.${process.pid}`;
68276
+ writeFileSync4(tmp, JSON.stringify(merged, null, 2) + "\n", "utf-8");
68277
+ renameSync2(tmp, path2);
68278
+ _cache = merged;
68279
+ return merged;
68280
+ }
68281
+ function getEmbeddingsEnabled() {
68282
+ const cfg = readUserConfig();
68283
+ if (cfg.embeddings && typeof cfg.embeddings.enabled === "boolean") {
68284
+ return cfg.embeddings.enabled;
68285
+ }
68286
+ if (_migrated) {
68287
+ return migrationValueFromEnv();
68288
+ }
68289
+ _migrated = true;
68290
+ const enabled = migrationValueFromEnv();
68291
+ try {
68292
+ writeUserConfig({ embeddings: { enabled } });
68293
+ } catch {
68294
+ _cache = { ...cfg ?? {}, embeddings: { ...cfg?.embeddings ?? {}, enabled } };
68295
+ }
68296
+ return enabled;
68297
+ }
68298
+ function migrationValueFromEnv() {
68299
+ const raw = process.env.HIVEMIND_EMBEDDINGS;
68300
+ if (raw === void 0)
68301
+ return false;
68302
+ if (raw === "false")
68303
+ return false;
68304
+ return true;
68305
+ }
68306
+ function isPlainObject(value) {
68307
+ return typeof value === "object" && value !== null && !Array.isArray(value);
68308
+ }
68309
+ function deepMerge(base, patch) {
68310
+ const out = { ...base };
68311
+ for (const key of Object.keys(patch)) {
68312
+ const patchVal = patch[key];
68313
+ const baseVal = base[key];
68314
+ if (isPlainObject(patchVal) && isPlainObject(baseVal)) {
68315
+ out[key] = { ...baseVal, ...patchVal };
68316
+ } else if (patchVal !== void 0) {
68317
+ out[key] = patchVal;
68318
+ }
68319
+ }
68320
+ return out;
68321
+ }
68322
+
68323
+ // dist/src/embeddings/disable.js
68324
+ var cachedStatus = null;
68325
+ function defaultResolveTransformers() {
68326
+ const sharedDir = join11(homedir7(), ".hivemind", "embed-deps");
68327
+ try {
68328
+ createRequire(pathToFileURL(`${sharedDir}/`).href).resolve("@huggingface/transformers");
68329
+ return;
68330
+ } catch {
68331
+ }
68332
+ createRequire(import.meta.url).resolve("@huggingface/transformers");
68333
+ }
68334
+ var _resolve = defaultResolveTransformers;
68335
+ var _readEnabled = getEmbeddingsEnabled;
68336
+ function detectStatus() {
68337
+ if (!_readEnabled())
68338
+ return "user-disabled";
68339
+ try {
68340
+ _resolve();
68341
+ return "enabled";
68342
+ } catch {
68343
+ return "no-transformers";
68344
+ }
68345
+ }
68346
+ function embeddingsStatus() {
68347
+ if (cachedStatus !== null)
68348
+ return cachedStatus;
68349
+ cachedStatus = detectStatus();
68350
+ return cachedStatus;
68351
+ }
68352
+ function embeddingsDisabled() {
68353
+ return embeddingsStatus() !== "enabled";
68354
+ }
68355
+
68323
68356
  // dist/src/hooks/virtual-table-query.js
68324
68357
  var INDEX_LIMIT_PER_SECTION = 50;
68325
68358
  function buildVirtualIndexContent(summaryRows, sessionRows = [], opts = {}) {
@@ -68412,7 +68445,7 @@ function normalizeSessionMessage(path2, message) {
68412
68445
  return normalizeContent(path2, raw);
68413
68446
  }
68414
68447
  function resolveEmbedDaemonPath() {
68415
- return join11(dirname5(fileURLToPath(import.meta.url)), "..", "embeddings", "embed-daemon.js");
68448
+ return join12(dirname5(fileURLToPath(import.meta.url)), "..", "embeddings", "embed-daemon.js");
68416
68449
  }
68417
68450
  function joinSessionMessages(path2, messages) {
68418
68451
  return messages.map((message) => normalizeSessionMessage(path2, message)).join("\n");
@@ -69916,7 +69949,7 @@ function stripQuotes(val) {
69916
69949
  }
69917
69950
 
69918
69951
  // node_modules/yargs-parser/build/lib/index.js
69919
- import { readFileSync as readFileSync6 } from "fs";
69952
+ import { readFileSync as readFileSync7 } from "fs";
69920
69953
  import { createRequire as createRequire2 } from "node:module";
69921
69954
  var _a3;
69922
69955
  var _b;
@@ -69943,7 +69976,7 @@ var parser = new YargsParser({
69943
69976
  if (typeof require2 !== "undefined") {
69944
69977
  return require2(path2);
69945
69978
  } else if (path2.match(/\.json$/)) {
69946
- return JSON.parse(readFileSync6(path2, "utf8"));
69979
+ return JSON.parse(readFileSync7(path2, "utf8"));
69947
69980
  } else {
69948
69981
  throw Error("only .json config files are supported in ESM");
69949
69982
  }
@@ -69963,11 +69996,11 @@ var lib_default = yargsParser;
69963
69996
 
69964
69997
  // dist/src/shell/grep-interceptor.js
69965
69998
  import { fileURLToPath as fileURLToPath2 } from "node:url";
69966
- import { dirname as dirname6, join as join12 } from "node:path";
69999
+ import { dirname as dirname6, join as join13 } from "node:path";
69967
70000
  var SEMANTIC_SEARCH_ENABLED = process.env.HIVEMIND_SEMANTIC_SEARCH !== "false" && !embeddingsDisabled();
69968
70001
  var SEMANTIC_EMBED_TIMEOUT_MS = Number(process.env.HIVEMIND_SEMANTIC_EMBED_TIMEOUT_MS ?? "500");
69969
70002
  function resolveGrepEmbedDaemonPath() {
69970
- return join12(dirname6(fileURLToPath2(import.meta.url)), "..", "embeddings", "embed-daemon.js");
70003
+ return join13(dirname6(fileURLToPath2(import.meta.url)), "..", "embeddings", "embed-daemon.js");
69971
70004
  }
69972
70005
  var sharedGrepEmbedClient = null;
69973
70006
  function getGrepEmbedClient() {