@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.
Files changed (211) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/SKILL.md +1 -1
  3. package/package.json +1 -1
  4. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/.env.example +0 -20
  5. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/.publish-skill.json +0 -1
  6. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/CHANGELOG.md +0 -1297
  7. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/CLA.md +0 -19
  8. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/LICENSE +0 -52
  9. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/README-ENTERPRISE.md +0 -226
  10. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/README.md +0 -151
  11. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/RELAY.md +0 -199
  12. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/SKILL.md +0 -462
  13. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/TECHNICAL.md +0 -656
  14. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
  15. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
  16. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
  17. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
  18. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
  19. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
  20. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
  21. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/README.md +0 -116
  22. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/docs/gpt-system-instructions.md +0 -69
  23. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/cloud/migrations/0001_init.sql +0 -52
  24. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/migrations/0001_init.sql +0 -51
  25. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/migrations/0002_cloud_storage.sql +0 -49
  26. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/openclaw.plugin.json +0 -11
  27. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/package-lock.json +0 -4169
  28. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/package.json +0 -61
  29. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/crystal-capture.sh +0 -29
  30. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/deploy-cloud.sh +0 -153
  31. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/ldm-backup.sh +0 -116
  32. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/scripts/migrate-lance-to-sqlite.mjs +0 -218
  33. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/skills/memory/SKILL.md +0 -438
  34. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/wrangler-demo.toml +0 -8
  35. package/.worktrees/memory-crystal-private--cc-mini-fix-home-fallback/wrangler-mcp.toml +0 -24
  36. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/.env.example +0 -20
  37. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/.publish-skill.json +0 -1
  38. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/CHANGELOG.md +0 -1297
  39. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/CLA.md +0 -19
  40. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/LICENSE +0 -52
  41. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/README-ENTERPRISE.md +0 -226
  42. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/README.md +0 -151
  43. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/RELAY.md +0 -199
  44. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/RELEASE-NOTES-v0.7.30.md +0 -29
  45. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/SKILL.md +0 -462
  46. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/TECHNICAL.md +0 -656
  47. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
  48. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
  49. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
  50. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
  51. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
  52. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
  53. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
  54. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/README.md +0 -116
  55. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/docs/gpt-system-instructions.md +0 -69
  56. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/cloud/migrations/0001_init.sql +0 -52
  57. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/migrations/0001_init.sql +0 -51
  58. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/migrations/0002_cloud_storage.sql +0 -49
  59. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/openclaw.plugin.json +0 -11
  60. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/package-lock.json +0 -4169
  61. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/package.json +0 -61
  62. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/crystal-capture.sh +0 -29
  63. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/deploy-cloud.sh +0 -153
  64. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/ldm-backup.sh +0 -116
  65. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/scripts/migrate-lance-to-sqlite.mjs +0 -218
  66. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/skills/memory/SKILL.md +0 -438
  67. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/wrangler-demo.toml +0 -8
  68. package/.worktrees/memory-crystal-private--cc-mini-release-notes-v0.7.30/wrangler-mcp.toml +0 -24
  69. package/_trash/RELEASE-NOTES-v0-7-23.md +0 -48
  70. package/_trash/RELEASE-NOTES-v0-7-25.md +0 -24
  71. package/_trash/RELEASE-NOTES-v0-7-26.md +0 -7
  72. package/_trash/RELEASE-NOTES-v0-7-28.md +0 -31
  73. package/_trash/RELEASE-NOTES-v0-7-29.md +0 -28
  74. package/_trash/RELEASE-NOTES-v0-7-4.md +0 -64
  75. package/_trash/RELEASE-NOTES-v0-7-5.md +0 -19
  76. package/_trash/RELEASE-NOTES-v0.7.30.md +0 -29
  77. package/dist/bridge.d.ts +0 -7
  78. package/dist/bridge.js +0 -14
  79. package/dist/bulk-copy.d.ts +0 -17
  80. package/dist/bulk-copy.js +0 -90
  81. package/dist/cc-hook.d.ts +0 -8
  82. package/dist/cc-hook.js +0 -368
  83. package/dist/cc-poller.d.ts +0 -1
  84. package/dist/cc-poller.js +0 -550
  85. package/dist/chunk-25LXQJ4Z.js +0 -110
  86. package/dist/chunk-2DRXIRQW.js +0 -97
  87. package/dist/chunk-2ZNH5F6E.js +0 -1281
  88. package/dist/chunk-3G3SFYYI.js +0 -288
  89. package/dist/chunk-3RG5ZIWI.js +0 -10
  90. package/dist/chunk-3S6TI23B.js +0 -97
  91. package/dist/chunk-3VFIJYS4.js +0 -818
  92. package/dist/chunk-52QE3YI3.js +0 -1169
  93. package/dist/chunk-57RP3DIN.js +0 -1205
  94. package/dist/chunk-5HSZ4W2P.js +0 -62
  95. package/dist/chunk-645IPXW3.js +0 -290
  96. package/dist/chunk-7A7ELD4C.js +0 -1205
  97. package/dist/chunk-7FYY4GZM.js +0 -1205
  98. package/dist/chunk-7IUE7ODU.js +0 -254
  99. package/dist/chunk-7RMLKZIS.js +0 -108
  100. package/dist/chunk-AA3OPP4Z.js +0 -432
  101. package/dist/chunk-AEWLSYPH.js +0 -72
  102. package/dist/chunk-ASSZDR6I.js +0 -108
  103. package/dist/chunk-AYRJVWUC.js +0 -1205
  104. package/dist/chunk-CCYI5O3D.js +0 -148
  105. package/dist/chunk-D3I3ZSE2.js +0 -411
  106. package/dist/chunk-DACSKLY6.js +0 -219
  107. package/dist/chunk-DW5B4BL7.js +0 -108
  108. package/dist/chunk-EKSACBTJ.js +0 -1070
  109. package/dist/chunk-EXEZZADG.js +0 -248
  110. package/dist/chunk-F3Y7EL7K.js +0 -83
  111. package/dist/chunk-FBQWSDPC.js +0 -1328
  112. package/dist/chunk-FHRZNOMW.js +0 -1205
  113. package/dist/chunk-IM7N24MT.js +0 -129
  114. package/dist/chunk-IPNYIXFK.js +0 -1178
  115. package/dist/chunk-J7MRSZIO.js +0 -167
  116. package/dist/chunk-JITKI2OI.js +0 -106
  117. package/dist/chunk-JWZXYVET.js +0 -1068
  118. package/dist/chunk-KCQUXVYT.js +0 -108
  119. package/dist/chunk-KOQ43OX6.js +0 -1281
  120. package/dist/chunk-KYVWO6ZM.js +0 -1069
  121. package/dist/chunk-L3VHARQH.js +0 -413
  122. package/dist/chunk-LBWDS6BE.js +0 -288
  123. package/dist/chunk-LOVAHSQV.js +0 -411
  124. package/dist/chunk-LQOYCAGG.js +0 -446
  125. package/dist/chunk-LWAIPJ2W.js +0 -146
  126. package/dist/chunk-M5DHKW7M.js +0 -127
  127. package/dist/chunk-MBKCIJHM.js +0 -1328
  128. package/dist/chunk-MK42FMEG.js +0 -147
  129. package/dist/chunk-MOBMYHKL.js +0 -1205
  130. package/dist/chunk-MPLTNMRG.js +0 -67
  131. package/dist/chunk-NIJCVN3O.js +0 -147
  132. package/dist/chunk-NZCFSZQ7.js +0 -1205
  133. package/dist/chunk-O2UITJGH.js +0 -465
  134. package/dist/chunk-OCRA44AZ.js +0 -108
  135. package/dist/chunk-P3KJR66H.js +0 -117
  136. package/dist/chunk-PEK6JH65.js +0 -432
  137. package/dist/chunk-PJ6FFKEX.js +0 -77
  138. package/dist/chunk-PLUBBZYR.js +0 -800
  139. package/dist/chunk-PNKVD2UK.js +0 -26
  140. package/dist/chunk-PSQZURHO.js +0 -229
  141. package/dist/chunk-SGL6ISBJ.js +0 -1061
  142. package/dist/chunk-SJABZZT5.js +0 -97
  143. package/dist/chunk-TD3P3K32.js +0 -1199
  144. package/dist/chunk-TMDZJJKV.js +0 -288
  145. package/dist/chunk-UNHVZB5G.js +0 -411
  146. package/dist/chunk-VAFTWSTE.js +0 -1061
  147. package/dist/chunk-VNFXFQBB.js +0 -217
  148. package/dist/chunk-X3GVFKSJ.js +0 -1205
  149. package/dist/chunk-XZ3S56RQ.js +0 -1061
  150. package/dist/chunk-Y72C7F6O.js +0 -148
  151. package/dist/chunk-YLICP577.js +0 -1205
  152. package/dist/chunk-YX6AXLVK.js +0 -159
  153. package/dist/chunk-ZCQYHTNU.js +0 -146
  154. package/dist/cli.d.ts +0 -1
  155. package/dist/cli.js +0 -1105
  156. package/dist/cloud-crystal.js +0 -6
  157. package/dist/core.d.ts +0 -232
  158. package/dist/core.js +0 -12
  159. package/dist/crypto.d.ts +0 -20
  160. package/dist/crypto.js +0 -27
  161. package/dist/crystal-capture.sh +0 -29
  162. package/dist/crystal-serve.d.ts +0 -4
  163. package/dist/crystal-serve.js +0 -252
  164. package/dist/dev-update-SZ2Z4WCQ.js +0 -6
  165. package/dist/discover.d.ts +0 -30
  166. package/dist/discover.js +0 -177
  167. package/dist/doctor.d.ts +0 -9
  168. package/dist/doctor.js +0 -334
  169. package/dist/dream-weaver.d.ts +0 -8
  170. package/dist/dream-weaver.js +0 -56
  171. package/dist/file-sync.d.ts +0 -48
  172. package/dist/file-sync.js +0 -18
  173. package/dist/installer.d.ts +0 -61
  174. package/dist/installer.js +0 -676
  175. package/dist/ldm-backup.sh +0 -116
  176. package/dist/ldm.d.ts +0 -50
  177. package/dist/ldm.js +0 -32
  178. package/dist/mcp-server.d.ts +0 -1
  179. package/dist/mcp-server.js +0 -265
  180. package/dist/migrate.d.ts +0 -1
  181. package/dist/migrate.js +0 -89
  182. package/dist/mirror-sync.d.ts +0 -1
  183. package/dist/mirror-sync.js +0 -159
  184. package/dist/oc-backfill.d.ts +0 -19
  185. package/dist/oc-backfill.js +0 -74
  186. package/dist/openclaw.d.ts +0 -5
  187. package/dist/openclaw.js +0 -423
  188. package/dist/pair.d.ts +0 -4
  189. package/dist/pair.js +0 -75
  190. package/dist/poller.d.ts +0 -1
  191. package/dist/poller.js +0 -634
  192. package/dist/role.d.ts +0 -24
  193. package/dist/role.js +0 -13
  194. package/dist/search-pipeline-4K4OJSSS.js +0 -255
  195. package/dist/search-pipeline-4PRS6LI7.js +0 -280
  196. package/dist/search-pipeline-7UJMXPLO.js +0 -280
  197. package/dist/search-pipeline-DQTRLGBH.js +0 -74
  198. package/dist/search-pipeline-HNG37REH.js +0 -282
  199. package/dist/search-pipeline-IZFPLBUB.js +0 -280
  200. package/dist/search-pipeline-MID6F26Q.js +0 -73
  201. package/dist/search-pipeline-N52JZFNN.js +0 -282
  202. package/dist/search-pipeline-OPB2PRQQ.js +0 -280
  203. package/dist/search-pipeline-VXTE5HAD.js +0 -262
  204. package/dist/search-pipeline-XHFKADRG.js +0 -73
  205. package/dist/staging.d.ts +0 -29
  206. package/dist/staging.js +0 -21
  207. package/dist/summarize.d.ts +0 -19
  208. package/dist/summarize.js +0 -10
  209. package/dist/worker-demo.js +0 -186
  210. package/dist/worker-mcp.js +0 -404
  211. 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
- };