@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
package/dist/pair.js DELETED
@@ -1,75 +0,0 @@
1
- import {
2
- RELAY_KEY_PATH,
3
- decodePairingString,
4
- encodePairingString,
5
- generateRelayKey,
6
- loadRelayKey
7
- } from "./chunk-KCQUXVYT.js";
8
- import "./chunk-EXEZZADG.js";
9
-
10
- // src/pair.ts
11
- import { existsSync, writeFileSync, mkdirSync, chmodSync } from "fs";
12
- import { dirname } from "path";
13
- import qrcode from "qrcode-terminal";
14
- function generateQR(text) {
15
- return new Promise((resolve) => {
16
- qrcode.generate(text, { small: true }, (code) => {
17
- resolve(code);
18
- });
19
- });
20
- }
21
- function saveKey(key) {
22
- const dir = dirname(RELAY_KEY_PATH);
23
- if (!existsSync(dir)) {
24
- mkdirSync(dir, { recursive: true });
25
- }
26
- writeFileSync(RELAY_KEY_PATH, key.toString("base64") + "\n", { mode: 384 });
27
- try {
28
- chmodSync(RELAY_KEY_PATH, 384);
29
- } catch {
30
- }
31
- }
32
- async function pairShow() {
33
- let key;
34
- try {
35
- key = loadRelayKey();
36
- console.log("Relay key found.\n");
37
- } catch {
38
- console.log("No relay key found. Generating one...");
39
- key = generateRelayKey();
40
- saveKey(key);
41
- console.log(`Key saved to ${RELAY_KEY_PATH}
42
- `);
43
- }
44
- const pairingString = encodePairingString(key);
45
- console.log("Scan this QR code from your other device:\n");
46
- const qr = await generateQR(pairingString);
47
- console.log(qr);
48
- console.log("Or copy this pairing code:\n");
49
- console.log(` ${pairingString}
50
- `);
51
- console.log("On the other device, run:");
52
- console.log(` crystal pair --code ${pairingString}
53
- `);
54
- }
55
- function pairReceive(code) {
56
- const key = decodePairingString(code);
57
- if (existsSync(RELAY_KEY_PATH)) {
58
- try {
59
- const existing = loadRelayKey();
60
- if (existing.equals(key)) {
61
- console.log("This device already has the same key. Nothing to do.");
62
- return;
63
- }
64
- console.log("Replacing existing relay key with new key from pairing code.");
65
- } catch {
66
- }
67
- }
68
- saveKey(key);
69
- console.log(`Key received and saved to ${RELAY_KEY_PATH}`);
70
- console.log("Relay encryption is now active on this device.");
71
- }
72
- export {
73
- pairReceive,
74
- pairShow
75
- };
package/dist/poller.d.ts DELETED
@@ -1 +0,0 @@
1
- #!/usr/bin/env node
package/dist/poller.js DELETED
@@ -1,634 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- ensureStaging,
4
- isNewAgent,
5
- markReady
6
- } from "./chunk-ZCQYHTNU.js";
7
- import {
8
- generateSessionSummary,
9
- writeSummaryFile
10
- } from "./chunk-Y72C7F6O.js";
11
- import {
12
- pushFileSync
13
- } from "./chunk-3G3SFYYI.js";
14
- import {
15
- Crystal,
16
- resolveConfig
17
- } from "./chunk-FBQWSDPC.js";
18
- import {
19
- decryptJSON,
20
- encryptJSON,
21
- loadRelayKey
22
- } from "./chunk-KCQUXVYT.js";
23
- import {
24
- ensureLdm,
25
- resolveStatePath,
26
- stateWritePath
27
- } from "./chunk-EXEZZADG.js";
28
-
29
- // src/poller.ts
30
- import { readFileSync, writeFileSync, appendFileSync, existsSync, mkdirSync } from "fs";
31
- import { join } from "path";
32
- import { createDecipheriv } from "crypto";
33
- var RELAY_URL = process.env.CRYSTAL_RELAY_URL || "";
34
- var RELAY_TOKEN = process.env.CRYSTAL_RELAY_TOKEN || "";
35
- var POLLER_STATE_PATH = resolveStatePath("relay-poller-state.json");
36
- function loadState() {
37
- try {
38
- if (existsSync(POLLER_STATE_PATH)) {
39
- const raw = JSON.parse(readFileSync(POLLER_STATE_PATH, "utf-8"));
40
- return {
41
- lastPoll: raw.lastPoll ?? null,
42
- totalIngested: raw.totalIngested ?? 0,
43
- totalChatgptIngested: raw.totalChatgptIngested ?? 0,
44
- totalAttachments: raw.totalAttachments ?? 0,
45
- lastMirrorPush: raw.lastMirrorPush ?? null,
46
- lastDeltaChunkId: raw.lastDeltaChunkId ?? 0
47
- };
48
- }
49
- } catch {
50
- }
51
- return { lastPoll: null, totalIngested: 0, totalChatgptIngested: 0, totalAttachments: 0, lastMirrorPush: null, lastDeltaChunkId: 0 };
52
- }
53
- function saveState(state) {
54
- const writePath = stateWritePath("relay-poller-state.json");
55
- writeFileSync(writePath, JSON.stringify(state, null, 2));
56
- }
57
- async function pollConversations(crystal, relayKey) {
58
- let ingested = 0;
59
- let errors = 0;
60
- const listResp = await fetch(`${RELAY_URL}/pickup/conversations`, {
61
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
62
- });
63
- if (!listResp.ok) {
64
- throw new Error(`Relay list failed: ${listResp.status} ${await listResp.text()}`);
65
- }
66
- const listData = await listResp.json();
67
- if (listData.count === 0) return { ingested: 0, errors: 0 };
68
- process.stderr.write(`[relay-poller] conversations: ${listData.count} blob(s) waiting
69
- `);
70
- for (const blob of listData.blobs) {
71
- try {
72
- const blobResp = await fetch(`${RELAY_URL}/pickup/conversations/${blob.id}`, {
73
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
74
- });
75
- if (!blobResp.ok) {
76
- process.stderr.write(`[relay-poller] failed to fetch blob ${blob.id}: ${blobResp.status}
77
- `);
78
- errors++;
79
- continue;
80
- }
81
- const encryptedText = await blobResp.text();
82
- const encrypted = JSON.parse(encryptedText);
83
- let drop;
84
- try {
85
- drop = decryptJSON(encrypted, relayKey);
86
- } catch (err) {
87
- process.stderr.write(`[relay-poller] blob ${blob.id} failed verification: ${err.message} ... DISCARDED
88
- `);
89
- await fetch(`${RELAY_URL}/confirm/conversations/${blob.id}`, {
90
- method: "DELETE",
91
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
92
- });
93
- errors++;
94
- continue;
95
- }
96
- if (isNewAgent(drop.agent_id)) {
97
- process.stderr.write(`[relay-poller] new agent "${drop.agent_id}" detected, routing to staging
98
- `);
99
- const staging = ensureStaging(drop.agent_id);
100
- const jsonlPath = join(staging.transcripts, `relay-${blob.id}.jsonl`);
101
- const jsonlLines = drop.messages.map((m) => JSON.stringify(m)).join("\n") + "\n";
102
- writeFileSync(jsonlPath, jsonlLines);
103
- markReady(drop.agent_id);
104
- await fetch(`${RELAY_URL}/confirm/conversations/${blob.id}`, {
105
- method: "DELETE",
106
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
107
- });
108
- process.stderr.write(`[relay-poller] staged ${drop.messages.length} messages for ${drop.agent_id}
109
- `);
110
- continue;
111
- }
112
- const maxSingleChunkChars = 2e3 * 4;
113
- const chunks = [];
114
- for (const msg of drop.messages) {
115
- if (msg.text.length <= maxSingleChunkChars) {
116
- chunks.push({
117
- text: msg.text,
118
- role: msg.role,
119
- source_type: "conversation",
120
- source_id: `cc:${msg.sessionId}`,
121
- agent_id: drop.agent_id,
122
- token_count: Math.ceil(msg.text.length / 4),
123
- created_at: msg.timestamp
124
- });
125
- } else {
126
- for (const ct of crystal.chunkText(msg.text)) {
127
- chunks.push({
128
- text: ct,
129
- role: msg.role,
130
- source_type: "conversation",
131
- source_id: `cc:${msg.sessionId}`,
132
- agent_id: drop.agent_id,
133
- token_count: Math.ceil(ct.length / 4),
134
- created_at: msg.timestamp
135
- });
136
- }
137
- }
138
- }
139
- const count = await crystal.ingest(chunks);
140
- ingested += count;
141
- await fetch(`${RELAY_URL}/confirm/conversations/${blob.id}`, {
142
- method: "DELETE",
143
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
144
- });
145
- process.stderr.write(`[relay-poller] blob ${blob.id}: ${count} chunks ingested from ${drop.agent_id}
146
- `);
147
- try {
148
- const remotePaths = ensureLdm(drop.agent_id);
149
- const jsonlPath = join(remotePaths.transcripts, `relay-${blob.id}.jsonl`);
150
- const jsonlLines = drop.messages.map((m) => JSON.stringify(m)).join("\n") + "\n";
151
- writeFileSync(jsonlPath, jsonlLines);
152
- const summaryMsgs = drop.messages.map((m) => ({
153
- role: m.role,
154
- text: m.text,
155
- timestamp: m.timestamp,
156
- sessionId: m.sessionId
157
- }));
158
- const summary = await generateSessionSummary(summaryMsgs);
159
- const sessionId = drop.messages[0]?.sessionId || "unknown";
160
- writeSummaryFile(remotePaths.sessions, summary, drop.agent_id, sessionId);
161
- appendDailyBreadcrumb(drop.agent_id, drop.messages.find((m) => m.role === "user")?.text || "");
162
- } catch (fileErr) {
163
- process.stderr.write(`[relay-poller] file tree write failed (non-fatal): ${fileErr.message}
164
- `);
165
- }
166
- } catch (err) {
167
- process.stderr.write(`[relay-poller] error processing blob ${blob.id}: ${err.message}
168
- `);
169
- errors++;
170
- }
171
- }
172
- try {
173
- await pollCommands();
174
- } catch (err) {
175
- process.stderr.write(`[relay-poller] commands poll failed (non-fatal): ${err.message}
176
- `);
177
- }
178
- return { ingested, errors };
179
- }
180
- async function pollChatgpt(crystal, relayKey) {
181
- let ingested = 0;
182
- let attachments = 0;
183
- let errors = 0;
184
- const listResp = await fetch(`${RELAY_URL}/pickup/chatgpt`, {
185
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
186
- });
187
- if (!listResp.ok) {
188
- process.stderr.write(`[relay-poller] chatgpt list failed: ${listResp.status}
189
- `);
190
- return { ingested: 0, attachments: 0, errors: 1 };
191
- }
192
- const listData = await listResp.json();
193
- if (listData.count > 0) {
194
- process.stderr.write(`[relay-poller] chatgpt: ${listData.count} drop(s) waiting
195
- `);
196
- }
197
- for (const blob of listData.blobs) {
198
- try {
199
- const blobResp = await fetch(`${RELAY_URL}/pickup/chatgpt/${blob.id}`, {
200
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
201
- });
202
- if (!blobResp.ok) {
203
- process.stderr.write(`[relay-poller] chatgpt: failed to fetch ${blob.id}: ${blobResp.status}
204
- `);
205
- errors++;
206
- continue;
207
- }
208
- const encryptedText = await blobResp.text();
209
- const encrypted = JSON.parse(encryptedText);
210
- let drop;
211
- try {
212
- drop = decryptJSON(encrypted, relayKey);
213
- } catch (err) {
214
- process.stderr.write(`[relay-poller] chatgpt: ${blob.id} failed verification: ${err.message} ... DISCARDED
215
- `);
216
- await confirmBlob("chatgpt", blob.id);
217
- errors++;
218
- continue;
219
- }
220
- switch (drop.type) {
221
- case "conversation": {
222
- const data = drop.data;
223
- const result = await ingestConversationDrop(crystal, drop, data);
224
- ingested += result;
225
- break;
226
- }
227
- case "remember": {
228
- const data = drop.data;
229
- await crystal.remember(data.text, data.category);
230
- ingested++;
231
- process.stderr.write(`[relay-poller] chatgpt: remembered "${data.text.slice(0, 60)}..." (${data.category}) from ${drop.agent_id}
232
- `);
233
- break;
234
- }
235
- case "forget": {
236
- const data = drop.data;
237
- const ok = crystal.forget(data.memory_id);
238
- process.stderr.write(`[relay-poller] chatgpt: forget memory #${data.memory_id} from ${drop.agent_id}: ${ok ? "done" : "not found"}
239
- `);
240
- break;
241
- }
242
- case "attachment": {
243
- const data = drop.data;
244
- const result = await fetchAndSaveAttachment(data, drop.agent_id, relayKey);
245
- if (result) attachments++;
246
- break;
247
- }
248
- default:
249
- process.stderr.write(`[relay-poller] chatgpt: unknown drop type "${drop.type}" ... skipping
250
- `);
251
- }
252
- await confirmBlob("chatgpt", blob.id);
253
- } catch (err) {
254
- process.stderr.write(`[relay-poller] chatgpt: error processing ${blob.id}: ${err.message}
255
- `);
256
- errors++;
257
- }
258
- }
259
- const attResp = await fetch(`${RELAY_URL}/pickup/chatgpt-attachments`, {
260
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
261
- });
262
- if (attResp.ok) {
263
- const attData = await attResp.json();
264
- if (attData.count > 0) {
265
- process.stderr.write(`[relay-poller] chatgpt-attachments: ${attData.count} blob(s) (cleaned up after metadata processing)
266
- `);
267
- }
268
- }
269
- return { ingested, attachments, errors };
270
- }
271
- async function ingestConversationDrop(crystal, drop, data) {
272
- const maxSingleChunkChars = 2e3 * 4;
273
- const chunks = [];
274
- const sessionTag = data.session_id ? `cloud:${data.session_id}` : `cloud:${drop.timestamp.slice(0, 10)}`;
275
- const text = data.content;
276
- if (text.length <= maxSingleChunkChars) {
277
- chunks.push({
278
- text,
279
- role: data.role,
280
- source_type: "conversation",
281
- source_id: sessionTag,
282
- agent_id: drop.agent_id,
283
- token_count: Math.ceil(text.length / 4),
284
- created_at: drop.timestamp
285
- });
286
- } else {
287
- for (const ct of crystal.chunkText(text)) {
288
- chunks.push({
289
- text: ct,
290
- role: data.role,
291
- source_type: "conversation",
292
- source_id: sessionTag,
293
- agent_id: drop.agent_id,
294
- token_count: Math.ceil(ct.length / 4),
295
- created_at: drop.timestamp
296
- });
297
- }
298
- }
299
- if (data.tool_calls?.length) {
300
- for (const tc of data.tool_calls) {
301
- const toolText = `[Tool: ${tc.tool_name}] Args: ${tc.arguments}${tc.result ? `
302
- Result: ${tc.result}` : ""}`;
303
- chunks.push({
304
- text: toolText,
305
- role: "assistant",
306
- source_type: "tool_call",
307
- source_id: sessionTag,
308
- agent_id: drop.agent_id,
309
- token_count: Math.ceil(toolText.length / 4),
310
- created_at: drop.timestamp
311
- });
312
- }
313
- }
314
- const count = await crystal.ingest(chunks);
315
- try {
316
- const remotePaths = ensureLdm(drop.agent_id);
317
- const jsonlPath = join(remotePaths.transcripts, `cloud-${drop.timestamp.replace(/[:.]/g, "-")}.jsonl`);
318
- const line = JSON.stringify({
319
- type: "conversation",
320
- agent_id: drop.agent_id,
321
- timestamp: drop.timestamp,
322
- role: data.role,
323
- content: data.content,
324
- session_id: data.session_id,
325
- turn_index: data.turn_index,
326
- model: data.model,
327
- tool_calls: data.tool_calls,
328
- raw_json: data.raw_json
329
- });
330
- appendFileSync(jsonlPath, line + "\n");
331
- appendDailyBreadcrumb(drop.agent_id, data.role === "user" ? data.content : `[${data.model || "assistant"}] ${data.content.slice(0, 80)}`);
332
- } catch (fileErr) {
333
- process.stderr.write(`[relay-poller] chatgpt file tree write failed (non-fatal): ${fileErr.message}
334
- `);
335
- }
336
- if (count > 0) {
337
- process.stderr.write(`[relay-poller] chatgpt: ${count} chunk(s) from ${drop.agent_id} (${data.role}, turn ${data.turn_index ?? "?"})
338
- `);
339
- }
340
- return count;
341
- }
342
- async function fetchAndSaveAttachment(data, agentId, relayKey) {
343
- try {
344
- const blobId = data.r2_key.split("/").pop();
345
- if (!blobId) {
346
- process.stderr.write(`[relay-poller] chatgpt: invalid attachment r2_key: ${data.r2_key}
347
- `);
348
- return false;
349
- }
350
- const blobResp = await fetch(`${RELAY_URL}/pickup/chatgpt-attachments/${blobId}`, {
351
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
352
- });
353
- if (!blobResp.ok) {
354
- process.stderr.write(`[relay-poller] chatgpt: failed to fetch attachment ${blobId}: ${blobResp.status}
355
- `);
356
- return false;
357
- }
358
- const encryptedText = await blobResp.text();
359
- const encryptedPayload = JSON.parse(encryptedText);
360
- const nonce = Buffer.from(encryptedPayload.nonce, "base64");
361
- const encryptedData = Buffer.from(encryptedPayload.data, "base64");
362
- const ciphertext = encryptedData.subarray(0, encryptedData.length - 16);
363
- const tag = encryptedData.subarray(encryptedData.length - 16);
364
- const decipher = createDecipheriv("aes-256-gcm", relayKey, nonce);
365
- decipher.setAuthTag(tag);
366
- const decryptedBuf = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
367
- const remotePaths = ensureLdm(agentId);
368
- const attachmentsDir = join(remotePaths.agentRoot, "memory", "attachments");
369
- if (!existsSync(attachmentsDir)) mkdirSync(attachmentsDir, { recursive: true });
370
- const safeFilename = data.filename.replace(/[^a-zA-Z0-9._-]/g, "_");
371
- const filePath = join(attachmentsDir, `${blobId}-${safeFilename}`);
372
- writeFileSync(filePath, decryptedBuf);
373
- const metaPath = filePath + ".meta.json";
374
- writeFileSync(metaPath, JSON.stringify({
375
- filename: data.filename,
376
- mime_type: data.mime_type,
377
- size_bytes: data.size_bytes,
378
- source: data.source,
379
- surface: data.surface,
380
- context: data.context,
381
- session_id: data.session_id,
382
- agent_id: agentId,
383
- saved_at: (/* @__PURE__ */ new Date()).toISOString()
384
- }, null, 2));
385
- await confirmBlob("chatgpt-attachments", blobId);
386
- process.stderr.write(`[relay-poller] chatgpt: saved attachment ${data.filename} (${data.mime_type}, ${(data.size_bytes / 1024).toFixed(1)}KB) from ${agentId}
387
- `);
388
- return true;
389
- } catch (err) {
390
- process.stderr.write(`[relay-poller] chatgpt: attachment save failed: ${err.message}
391
- `);
392
- return false;
393
- }
394
- }
395
- async function confirmBlob(channel, id) {
396
- await fetch(`${RELAY_URL}/confirm/${channel}/${id}`, {
397
- method: "DELETE",
398
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
399
- });
400
- }
401
- function appendDailyBreadcrumb(agentId, text) {
402
- try {
403
- const remotePaths = ensureLdm(agentId);
404
- const now = /* @__PURE__ */ new Date();
405
- const dateStr = now.toISOString().slice(0, 10);
406
- const dailyPath = join(remotePaths.daily, `${dateStr}.md`);
407
- if (!existsSync(dailyPath)) {
408
- writeFileSync(dailyPath, `# ${dateStr} - ${agentId} Daily Log (via relay)
409
-
410
- `);
411
- }
412
- if (text) {
413
- const snippet = text.slice(0, 120).replace(/\n/g, " ").trim();
414
- appendFileSync(dailyPath, `- **${now.toISOString().slice(11, 16)}** [relay] ${snippet}
415
- `);
416
- }
417
- } catch {
418
- }
419
- }
420
- async function pollOnce() {
421
- if (!RELAY_URL || !RELAY_TOKEN) {
422
- throw new Error("CRYSTAL_RELAY_URL and CRYSTAL_RELAY_TOKEN must be set");
423
- }
424
- const relayKey = loadRelayKey();
425
- const config = resolveConfig();
426
- const crystal = new Crystal(config);
427
- await crystal.init();
428
- const conv = await pollConversations(crystal, relayKey);
429
- const chatgpt = await pollChatgpt(crystal, relayKey);
430
- return {
431
- ingested: conv.ingested + chatgpt.ingested,
432
- errors: conv.errors + chatgpt.errors,
433
- chatgptIngested: chatgpt.ingested,
434
- chatgptAttachments: chatgpt.attachments
435
- };
436
- }
437
- async function pollCommands() {
438
- const relayKey = loadRelayKey();
439
- const listResp = await fetch(`${RELAY_URL}/pickup/commands`, {
440
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
441
- });
442
- if (!listResp.ok) return;
443
- const listData = await listResp.json();
444
- if (listData.count === 0) return;
445
- process.stderr.write(`[relay-poller] ${listData.count} command(s) waiting
446
- `);
447
- for (const blob of listData.blobs) {
448
- try {
449
- const blobResp = await fetch(`${RELAY_URL}/pickup/commands/${blob.id}`, {
450
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
451
- });
452
- if (!blobResp.ok) continue;
453
- const encryptedText = await blobResp.text();
454
- const encrypted = JSON.parse(encryptedText);
455
- let cmd;
456
- try {
457
- cmd = decryptJSON(encrypted, relayKey);
458
- } catch {
459
- await fetch(`${RELAY_URL}/confirm/commands/${blob.id}`, {
460
- method: "DELETE",
461
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
462
- });
463
- continue;
464
- }
465
- const gatewayPort = process.env.CRYSTAL_SERVE_PORT || "18790";
466
- try {
467
- const resp = await fetch(`http://127.0.0.1:${gatewayPort}/process`, {
468
- method: "POST",
469
- headers: { "Content-Type": "application/json" },
470
- body: JSON.stringify({
471
- action: cmd.action || "dream-weave",
472
- agent_id: cmd.agent_id,
473
- mode: cmd.mode
474
- })
475
- });
476
- if (resp.ok) {
477
- process.stderr.write(`[relay-poller] delivered command: ${cmd.action} for ${cmd.agent_id}
478
- `);
479
- } else {
480
- process.stderr.write(`[relay-poller] gateway rejected command: ${resp.status}
481
- `);
482
- }
483
- } catch (err) {
484
- process.stderr.write(`[relay-poller] gateway not available (non-fatal): ${err.message}
485
- `);
486
- }
487
- await fetch(`${RELAY_URL}/confirm/commands/${blob.id}`, {
488
- method: "DELETE",
489
- headers: { "Authorization": `Bearer ${RELAY_TOKEN}` }
490
- });
491
- } catch (err) {
492
- process.stderr.write(`[relay-poller] command processing error: ${err.message}
493
- `);
494
- }
495
- }
496
- }
497
- async function pushDelta(force) {
498
- if (!RELAY_URL || !RELAY_TOKEN) {
499
- throw new Error("CRYSTAL_RELAY_URL and CRYSTAL_RELAY_TOKEN must be set");
500
- }
501
- const relayKey = loadRelayKey();
502
- const config = resolveConfig();
503
- const crystal = new Crystal(config);
504
- await crystal.init();
505
- const state = loadState();
506
- const sinceId = force ? 0 : state.lastDeltaChunkId || 0;
507
- const maxId = crystal.getMaxChunkId();
508
- if (maxId <= sinceId) {
509
- process.stderr.write(`[relay-poller] no new chunks since ID ${sinceId}
510
- `);
511
- return;
512
- }
513
- const chunks = crystal.exportChunksSince(sinceId);
514
- if (chunks.length === 0) {
515
- process.stderr.write(`[relay-poller] no new chunks to push
516
- `);
517
- return;
518
- }
519
- const deltaPayload = {
520
- version: Crystal.DELTA_VERSION,
521
- sinceId,
522
- maxId,
523
- chunkCount: chunks.length,
524
- pushedAt: (/* @__PURE__ */ new Date()).toISOString(),
525
- chunks
526
- };
527
- const encrypted = encryptJSON(deltaPayload, relayKey);
528
- const resp = await fetch(`${RELAY_URL}/drop/mirror`, {
529
- method: "POST",
530
- headers: {
531
- "Authorization": `Bearer ${RELAY_TOKEN}`,
532
- "Content-Type": "application/octet-stream"
533
- },
534
- body: JSON.stringify(encrypted)
535
- });
536
- if (!resp.ok) {
537
- throw new Error(`Delta push failed: ${resp.status} ${await resp.text()}`);
538
- }
539
- state.lastDeltaChunkId = maxId;
540
- state.lastMirrorPush = (/* @__PURE__ */ new Date()).toISOString();
541
- saveState(state);
542
- const payloadSize = JSON.stringify(encrypted).length;
543
- process.stderr.write(
544
- `[relay-poller] delta pushed: ${chunks.length} chunks (ID ${sinceId + 1}..${maxId}), ${(payloadSize / 1024).toFixed(1)}KB
545
- `
546
- );
547
- }
548
- var args = process.argv.slice(2);
549
- if (args.includes("--status")) {
550
- const state = loadState();
551
- const mode = RELAY_URL && RELAY_TOKEN ? "configured" : "not configured";
552
- console.log(`Relay poller status:`);
553
- console.log(` Relay URL: ${RELAY_URL || "(not set)"}`);
554
- console.log(` Mode: ${mode}`);
555
- console.log(` Last poll: ${state.lastPoll || "never"}`);
556
- console.log(` Total ingested: ${state.totalIngested} (conversations)`);
557
- console.log(` ChatGPT ingested: ${state.totalChatgptIngested} (cloud MCP)`);
558
- console.log(` Attachments saved: ${state.totalAttachments}`);
559
- console.log(` Last delta: ${state.lastMirrorPush || "never"}`);
560
- console.log(` Delta watermark: chunk ID ${state.lastDeltaChunkId || 0}`);
561
- process.exit(0);
562
- }
563
- if (args.includes("--push-mirror") || args.includes("--push-delta")) {
564
- const full = args.includes("--full");
565
- pushDelta(full).then(() => {
566
- process.exit(0);
567
- }).catch((err) => {
568
- process.stderr.write(`[relay-poller] mirror push error: ${err.message}
569
- `);
570
- process.exit(1);
571
- });
572
- } else if (args.includes("--watch")) {
573
- const POLL_INTERVAL = 2 * 60 * 1e3;
574
- async function loop() {
575
- process.stderr.write(`[relay-poller] watching (every ${POLL_INTERVAL / 1e3}s)...
576
- `);
577
- while (true) {
578
- try {
579
- const result = await pollOnce();
580
- const state = loadState();
581
- state.lastPoll = (/* @__PURE__ */ new Date()).toISOString();
582
- state.totalIngested += result.ingested;
583
- state.totalChatgptIngested += result.chatgptIngested;
584
- state.totalAttachments += result.chatgptAttachments;
585
- saveState(state);
586
- const totalNew = result.ingested + result.chatgptAttachments;
587
- if (totalNew > 0) {
588
- process.stderr.write(`[relay-poller] poll complete: ${result.ingested} ingested, ${result.chatgptAttachments} attachments, ${result.errors} errors
589
- `);
590
- try {
591
- await pushDelta();
592
- } catch (deltaErr) {
593
- process.stderr.write(`[relay-poller] delta push failed (non-fatal): ${deltaErr.message}
594
- `);
595
- }
596
- }
597
- try {
598
- const { manifest, files } = await pushFileSync();
599
- if (files > 0) {
600
- process.stderr.write(`[relay-poller] file sync pushed: ${files} files
601
- `);
602
- }
603
- } catch (fileSyncErr) {
604
- process.stderr.write(`[relay-poller] file sync failed (non-fatal): ${fileSyncErr.message}
605
- `);
606
- }
607
- } catch (err) {
608
- process.stderr.write(`[relay-poller] poll error: ${err.message}
609
- `);
610
- }
611
- await new Promise((r) => setTimeout(r, POLL_INTERVAL));
612
- }
613
- }
614
- loop();
615
- } else {
616
- pollOnce().then((result) => {
617
- const state = loadState();
618
- state.lastPoll = (/* @__PURE__ */ new Date()).toISOString();
619
- state.totalIngested += result.ingested;
620
- state.totalChatgptIngested += result.chatgptIngested;
621
- state.totalAttachments += result.chatgptAttachments;
622
- saveState(state);
623
- const totalNew = result.ingested + result.chatgptAttachments;
624
- if (totalNew > 0) {
625
- process.stderr.write(`[relay-poller] ${result.ingested} chunks ingested, ${result.chatgptAttachments} attachments, ${result.errors} errors
626
- `);
627
- }
628
- process.exit(result.errors > 0 ? 1 : 0);
629
- }).catch((err) => {
630
- process.stderr.write(`[relay-poller] error: ${err.message}
631
- `);
632
- process.exit(1);
633
- });
634
- }