@deeplake/hivemind 0.7.15 → 0.7.17

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.
@@ -26,12 +26,12 @@
26
26
  import type { ExtensionAPI } from "@mariozechner/pi-coding-agent";
27
27
  import {
28
28
  readFileSync, existsSync, appendFileSync, mkdirSync, writeFileSync,
29
- openSync, closeSync, constants as fsConstants,
29
+ openSync, closeSync, renameSync, constants as fsConstants,
30
30
  } from "node:fs";
31
31
  import { homedir, tmpdir } from "node:os";
32
32
  import { join, dirname } from "node:path";
33
33
  import { connect } from "node:net";
34
- import { spawn, execSync } from "node:child_process";
34
+ import { spawn, spawnSync, execSync } from "node:child_process";
35
35
  import { createHash } from "node:crypto";
36
36
 
37
37
  // ---------- diagnostic logging --------------------------------------------------
@@ -209,7 +209,47 @@ const PI_WIKI_WORKER_PATH = join(homedir(), ".pi", "agent", "hivemind", "wiki-wo
209
209
  // Spawned on session_shutdown to mine reusable Claude skills from the just-
210
210
  // finished session. Same shared bundle used by CC/Codex/Cursor/Hermes.
211
211
  const PI_SKILIFY_WORKER_PATH = join(homedir(), ".pi", "agent", "hivemind", "skilify-worker.js");
212
- const SKILIFY_STATE_DIR = join(homedir(), ".deeplake", "state", "skilify");
212
+ // Auto-pull worker installed alongside wiki-worker / skilify-worker by
213
+ // `hivemind pi install`. Spawned synchronously on session_start to fetch
214
+ // all-author skills from the org table. The worker is a thin wrapper
215
+ // around the shared autoPullSkills() that codex / cursor / hermes call
216
+ // directly — pi can't import the TS module (raw .ts, zero deps), so it
217
+ // routes through this child process. Keeps pi's pulled skills layout +
218
+ // symlink fan-out in lockstep with the other agents automatically.
219
+ const PI_AUTOPULL_WORKER_PATH = join(homedir(), ".pi", "agent", "hivemind", "autopull-worker.js");
220
+
221
+ /**
222
+ * Synchronously run the bundled auto-pull worker. Bounded by a 6s
223
+ * wall-clock cap (the worker's internal timeout is 5s; the extra second
224
+ * is defence-in-depth for spawn overhead). Returns when the worker
225
+ * exits, regardless of exit code — autoPullSkills is documented as
226
+ * never-rejecting and the worker swallows all failures, so a non-zero
227
+ * exit code can only mean an unrecoverable runtime error that we want
228
+ * to ignore here too. Pi's session_start blocks on this, mirroring the
229
+ * `await autoPullSkills()` in the other agents.
230
+ */
231
+ function runAutopullWorker(): void {
232
+ if (!existsSync(PI_AUTOPULL_WORKER_PATH)) {
233
+ logHm(`autopull: worker bundle missing at ${PI_AUTOPULL_WORKER_PATH} — skipping`);
234
+ return;
235
+ }
236
+ try {
237
+ const result = spawnSync(process.execPath, [PI_AUTOPULL_WORKER_PATH], {
238
+ stdio: "ignore",
239
+ timeout: 6_000,
240
+ env: process.env,
241
+ });
242
+ if (result.error) {
243
+ logHm(`autopull: spawn failed (swallowed): ${result.error.message}`);
244
+ } else if (result.signal) {
245
+ logHm(`autopull: worker killed by signal ${result.signal} (likely the 6s cap)`);
246
+ } else {
247
+ logHm(`autopull: worker exited code=${result.status}`);
248
+ }
249
+ } catch (e: any) {
250
+ logHm(`autopull: spawn threw (swallowed): ${e?.message ?? e}`);
251
+ }
252
+ }
213
253
 
214
254
  interface SummaryState {
215
255
  lastSummaryAt: number;
@@ -850,6 +890,15 @@ export default function hivemindExtension(pi: ExtensionAPI): void {
850
890
  }
851
891
  logHm(`session_start: sessions table visible=${visible} (probe took ${Date.now() - start}ms)`);
852
892
  }
893
+
894
+ // Auto-pull all-author skills via the bundled worker (same shared
895
+ // autoPullSkills as codex / cursor / hermes — see runAutopullWorker
896
+ // above). Synchronous so freshly pulled skills are visible to pi
897
+ // before the first prompt; 6s upper bound. Throttling, layout, and
898
+ // per-agent symlink fan-out all live in the worker — no inline
899
+ // duplicate maintained here.
900
+ if (creds) runAutopullWorker();
901
+
853
902
  const additional = creds
854
903
  ? `${CONTEXT_PREAMBLE}\nLogged in to Deeplake as org: ${creds.orgName ?? creds.orgId} (workspace: ${creds.workspaceId}).`
855
904
  : `${CONTEXT_PREAMBLE}\nNot logged in to Deeplake. Run \`hivemind login\` to authenticate.`;