@deeplake/hivemind 0.7.16 → 0.7.18
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/bundle/cli.js +294 -105
- package/codex/bundle/session-start.js +1154 -25
- package/codex/bundle/{skilify-worker.js → skillify-worker.js} +65 -30
- package/codex/bundle/stop.js +105 -68
- package/cursor/bundle/capture.js +84 -47
- package/cursor/bundle/session-end.js +82 -45
- package/cursor/bundle/session-start.js +633 -25
- package/cursor/bundle/{skilify-worker.js → skillify-worker.js} +65 -30
- package/hermes/bundle/capture.js +84 -47
- package/hermes/bundle/session-end.js +82 -45
- package/hermes/bundle/session-start.js +631 -23
- package/hermes/bundle/{skilify-worker.js → skillify-worker.js} +65 -30
- package/openclaw/dist/index.js +47 -30
- package/openclaw/dist/{skilify-worker.js → skillify-worker.js} +65 -30
- package/openclaw/openclaw.plugin.json +1 -1
- package/openclaw/package.json +1 -1
- package/openclaw/skills/SKILL.md +19 -19
- package/package.json +1 -1
- package/pi/extension-source/hivemind.ts +94 -45
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
// dist/src/
|
|
4
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, existsSync as
|
|
5
|
-
import { join as
|
|
3
|
+
// dist/src/skillify/skillify-worker.js
|
|
4
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync3, existsSync as existsSync5, appendFileSync as appendFileSync2, rmSync } from "node:fs";
|
|
5
|
+
import { join as join6 } from "node:path";
|
|
6
6
|
|
|
7
7
|
// dist/src/utils/debug.js
|
|
8
8
|
import { appendFileSync } from "node:fs";
|
|
@@ -29,7 +29,7 @@ function deeplakeClientHeader() {
|
|
|
29
29
|
return { [DEEPLAKE_CLIENT_HEADER]: deeplakeClientValue() };
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// dist/src/
|
|
32
|
+
// dist/src/skillify/extractors/index.js
|
|
33
33
|
function extractPairs(rows) {
|
|
34
34
|
const pairs = [];
|
|
35
35
|
let pendingPrompt = null;
|
|
@@ -60,7 +60,7 @@ function extractPairs(rows) {
|
|
|
60
60
|
return pairs;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
// dist/src/
|
|
63
|
+
// dist/src/skillify/skill-writer.js
|
|
64
64
|
import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
65
65
|
import { homedir as homedir2 } from "node:os";
|
|
66
66
|
import { join as join2 } from "node:path";
|
|
@@ -216,7 +216,7 @@ function resolveSkillsRoot(install, cwd) {
|
|
|
216
216
|
return join2(cwd, ".claude", "skills");
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
// dist/src/
|
|
219
|
+
// dist/src/skillify/skills-table.js
|
|
220
220
|
import { randomUUID } from "node:crypto";
|
|
221
221
|
|
|
222
222
|
// dist/src/utils/sql.js
|
|
@@ -227,7 +227,7 @@ function sqlIdent(name) {
|
|
|
227
227
|
return name;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
-
// dist/src/
|
|
230
|
+
// dist/src/skillify/skills-table.js
|
|
231
231
|
function createSkillsTableSql(tableName) {
|
|
232
232
|
const safe = sqlIdent(tableName);
|
|
233
233
|
return `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`;
|
|
@@ -256,7 +256,7 @@ async function insertSkillRow(args) {
|
|
|
256
256
|
}
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
// dist/src/
|
|
259
|
+
// dist/src/skillify/gate-parser.js
|
|
260
260
|
function extractJsonBlock(s) {
|
|
261
261
|
const trimmed = s.trim();
|
|
262
262
|
if (!trimmed)
|
|
@@ -294,7 +294,7 @@ function parseVerdict(raw) {
|
|
|
294
294
|
}
|
|
295
295
|
}
|
|
296
296
|
|
|
297
|
-
// dist/src/
|
|
297
|
+
// dist/src/skillify/gate-runner.js
|
|
298
298
|
import { execFileSync } from "node:child_process";
|
|
299
299
|
import { existsSync as existsSync2 } from "node:fs";
|
|
300
300
|
import { homedir as homedir3 } from "node:os";
|
|
@@ -403,28 +403,61 @@ function runGate(opts) {
|
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
405
|
|
|
406
|
-
// dist/src/
|
|
407
|
-
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, writeSync, mkdirSync as mkdirSync2, renameSync, existsSync as
|
|
406
|
+
// dist/src/skillify/state.js
|
|
407
|
+
import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, writeSync, mkdirSync as mkdirSync2, renameSync as renameSync2, existsSync as existsSync4, unlinkSync, openSync, closeSync } from "node:fs";
|
|
408
408
|
import { execSync } from "node:child_process";
|
|
409
|
-
import { homedir as
|
|
409
|
+
import { homedir as homedir5 } from "node:os";
|
|
410
410
|
import { createHash } from "node:crypto";
|
|
411
|
-
import { join as
|
|
412
|
-
|
|
413
|
-
|
|
411
|
+
import { join as join5, basename } from "node:path";
|
|
412
|
+
|
|
413
|
+
// dist/src/skillify/legacy-migration.js
|
|
414
|
+
import { existsSync as existsSync3, renameSync } from "node:fs";
|
|
415
|
+
import { homedir as homedir4 } from "node:os";
|
|
416
|
+
import { join as join4 } from "node:path";
|
|
417
|
+
var dlog = (msg) => log("skillify-migrate", msg);
|
|
418
|
+
var attempted = false;
|
|
419
|
+
function migrateLegacyStateDir() {
|
|
420
|
+
if (attempted)
|
|
421
|
+
return;
|
|
422
|
+
attempted = true;
|
|
423
|
+
const root = join4(homedir4(), ".deeplake", "state");
|
|
424
|
+
const legacy = join4(root, "skilify");
|
|
425
|
+
const current = join4(root, "skillify");
|
|
426
|
+
if (!existsSync3(legacy))
|
|
427
|
+
return;
|
|
428
|
+
if (existsSync3(current))
|
|
429
|
+
return;
|
|
430
|
+
try {
|
|
431
|
+
renameSync(legacy, current);
|
|
432
|
+
dlog(`migrated ${legacy} -> ${current}`);
|
|
433
|
+
} catch (err) {
|
|
434
|
+
const code = err.code;
|
|
435
|
+
if (code === "EXDEV" || code === "EPERM") {
|
|
436
|
+
dlog(`migration failed (${code}); leaving legacy dir in place`);
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
throw err;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// dist/src/skillify/state.js
|
|
444
|
+
var dlog2 = (msg) => log("skillify-state", msg);
|
|
445
|
+
var STATE_DIR = join5(homedir5(), ".deeplake", "state", "skillify");
|
|
414
446
|
var YIELD_BUF = new Int32Array(new SharedArrayBuffer(4));
|
|
415
447
|
var TRIGGER_THRESHOLD = (() => {
|
|
416
|
-
const n = Number(process.env.
|
|
448
|
+
const n = Number(process.env.HIVEMIND_SKILLIFY_EVERY_N_TURNS ?? "");
|
|
417
449
|
return Number.isInteger(n) && n > 0 ? n : 20;
|
|
418
450
|
})();
|
|
419
451
|
function statePath(projectKey) {
|
|
420
|
-
return
|
|
452
|
+
return join5(STATE_DIR, `${projectKey}.json`);
|
|
421
453
|
}
|
|
422
454
|
function lockPath(projectKey) {
|
|
423
|
-
return
|
|
455
|
+
return join5(STATE_DIR, `${projectKey}.lock`);
|
|
424
456
|
}
|
|
425
457
|
function readState(projectKey) {
|
|
458
|
+
migrateLegacyStateDir();
|
|
426
459
|
const p = statePath(projectKey);
|
|
427
|
-
if (!
|
|
460
|
+
if (!existsSync4(p))
|
|
428
461
|
return null;
|
|
429
462
|
try {
|
|
430
463
|
return JSON.parse(readFileSync2(p, "utf-8"));
|
|
@@ -433,13 +466,15 @@ function readState(projectKey) {
|
|
|
433
466
|
}
|
|
434
467
|
}
|
|
435
468
|
function writeState(projectKey, state) {
|
|
469
|
+
migrateLegacyStateDir();
|
|
436
470
|
mkdirSync2(STATE_DIR, { recursive: true });
|
|
437
471
|
const p = statePath(projectKey);
|
|
438
472
|
const tmp = `${p}.${process.pid}.${Date.now()}.tmp`;
|
|
439
473
|
writeFileSync2(tmp, JSON.stringify(state, null, 2));
|
|
440
|
-
|
|
474
|
+
renameSync2(tmp, p);
|
|
441
475
|
}
|
|
442
476
|
function withRmwLock(projectKey, fn) {
|
|
477
|
+
migrateLegacyStateDir();
|
|
443
478
|
mkdirSync2(STATE_DIR, { recursive: true });
|
|
444
479
|
const rmw = lockPath(projectKey) + ".rmw";
|
|
445
480
|
const deadline = Date.now() + 2e3;
|
|
@@ -451,11 +486,11 @@ function withRmwLock(projectKey, fn) {
|
|
|
451
486
|
if (e.code !== "EEXIST")
|
|
452
487
|
throw e;
|
|
453
488
|
if (Date.now() > deadline) {
|
|
454
|
-
|
|
489
|
+
dlog2(`rmw lock deadline exceeded for ${projectKey}, reclaiming stale lock`);
|
|
455
490
|
try {
|
|
456
491
|
unlinkSync(rmw);
|
|
457
492
|
} catch (unlinkErr) {
|
|
458
|
-
|
|
493
|
+
dlog2(`stale rmw lock unlink failed for ${projectKey}: ${unlinkErr.message}`);
|
|
459
494
|
}
|
|
460
495
|
continue;
|
|
461
496
|
}
|
|
@@ -469,7 +504,7 @@ function withRmwLock(projectKey, fn) {
|
|
|
469
504
|
try {
|
|
470
505
|
unlinkSync(rmw);
|
|
471
506
|
} catch (unlinkErr) {
|
|
472
|
-
|
|
507
|
+
dlog2(`rmw lock cleanup failed for ${projectKey}: ${unlinkErr.message}`);
|
|
473
508
|
}
|
|
474
509
|
}
|
|
475
510
|
}
|
|
@@ -509,18 +544,18 @@ function releaseWorkerLock(projectKey) {
|
|
|
509
544
|
}
|
|
510
545
|
}
|
|
511
546
|
|
|
512
|
-
// dist/src/
|
|
547
|
+
// dist/src/skillify/skillify-worker.js
|
|
513
548
|
var cfg = JSON.parse(readFileSync3(process.argv[2], "utf-8"));
|
|
514
549
|
var tmpDir = cfg.tmpDir;
|
|
515
|
-
var verdictPath =
|
|
516
|
-
var promptPath =
|
|
550
|
+
var verdictPath = join6(tmpDir, "verdict.json");
|
|
551
|
+
var promptPath = join6(tmpDir, "prompt.txt");
|
|
517
552
|
var SESSIONS_TO_MINE = 10;
|
|
518
553
|
var PAIR_CHAR_CAP = 2e3;
|
|
519
554
|
var TOTAL_PAIRS_CHAR_CAP = 4e4;
|
|
520
555
|
var EXISTING_SKILLS_CHAR_CAP = 3e4;
|
|
521
556
|
function wlog(msg) {
|
|
522
557
|
try {
|
|
523
|
-
appendFileSync2(cfg.
|
|
558
|
+
appendFileSync2(cfg.skillifyLog, `[${utcTimestamp()}] skillify-worker(${cfg.projectKey}): ${msg}
|
|
524
559
|
`);
|
|
525
560
|
} catch {
|
|
526
561
|
}
|
|
@@ -715,7 +750,7 @@ function buildPrompt(pairs) {
|
|
|
715
750
|
].join("\n");
|
|
716
751
|
}
|
|
717
752
|
function readVerdict(stdout) {
|
|
718
|
-
if (
|
|
753
|
+
if (existsSync5(verdictPath)) {
|
|
719
754
|
try {
|
|
720
755
|
const text = readFileSync3(verdictPath, "utf-8");
|
|
721
756
|
const v2 = parseVerdict(text);
|
|
@@ -784,9 +819,9 @@ async function main() {
|
|
|
784
819
|
timeoutMs: 12e4
|
|
785
820
|
});
|
|
786
821
|
try {
|
|
787
|
-
writeFileSync3(
|
|
822
|
+
writeFileSync3(join6(tmpDir, "gate-stdout.txt"), gate.stdout);
|
|
788
823
|
if (gate.stderr)
|
|
789
|
-
writeFileSync3(
|
|
824
|
+
writeFileSync3(join6(tmpDir, "gate-stderr.txt"), gate.stderr);
|
|
790
825
|
} catch {
|
|
791
826
|
}
|
|
792
827
|
if (gate.errored) {
|
package/codex/bundle/stop.js
CHANGED
|
@@ -53,9 +53,9 @@ var init_index_marker_store = __esm({
|
|
|
53
53
|
});
|
|
54
54
|
|
|
55
55
|
// dist/src/hooks/codex/stop.js
|
|
56
|
-
import { readFileSync as readFileSync7, existsSync as
|
|
56
|
+
import { readFileSync as readFileSync7, existsSync as existsSync9 } from "node:fs";
|
|
57
57
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
58
|
-
import { dirname as dirname3, join as
|
|
58
|
+
import { dirname as dirname3, join as join14 } from "node:path";
|
|
59
59
|
|
|
60
60
|
// dist/src/utils/stdin.js
|
|
61
61
|
function readStdin() {
|
|
@@ -679,14 +679,14 @@ function bundleDirFromImportMeta(importMetaUrl) {
|
|
|
679
679
|
return dirname(fileURLToPath(importMetaUrl));
|
|
680
680
|
}
|
|
681
681
|
|
|
682
|
-
// dist/src/
|
|
682
|
+
// dist/src/skillify/spawn-skillify-worker.js
|
|
683
683
|
import { spawn as spawn2 } from "node:child_process";
|
|
684
684
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
685
685
|
import { dirname as dirname2, join as join7 } from "node:path";
|
|
686
686
|
import { writeFileSync as writeFileSync3, mkdirSync as mkdirSync4, appendFileSync as appendFileSync3, chmodSync } from "node:fs";
|
|
687
687
|
import { homedir as homedir5, tmpdir as tmpdir3 } from "node:os";
|
|
688
688
|
|
|
689
|
-
// dist/src/
|
|
689
|
+
// dist/src/skillify/gate-runner.js
|
|
690
690
|
import { execFileSync } from "node:child_process";
|
|
691
691
|
import { existsSync as existsSync3 } from "node:fs";
|
|
692
692
|
import { homedir as homedir4 } from "node:os";
|
|
@@ -717,20 +717,20 @@ function findAgentBin(agent) {
|
|
|
717
717
|
}
|
|
718
718
|
}
|
|
719
719
|
|
|
720
|
-
// dist/src/
|
|
720
|
+
// dist/src/skillify/spawn-skillify-worker.js
|
|
721
721
|
var HOME2 = homedir5();
|
|
722
|
-
var
|
|
723
|
-
function
|
|
722
|
+
var SKILLIFY_LOG = join7(HOME2, ".claude", "hooks", "skillify.log");
|
|
723
|
+
function skillifyLog(msg) {
|
|
724
724
|
try {
|
|
725
|
-
mkdirSync4(dirname2(
|
|
726
|
-
appendFileSync3(
|
|
725
|
+
mkdirSync4(dirname2(SKILLIFY_LOG), { recursive: true });
|
|
726
|
+
appendFileSync3(SKILLIFY_LOG, `[${utcTimestamp()}] ${msg}
|
|
727
727
|
`);
|
|
728
728
|
} catch {
|
|
729
729
|
}
|
|
730
730
|
}
|
|
731
|
-
function
|
|
731
|
+
function spawnSkillifyWorker(opts) {
|
|
732
732
|
const { config, cwd, projectKey, project, bundleDir, agent, scopeConfig, currentSessionId, reason } = opts;
|
|
733
|
-
const tmpDir = join7(tmpdir3(), `deeplake-
|
|
733
|
+
const tmpDir = join7(tmpdir3(), `deeplake-skillify-${projectKey}-${Date.now()}`);
|
|
734
734
|
mkdirSync4(tmpDir, { recursive: true, mode: 448 });
|
|
735
735
|
const gateBin = findAgentBin(agent);
|
|
736
736
|
const configFile = join7(tmpDir, "config.json");
|
|
@@ -756,40 +756,72 @@ function spawnSkilifyWorker(opts) {
|
|
|
756
756
|
hermesModel: process.env.HIVEMIND_HERMES_MODEL,
|
|
757
757
|
piProvider: process.env.HIVEMIND_PI_PROVIDER,
|
|
758
758
|
piModel: process.env.HIVEMIND_PI_MODEL,
|
|
759
|
-
|
|
759
|
+
skillifyLog: SKILLIFY_LOG,
|
|
760
760
|
currentSessionId
|
|
761
761
|
}), { mode: 384 });
|
|
762
762
|
try {
|
|
763
763
|
chmodSync(configFile, 384);
|
|
764
764
|
} catch {
|
|
765
765
|
}
|
|
766
|
-
|
|
767
|
-
const workerPath = join7(bundleDir, "
|
|
766
|
+
skillifyLog(`${reason}: spawning skillify worker for project=${project} key=${projectKey}`);
|
|
767
|
+
const workerPath = join7(bundleDir, "skillify-worker.js");
|
|
768
768
|
spawn2("nohup", ["node", workerPath, configFile], {
|
|
769
769
|
detached: true,
|
|
770
770
|
stdio: ["ignore", "ignore", "ignore"]
|
|
771
771
|
}).unref();
|
|
772
|
-
|
|
772
|
+
skillifyLog(`${reason}: spawned skillify worker for ${projectKey}`);
|
|
773
773
|
}
|
|
774
774
|
|
|
775
|
-
// dist/src/
|
|
776
|
-
import { readFileSync as readFileSync3, writeFileSync as writeFileSync4, writeSync, mkdirSync as mkdirSync5, renameSync, existsSync as
|
|
775
|
+
// dist/src/skillify/state.js
|
|
776
|
+
import { readFileSync as readFileSync3, writeFileSync as writeFileSync4, writeSync, mkdirSync as mkdirSync5, renameSync as renameSync2, existsSync as existsSync5, unlinkSync, openSync, closeSync } from "node:fs";
|
|
777
777
|
import { execSync as execSync2 } from "node:child_process";
|
|
778
|
-
import { homedir as
|
|
778
|
+
import { homedir as homedir7 } from "node:os";
|
|
779
779
|
import { createHash } from "node:crypto";
|
|
780
|
-
import { join as
|
|
781
|
-
|
|
782
|
-
|
|
780
|
+
import { join as join9, basename } from "node:path";
|
|
781
|
+
|
|
782
|
+
// dist/src/skillify/legacy-migration.js
|
|
783
|
+
import { existsSync as existsSync4, renameSync } from "node:fs";
|
|
784
|
+
import { homedir as homedir6 } from "node:os";
|
|
785
|
+
import { join as join8 } from "node:path";
|
|
786
|
+
var dlog = (msg) => log("skillify-migrate", msg);
|
|
787
|
+
var attempted = false;
|
|
788
|
+
function migrateLegacyStateDir() {
|
|
789
|
+
if (attempted)
|
|
790
|
+
return;
|
|
791
|
+
attempted = true;
|
|
792
|
+
const root = join8(homedir6(), ".deeplake", "state");
|
|
793
|
+
const legacy = join8(root, "skilify");
|
|
794
|
+
const current = join8(root, "skillify");
|
|
795
|
+
if (!existsSync4(legacy))
|
|
796
|
+
return;
|
|
797
|
+
if (existsSync4(current))
|
|
798
|
+
return;
|
|
799
|
+
try {
|
|
800
|
+
renameSync(legacy, current);
|
|
801
|
+
dlog(`migrated ${legacy} -> ${current}`);
|
|
802
|
+
} catch (err) {
|
|
803
|
+
const code = err.code;
|
|
804
|
+
if (code === "EXDEV" || code === "EPERM") {
|
|
805
|
+
dlog(`migration failed (${code}); leaving legacy dir in place`);
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
throw err;
|
|
809
|
+
}
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
// dist/src/skillify/state.js
|
|
813
|
+
var dlog2 = (msg) => log("skillify-state", msg);
|
|
814
|
+
var STATE_DIR = join9(homedir7(), ".deeplake", "state", "skillify");
|
|
783
815
|
var YIELD_BUF = new Int32Array(new SharedArrayBuffer(4));
|
|
784
816
|
var TRIGGER_THRESHOLD = (() => {
|
|
785
|
-
const n = Number(process.env.
|
|
817
|
+
const n = Number(process.env.HIVEMIND_SKILLIFY_EVERY_N_TURNS ?? "");
|
|
786
818
|
return Number.isInteger(n) && n > 0 ? n : 20;
|
|
787
819
|
})();
|
|
788
820
|
function statePath(projectKey) {
|
|
789
|
-
return
|
|
821
|
+
return join9(STATE_DIR, `${projectKey}.json`);
|
|
790
822
|
}
|
|
791
823
|
function lockPath(projectKey) {
|
|
792
|
-
return
|
|
824
|
+
return join9(STATE_DIR, `${projectKey}.lock`);
|
|
793
825
|
}
|
|
794
826
|
function deriveProjectKey(cwd) {
|
|
795
827
|
const project = basename(cwd) || "unknown";
|
|
@@ -807,8 +839,9 @@ function deriveProjectKey(cwd) {
|
|
|
807
839
|
return { key, project };
|
|
808
840
|
}
|
|
809
841
|
function readState(projectKey) {
|
|
842
|
+
migrateLegacyStateDir();
|
|
810
843
|
const p = statePath(projectKey);
|
|
811
|
-
if (!
|
|
844
|
+
if (!existsSync5(p))
|
|
812
845
|
return null;
|
|
813
846
|
try {
|
|
814
847
|
return JSON.parse(readFileSync3(p, "utf-8"));
|
|
@@ -817,13 +850,15 @@ function readState(projectKey) {
|
|
|
817
850
|
}
|
|
818
851
|
}
|
|
819
852
|
function writeState(projectKey, state) {
|
|
853
|
+
migrateLegacyStateDir();
|
|
820
854
|
mkdirSync5(STATE_DIR, { recursive: true });
|
|
821
855
|
const p = statePath(projectKey);
|
|
822
856
|
const tmp = `${p}.${process.pid}.${Date.now()}.tmp`;
|
|
823
857
|
writeFileSync4(tmp, JSON.stringify(state, null, 2));
|
|
824
|
-
|
|
858
|
+
renameSync2(tmp, p);
|
|
825
859
|
}
|
|
826
860
|
function withRmwLock(projectKey, fn) {
|
|
861
|
+
migrateLegacyStateDir();
|
|
827
862
|
mkdirSync5(STATE_DIR, { recursive: true });
|
|
828
863
|
const rmw = lockPath(projectKey) + ".rmw";
|
|
829
864
|
const deadline = Date.now() + 2e3;
|
|
@@ -835,11 +870,11 @@ function withRmwLock(projectKey, fn) {
|
|
|
835
870
|
if (e.code !== "EEXIST")
|
|
836
871
|
throw e;
|
|
837
872
|
if (Date.now() > deadline) {
|
|
838
|
-
|
|
873
|
+
dlog2(`rmw lock deadline exceeded for ${projectKey}, reclaiming stale lock`);
|
|
839
874
|
try {
|
|
840
875
|
unlinkSync(rmw);
|
|
841
876
|
} catch (unlinkErr) {
|
|
842
|
-
|
|
877
|
+
dlog2(`stale rmw lock unlink failed for ${projectKey}: ${unlinkErr.message}`);
|
|
843
878
|
}
|
|
844
879
|
continue;
|
|
845
880
|
}
|
|
@@ -853,7 +888,7 @@ function withRmwLock(projectKey, fn) {
|
|
|
853
888
|
try {
|
|
854
889
|
unlinkSync(rmw);
|
|
855
890
|
} catch (unlinkErr) {
|
|
856
|
-
|
|
891
|
+
dlog2(`rmw lock cleanup failed for ${projectKey}: ${unlinkErr.message}`);
|
|
857
892
|
}
|
|
858
893
|
}
|
|
859
894
|
}
|
|
@@ -866,20 +901,21 @@ function resetCounter(projectKey) {
|
|
|
866
901
|
});
|
|
867
902
|
}
|
|
868
903
|
function tryAcquireWorkerLock(projectKey, maxAgeMs = 10 * 60 * 1e3) {
|
|
904
|
+
migrateLegacyStateDir();
|
|
869
905
|
mkdirSync5(STATE_DIR, { recursive: true });
|
|
870
906
|
const p = lockPath(projectKey);
|
|
871
|
-
if (
|
|
907
|
+
if (existsSync5(p)) {
|
|
872
908
|
try {
|
|
873
909
|
const ageMs = Date.now() - parseInt(readFileSync3(p, "utf-8"), 10);
|
|
874
910
|
if (Number.isFinite(ageMs) && ageMs < maxAgeMs)
|
|
875
911
|
return false;
|
|
876
912
|
} catch (readErr) {
|
|
877
|
-
|
|
913
|
+
dlog2(`worker lock unreadable for ${projectKey}, treating as stale: ${readErr.message}`);
|
|
878
914
|
}
|
|
879
915
|
try {
|
|
880
916
|
unlinkSync(p);
|
|
881
917
|
} catch (unlinkErr) {
|
|
882
|
-
|
|
918
|
+
dlog2(`could not unlink stale worker lock for ${projectKey}: ${unlinkErr.message}`);
|
|
883
919
|
return false;
|
|
884
920
|
}
|
|
885
921
|
}
|
|
@@ -903,15 +939,16 @@ function releaseWorkerLock(projectKey) {
|
|
|
903
939
|
}
|
|
904
940
|
}
|
|
905
941
|
|
|
906
|
-
// dist/src/
|
|
907
|
-
import { existsSync as
|
|
908
|
-
import { homedir as
|
|
909
|
-
import { join as
|
|
910
|
-
var STATE_DIR2 =
|
|
911
|
-
var CONFIG_PATH =
|
|
942
|
+
// dist/src/skillify/scope-config.js
|
|
943
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync6, readFileSync as readFileSync4, writeFileSync as writeFileSync5 } from "node:fs";
|
|
944
|
+
import { homedir as homedir8 } from "node:os";
|
|
945
|
+
import { join as join10 } from "node:path";
|
|
946
|
+
var STATE_DIR2 = join10(homedir8(), ".deeplake", "state", "skillify");
|
|
947
|
+
var CONFIG_PATH = join10(STATE_DIR2, "config.json");
|
|
912
948
|
var DEFAULT = { scope: "me", team: [], install: "project" };
|
|
913
949
|
function loadScopeConfig() {
|
|
914
|
-
|
|
950
|
+
migrateLegacyStateDir();
|
|
951
|
+
if (!existsSync6(CONFIG_PATH))
|
|
915
952
|
return DEFAULT;
|
|
916
953
|
try {
|
|
917
954
|
const raw = JSON.parse(readFileSync4(CONFIG_PATH, "utf-8"));
|
|
@@ -924,24 +961,24 @@ function loadScopeConfig() {
|
|
|
924
961
|
}
|
|
925
962
|
}
|
|
926
963
|
|
|
927
|
-
// dist/src/
|
|
964
|
+
// dist/src/skillify/triggers.js
|
|
928
965
|
function forceSessionEndTrigger(opts) {
|
|
929
|
-
if (process.env.
|
|
966
|
+
if (process.env.HIVEMIND_SKILLIFY_WORKER === "1")
|
|
930
967
|
return;
|
|
931
968
|
if (!opts.cwd)
|
|
932
969
|
return;
|
|
933
970
|
try {
|
|
934
971
|
const { key: projectKey, project } = deriveProjectKey(opts.cwd);
|
|
935
972
|
if (!tryAcquireWorkerLock(projectKey)) {
|
|
936
|
-
|
|
973
|
+
skillifyLog(`SessionEnd: skillify worker already running for ${projectKey}, skipping`);
|
|
937
974
|
return;
|
|
938
975
|
}
|
|
939
976
|
if (readState(projectKey)) {
|
|
940
977
|
resetCounter(projectKey);
|
|
941
978
|
}
|
|
942
|
-
|
|
979
|
+
skillifyLog(`SessionEnd: spawning skillify worker for project=${project} agent=${opts.agent}`);
|
|
943
980
|
try {
|
|
944
|
-
|
|
981
|
+
spawnSkillifyWorker({
|
|
945
982
|
config: opts.config,
|
|
946
983
|
cwd: opts.cwd,
|
|
947
984
|
projectKey,
|
|
@@ -953,42 +990,42 @@ function forceSessionEndTrigger(opts) {
|
|
|
953
990
|
reason: "SessionEnd"
|
|
954
991
|
});
|
|
955
992
|
} catch (e) {
|
|
956
|
-
|
|
993
|
+
skillifyLog(`SessionEnd spawn failed: ${e?.message ?? e}`);
|
|
957
994
|
try {
|
|
958
995
|
releaseWorkerLock(projectKey);
|
|
959
996
|
} catch {
|
|
960
997
|
}
|
|
961
998
|
}
|
|
962
999
|
} catch (e) {
|
|
963
|
-
|
|
1000
|
+
skillifyLog(`SessionEnd trigger error: ${e?.message ?? e}`);
|
|
964
1001
|
}
|
|
965
1002
|
}
|
|
966
1003
|
|
|
967
1004
|
// dist/src/hooks/summary-state.js
|
|
968
|
-
import { readFileSync as readFileSync5, writeFileSync as writeFileSync6, writeSync as writeSync2, mkdirSync as mkdirSync7, renameSync as
|
|
969
|
-
import { homedir as
|
|
970
|
-
import { join as
|
|
971
|
-
var
|
|
972
|
-
var STATE_DIR3 =
|
|
1005
|
+
import { readFileSync as readFileSync5, writeFileSync as writeFileSync6, writeSync as writeSync2, mkdirSync as mkdirSync7, renameSync as renameSync3, existsSync as existsSync7, unlinkSync as unlinkSync2, openSync as openSync2, closeSync as closeSync2 } from "node:fs";
|
|
1006
|
+
import { homedir as homedir9 } from "node:os";
|
|
1007
|
+
import { join as join11 } from "node:path";
|
|
1008
|
+
var dlog3 = (msg) => log("summary-state", msg);
|
|
1009
|
+
var STATE_DIR3 = join11(homedir9(), ".claude", "hooks", "summary-state");
|
|
973
1010
|
var YIELD_BUF2 = new Int32Array(new SharedArrayBuffer(4));
|
|
974
1011
|
function lockPath2(sessionId) {
|
|
975
|
-
return
|
|
1012
|
+
return join11(STATE_DIR3, `${sessionId}.lock`);
|
|
976
1013
|
}
|
|
977
1014
|
function tryAcquireLock(sessionId, maxAgeMs = 10 * 60 * 1e3) {
|
|
978
1015
|
mkdirSync7(STATE_DIR3, { recursive: true });
|
|
979
1016
|
const p = lockPath2(sessionId);
|
|
980
|
-
if (
|
|
1017
|
+
if (existsSync7(p)) {
|
|
981
1018
|
try {
|
|
982
1019
|
const ageMs = Date.now() - parseInt(readFileSync5(p, "utf-8"), 10);
|
|
983
1020
|
if (Number.isFinite(ageMs) && ageMs < maxAgeMs)
|
|
984
1021
|
return false;
|
|
985
1022
|
} catch (readErr) {
|
|
986
|
-
|
|
1023
|
+
dlog3(`lock file unreadable for ${sessionId}, treating as stale: ${readErr.message}`);
|
|
987
1024
|
}
|
|
988
1025
|
try {
|
|
989
1026
|
unlinkSync2(p);
|
|
990
1027
|
} catch (unlinkErr) {
|
|
991
|
-
|
|
1028
|
+
dlog3(`could not unlink stale lock for ${sessionId}: ${unlinkErr.message}`);
|
|
992
1029
|
return false;
|
|
993
1030
|
}
|
|
994
1031
|
}
|
|
@@ -1011,7 +1048,7 @@ function releaseLock(sessionId) {
|
|
|
1011
1048
|
unlinkSync2(lockPath2(sessionId));
|
|
1012
1049
|
} catch (e) {
|
|
1013
1050
|
if (e?.code !== "ENOENT") {
|
|
1014
|
-
|
|
1051
|
+
dlog3(`releaseLock unlink failed for ${sessionId}: ${e.message}`);
|
|
1015
1052
|
}
|
|
1016
1053
|
}
|
|
1017
1054
|
}
|
|
@@ -1025,9 +1062,9 @@ function buildSessionPath(config, sessionId) {
|
|
|
1025
1062
|
// dist/src/embeddings/client.js
|
|
1026
1063
|
import { connect } from "node:net";
|
|
1027
1064
|
import { spawn as spawn3 } from "node:child_process";
|
|
1028
|
-
import { openSync as openSync3, closeSync as closeSync3, writeSync as writeSync3, unlinkSync as unlinkSync3, existsSync as
|
|
1029
|
-
import { homedir as
|
|
1030
|
-
import { join as
|
|
1065
|
+
import { openSync as openSync3, closeSync as closeSync3, writeSync as writeSync3, unlinkSync as unlinkSync3, existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
|
|
1066
|
+
import { homedir as homedir10 } from "node:os";
|
|
1067
|
+
import { join as join12 } from "node:path";
|
|
1031
1068
|
|
|
1032
1069
|
// dist/src/embeddings/protocol.js
|
|
1033
1070
|
var DEFAULT_SOCKET_DIR = "/tmp";
|
|
@@ -1041,7 +1078,7 @@ function pidPathFor(uid, dir = DEFAULT_SOCKET_DIR) {
|
|
|
1041
1078
|
}
|
|
1042
1079
|
|
|
1043
1080
|
// dist/src/embeddings/client.js
|
|
1044
|
-
var SHARED_DAEMON_PATH =
|
|
1081
|
+
var SHARED_DAEMON_PATH = join12(homedir10(), ".hivemind", "embed-deps", "embed-daemon.js");
|
|
1045
1082
|
var log3 = (m) => log("embed-client", m);
|
|
1046
1083
|
function getUid() {
|
|
1047
1084
|
const uid = typeof process.getuid === "function" ? process.getuid() : void 0;
|
|
@@ -1061,7 +1098,7 @@ var EmbedClient = class {
|
|
|
1061
1098
|
this.socketPath = socketPathFor(uid, dir);
|
|
1062
1099
|
this.pidPath = pidPathFor(uid, dir);
|
|
1063
1100
|
this.timeoutMs = opts.timeoutMs ?? DEFAULT_CLIENT_TIMEOUT_MS;
|
|
1064
|
-
this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (
|
|
1101
|
+
this.daemonEntry = opts.daemonEntry ?? process.env.HIVEMIND_EMBED_DAEMON ?? (existsSync8(SHARED_DAEMON_PATH) ? SHARED_DAEMON_PATH : void 0);
|
|
1065
1102
|
this.autoSpawn = opts.autoSpawn ?? true;
|
|
1066
1103
|
this.spawnWaitMs = opts.spawnWaitMs ?? 5e3;
|
|
1067
1104
|
}
|
|
@@ -1161,7 +1198,7 @@ var EmbedClient = class {
|
|
|
1161
1198
|
return;
|
|
1162
1199
|
}
|
|
1163
1200
|
}
|
|
1164
|
-
if (!this.daemonEntry || !
|
|
1201
|
+
if (!this.daemonEntry || !existsSync8(this.daemonEntry)) {
|
|
1165
1202
|
log3(`daemonEntry not configured or missing: ${this.daemonEntry}`);
|
|
1166
1203
|
try {
|
|
1167
1204
|
closeSync3(fd);
|
|
@@ -1204,7 +1241,7 @@ var EmbedClient = class {
|
|
|
1204
1241
|
while (Date.now() < deadline) {
|
|
1205
1242
|
await sleep2(delay);
|
|
1206
1243
|
delay = Math.min(delay * 1.5, 300);
|
|
1207
|
-
if (!
|
|
1244
|
+
if (!existsSync8(this.socketPath))
|
|
1208
1245
|
continue;
|
|
1209
1246
|
try {
|
|
1210
1247
|
return await this.connectOnce();
|
|
@@ -1265,8 +1302,8 @@ function embeddingSqlLiteral(vec) {
|
|
|
1265
1302
|
|
|
1266
1303
|
// dist/src/embeddings/disable.js
|
|
1267
1304
|
import { createRequire } from "node:module";
|
|
1268
|
-
import { homedir as
|
|
1269
|
-
import { join as
|
|
1305
|
+
import { homedir as homedir11 } from "node:os";
|
|
1306
|
+
import { join as join13 } from "node:path";
|
|
1270
1307
|
import { pathToFileURL } from "node:url";
|
|
1271
1308
|
var cachedStatus = null;
|
|
1272
1309
|
function defaultResolveTransformers() {
|
|
@@ -1275,7 +1312,7 @@ function defaultResolveTransformers() {
|
|
|
1275
1312
|
return;
|
|
1276
1313
|
} catch {
|
|
1277
1314
|
}
|
|
1278
|
-
const sharedDir =
|
|
1315
|
+
const sharedDir = join13(homedir11(), ".hivemind", "embed-deps");
|
|
1279
1316
|
createRequire(pathToFileURL(`${sharedDir}/`).href).resolve("@huggingface/transformers");
|
|
1280
1317
|
}
|
|
1281
1318
|
var _resolve = defaultResolveTransformers;
|
|
@@ -1302,7 +1339,7 @@ function embeddingsDisabled() {
|
|
|
1302
1339
|
// dist/src/hooks/codex/stop.js
|
|
1303
1340
|
var log4 = (msg) => log("codex-stop", msg);
|
|
1304
1341
|
function resolveEmbedDaemonPath() {
|
|
1305
|
-
return
|
|
1342
|
+
return join14(dirname3(fileURLToPath3(import.meta.url)), "embeddings", "embed-daemon.js");
|
|
1306
1343
|
}
|
|
1307
1344
|
var CAPTURE = process.env.HIVEMIND_CAPTURE !== "false";
|
|
1308
1345
|
async function main() {
|
|
@@ -1326,7 +1363,7 @@ async function main() {
|
|
|
1326
1363
|
if (input.transcript_path) {
|
|
1327
1364
|
try {
|
|
1328
1365
|
const transcriptPath = input.transcript_path;
|
|
1329
|
-
if (
|
|
1366
|
+
if (existsSync9(transcriptPath)) {
|
|
1330
1367
|
const transcript = readFileSync7(transcriptPath, "utf-8");
|
|
1331
1368
|
const lines = transcript.trim().split("\n").reverse();
|
|
1332
1369
|
for (const line2 of lines) {
|