@deeplake/hivemind 0.6.47 → 0.7.4
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/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/README.md +158 -51
- package/bundle/cli.js +4103 -282
- package/codex/bundle/capture.js +510 -90
- package/codex/bundle/commands/auth-login.js +219 -72
- package/codex/bundle/embeddings/embed-daemon.js +243 -0
- package/codex/bundle/pre-tool-use.js +713 -108
- package/codex/bundle/session-start-setup.js +209 -58
- package/codex/bundle/session-start.js +40 -11
- package/codex/bundle/shell/deeplake-shell.js +679 -112
- package/codex/bundle/stop.js +477 -59
- package/codex/bundle/wiki-worker.js +312 -11
- package/cursor/bundle/capture.js +768 -57
- package/cursor/bundle/commands/auth-login.js +219 -72
- package/cursor/bundle/embeddings/embed-daemon.js +243 -0
- package/cursor/bundle/pre-tool-use.js +1684 -0
- package/cursor/bundle/session-end.js +223 -2
- package/cursor/bundle/session-start.js +209 -57
- package/cursor/bundle/shell/deeplake-shell.js +679 -112
- package/cursor/bundle/wiki-worker.js +571 -0
- package/hermes/bundle/capture.js +1194 -0
- package/hermes/bundle/commands/auth-login.js +1009 -0
- package/hermes/bundle/embeddings/embed-daemon.js +243 -0
- package/hermes/bundle/package.json +1 -0
- package/hermes/bundle/pre-tool-use.js +1681 -0
- package/hermes/bundle/session-end.js +265 -0
- package/hermes/bundle/session-start.js +655 -0
- package/hermes/bundle/shell/deeplake-shell.js +69905 -0
- package/hermes/bundle/wiki-worker.js +572 -0
- package/mcp/bundle/server.js +289 -69
- package/openclaw/dist/chunks/auth-creds-AEKS6D3P.js +14 -0
- package/openclaw/dist/chunks/chunk-SRCBBT4H.js +37 -0
- package/openclaw/dist/chunks/config-G23NI5TV.js +33 -0
- package/openclaw/dist/chunks/index-marker-store-PGT5CW6T.js +33 -0
- package/openclaw/dist/chunks/setup-config-C35UK4LP.js +114 -0
- package/openclaw/dist/index.js +752 -702
- package/openclaw/openclaw.plugin.json +1 -1
- package/openclaw/package.json +1 -1
- package/package.json +7 -3
- package/pi/extension-source/hivemind.ts +807 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// dist/src/embeddings/daemon.js
|
|
4
|
+
import { createServer } from "node:net";
|
|
5
|
+
import { unlinkSync, writeFileSync, existsSync, mkdirSync, chmodSync } from "node:fs";
|
|
6
|
+
|
|
7
|
+
// dist/src/embeddings/protocol.js
|
|
8
|
+
var DEFAULT_SOCKET_DIR = "/tmp";
|
|
9
|
+
var DEFAULT_MODEL_REPO = "nomic-ai/nomic-embed-text-v1.5";
|
|
10
|
+
var DEFAULT_DTYPE = "q8";
|
|
11
|
+
var DEFAULT_DIMS = 768;
|
|
12
|
+
var DEFAULT_IDLE_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
13
|
+
var DOC_PREFIX = "search_document: ";
|
|
14
|
+
var QUERY_PREFIX = "search_query: ";
|
|
15
|
+
function socketPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
|
|
16
|
+
return `${dir}/hivemind-embed-${uid}.sock`;
|
|
17
|
+
}
|
|
18
|
+
function pidPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
|
|
19
|
+
return `${dir}/hivemind-embed-${uid}.pid`;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// dist/src/embeddings/nomic.js
|
|
23
|
+
var NomicEmbedder = class {
|
|
24
|
+
pipeline = null;
|
|
25
|
+
loading = null;
|
|
26
|
+
repo;
|
|
27
|
+
dtype;
|
|
28
|
+
dims;
|
|
29
|
+
constructor(opts = {}) {
|
|
30
|
+
this.repo = opts.repo ?? DEFAULT_MODEL_REPO;
|
|
31
|
+
this.dtype = opts.dtype ?? DEFAULT_DTYPE;
|
|
32
|
+
this.dims = opts.dims ?? DEFAULT_DIMS;
|
|
33
|
+
}
|
|
34
|
+
async load() {
|
|
35
|
+
if (this.pipeline)
|
|
36
|
+
return;
|
|
37
|
+
if (this.loading)
|
|
38
|
+
return this.loading;
|
|
39
|
+
this.loading = (async () => {
|
|
40
|
+
const mod = await import("@huggingface/transformers");
|
|
41
|
+
mod.env.allowLocalModels = false;
|
|
42
|
+
mod.env.useFSCache = true;
|
|
43
|
+
this.pipeline = await mod.pipeline("feature-extraction", this.repo, { dtype: this.dtype });
|
|
44
|
+
})();
|
|
45
|
+
try {
|
|
46
|
+
await this.loading;
|
|
47
|
+
} finally {
|
|
48
|
+
this.loading = null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
addPrefix(text, kind) {
|
|
52
|
+
return (kind === "query" ? QUERY_PREFIX : DOC_PREFIX) + text;
|
|
53
|
+
}
|
|
54
|
+
async embed(text, kind = "document") {
|
|
55
|
+
await this.load();
|
|
56
|
+
if (!this.pipeline)
|
|
57
|
+
throw new Error("embedder not loaded");
|
|
58
|
+
const out = await this.pipeline(this.addPrefix(text, kind), { pooling: "mean", normalize: true });
|
|
59
|
+
const full = Array.from(out.data);
|
|
60
|
+
return this.truncate(full);
|
|
61
|
+
}
|
|
62
|
+
async embedBatch(texts, kind = "document") {
|
|
63
|
+
if (texts.length === 0)
|
|
64
|
+
return [];
|
|
65
|
+
await this.load();
|
|
66
|
+
if (!this.pipeline)
|
|
67
|
+
throw new Error("embedder not loaded");
|
|
68
|
+
const prefixed = texts.map((t) => this.addPrefix(t, kind));
|
|
69
|
+
const out = await this.pipeline(prefixed, { pooling: "mean", normalize: true });
|
|
70
|
+
const flat = Array.from(out.data);
|
|
71
|
+
const total = flat.length;
|
|
72
|
+
const full = total / texts.length;
|
|
73
|
+
const batches = [];
|
|
74
|
+
for (let i = 0; i < texts.length; i++) {
|
|
75
|
+
batches.push(this.truncate(flat.slice(i * full, (i + 1) * full)));
|
|
76
|
+
}
|
|
77
|
+
return batches;
|
|
78
|
+
}
|
|
79
|
+
truncate(vec) {
|
|
80
|
+
if (this.dims >= vec.length)
|
|
81
|
+
return vec;
|
|
82
|
+
const head = vec.slice(0, this.dims);
|
|
83
|
+
let norm = 0;
|
|
84
|
+
for (const v of head)
|
|
85
|
+
norm += v * v;
|
|
86
|
+
norm = Math.sqrt(norm);
|
|
87
|
+
if (norm === 0)
|
|
88
|
+
return head;
|
|
89
|
+
for (let i = 0; i < head.length; i++)
|
|
90
|
+
head[i] /= norm;
|
|
91
|
+
return head;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// dist/src/utils/debug.js
|
|
96
|
+
import { appendFileSync } from "node:fs";
|
|
97
|
+
import { join } from "node:path";
|
|
98
|
+
import { homedir } from "node:os";
|
|
99
|
+
var DEBUG = process.env.HIVEMIND_DEBUG === "1";
|
|
100
|
+
var LOG = join(homedir(), ".deeplake", "hook-debug.log");
|
|
101
|
+
function log(tag, msg) {
|
|
102
|
+
if (!DEBUG)
|
|
103
|
+
return;
|
|
104
|
+
appendFileSync(LOG, `${(/* @__PURE__ */ new Date()).toISOString()} [${tag}] ${msg}
|
|
105
|
+
`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// dist/src/embeddings/daemon.js
|
|
109
|
+
var log2 = (m) => log("embed-daemon", m);
|
|
110
|
+
function getUid() {
|
|
111
|
+
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
112
|
+
return uid !== void 0 ? String(uid) : process.env.USER ?? "default";
|
|
113
|
+
}
|
|
114
|
+
var EmbedDaemon = class {
|
|
115
|
+
server = null;
|
|
116
|
+
embedder;
|
|
117
|
+
socketPath;
|
|
118
|
+
pidPath;
|
|
119
|
+
idleTimeoutMs;
|
|
120
|
+
idleTimer = null;
|
|
121
|
+
constructor(opts = {}) {
|
|
122
|
+
const uid = getUid();
|
|
123
|
+
const dir = opts.socketDir ?? "/tmp";
|
|
124
|
+
this.socketPath = socketPathFor(uid, dir);
|
|
125
|
+
this.pidPath = pidPathFor(uid, dir);
|
|
126
|
+
this.idleTimeoutMs = opts.idleTimeoutMs ?? DEFAULT_IDLE_TIMEOUT_MS;
|
|
127
|
+
this.embedder = new NomicEmbedder({ repo: opts.repo, dtype: opts.dtype, dims: opts.dims });
|
|
128
|
+
}
|
|
129
|
+
async start() {
|
|
130
|
+
mkdirSync(this.socketPath.replace(/\/[^/]+$/, ""), { recursive: true });
|
|
131
|
+
writeFileSync(this.pidPath, String(process.pid), { mode: 384 });
|
|
132
|
+
if (existsSync(this.socketPath)) {
|
|
133
|
+
try {
|
|
134
|
+
unlinkSync(this.socketPath);
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
this.embedder.load().then(() => log2("model ready")).catch((e) => log2(`load err: ${e.message}`));
|
|
139
|
+
this.server = createServer((sock) => this.handleConnection(sock));
|
|
140
|
+
await new Promise((resolve, reject) => {
|
|
141
|
+
this.server.once("error", reject);
|
|
142
|
+
const prevUmask = process.umask(127);
|
|
143
|
+
this.server.listen(this.socketPath, () => {
|
|
144
|
+
process.umask(prevUmask);
|
|
145
|
+
try {
|
|
146
|
+
chmodSync(this.socketPath, 384);
|
|
147
|
+
} catch {
|
|
148
|
+
}
|
|
149
|
+
log2(`listening on ${this.socketPath}`);
|
|
150
|
+
resolve();
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
this.resetIdleTimer();
|
|
154
|
+
process.on("SIGINT", () => this.shutdown());
|
|
155
|
+
process.on("SIGTERM", () => this.shutdown());
|
|
156
|
+
}
|
|
157
|
+
resetIdleTimer() {
|
|
158
|
+
if (this.idleTimer)
|
|
159
|
+
clearTimeout(this.idleTimer);
|
|
160
|
+
this.idleTimer = setTimeout(() => {
|
|
161
|
+
log2(`idle timeout ${this.idleTimeoutMs}ms reached, shutting down`);
|
|
162
|
+
this.shutdown();
|
|
163
|
+
}, this.idleTimeoutMs);
|
|
164
|
+
this.idleTimer.unref();
|
|
165
|
+
}
|
|
166
|
+
shutdown() {
|
|
167
|
+
try {
|
|
168
|
+
this.server?.close();
|
|
169
|
+
} catch {
|
|
170
|
+
}
|
|
171
|
+
try {
|
|
172
|
+
if (existsSync(this.socketPath))
|
|
173
|
+
unlinkSync(this.socketPath);
|
|
174
|
+
} catch {
|
|
175
|
+
}
|
|
176
|
+
try {
|
|
177
|
+
if (existsSync(this.pidPath))
|
|
178
|
+
unlinkSync(this.pidPath);
|
|
179
|
+
} catch {
|
|
180
|
+
}
|
|
181
|
+
process.exit(0);
|
|
182
|
+
}
|
|
183
|
+
handleConnection(sock) {
|
|
184
|
+
let buf = "";
|
|
185
|
+
sock.setEncoding("utf-8");
|
|
186
|
+
sock.on("data", (chunk) => {
|
|
187
|
+
buf += chunk;
|
|
188
|
+
let nl;
|
|
189
|
+
while ((nl = buf.indexOf("\n")) !== -1) {
|
|
190
|
+
const line = buf.slice(0, nl);
|
|
191
|
+
buf = buf.slice(nl + 1);
|
|
192
|
+
if (line.length === 0)
|
|
193
|
+
continue;
|
|
194
|
+
this.handleLine(sock, line);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
sock.on("error", () => {
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
async handleLine(sock, line) {
|
|
201
|
+
this.resetIdleTimer();
|
|
202
|
+
let req;
|
|
203
|
+
try {
|
|
204
|
+
req = JSON.parse(line);
|
|
205
|
+
} catch {
|
|
206
|
+
sock.write(JSON.stringify({ id: "unknown", error: "parse error" }) + "\n");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const resp = await this.dispatch(req);
|
|
211
|
+
sock.write(JSON.stringify(resp) + "\n");
|
|
212
|
+
} catch (e) {
|
|
213
|
+
const err = e instanceof Error ? e.message : String(e);
|
|
214
|
+
const resp = { id: req.id, error: err };
|
|
215
|
+
sock.write(JSON.stringify(resp) + "\n");
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async dispatch(req) {
|
|
219
|
+
if (req.op === "ping") {
|
|
220
|
+
const p = req;
|
|
221
|
+
return { id: p.id, ready: true, model: this.embedder.repo, dims: this.embedder.dims };
|
|
222
|
+
}
|
|
223
|
+
if (req.op === "embed") {
|
|
224
|
+
const e = req;
|
|
225
|
+
const vec = await this.embedder.embed(e.text, e.kind);
|
|
226
|
+
return { id: e.id, embedding: vec };
|
|
227
|
+
}
|
|
228
|
+
return { id: req.id, error: "unknown op" };
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
var invokedDirectly = import.meta.url === `file://${process.argv[1]}` || process.argv[1] && import.meta.url.endsWith(process.argv[1].split("/").pop() ?? "");
|
|
232
|
+
if (invokedDirectly) {
|
|
233
|
+
const dims = process.env.HIVEMIND_EMBED_DIMS ? Number(process.env.HIVEMIND_EMBED_DIMS) : void 0;
|
|
234
|
+
const idleTimeoutMs = process.env.HIVEMIND_EMBED_IDLE_MS ? Number(process.env.HIVEMIND_EMBED_IDLE_MS) : void 0;
|
|
235
|
+
const d = new EmbedDaemon({ dims, idleTimeoutMs });
|
|
236
|
+
d.start().catch((e) => {
|
|
237
|
+
log2(`fatal: ${e.message}`);
|
|
238
|
+
process.exit(1);
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
export {
|
|
242
|
+
EmbedDaemon
|
|
243
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|