@wipcomputer/memory-crystal 0.7.29 → 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.
Files changed (146) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/SKILL.md +1 -1
  3. package/package.json +1 -1
  4. package/scripts/migrate-lance-to-sqlite.mjs +2 -1
  5. package/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
  6. package/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
  7. package/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
  8. package/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
  9. package/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
  10. package/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
  11. package/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
  12. package/dist/bridge.d.ts +0 -7
  13. package/dist/bridge.js +0 -14
  14. package/dist/bulk-copy.d.ts +0 -17
  15. package/dist/bulk-copy.js +0 -90
  16. package/dist/cc-hook.d.ts +0 -8
  17. package/dist/cc-hook.js +0 -368
  18. package/dist/cc-poller.d.ts +0 -1
  19. package/dist/cc-poller.js +0 -550
  20. package/dist/chunk-25LXQJ4Z.js +0 -110
  21. package/dist/chunk-2DRXIRQW.js +0 -97
  22. package/dist/chunk-2ZNH5F6E.js +0 -1281
  23. package/dist/chunk-3G3SFYYI.js +0 -288
  24. package/dist/chunk-3RG5ZIWI.js +0 -10
  25. package/dist/chunk-3S6TI23B.js +0 -97
  26. package/dist/chunk-3VFIJYS4.js +0 -818
  27. package/dist/chunk-52QE3YI3.js +0 -1169
  28. package/dist/chunk-57RP3DIN.js +0 -1205
  29. package/dist/chunk-5HSZ4W2P.js +0 -62
  30. package/dist/chunk-645IPXW3.js +0 -290
  31. package/dist/chunk-7A7ELD4C.js +0 -1205
  32. package/dist/chunk-7FYY4GZM.js +0 -1205
  33. package/dist/chunk-7IUE7ODU.js +0 -254
  34. package/dist/chunk-7RMLKZIS.js +0 -108
  35. package/dist/chunk-AA3OPP4Z.js +0 -432
  36. package/dist/chunk-AEWLSYPH.js +0 -72
  37. package/dist/chunk-ASSZDR6I.js +0 -108
  38. package/dist/chunk-AYRJVWUC.js +0 -1205
  39. package/dist/chunk-CCYI5O3D.js +0 -148
  40. package/dist/chunk-D3I3ZSE2.js +0 -411
  41. package/dist/chunk-DACSKLY6.js +0 -219
  42. package/dist/chunk-DW5B4BL7.js +0 -108
  43. package/dist/chunk-EKSACBTJ.js +0 -1070
  44. package/dist/chunk-EXEZZADG.js +0 -248
  45. package/dist/chunk-F3Y7EL7K.js +0 -83
  46. package/dist/chunk-FBQWSDPC.js +0 -1328
  47. package/dist/chunk-FHRZNOMW.js +0 -1205
  48. package/dist/chunk-IM7N24MT.js +0 -129
  49. package/dist/chunk-IPNYIXFK.js +0 -1178
  50. package/dist/chunk-J7MRSZIO.js +0 -167
  51. package/dist/chunk-JITKI2OI.js +0 -106
  52. package/dist/chunk-JWZXYVET.js +0 -1068
  53. package/dist/chunk-KCQUXVYT.js +0 -108
  54. package/dist/chunk-KOQ43OX6.js +0 -1281
  55. package/dist/chunk-KYVWO6ZM.js +0 -1069
  56. package/dist/chunk-L3VHARQH.js +0 -413
  57. package/dist/chunk-LBWDS6BE.js +0 -288
  58. package/dist/chunk-LOVAHSQV.js +0 -411
  59. package/dist/chunk-LQOYCAGG.js +0 -446
  60. package/dist/chunk-LWAIPJ2W.js +0 -146
  61. package/dist/chunk-M5DHKW7M.js +0 -127
  62. package/dist/chunk-MBKCIJHM.js +0 -1328
  63. package/dist/chunk-MK42FMEG.js +0 -147
  64. package/dist/chunk-MOBMYHKL.js +0 -1205
  65. package/dist/chunk-MPLTNMRG.js +0 -67
  66. package/dist/chunk-NIJCVN3O.js +0 -147
  67. package/dist/chunk-NZCFSZQ7.js +0 -1205
  68. package/dist/chunk-O2UITJGH.js +0 -465
  69. package/dist/chunk-OCRA44AZ.js +0 -108
  70. package/dist/chunk-P3KJR66H.js +0 -117
  71. package/dist/chunk-PEK6JH65.js +0 -432
  72. package/dist/chunk-PJ6FFKEX.js +0 -77
  73. package/dist/chunk-PLUBBZYR.js +0 -800
  74. package/dist/chunk-PNKVD2UK.js +0 -26
  75. package/dist/chunk-PSQZURHO.js +0 -229
  76. package/dist/chunk-SGL6ISBJ.js +0 -1061
  77. package/dist/chunk-SJABZZT5.js +0 -97
  78. package/dist/chunk-TD3P3K32.js +0 -1199
  79. package/dist/chunk-TMDZJJKV.js +0 -288
  80. package/dist/chunk-UNHVZB5G.js +0 -411
  81. package/dist/chunk-VAFTWSTE.js +0 -1061
  82. package/dist/chunk-VNFXFQBB.js +0 -217
  83. package/dist/chunk-X3GVFKSJ.js +0 -1205
  84. package/dist/chunk-XZ3S56RQ.js +0 -1061
  85. package/dist/chunk-Y72C7F6O.js +0 -148
  86. package/dist/chunk-YLICP577.js +0 -1205
  87. package/dist/chunk-YX6AXLVK.js +0 -159
  88. package/dist/chunk-ZCQYHTNU.js +0 -146
  89. package/dist/cli.d.ts +0 -1
  90. package/dist/cli.js +0 -1105
  91. package/dist/cloud-crystal.js +0 -6
  92. package/dist/core.d.ts +0 -232
  93. package/dist/core.js +0 -12
  94. package/dist/crypto.d.ts +0 -20
  95. package/dist/crypto.js +0 -27
  96. package/dist/crystal-capture.sh +0 -29
  97. package/dist/crystal-serve.d.ts +0 -4
  98. package/dist/crystal-serve.js +0 -252
  99. package/dist/dev-update-SZ2Z4WCQ.js +0 -6
  100. package/dist/discover.d.ts +0 -30
  101. package/dist/discover.js +0 -177
  102. package/dist/doctor.d.ts +0 -9
  103. package/dist/doctor.js +0 -334
  104. package/dist/dream-weaver.d.ts +0 -8
  105. package/dist/dream-weaver.js +0 -56
  106. package/dist/file-sync.d.ts +0 -48
  107. package/dist/file-sync.js +0 -18
  108. package/dist/installer.d.ts +0 -61
  109. package/dist/installer.js +0 -676
  110. package/dist/ldm-backup.sh +0 -116
  111. package/dist/ldm.d.ts +0 -50
  112. package/dist/ldm.js +0 -32
  113. package/dist/mcp-server.d.ts +0 -1
  114. package/dist/mcp-server.js +0 -265
  115. package/dist/migrate.d.ts +0 -1
  116. package/dist/migrate.js +0 -89
  117. package/dist/mirror-sync.d.ts +0 -1
  118. package/dist/mirror-sync.js +0 -159
  119. package/dist/oc-backfill.d.ts +0 -19
  120. package/dist/oc-backfill.js +0 -74
  121. package/dist/openclaw.d.ts +0 -5
  122. package/dist/openclaw.js +0 -423
  123. package/dist/pair.d.ts +0 -4
  124. package/dist/pair.js +0 -75
  125. package/dist/poller.d.ts +0 -1
  126. package/dist/poller.js +0 -634
  127. package/dist/role.d.ts +0 -24
  128. package/dist/role.js +0 -13
  129. package/dist/search-pipeline-4K4OJSSS.js +0 -255
  130. package/dist/search-pipeline-4PRS6LI7.js +0 -280
  131. package/dist/search-pipeline-7UJMXPLO.js +0 -280
  132. package/dist/search-pipeline-DQTRLGBH.js +0 -74
  133. package/dist/search-pipeline-HNG37REH.js +0 -282
  134. package/dist/search-pipeline-IZFPLBUB.js +0 -280
  135. package/dist/search-pipeline-MID6F26Q.js +0 -73
  136. package/dist/search-pipeline-N52JZFNN.js +0 -282
  137. package/dist/search-pipeline-OPB2PRQQ.js +0 -280
  138. package/dist/search-pipeline-VXTE5HAD.js +0 -262
  139. package/dist/search-pipeline-XHFKADRG.js +0 -73
  140. package/dist/staging.d.ts +0 -29
  141. package/dist/staging.js +0 -21
  142. package/dist/summarize.d.ts +0 -19
  143. package/dist/summarize.js +0 -10
  144. package/dist/worker-demo.js +0 -186
  145. package/dist/worker-mcp.js +0 -404
  146. package/dist/worker.js +0 -137
