@wipcomputer/memory-crystal 0.7.30 → 0.7.32
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/CHANGELOG.md +43 -0
- package/SKILL.md +1 -1
- package/package.json +1 -1
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/.env.example +0 -20
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/.publish-skill.json +0 -1
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/CHANGELOG.md +0 -1297
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/CLA.md +0 -19
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/LICENSE +0 -52
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/README-ENTERPRISE.md +0 -226
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/README.md +0 -151
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/RELAY.md +0 -199
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/SKILL.md +0 -462
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/TECHNICAL.md +0 -656
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/README.md +0 -116
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/docs/gpt-system-instructions.md +0 -69
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/migrations/0001_init.sql +0 -52
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/migrations/0001_init.sql +0 -51
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/migrations/0002_cloud_storage.sql +0 -49
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/openclaw.plugin.json +0 -11
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/package-lock.json +0 -4169
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/package.json +0 -61
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/crystal-capture.sh +0 -29
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/deploy-cloud.sh +0 -153
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/ldm-backup.sh +0 -116
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/migrate-lance-to-sqlite.mjs +0 -218
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/skills/memory/SKILL.md +0 -438
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/wrangler-demo.toml +0 -8
- package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/wrangler-mcp.toml +0 -24
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/.env.example +0 -20
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/.publish-skill.json +0 -1
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/CHANGELOG.md +0 -1297
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/CLA.md +0 -19
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/LICENSE +0 -52
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/README-ENTERPRISE.md +0 -226
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/README.md +0 -151
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/RELAY.md +0 -199
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/RELEASE-NOTES-v0.7.30.md +0 -29
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/SKILL.md +0 -462
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/TECHNICAL.md +0 -656
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/README.md +0 -116
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/docs/gpt-system-instructions.md +0 -69
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/migrations/0001_init.sql +0 -52
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/migrations/0001_init.sql +0 -51
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/migrations/0002_cloud_storage.sql +0 -49
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/openclaw.plugin.json +0 -11
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/package-lock.json +0 -4169
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/package.json +0 -61
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/crystal-capture.sh +0 -29
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/deploy-cloud.sh +0 -153
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/ldm-backup.sh +0 -116
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/migrate-lance-to-sqlite.mjs +0 -218
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/skills/memory/SKILL.md +0 -438
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/wrangler-demo.toml +0 -8
- package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/wrangler-mcp.toml +0 -24
- package/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
- package/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
- package/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
- package/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
- package/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
- package/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
- package/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
- package/_trash/RELEASE-NOTES-v0.7.30.md +0 -29
- package/dist/bridge.d.ts +0 -7
- package/dist/bridge.js +0 -14
- package/dist/bulk-copy.d.ts +0 -17
- package/dist/bulk-copy.js +0 -90
- package/dist/cc-hook.d.ts +0 -8
- package/dist/cc-hook.js +0 -368
- package/dist/cc-poller.d.ts +0 -1
- package/dist/cc-poller.js +0 -550
- package/dist/chunk-25LXQJ4Z.js +0 -110
- package/dist/chunk-2DRXIRQW.js +0 -97
- package/dist/chunk-2ZNH5F6E.js +0 -1281
- package/dist/chunk-3G3SFYYI.js +0 -288
- package/dist/chunk-3RG5ZIWI.js +0 -10
- package/dist/chunk-3S6TI23B.js +0 -97
- package/dist/chunk-3VFIJYS4.js +0 -818
- package/dist/chunk-52QE3YI3.js +0 -1169
- package/dist/chunk-57RP3DIN.js +0 -1205
- package/dist/chunk-5HSZ4W2P.js +0 -62
- package/dist/chunk-645IPXW3.js +0 -290
- package/dist/chunk-7A7ELD4C.js +0 -1205
- package/dist/chunk-7FYY4GZM.js +0 -1205
- package/dist/chunk-7IUE7ODU.js +0 -254
- package/dist/chunk-7RMLKZIS.js +0 -108
- package/dist/chunk-AA3OPP4Z.js +0 -432
- package/dist/chunk-AEWLSYPH.js +0 -72
- package/dist/chunk-ASSZDR6I.js +0 -108
- package/dist/chunk-AYRJVWUC.js +0 -1205
- package/dist/chunk-CCYI5O3D.js +0 -148
- package/dist/chunk-D3I3ZSE2.js +0 -411
- package/dist/chunk-DACSKLY6.js +0 -219
- package/dist/chunk-DW5B4BL7.js +0 -108
- package/dist/chunk-EKSACBTJ.js +0 -1070
- package/dist/chunk-EXEZZADG.js +0 -248
- package/dist/chunk-F3Y7EL7K.js +0 -83
- package/dist/chunk-FBQWSDPC.js +0 -1328
- package/dist/chunk-FHRZNOMW.js +0 -1205
- package/dist/chunk-IM7N24MT.js +0 -129
- package/dist/chunk-IPNYIXFK.js +0 -1178
- package/dist/chunk-J7MRSZIO.js +0 -167
- package/dist/chunk-JITKI2OI.js +0 -106
- package/dist/chunk-JWZXYVET.js +0 -1068
- package/dist/chunk-KCQUXVYT.js +0 -108
- package/dist/chunk-KOQ43OX6.js +0 -1281
- package/dist/chunk-KYVWO6ZM.js +0 -1069
- package/dist/chunk-L3VHARQH.js +0 -413
- package/dist/chunk-LBWDS6BE.js +0 -288
- package/dist/chunk-LOVAHSQV.js +0 -411
- package/dist/chunk-LQOYCAGG.js +0 -446
- package/dist/chunk-LWAIPJ2W.js +0 -146
- package/dist/chunk-M5DHKW7M.js +0 -127
- package/dist/chunk-MBKCIJHM.js +0 -1328
- package/dist/chunk-MK42FMEG.js +0 -147
- package/dist/chunk-MOBMYHKL.js +0 -1205
- package/dist/chunk-MPLTNMRG.js +0 -67
- package/dist/chunk-NIJCVN3O.js +0 -147
- package/dist/chunk-NZCFSZQ7.js +0 -1205
- package/dist/chunk-O2UITJGH.js +0 -465
- package/dist/chunk-OCRA44AZ.js +0 -108
- package/dist/chunk-P3KJR66H.js +0 -117
- package/dist/chunk-PEK6JH65.js +0 -432
- package/dist/chunk-PJ6FFKEX.js +0 -77
- package/dist/chunk-PLUBBZYR.js +0 -800
- package/dist/chunk-PNKVD2UK.js +0 -26
- package/dist/chunk-PSQZURHO.js +0 -229
- package/dist/chunk-SGL6ISBJ.js +0 -1061
- package/dist/chunk-SJABZZT5.js +0 -97
- package/dist/chunk-TD3P3K32.js +0 -1199
- package/dist/chunk-TMDZJJKV.js +0 -288
- package/dist/chunk-UNHVZB5G.js +0 -411
- package/dist/chunk-VAFTWSTE.js +0 -1061
- package/dist/chunk-VNFXFQBB.js +0 -217
- package/dist/chunk-X3GVFKSJ.js +0 -1205
- package/dist/chunk-XZ3S56RQ.js +0 -1061
- package/dist/chunk-Y72C7F6O.js +0 -148
- package/dist/chunk-YLICP577.js +0 -1205
- package/dist/chunk-YX6AXLVK.js +0 -159
- package/dist/chunk-ZCQYHTNU.js +0 -146
- package/dist/cli.d.ts +0 -1
- package/dist/cli.js +0 -1105
- package/dist/cloud-crystal.js +0 -6
- package/dist/core.d.ts +0 -232
- package/dist/core.js +0 -12
- package/dist/crypto.d.ts +0 -20
- package/dist/crypto.js +0 -27
- package/dist/crystal-capture.sh +0 -29
- package/dist/crystal-serve.d.ts +0 -4
- package/dist/crystal-serve.js +0 -252
- package/dist/dev-update-SZ2Z4WCQ.js +0 -6
- package/dist/discover.d.ts +0 -30
- package/dist/discover.js +0 -177
- package/dist/doctor.d.ts +0 -9
- package/dist/doctor.js +0 -334
- package/dist/dream-weaver.d.ts +0 -8
- package/dist/dream-weaver.js +0 -56
- package/dist/file-sync.d.ts +0 -48
- package/dist/file-sync.js +0 -18
- package/dist/installer.d.ts +0 -61
- package/dist/installer.js +0 -676
- package/dist/ldm-backup.sh +0 -116
- package/dist/ldm.d.ts +0 -50
- package/dist/ldm.js +0 -32
- package/dist/mcp-server.d.ts +0 -1
- package/dist/mcp-server.js +0 -265
- package/dist/migrate.d.ts +0 -1
- package/dist/migrate.js +0 -89
- package/dist/mirror-sync.d.ts +0 -1
- package/dist/mirror-sync.js +0 -159
- package/dist/oc-backfill.d.ts +0 -19
- package/dist/oc-backfill.js +0 -74
- package/dist/openclaw.d.ts +0 -5
- package/dist/openclaw.js +0 -423
- package/dist/pair.d.ts +0 -4
- package/dist/pair.js +0 -75
- package/dist/poller.d.ts +0 -1
- package/dist/poller.js +0 -634
- package/dist/role.d.ts +0 -24
- package/dist/role.js +0 -13
- package/dist/search-pipeline-4K4OJSSS.js +0 -255
- package/dist/search-pipeline-4PRS6LI7.js +0 -280
- package/dist/search-pipeline-7UJMXPLO.js +0 -280
- package/dist/search-pipeline-DQTRLGBH.js +0 -74
- package/dist/search-pipeline-HNG37REH.js +0 -282
- package/dist/search-pipeline-IZFPLBUB.js +0 -280
- package/dist/search-pipeline-MID6F26Q.js +0 -73
- package/dist/search-pipeline-N52JZFNN.js +0 -282
- package/dist/search-pipeline-OPB2PRQQ.js +0 -280
- package/dist/search-pipeline-VXTE5HAD.js +0 -262
- package/dist/search-pipeline-XHFKADRG.js +0 -73
- package/dist/staging.d.ts +0 -29
- package/dist/staging.js +0 -21
- package/dist/summarize.d.ts +0 -19
- package/dist/summarize.js +0 -10
- package/dist/worker-demo.js +0 -186
- package/dist/worker-mcp.js +0 -404
- package/dist/worker.js +0 -137
package/dist/chunk-5HSZ4W2P.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
// src/bridge.ts
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
3
|
-
import { execSync } from "child_process";
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
var HOME = process.env.HOME || "";
|
|
6
|
-
function isBridgeInstalled() {
|
|
7
|
-
try {
|
|
8
|
-
execSync("which lesa 2>/dev/null", { encoding: "utf-8" });
|
|
9
|
-
return true;
|
|
10
|
-
} catch {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
function isBridgeRegistered() {
|
|
15
|
-
const mcpPath = join(HOME, ".claude", ".mcp.json");
|
|
16
|
-
try {
|
|
17
|
-
if (existsSync(mcpPath)) {
|
|
18
|
-
const config = JSON.parse(readFileSync(mcpPath, "utf-8"));
|
|
19
|
-
if (config.mcpServers && config.mcpServers["lesa-bridge"]) return true;
|
|
20
|
-
}
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
function isBridgeDesktopRegistered() {
|
|
26
|
-
const desktopConfig = join(HOME, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
27
|
-
try {
|
|
28
|
-
if (existsSync(desktopConfig)) {
|
|
29
|
-
const config = JSON.parse(readFileSync(desktopConfig, "utf-8"));
|
|
30
|
-
if (config.mcpServers && config.mcpServers["lesa-bridge"]) return true;
|
|
31
|
-
}
|
|
32
|
-
} catch {
|
|
33
|
-
}
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
function registerBridgeMcp() {
|
|
37
|
-
execSync("claude mcp add --scope user lesa-bridge -- lesa", {
|
|
38
|
-
encoding: "utf-8",
|
|
39
|
-
stdio: "pipe"
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
function registerBridgeDesktop() {
|
|
43
|
-
const desktopConfig = join(HOME, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
44
|
-
if (!existsSync(desktopConfig)) return false;
|
|
45
|
-
try {
|
|
46
|
-
const config = JSON.parse(readFileSync(desktopConfig, "utf-8"));
|
|
47
|
-
if (!config.mcpServers) config.mcpServers = {};
|
|
48
|
-
config.mcpServers["lesa-bridge"] = { command: "lesa" };
|
|
49
|
-
writeFileSync(desktopConfig, JSON.stringify(config, null, 2) + "\n");
|
|
50
|
-
return true;
|
|
51
|
-
} catch {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export {
|
|
57
|
-
isBridgeInstalled,
|
|
58
|
-
isBridgeRegistered,
|
|
59
|
-
isBridgeDesktopRegistered,
|
|
60
|
-
registerBridgeMcp,
|
|
61
|
-
registerBridgeDesktop
|
|
62
|
-
};
|
package/dist/chunk-645IPXW3.js
DELETED
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
decrypt,
|
|
3
|
-
decryptJSON,
|
|
4
|
-
encrypt,
|
|
5
|
-
encryptJSON,
|
|
6
|
-
loadRelayKey
|
|
7
|
-
} from "./chunk-25LXQJ4Z.js";
|
|
8
|
-
import {
|
|
9
|
-
init_ldm,
|
|
10
|
-
ldmPaths,
|
|
11
|
-
resolveStatePath,
|
|
12
|
-
stateWritePath
|
|
13
|
-
} from "./chunk-PSQZURHO.js";
|
|
14
|
-
|
|
15
|
-
// src/file-sync.ts
|
|
16
|
-
init_ldm();
|
|
17
|
-
import { createHash } from "crypto";
|
|
18
|
-
import {
|
|
19
|
-
existsSync,
|
|
20
|
-
mkdirSync,
|
|
21
|
-
readFileSync,
|
|
22
|
-
writeFileSync,
|
|
23
|
-
unlinkSync,
|
|
24
|
-
readdirSync,
|
|
25
|
-
statSync
|
|
26
|
-
} from "fs";
|
|
27
|
-
import { join, relative, dirname } from "path";
|
|
28
|
-
var RELAY_URL = process.env.CRYSTAL_RELAY_URL || "";
|
|
29
|
-
var RELAY_TOKEN = process.env.CRYSTAL_RELAY_TOKEN || "";
|
|
30
|
-
var EXCLUDE_PATTERNS = [
|
|
31
|
-
"memory/crystal.db",
|
|
32
|
-
// DB syncs via delta chunks, not file copy
|
|
33
|
-
"memory/crystal.db-wal",
|
|
34
|
-
"memory/crystal.db-shm",
|
|
35
|
-
"memory/crystal.db.bak",
|
|
36
|
-
"memory/crystal.db.tmp",
|
|
37
|
-
"memory/lance/",
|
|
38
|
-
// LanceDB (deprecated, not synced)
|
|
39
|
-
"state/",
|
|
40
|
-
// Local state files (watermarks, etc.)
|
|
41
|
-
"secrets/",
|
|
42
|
-
// Encryption keys, tokens
|
|
43
|
-
"staging/",
|
|
44
|
-
// Staging pipeline (Core-only)
|
|
45
|
-
"bin/",
|
|
46
|
-
// Local scripts
|
|
47
|
-
".DS_Store"
|
|
48
|
-
];
|
|
49
|
-
function shouldExclude(relativePath) {
|
|
50
|
-
for (const pattern of EXCLUDE_PATTERNS) {
|
|
51
|
-
if (relativePath === pattern || relativePath.startsWith(pattern)) return true;
|
|
52
|
-
}
|
|
53
|
-
const parts = relativePath.split("/");
|
|
54
|
-
for (const part of parts) {
|
|
55
|
-
if (part.startsWith(".") && part !== ".ldm") return true;
|
|
56
|
-
}
|
|
57
|
-
return false;
|
|
58
|
-
}
|
|
59
|
-
function scanDir(baseDir, currentDir, entries) {
|
|
60
|
-
if (!existsSync(currentDir)) return;
|
|
61
|
-
const items = readdirSync(currentDir);
|
|
62
|
-
for (const item of items) {
|
|
63
|
-
const fullPath = join(currentDir, item);
|
|
64
|
-
const relPath = relative(baseDir, fullPath);
|
|
65
|
-
if (shouldExclude(relPath)) continue;
|
|
66
|
-
let stat;
|
|
67
|
-
try {
|
|
68
|
-
stat = statSync(fullPath);
|
|
69
|
-
} catch {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
if (stat.isDirectory()) {
|
|
73
|
-
scanDir(baseDir, fullPath, entries);
|
|
74
|
-
} else if (stat.isFile()) {
|
|
75
|
-
if (stat.size > 50 * 1024 * 1024) continue;
|
|
76
|
-
const content = readFileSync(fullPath);
|
|
77
|
-
const sha256 = createHash("sha256").update(content).digest("hex");
|
|
78
|
-
entries.push({ path: relPath, sha256, size: stat.size });
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
function generateManifest() {
|
|
83
|
-
const paths = ldmPaths();
|
|
84
|
-
const entries = [];
|
|
85
|
-
scanDir(paths.root, paths.root, entries);
|
|
86
|
-
return {
|
|
87
|
-
version: 1,
|
|
88
|
-
generatedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
89
|
-
fileCount: entries.length,
|
|
90
|
-
entries
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
function compareManifest(coreManifest) {
|
|
94
|
-
const paths = ldmPaths();
|
|
95
|
-
const upsert = [];
|
|
96
|
-
const toDelete = [];
|
|
97
|
-
const localManifest = generateManifest();
|
|
98
|
-
const localMap = new Map(localManifest.entries.map((e) => [e.path, e]));
|
|
99
|
-
const coreMap = new Map(coreManifest.entries.map((e) => [e.path, e]));
|
|
100
|
-
for (const entry of coreManifest.entries) {
|
|
101
|
-
const local = localMap.get(entry.path);
|
|
102
|
-
if (!local || local.sha256 !== entry.sha256) {
|
|
103
|
-
upsert.push({ path: entry.path, sha256: entry.sha256 });
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
for (const entry of localManifest.entries) {
|
|
107
|
-
if (!coreMap.has(entry.path)) {
|
|
108
|
-
toDelete.push(entry.path);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return { upsert, delete: toDelete };
|
|
112
|
-
}
|
|
113
|
-
function loadFileSyncState() {
|
|
114
|
-
const statePath = resolveStatePath("file-sync-state.json");
|
|
115
|
-
try {
|
|
116
|
-
if (existsSync(statePath)) {
|
|
117
|
-
return JSON.parse(readFileSync(statePath, "utf-8"));
|
|
118
|
-
}
|
|
119
|
-
} catch {
|
|
120
|
-
}
|
|
121
|
-
return { lastSync: null, lastManifestHash: null, filesTransferred: 0, filesDeleted: 0 };
|
|
122
|
-
}
|
|
123
|
-
function saveFileSyncState(state) {
|
|
124
|
-
const writePath = stateWritePath("file-sync-state.json");
|
|
125
|
-
writeFileSync(writePath, JSON.stringify(state, null, 2));
|
|
126
|
-
}
|
|
127
|
-
async function pushFileSync() {
|
|
128
|
-
if (!RELAY_URL || !RELAY_TOKEN) {
|
|
129
|
-
throw new Error("CRYSTAL_RELAY_URL and CRYSTAL_RELAY_TOKEN must be set");
|
|
130
|
-
}
|
|
131
|
-
const relayKey = loadRelayKey();
|
|
132
|
-
const paths = ldmPaths();
|
|
133
|
-
const manifest = generateManifest();
|
|
134
|
-
const manifestJson = JSON.stringify(manifest.entries.map((e) => `${e.path}:${e.sha256}`));
|
|
135
|
-
const manifestHash = createHash("sha256").update(manifestJson).digest("hex");
|
|
136
|
-
const state = loadFileSyncState();
|
|
137
|
-
if (state.lastManifestHash === manifestHash) {
|
|
138
|
-
return { manifest: 0, files: 0 };
|
|
139
|
-
}
|
|
140
|
-
const encryptedManifest = encryptJSON(manifest, relayKey);
|
|
141
|
-
const manifestResp = await fetch(`${RELAY_URL}/drop/files`, {
|
|
142
|
-
method: "POST",
|
|
143
|
-
headers: {
|
|
144
|
-
"Authorization": `Bearer ${RELAY_TOKEN}`,
|
|
145
|
-
"Content-Type": "application/octet-stream",
|
|
146
|
-
"X-File-Type": "manifest"
|
|
147
|
-
},
|
|
148
|
-
body: JSON.stringify(encryptedManifest)
|
|
149
|
-
});
|
|
150
|
-
if (!manifestResp.ok) {
|
|
151
|
-
throw new Error(`Manifest push failed: ${manifestResp.status} ${await manifestResp.text()}`);
|
|
152
|
-
}
|
|
153
|
-
let filesPushed = 0;
|
|
154
|
-
for (const entry of manifest.entries) {
|
|
155
|
-
const fullPath = join(paths.root, entry.path);
|
|
156
|
-
if (!existsSync(fullPath)) continue;
|
|
157
|
-
const content = readFileSync(fullPath);
|
|
158
|
-
const encrypted = encrypt(content, relayKey);
|
|
159
|
-
const filePayload = JSON.stringify({
|
|
160
|
-
path: entry.path,
|
|
161
|
-
sha256: entry.sha256,
|
|
162
|
-
size: entry.size,
|
|
163
|
-
data: encrypted
|
|
164
|
-
});
|
|
165
|
-
const fileResp = await fetch(`${RELAY_URL}/drop/files`, {
|
|
166
|
-
method: "POST",
|
|
167
|
-
headers: {
|
|
168
|
-
"Authorization": `Bearer ${RELAY_TOKEN}`,
|
|
169
|
-
"Content-Type": "application/octet-stream",
|
|
170
|
-
"X-File-Type": "file"
|
|
171
|
-
},
|
|
172
|
-
body: filePayload
|
|
173
|
-
});
|
|
174
|
-
if (fileResp.ok) filesPushed++;
|
|
175
|
-
}
|
|
176
|
-
state.lastSync = (/* @__PURE__ */ new Date()).toISOString();
|
|
177
|
-
state.lastManifestHash = manifestHash;
|
|
178
|
-
state.filesTransferred += filesPushed;
|
|
179
|
-
saveFileSyncState(state);
|
|
180
|
-
return { manifest: manifest.fileCount, files: filesPushed };
|
|
181
|
-
}
|
|
182
|
-
async function pullFileSync() {
|
|
183
|
-
if (!RELAY_URL || !RELAY_TOKEN) {
|
|
184
|
-
throw new Error("CRYSTAL_RELAY_URL and CRYSTAL_RELAY_TOKEN must be set");
|
|
185
|
-
}
|
|
186
|
-
const relayKey = loadRelayKey();
|
|
187
|
-
const paths = ldmPaths();
|
|
188
|
-
const listResp = await fetch(`${RELAY_URL}/pickup/files`, {
|
|
189
|
-
headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
|
|
190
|
-
});
|
|
191
|
-
if (!listResp.ok) {
|
|
192
|
-
throw new Error(`File sync list failed: ${listResp.status} ${await listResp.text()}`);
|
|
193
|
-
}
|
|
194
|
-
const listData = await listResp.json();
|
|
195
|
-
if (listData.count === 0) {
|
|
196
|
-
return { imported: 0, deleted: 0 };
|
|
197
|
-
}
|
|
198
|
-
let coreManifest = null;
|
|
199
|
-
const fileBlobs = [];
|
|
200
|
-
for (const blob of listData.blobs) {
|
|
201
|
-
try {
|
|
202
|
-
const blobResp = await fetch(`${RELAY_URL}/pickup/files/${blob.id}`, {
|
|
203
|
-
headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
|
|
204
|
-
});
|
|
205
|
-
if (!blobResp.ok) continue;
|
|
206
|
-
const text = await blobResp.text();
|
|
207
|
-
const parsed = JSON.parse(text);
|
|
208
|
-
if (parsed.v !== void 0 && parsed.nonce !== void 0) {
|
|
209
|
-
try {
|
|
210
|
-
const manifest = decryptJSON(parsed, relayKey);
|
|
211
|
-
if (manifest.version && manifest.entries) {
|
|
212
|
-
coreManifest = manifest;
|
|
213
|
-
}
|
|
214
|
-
} catch {
|
|
215
|
-
}
|
|
216
|
-
} else if (parsed.path && parsed.data) {
|
|
217
|
-
fileBlobs.push({
|
|
218
|
-
id: blob.id,
|
|
219
|
-
path: parsed.path,
|
|
220
|
-
sha256: parsed.sha256,
|
|
221
|
-
data: parsed.data
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
await fetch(`${RELAY_URL}/confirm/files/${blob.id}`, {
|
|
225
|
-
method: "DELETE",
|
|
226
|
-
headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
|
|
227
|
-
});
|
|
228
|
-
} catch (err) {
|
|
229
|
-
process.stderr.write(`[file-sync] error processing blob ${blob.id}: ${err.message}
|
|
230
|
-
`);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (!coreManifest) {
|
|
234
|
-
process.stderr.write("[file-sync] no manifest found in relay\n");
|
|
235
|
-
return { imported: 0, deleted: 0 };
|
|
236
|
-
}
|
|
237
|
-
const delta = compareManifest(coreManifest);
|
|
238
|
-
const fileBlobMap = new Map(fileBlobs.map((f) => [f.path, f]));
|
|
239
|
-
let imported = 0;
|
|
240
|
-
for (const entry of delta.upsert) {
|
|
241
|
-
const fileBlob = fileBlobMap.get(entry.path);
|
|
242
|
-
if (!fileBlob) {
|
|
243
|
-
continue;
|
|
244
|
-
}
|
|
245
|
-
try {
|
|
246
|
-
const content = decrypt(fileBlob.data, relayKey);
|
|
247
|
-
const actualHash = createHash("sha256").update(content).digest("hex");
|
|
248
|
-
if (actualHash !== entry.sha256) {
|
|
249
|
-
process.stderr.write(`[file-sync] hash mismatch for ${entry.path}, skipping
|
|
250
|
-
`);
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
const destPath = join(paths.root, entry.path);
|
|
254
|
-
mkdirSync(dirname(destPath), { recursive: true });
|
|
255
|
-
writeFileSync(destPath, content);
|
|
256
|
-
imported++;
|
|
257
|
-
} catch (err) {
|
|
258
|
-
process.stderr.write(`[file-sync] failed to write ${entry.path}: ${err.message}
|
|
259
|
-
`);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
let deleted = 0;
|
|
263
|
-
for (const path of delta.delete) {
|
|
264
|
-
const destPath = join(paths.root, path);
|
|
265
|
-
if (existsSync(destPath)) {
|
|
266
|
-
try {
|
|
267
|
-
unlinkSync(destPath);
|
|
268
|
-
deleted++;
|
|
269
|
-
} catch (err) {
|
|
270
|
-
process.stderr.write(`[file-sync] failed to delete ${path}: ${err.message}
|
|
271
|
-
`);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
const state = loadFileSyncState();
|
|
276
|
-
state.lastSync = (/* @__PURE__ */ new Date()).toISOString();
|
|
277
|
-
state.filesTransferred += imported;
|
|
278
|
-
state.filesDeleted += deleted;
|
|
279
|
-
saveFileSyncState(state);
|
|
280
|
-
return { imported, deleted };
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
export {
|
|
284
|
-
generateManifest,
|
|
285
|
-
compareManifest,
|
|
286
|
-
loadFileSyncState,
|
|
287
|
-
saveFileSyncState,
|
|
288
|
-
pushFileSync,
|
|
289
|
-
pullFileSync
|
|
290
|
-
};
|