@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
package/dist/cc-hook.js DELETED
@@ -1,368 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- createCrystal,
4
- resolveConfig
5
- } from "./chunk-FBQWSDPC.js";
6
- import {
7
- encryptJSON,
8
- loadRelayKey
9
- } from "./chunk-KCQUXVYT.js";
10
- import {
11
- ensureLdm,
12
- getAgentId,
13
- ldmPaths,
14
- resolveStatePath,
15
- stateWritePath
16
- } from "./chunk-EXEZZADG.js";
17
-
18
- // src/cc-hook.ts
19
- import {
20
- readFileSync,
21
- writeFileSync,
22
- appendFileSync,
23
- existsSync,
24
- mkdirSync,
25
- statSync,
26
- openSync,
27
- readSync,
28
- closeSync,
29
- copyFileSync
30
- } from "fs";
31
- import { join, basename } from "path";
32
- var CC_AGENT_ID = getAgentId("claude-code");
33
- var RELAY_URL = process.env.CRYSTAL_RELAY_URL || "";
34
- var RELAY_TOKEN = process.env.CRYSTAL_RELAY_TOKEN || "";
35
- var PRIVATE_MODE_PATH = resolveStatePath("memory-capture-state.json");
36
- var WATERMARK_PATH = resolveStatePath("cc-capture-watermark.json");
37
- var CC_ENABLED_PATH = resolveStatePath("cc-capture-enabled.json");
38
- function getCaptureMode() {
39
- if (RELAY_URL && RELAY_TOKEN) return "relay";
40
- return "local";
41
- }
42
- function isPrivateMode() {
43
- try {
44
- if (existsSync(PRIVATE_MODE_PATH)) {
45
- const state = JSON.parse(readFileSync(PRIVATE_MODE_PATH, "utf-8"));
46
- return state.enabled === false;
47
- }
48
- } catch {
49
- }
50
- return false;
51
- }
52
- function isCaptureEnabled() {
53
- try {
54
- if (existsSync(CC_ENABLED_PATH)) {
55
- const state = JSON.parse(readFileSync(CC_ENABLED_PATH, "utf-8"));
56
- return state.enabled !== false;
57
- }
58
- } catch {
59
- }
60
- return true;
61
- }
62
- function setCaptureEnabled(enabled) {
63
- const writePath = stateWritePath("cc-capture-enabled.json");
64
- writeFileSync(writePath, JSON.stringify({
65
- enabled,
66
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
67
- }, null, 2));
68
- }
69
- function loadWatermark() {
70
- try {
71
- if (existsSync(WATERMARK_PATH)) {
72
- return JSON.parse(readFileSync(WATERMARK_PATH, "utf-8"));
73
- }
74
- } catch {
75
- }
76
- return { files: {}, lastRun: null };
77
- }
78
- function saveWatermark(wm) {
79
- const writePath = stateWritePath("cc-capture-watermark.json");
80
- wm.lastRun = (/* @__PURE__ */ new Date()).toISOString();
81
- writeFileSync(writePath, JSON.stringify(wm, null, 2));
82
- }
83
- function extractMessages(filePath, lastByteOffset) {
84
- const fileSize = statSync(filePath).size;
85
- if (lastByteOffset >= fileSize) {
86
- return { messages: [], newByteOffset: fileSize };
87
- }
88
- const fd = openSync(filePath, "r");
89
- const bufSize = fileSize - lastByteOffset;
90
- const buf = Buffer.alloc(bufSize);
91
- readSync(fd, buf, 0, bufSize, lastByteOffset);
92
- closeSync(fd);
93
- const lines = buf.toString("utf-8").split("\n").filter(Boolean);
94
- const messages = [];
95
- for (const line of lines) {
96
- try {
97
- const obj = JSON.parse(line);
98
- if (obj.type !== "user" && obj.type !== "assistant") continue;
99
- const msg = obj.message;
100
- if (!msg) continue;
101
- let text = "";
102
- if (typeof msg.content === "string") {
103
- text = msg.content;
104
- } else if (Array.isArray(msg.content)) {
105
- const parts = [];
106
- for (const block of msg.content) {
107
- if (block.type === "text" && block.text) parts.push(block.text);
108
- if (block.type === "thinking" && block.thinking) parts.push(`[thinking] ${block.thinking}`);
109
- }
110
- text = parts.join("\n\n");
111
- }
112
- if (text.length < 20) continue;
113
- messages.push({
114
- role: msg.role || obj.type,
115
- text,
116
- timestamp: obj.timestamp || (/* @__PURE__ */ new Date()).toISOString(),
117
- sessionId: obj.sessionId || "unknown"
118
- });
119
- } catch {
120
- }
121
- }
122
- return { messages, newByteOffset: fileSize };
123
- }
124
- function archiveTranscript(transcriptPath, agentId) {
125
- try {
126
- if (isPrivateMode()) return;
127
- const paths = ensureLdm(agentId);
128
- const dest = join(paths.transcripts, basename(transcriptPath));
129
- if (existsSync(dest)) {
130
- const srcMtime = statSync(transcriptPath).mtimeMs;
131
- const dstMtime = statSync(dest).mtimeMs;
132
- if (srcMtime <= dstMtime) return;
133
- }
134
- copyFileSync(transcriptPath, dest);
135
- } catch {
136
- }
137
- }
138
- function appendDailyLog(messages, agentId) {
139
- try {
140
- const paths = ldmPaths(agentId);
141
- if (!existsSync(paths.root)) return;
142
- if (!existsSync(paths.daily)) mkdirSync(paths.daily, { recursive: true });
143
- const now = /* @__PURE__ */ new Date();
144
- const dateStr = now.toISOString().slice(0, 10);
145
- const timeStr = now.toLocaleTimeString("en-US", {
146
- hour: "2-digit",
147
- minute: "2-digit",
148
- hour12: false,
149
- timeZone: "America/Los_Angeles"
150
- });
151
- const logPath = join(paths.daily, `${dateStr}.md`);
152
- const userMsg = messages.find((m) => m.role === "user");
153
- if (!userMsg) return;
154
- const snippet = userMsg.text.slice(0, 120).replace(/\n/g, " ").trim();
155
- const line = `- **${timeStr}** ${snippet}${userMsg.text.length > 120 ? "..." : ""}
156
- `;
157
- if (!existsSync(logPath)) {
158
- writeFileSync(logPath, `# ${dateStr} - CC Daily Log
159
-
160
- `);
161
- }
162
- appendFileSync(logPath, line);
163
- } catch {
164
- }
165
- }
166
- async function dropAtRelay(messages) {
167
- const relayKey = loadRelayKey();
168
- const payload = {
169
- agent_id: CC_AGENT_ID,
170
- dropped_at: (/* @__PURE__ */ new Date()).toISOString(),
171
- messages: messages.map((m) => ({
172
- text: m.text,
173
- role: m.role,
174
- timestamp: m.timestamp,
175
- sessionId: m.sessionId
176
- }))
177
- };
178
- const encrypted = encryptJSON(payload, relayKey);
179
- const body = JSON.stringify(encrypted);
180
- let retries = 0;
181
- while (retries < 4) {
182
- try {
183
- const resp = await fetch(`${RELAY_URL}/drop/conversations`, {
184
- method: "POST",
185
- headers: {
186
- "Authorization": `Bearer ${RELAY_TOKEN}`,
187
- "Content-Type": "application/octet-stream"
188
- },
189
- body
190
- });
191
- if (!resp.ok) {
192
- const err = await resp.text();
193
- throw new Error(`Relay drop failed: ${resp.status} ${err}`);
194
- }
195
- const result = await resp.json();
196
- return messages.length;
197
- } catch (err) {
198
- retries++;
199
- if (retries >= 4) throw err;
200
- const delay = Math.min(1e3 * 2 ** retries, 3e4);
201
- process.stderr.write(` [relay retry ${retries}] ${err.message}, waiting ${delay}ms
202
- `);
203
- await new Promise((r) => setTimeout(r, delay));
204
- }
205
- }
206
- return 0;
207
- }
208
- async function sendCommand(command) {
209
- if (!RELAY_URL || !RELAY_TOKEN) {
210
- throw new Error("Relay not configured. Set CRYSTAL_RELAY_URL and CRYSTAL_RELAY_TOKEN.");
211
- }
212
- const relayKey = loadRelayKey();
213
- const payload = {
214
- ...command,
215
- from_agent: CC_AGENT_ID,
216
- sent_at: (/* @__PURE__ */ new Date()).toISOString()
217
- };
218
- const encrypted = encryptJSON(payload, relayKey);
219
- const body = JSON.stringify(encrypted);
220
- const resp = await fetch(`${RELAY_URL}/drop/commands`, {
221
- method: "POST",
222
- headers: {
223
- "Authorization": `Bearer ${RELAY_TOKEN}`,
224
- "Content-Type": "application/octet-stream"
225
- },
226
- body
227
- });
228
- if (!resp.ok) {
229
- throw new Error(`Command relay failed: ${resp.status} ${await resp.text()}`);
230
- }
231
- }
232
- var BATCH_SIZE = 200;
233
- async function ingestLocal(messages) {
234
- const config = resolveConfig();
235
- const crystal = createCrystal(config);
236
- await crystal.init();
237
- const maxSingleChunkChars = 2e3 * 4;
238
- const chunks = [];
239
- for (const msg of messages) {
240
- if (msg.text.length <= maxSingleChunkChars) {
241
- chunks.push({
242
- text: msg.text,
243
- role: msg.role,
244
- source_type: "conversation",
245
- source_id: `cc:${msg.sessionId}`,
246
- agent_id: CC_AGENT_ID,
247
- token_count: Math.ceil(msg.text.length / 4),
248
- created_at: msg.timestamp
249
- });
250
- } else {
251
- for (const ct of crystal.chunkText(msg.text)) {
252
- chunks.push({
253
- text: ct,
254
- role: msg.role,
255
- source_type: "conversation",
256
- source_id: `cc:${msg.sessionId}`,
257
- agent_id: CC_AGENT_ID,
258
- token_count: Math.ceil(ct.length / 4),
259
- created_at: msg.timestamp
260
- });
261
- }
262
- }
263
- }
264
- let total = 0;
265
- for (let i = 0; i < chunks.length; i += BATCH_SIZE) {
266
- const batch = chunks.slice(i, i + BATCH_SIZE);
267
- let retries = 0;
268
- while (retries < 4) {
269
- try {
270
- total += await crystal.ingest(batch);
271
- break;
272
- } catch (err) {
273
- retries++;
274
- if (retries >= 4) throw err;
275
- const delay = Math.min(1e3 * 2 ** retries, 3e4);
276
- process.stderr.write(` [retry ${retries}] ${err.message}, waiting ${delay}ms
277
- `);
278
- await new Promise((r) => setTimeout(r, delay));
279
- }
280
- }
281
- }
282
- return total;
283
- }
284
- var args = process.argv.slice(2);
285
- if (args.includes("--on")) {
286
- setCaptureEnabled(true);
287
- console.log("(*) Claude Code memory capture ON");
288
- process.exit(0);
289
- }
290
- if (args.includes("--off")) {
291
- setCaptureEnabled(false);
292
- console.log("( ) Claude Code memory capture OFF");
293
- process.exit(0);
294
- }
295
- if (args.includes("--status")) {
296
- const mode = getCaptureMode();
297
- console.log(isCaptureEnabled() ? "(*) CC capture: ON" : "( ) CC capture: OFF");
298
- console.log(isPrivateMode() ? "( ) Private mode: ON (blocks all capture)" : "(*) Private mode: OFF");
299
- console.log(` Mode: ${mode}${mode === "relay" ? ` (${RELAY_URL})` : ""}`);
300
- console.log(` Agent ID: ${CC_AGENT_ID}`);
301
- process.exit(0);
302
- }
303
- async function main() {
304
- let input = "";
305
- for await (const chunk of process.stdin) {
306
- input += chunk;
307
- }
308
- let hookData;
309
- try {
310
- hookData = JSON.parse(input);
311
- } catch {
312
- process.exit(0);
313
- }
314
- const transcriptPath = hookData.transcript_path;
315
- if (!transcriptPath || !existsSync(transcriptPath)) process.exit(0);
316
- if (isPrivateMode() || !isCaptureEnabled()) process.exit(0);
317
- archiveTranscript(transcriptPath);
318
- const wm = loadWatermark();
319
- const fileKey = transcriptPath;
320
- if (!wm.files[fileKey]) {
321
- wm.files[fileKey] = { lastByteOffset: 0, lastTimestamp: (/* @__PURE__ */ new Date()).toISOString() };
322
- }
323
- const lastOffset = wm.files[fileKey].lastByteOffset || 0;
324
- const { messages, newByteOffset } = extractMessages(transcriptPath, lastOffset);
325
- if (messages.length === 0) {
326
- wm.files[fileKey] = { lastByteOffset: newByteOffset, lastTimestamp: (/* @__PURE__ */ new Date()).toISOString() };
327
- saveWatermark(wm);
328
- process.exit(0);
329
- }
330
- const totalTokens = messages.reduce((sum, m) => sum + Math.ceil(m.text.length / 4), 0);
331
- if (totalTokens < 100) {
332
- wm.files[fileKey] = { lastByteOffset: newByteOffset, lastTimestamp: (/* @__PURE__ */ new Date()).toISOString() };
333
- saveWatermark(wm);
334
- process.exit(0);
335
- }
336
- const mode = getCaptureMode();
337
- try {
338
- if (mode === "relay") {
339
- const count = await dropAtRelay(messages);
340
- process.stderr.write(`[cc-memory-capture] relayed ${count} messages (${totalTokens} tokens) from ${basename(transcriptPath)}
341
- `);
342
- } else {
343
- const count = await ingestLocal(messages);
344
- process.stderr.write(`[cc-memory-capture] ${count} chunks (${totalTokens} tokens) from ${basename(transcriptPath)}
345
- `);
346
- }
347
- wm.files[fileKey] = { lastByteOffset: newByteOffset, lastTimestamp: (/* @__PURE__ */ new Date()).toISOString() };
348
- saveWatermark(wm);
349
- appendDailyLog(messages);
350
- try {
351
- const { generateSessionSummary, writeSummaryFile } = await import("./summarize.js");
352
- const paths = ldmPaths();
353
- const summaryMsgs = messages.map((m) => ({ role: m.role, text: m.text, timestamp: m.timestamp, sessionId: m.sessionId }));
354
- const summary = await generateSessionSummary(summaryMsgs);
355
- const sessionId = messages[0]?.sessionId || "unknown";
356
- writeSummaryFile(paths.sessions, summary, CC_AGENT_ID, sessionId);
357
- } catch {
358
- }
359
- } catch (err) {
360
- process.stderr.write(`[cc-memory-capture] error: ${err.message}
361
- `);
362
- process.exit(1);
363
- }
364
- }
365
- main();
366
- export {
367
- sendCommand
368
- };
@@ -1 +0,0 @@
1
- #!/usr/bin/env node