@@ -1,167 +0,0 @@
1
- // src/cloud-crystal.ts
2
- async function embed(text, apiKey) {
3
- const resp = await fetch("https://api.openai.com/v1/embeddings", {
4
- method: "POST",
5
- headers: {
6
- "Authorization": `Bearer ${apiKey}`,
7
- "Content-Type": "application/json"
8
- },
9
- body: JSON.stringify({
10
- model: "text-embedding-3-small",
11
- input: text,
12
- dimensions: 1024
13
- })
14
- });
15
- if (!resp.ok) {
16
- const err = await resp.text();
17
- throw new Error(`Embedding failed: ${resp.status} ${err}`);
18
- }
19
- const data = await resp.json();
20
- return data.data[0].embedding;
21
- }
22
- var CloudCrystal = class {
23
- constructor(db, vectorize, apiKey) {
24
- this.db = db;
25
- this.vectorize = vectorize;
26
- this.apiKey = apiKey;
27
- }
28
- // Hybrid search: BM25 (FTS5) + vector (Vectorize) + RRF fusion + recency
29
- async search(userId, query, limit = 5, agentId) {
30
- const agentFilter = agentId ? "AND c.agent_id = ?" : "";
31
- const bm25Params = [userId, query];
32
- if (agentId) bm25Params.push(agentId);
33
- const bm25Results = await this.db.prepare(`
34
- SELECT c.id, c.text, c.role, c.agent_id, c.created_at, c.source_type,
35
- rank AS bm25_score
36
- FROM chunks_fts f
37
- JOIN chunks c ON c.id = f.rowid
38
- WHERE f.text MATCH ? AND c.user_id = ? ${agentFilter}
39
- ORDER BY rank
40
- LIMIT ?
41
- `).bind(query, userId, ...agentId ? [agentId] : [], limit * 3).all();
42
- const queryVec = await embed(query, this.apiKey);
43
- const vecResults = await this.vectorize.query(queryVec, {
44
- topK: limit * 3,
45
- filter: { user_id: userId, ...agentId ? { agent_id: agentId } : {} },
46
- returnMetadata: "all"
47
- });
48
- const k = 60;
49
- const scores = /* @__PURE__ */ new Map();
50
- const bm25Rows = bm25Results.results || [];
51
- for (let i = 0; i < bm25Rows.length; i++) {
52
- const id = bm25Rows[i].id;
53
- const existing = scores.get(id) || { score: 0, data: bm25Rows[i] };
54
- existing.score += 1 / (k + i + 1);
55
- scores.set(id, existing);
56
- }
57
- for (let i = 0; i < vecResults.matches.length; i++) {
58
- const match = vecResults.matches[i];
59
- const id = parseInt(match.id, 10);
60
- const existing = scores.get(id) || { score: 0 };
61
- existing.score += 1 / (k + i + 1);
62
- scores.set(id, existing);
63
- }
64
- const now = Date.now();
65
- for (const [id, entry] of scores) {
66
- if (entry.data?.created_at) {
67
- const age = now - new Date(entry.data.created_at).getTime();
68
- const dayAge = age / (1e3 * 60 * 60 * 24);
69
- const recencyBoost = Math.max(0, 1 - dayAge / 90) * 0.15;
70
- entry.score += recencyBoost;
71
- }
72
- }
73
- const ranked = [...scores.entries()].sort((a, b) => b[1].score - a[1].score).slice(0, limit);
74
- const needFetch = ranked.filter(([_, v]) => !v.data).map(([id]) => id);
75
- if (needFetch.length > 0) {
76
- const placeholders = needFetch.map(() => "?").join(",");
77
- const rows = await this.db.prepare(
78
- `SELECT id, text, role, agent_id, created_at, source_type FROM chunks WHERE id IN (${placeholders})`
79
- ).bind(...needFetch).all();
80
- const rowMap = new Map(rows.results.map((r) => [r.id, r]));
81
- for (const [id, entry] of scores) {
82
- if (!entry.data && rowMap.has(id)) {
83
- entry.data = rowMap.get(id);
84
- }
85
- }
86
- }
87
- return ranked.map(([id, entry]) => ({
88
- id,
89
- text: entry.data?.text || "",
90
- score: entry.score,
91
- role: entry.data?.role || "unknown",
92
- agent_id: entry.data?.agent_id || "unknown",
93
- created_at: entry.data?.created_at || "",
94
- source_type: entry.data?.source_type || "unknown"
95
- }));
96
- }
97
- // Ingest chunks (conversation turns)
98
- async ingest(userId, chunks) {
99
- let ingested = 0;
100
- for (const chunk of chunks) {
101
- const result = await this.db.prepare(`
102
- INSERT INTO chunks (user_id, text, role, agent_id, source_type, token_count)
103
- VALUES (?, ?, ?, ?, ?, ?)
104
- `).bind(
105
- userId,
106
- chunk.text,
107
- chunk.role,
108
- chunk.agent_id,
109
- chunk.source_type || "chatgpt",
110
- Math.ceil(chunk.text.length / 4)
111
- // rough token estimate
112
- ).run();
113
- const chunkId = result.meta.last_row_id;
114
- const vec = await embed(chunk.text, this.apiKey);
115
- await this.vectorize.upsert([{
116
- id: String(chunkId),
117
- values: vec,
118
- metadata: {
119
- user_id: userId,
120
- agent_id: chunk.agent_id,
121
- role: chunk.role,
122
- source_type: chunk.source_type || "chatgpt"
123
- }
124
- }]);
125
- ingested++;
126
- }
127
- return ingested;
128
- }
129
- // Remember a fact/preference/event
130
- async remember(userId, text, category = "fact") {
131
- const result = await this.db.prepare(`
132
- INSERT INTO memories (user_id, text, category) VALUES (?, ?, ?)
133
- `).bind(userId, text, category).run();
134
- return result.meta.last_row_id;
135
- }
136
- // Forget (deprecate) a memory
137
- async forget(userId, memoryId) {
138
- const result = await this.db.prepare(`
139
- UPDATE memories SET status = 'deprecated', updated_at = datetime('now')
140
- WHERE id = ? AND user_id = ? AND status = 'active'
141
- `).bind(memoryId, userId).run();
142
- return (result.meta.changes || 0) > 0;
143
- }
144
- // Status
145
- async status(userId) {
146
- const chunkCount = await this.db.prepare(
147
- "SELECT COUNT(*) as count FROM chunks WHERE user_id = ?"
148
- ).bind(userId).first();
149
- const memoryCount = await this.db.prepare(
150
- "SELECT COUNT(*) as count FROM memories WHERE user_id = ? AND status = ?"
151
- ).bind(userId, "active").first();
152
- const agents = await this.db.prepare(
153
- "SELECT DISTINCT agent_id FROM chunks WHERE user_id = ?"
154
- ).bind(userId).all();
155
- return {
156
- chunks: chunkCount?.count || 0,
157
- memories: memoryCount?.count || 0,
158
- agents: (agents.results || []).map((r) => r.agent_id),
159
- tier: "convenience"
160
- // Tier 2 users only
161
- };
162
- }
163
- };
164
-
165
- export {
166
- CloudCrystal
167
- };
@@ -1,106 +0,0 @@
1
- // src/crypto.ts
2
- import { readFileSync, existsSync } from "fs";
3
- import { createCipheriv, createDecipheriv, createHmac, randomBytes, hkdfSync } from "crypto";
4
- import { join } from "path";
5
- import { createHash } from "crypto";
6
- var HOME = process.env.HOME || "";
7
- var KEY_PATH = process.env.CRYSTAL_RELAY_KEY_PATH || join(HOME, ".openclaw", "secrets", "crystal-relay-key");
8
- function loadRelayKey() {
9
- if (!existsSync(KEY_PATH)) {
10
- throw new Error(
11
- `Relay key not found at ${KEY_PATH}
12
- Generate one: openssl rand -base64 32 > ${KEY_PATH} && chmod 600 ${KEY_PATH}
13
- Copy the same key to all trusted machines.`
14
- );
15
- }
16
- const raw = readFileSync(KEY_PATH, "utf-8").trim();
17
- const key = Buffer.from(raw, "base64");
18
- if (key.length !== 32) {
19
- throw new Error(`Relay key must be 32 bytes (256 bits). Got ${key.length} bytes. Regenerate with: openssl rand -base64 32`);
20
- }
21
- return key;
22
- }
23
- function deriveSigningKey(masterKey) {
24
- return Buffer.from(hkdfSync("sha256", masterKey, "", "crystal-relay-sign", 32));
25
- }
26
- function encrypt(plaintext, masterKey) {
27
- const nonce = randomBytes(12);
28
- const cipher = createCipheriv("aes-256-gcm", masterKey, nonce);
29
- const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
30
- const tag = cipher.getAuthTag();
31
- const signingKey = deriveSigningKey(masterKey);
32
- const hmacData = Buffer.concat([nonce, ciphertext, tag]);
33
- const hmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
34
- return {
35
- v: 1,
36
- nonce: nonce.toString("base64"),
37
- ciphertext: ciphertext.toString("base64"),
38
- tag: tag.toString("base64"),
39
- hmac
40
- };
41
- }
42
- function decrypt(payload, masterKey) {
43
- if (payload.v !== 1) {
44
- throw new Error(`Unknown payload version: ${payload.v}`);
45
- }
46
- const nonce = Buffer.from(payload.nonce, "base64");
47
- const ciphertext = Buffer.from(payload.ciphertext, "base64");
48
- const tag = Buffer.from(payload.tag, "base64");
49
- const signingKey = deriveSigningKey(masterKey);
50
- const hmacData = Buffer.concat([nonce, ciphertext, tag]);
51
- const expectedHmac = createHmac("sha256", signingKey).update(hmacData).digest("hex");
52
- if (payload.hmac !== expectedHmac) {
53
- throw new Error("HMAC verification failed \u2014 blob rejected (tampered or wrong key)");
54
- }
55
- const decipher = createDecipheriv("aes-256-gcm", masterKey, nonce);
56
- decipher.setAuthTag(tag);
57
- return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
58
- }
59
- function encryptJSON(data, masterKey) {
60
- const plaintext = Buffer.from(JSON.stringify(data), "utf-8");
61
- return encrypt(plaintext, masterKey);
62
- }
63
- function decryptJSON(payload, masterKey) {
64
- const plaintext = decrypt(payload, masterKey);
65
- return JSON.parse(plaintext.toString("utf-8"));
66
- }
67
- function encryptFile(filePath, masterKey) {
68
- const plaintext = readFileSync(filePath);
69
- return encrypt(plaintext, masterKey);
70
- }
71
- var RELAY_KEY_PATH = KEY_PATH;
72
- function generateRelayKey() {
73
- return randomBytes(32);
74
- }
75
- function encodePairingString(key) {
76
- if (key.length !== 32) throw new Error("Key must be 32 bytes");
77
- return `mc1:${key.toString("base64")}`;
78
- }
79
- function decodePairingString(str) {
80
- const trimmed = str.trim();
81
- if (!trimmed.startsWith("mc1:")) {
82
- throw new Error("Invalid pairing string (expected mc1: prefix)");
83
- }
84
- const key = Buffer.from(trimmed.slice(4), "base64");
85
- if (key.length !== 32) {
86
- throw new Error(`Invalid key length: expected 32 bytes, got ${key.length}`);
87
- }
88
- return key;
89
- }
90
- function hashBuffer(data) {
91
- return createHash("sha256").update(data).digest("hex");
92
- }
93
-
94
- export {
95
- loadRelayKey,
96
- encrypt,
97
- decrypt,
98
- encryptJSON,
99
- decryptJSON,
100
- encryptFile,
101
- RELAY_KEY_PATH,
102
- generateRelayKey,
103
- encodePairingString,
104
- decodePairingString,
105
- hashBuffer
106
- };