@wipcomputer/memory-crystal 0.7.34-alpha.2 → 0.7.34-alpha.4

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 (120) hide show
  1. package/LICENSE +1 -1
  2. package/dist/bridge.js +64 -7
  3. package/dist/bulk-copy.js +67 -16
  4. package/dist/cc-hook.js +2163 -62
  5. package/dist/cc-poller.js +1967 -70
  6. package/dist/cli.js +4538 -139
  7. package/dist/core.js +1789 -6
  8. package/dist/crypto.js +153 -14
  9. package/dist/crystal-serve.js +64 -12
  10. package/dist/doctor.js +517 -52
  11. package/dist/dream-weaver.js +1755 -7
  12. package/dist/file-sync.js +407 -9
  13. package/dist/installer.js +840 -145
  14. package/dist/ldm.js +231 -16
  15. package/dist/mcp-server.js +1882 -17
  16. package/dist/migrate.js +1707 -11
  17. package/dist/mirror-sync.js +2052 -34
  18. package/dist/openclaw.js +1895 -84
  19. package/dist/pair.js +112 -16
  20. package/dist/poller.js +2275 -80
  21. package/dist/role.js +159 -7
  22. package/dist/staging.js +235 -10
  23. package/dist/summarize.js +142 -5
  24. package/package.json +7 -4
  25. package/dist/chunk-25LXQJ4Z.js +0 -110
  26. package/dist/chunk-2DRXIRQW.js +0 -97
  27. package/dist/chunk-2GBYLMEF.js +0 -1385
  28. package/dist/chunk-2ZNH5F6E.js +0 -1281
  29. package/dist/chunk-3G3SFYYI.js +0 -288
  30. package/dist/chunk-3RG5ZIWI.js +0 -10
  31. package/dist/chunk-3S6TI23B.js +0 -97
  32. package/dist/chunk-3VFIJYS4.js +0 -818
  33. package/dist/chunk-437F27T6.js +0 -97
  34. package/dist/chunk-52QE3YI3.js +0 -1169
  35. package/dist/chunk-57RP3DIN.js +0 -1205
  36. package/dist/chunk-5HSZ4W2P.js +0 -62
  37. package/dist/chunk-5I7GMRDN.js +0 -146
  38. package/dist/chunk-645IPXW3.js +0 -290
  39. package/dist/chunk-7A7ELD4C.js +0 -1205
  40. package/dist/chunk-7FYY4GZM.js +0 -1205
  41. package/dist/chunk-7IUE7ODU.js +0 -254
  42. package/dist/chunk-7RMLKZIS.js +0 -108
  43. package/dist/chunk-AA3OPP4Z.js +0 -432
  44. package/dist/chunk-AEWLSYPH.js +0 -72
  45. package/dist/chunk-ASSZDR6I.js +0 -108
  46. package/dist/chunk-AYRJVWUC.js +0 -1205
  47. package/dist/chunk-CCYI5O3D.js +0 -148
  48. package/dist/chunk-CGIDSAJB.js +0 -288
  49. package/dist/chunk-D3I3ZSE2.js +0 -411
  50. package/dist/chunk-D3MACYZ4.js +0 -108
  51. package/dist/chunk-DACSKLY6.js +0 -219
  52. package/dist/chunk-DFQ72B7M.js +0 -248
  53. package/dist/chunk-DW5B4BL7.js +0 -108
  54. package/dist/chunk-EKSACBTJ.js +0 -1070
  55. package/dist/chunk-EXEZZADG.js +0 -248
  56. package/dist/chunk-F3Y7EL7K.js +0 -83
  57. package/dist/chunk-FBQWSDPC.js +0 -1328
  58. package/dist/chunk-FHRZNOMW.js +0 -1205
  59. package/dist/chunk-IM7N24MT.js +0 -129
  60. package/dist/chunk-IPNYIXFK.js +0 -1178
  61. package/dist/chunk-J7MRSZIO.js +0 -167
  62. package/dist/chunk-JITKI2OI.js +0 -106
  63. package/dist/chunk-JWZXYVET.js +0 -1068
  64. package/dist/chunk-KCQUXVYT.js +0 -108
  65. package/dist/chunk-KOQ43OX6.js +0 -1281
  66. package/dist/chunk-KYVWO6ZM.js +0 -1069
  67. package/dist/chunk-L3VHARQH.js +0 -413
  68. package/dist/chunk-LBWDS6BE.js +0 -288
  69. package/dist/chunk-LOVAHSQV.js +0 -411
  70. package/dist/chunk-LQOYCAGG.js +0 -446
  71. package/dist/chunk-LWAIPJ2W.js +0 -146
  72. package/dist/chunk-M5DHKW7M.js +0 -127
  73. package/dist/chunk-MBKCIJHM.js +0 -1328
  74. package/dist/chunk-MK42FMEG.js +0 -147
  75. package/dist/chunk-MOBMYHKL.js +0 -1205
  76. package/dist/chunk-MPLTNMRG.js +0 -67
  77. package/dist/chunk-NIJCVN3O.js +0 -147
  78. package/dist/chunk-NX647OM3.js +0 -310
  79. package/dist/chunk-NZCFSZQ7.js +0 -1205
  80. package/dist/chunk-O2UITJGH.js +0 -465
  81. package/dist/chunk-OCRA44AZ.js +0 -108
  82. package/dist/chunk-P3KJR66H.js +0 -117
  83. package/dist/chunk-PEK6JH65.js +0 -432
  84. package/dist/chunk-PJ6FFKEX.js +0 -77
  85. package/dist/chunk-PLUBBZYR.js +0 -800
  86. package/dist/chunk-PNKVD2UK.js +0 -26
  87. package/dist/chunk-PSQZURHO.js +0 -229
  88. package/dist/chunk-SGL6ISBJ.js +0 -1061
  89. package/dist/chunk-SJABZZT5.js +0 -97
  90. package/dist/chunk-TD3P3K32.js +0 -1199
  91. package/dist/chunk-TMDZJJKV.js +0 -288
  92. package/dist/chunk-UNHVZB5G.js +0 -411
  93. package/dist/chunk-VAFTWSTE.js +0 -1061
  94. package/dist/chunk-VNFXFQBB.js +0 -217
  95. package/dist/chunk-X3GVFKSJ.js +0 -1205
  96. package/dist/chunk-XZ3S56RQ.js +0 -1061
  97. package/dist/chunk-Y72C7F6O.js +0 -148
  98. package/dist/chunk-YLICP577.js +0 -1205
  99. package/dist/chunk-YX6AXLVK.js +0 -159
  100. package/dist/chunk-ZCQYHTNU.js +0 -146
  101. package/dist/cloud-crystal.js +0 -6
  102. package/dist/dev-update-SZ2Z4WCQ.js +0 -6
  103. package/dist/llm-XXLYPIOF.js +0 -16
  104. package/dist/mlx-setup-XKU67WCT.js +0 -289
  105. package/dist/search-pipeline-4K4OJSSS.js +0 -255
  106. package/dist/search-pipeline-4PRS6LI7.js +0 -280
  107. package/dist/search-pipeline-7UJMXPLO.js +0 -280
  108. package/dist/search-pipeline-CBV25NX7.js +0 -99
  109. package/dist/search-pipeline-DQTRLGBH.js +0 -74
  110. package/dist/search-pipeline-HNG37REH.js +0 -282
  111. package/dist/search-pipeline-IZFPLBUB.js +0 -280
  112. package/dist/search-pipeline-MID6F26Q.js +0 -73
  113. package/dist/search-pipeline-N52JZFNN.js +0 -282
  114. package/dist/search-pipeline-OPB2PRQQ.js +0 -280
  115. package/dist/search-pipeline-VXTE5HAD.js +0 -262
  116. package/dist/search-pipeline-XHFKADRG.js +0 -73
  117. package/dist/worker-demo.js +0 -186
  118. package/dist/worker-mcp.js +0 -404
  119. package/scripts/crystal-capture 2.sh +0 -29
  120. package/scripts/deploy-cloud 2.sh +0 -153
@@ -1,404 +0,0 @@
1
- import {
2
- CloudCrystal
3
- } from "./chunk-J7MRSZIO.js";
4
-
5
- // src/worker-mcp.ts
6
- function json(data, status = 200, headers = {}) {
7
- return new Response(JSON.stringify(data), {
8
- status,
9
- headers: { "Content-Type": "application/json", ...headers }
10
- });
11
- }
12
- function cors(response) {
13
- const headers = new Headers(response.headers);
14
- headers.set("Access-Control-Allow-Origin", "*");
15
- headers.set("Access-Control-Allow-Methods", "GET, POST, DELETE, OPTIONS");
16
- headers.set("Access-Control-Allow-Headers", "Authorization, Content-Type");
17
- return new Response(response.body, { status: response.status, headers });
18
- }
19
- async function sha256(input) {
20
- const encoded = new TextEncoder().encode(input);
21
- const hash = await crypto.subtle.digest("SHA-256", encoded);
22
- return Array.from(new Uint8Array(hash)).map((b) => b.toString(16).padStart(2, "0")).join("");
23
- }
24
- async function sha256Base64url(input) {
25
- const encoded = new TextEncoder().encode(input);
26
- const hash = await crypto.subtle.digest("SHA-256", encoded);
27
- const bytes = new Uint8Array(hash);
28
- return btoa(String.fromCharCode.apply(null, Array.from(bytes))).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
29
- }
30
- function generateToken() {
31
- const bytes = new Uint8Array(32);
32
- crypto.getRandomValues(bytes);
33
- return Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
34
- }
35
- function handleProtectedResourceMetadata(url) {
36
- return json({
37
- resource: url.origin,
38
- authorization_servers: [url.origin],
39
- bearer_methods_supported: ["header"]
40
- });
41
- }
42
- function handleAuthServerMetadata(url) {
43
- return json({
44
- issuer: url.origin,
45
- authorization_endpoint: `${url.origin}/oauth/authorize`,
46
- token_endpoint: `${url.origin}/oauth/token`,
47
- registration_endpoint: `${url.origin}/oauth/register`,
48
- response_types_supported: ["code"],
49
- grant_types_supported: ["authorization_code"],
50
- code_challenge_methods_supported: ["S256"],
51
- token_endpoint_auth_methods_supported: ["none"],
52
- scopes_supported: ["memory"]
53
- });
54
- }
55
- async function handleRegister(request, env) {
56
- const body = await request.json();
57
- if (!body.redirect_uris?.length) {
58
- return json({ error: "redirect_uris required" }, 400);
59
- }
60
- const clientId = crypto.randomUUID();
61
- await env.DB.prepare(`
62
- INSERT INTO oauth_clients (client_id, redirect_uris, client_name)
63
- VALUES (?, ?, ?)
64
- `).bind(clientId, JSON.stringify(body.redirect_uris), body.client_name || "").run();
65
- return json({
66
- client_id: clientId,
67
- redirect_uris: body.redirect_uris,
68
- client_name: body.client_name || "",
69
- token_endpoint_auth_method: "none"
70
- }, 201);
71
- }
72
- async function handleAuthorize(request, url, env) {
73
- const clientId = url.searchParams.get("client_id");
74
- const redirectUri = url.searchParams.get("redirect_uri");
75
- const codeChallenge = url.searchParams.get("code_challenge");
76
- const codeChallengeMethod = url.searchParams.get("code_challenge_method") || "S256";
77
- const state = url.searchParams.get("state");
78
- const scope = url.searchParams.get("scope") || "memory";
79
- if (!clientId || !redirectUri || !codeChallenge) {
80
- return json({ error: "Missing required parameters (client_id, redirect_uri, code_challenge)" }, 400);
81
- }
82
- if (codeChallengeMethod !== "S256") {
83
- return json({ error: "Only S256 code_challenge_method supported" }, 400);
84
- }
85
- const client = await env.DB.prepare(
86
- "SELECT * FROM oauth_clients WHERE client_id = ?"
87
- ).bind(clientId).first();
88
- if (!client) {
89
- return json({ error: "Unknown client_id" }, 400);
90
- }
91
- const allowedUris = JSON.parse(client.redirect_uris);
92
- if (!allowedUris.includes(redirectUri)) {
93
- return json({ error: "redirect_uri not registered" }, 400);
94
- }
95
- if (request.method === "GET") {
96
- return new Response(consentPage(clientId, redirectUri, codeChallenge, codeChallengeMethod, state, scope), {
97
- headers: { "Content-Type": "text/html" }
98
- });
99
- }
100
- const formData = await request.formData();
101
- const email = formData.get("email");
102
- if (!email) {
103
- return json({ error: "Email required" }, 400);
104
- }
105
- const userId = await sha256(email.toLowerCase().trim());
106
- await env.DB.prepare(`
107
- INSERT INTO users (user_id, email) VALUES (?, ?)
108
- ON CONFLICT (user_id) DO NOTHING
109
- `).bind(userId, email.toLowerCase().trim()).run();
110
- const code = generateToken();
111
- const expiresAt = new Date(Date.now() + 10 * 60 * 1e3).toISOString();
112
- await env.DB.prepare(`
113
- INSERT INTO authorization_codes (code, client_id, user_id, code_challenge, code_challenge_method, redirect_uri, scope, expires_at)
114
- VALUES (?, ?, ?, ?, ?, ?, ?, ?)
115
- `).bind(code, clientId, userId, codeChallenge, codeChallengeMethod, redirectUri, scope, expiresAt).run();
116
- const redirect = new URL(redirectUri);
117
- redirect.searchParams.set("code", code);
118
- if (state) redirect.searchParams.set("state", state);
119
- return Response.redirect(redirect.toString(), 302);
120
- }
121
- async function handleToken(request, env) {
122
- const body = await request.formData();
123
- const grantType = body.get("grant_type");
124
- const code = body.get("code");
125
- const redirectUri = body.get("redirect_uri");
126
- const codeVerifier = body.get("code_verifier");
127
- if (grantType !== "authorization_code") {
128
- return json({ error: "unsupported_grant_type" }, 400);
129
- }
130
- if (!code || !codeVerifier) {
131
- return json({ error: "Missing code or code_verifier" }, 400);
132
- }
133
- const authCode = await env.DB.prepare(
134
- "SELECT * FROM authorization_codes WHERE code = ? AND used = 0"
135
- ).bind(code).first();
136
- if (!authCode) {
137
- return json({ error: "invalid_grant", error_description: "Code not found or already used" }, 400);
138
- }
139
- if (new Date(authCode.expires_at) < /* @__PURE__ */ new Date()) {
140
- return json({ error: "invalid_grant", error_description: "Code expired" }, 400);
141
- }
142
- if (redirectUri && authCode.redirect_uri !== redirectUri) {
143
- return json({ error: "invalid_grant", error_description: "redirect_uri mismatch" }, 400);
144
- }
145
- const expectedChallenge = await sha256Base64url(codeVerifier);
146
- if (expectedChallenge !== authCode.code_challenge) {
147
- return json({ error: "invalid_grant", error_description: "PKCE verification failed" }, 400);
148
- }
149
- await env.DB.prepare("UPDATE authorization_codes SET used = 1 WHERE code = ?").bind(code).run();
150
- const user = await env.DB.prepare("SELECT * FROM users WHERE user_id = ?").bind(authCode.user_id).first();
151
- const tier = user?.tier || "sovereign";
152
- const accessToken = generateToken();
153
- const tokenHash = await sha256(accessToken);
154
- const expiresAt = new Date(Date.now() + 90 * 24 * 60 * 60 * 1e3).toISOString();
155
- await env.DB.prepare(`
156
- INSERT INTO access_tokens (token_hash, client_id, user_id, scope, tier, expires_at)
157
- VALUES (?, ?, ?, ?, ?, ?)
158
- `).bind(tokenHash, authCode.client_id, authCode.user_id, authCode.scope, tier, expiresAt).run();
159
- return json({
160
- access_token: accessToken,
161
- token_type: "Bearer",
162
- expires_in: 90 * 24 * 60 * 60,
163
- scope: authCode.scope
164
- });
165
- }
166
- async function verifyToken(request, env) {
167
- const auth = request.headers.get("Authorization");
168
- if (!auth?.startsWith("Bearer ")) {
169
- return json({ error: "Missing Authorization header" }, 401);
170
- }
171
- const token = auth.slice(7);
172
- const tokenHash = await sha256(token);
173
- const row = await env.DB.prepare(
174
- "SELECT * FROM access_tokens WHERE token_hash = ?"
175
- ).bind(tokenHash).first();
176
- if (!row) {
177
- return json({ error: "Invalid token" }, 401);
178
- }
179
- if (new Date(row.expires_at) < /* @__PURE__ */ new Date()) {
180
- return json({ error: "Token expired" }, 401);
181
- }
182
- return {
183
- user_id: row.user_id,
184
- client_id: row.client_id,
185
- scope: row.scope,
186
- tier: row.tier
187
- };
188
- }
189
- function consentPage(clientId, redirectUri, codeChallenge, codeChallengeMethod, state, scope) {
190
- return `<!DOCTYPE html>
191
- <html>
192
- <head>
193
- <meta charset="utf-8">
194
- <meta name="viewport" content="width=device-width, initial-scale=1">
195
- <title>Memory Crystal</title>
196
- <style>
197
- body { font-family: -apple-system, system-ui, sans-serif; max-width: 420px; margin: 60px auto; padding: 0 20px; color: #1a1a1a; }
198
- h1 { font-size: 1.4em; }
199
- p { color: #555; line-height: 1.5; }
200
- form { margin-top: 24px; }
201
- label { display: block; font-weight: 500; margin-bottom: 6px; }
202
- input[type=email] { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 16px; box-sizing: border-box; }
203
- button { margin-top: 16px; width: 100%; padding: 12px; background: #1a1a1a; color: white; border: none; border-radius: 6px; font-size: 16px; cursor: pointer; }
204
- button:hover { background: #333; }
205
- .note { font-size: 0.85em; color: #888; margin-top: 16px; }
206
- </style>
207
- </head>
208
- <body>
209
- <h1>Memory Crystal</h1>
210
- <p>An app wants to access your memory. Enter your email to continue.</p>
211
- <form method="POST">
212
- <input type="hidden" name="client_id" value="${clientId}">
213
- <input type="hidden" name="redirect_uri" value="${redirectUri}">
214
- <input type="hidden" name="code_challenge" value="${codeChallenge}">
215
- <input type="hidden" name="code_challenge_method" value="${codeChallengeMethod}">
216
- ${state ? `<input type="hidden" name="state" value="${state}">` : ""}
217
- <input type="hidden" name="scope" value="${scope}">
218
- <label for="email">Email</label>
219
- <input type="email" id="email" name="email" required placeholder="you@example.com" autocomplete="email">
220
- <button type="submit">Connect Memory</button>
221
- </form>
222
- <p class="note">Your email identifies your memory account. No password needed... your AI client handles authentication.</p>
223
- </body>
224
- </html>`;
225
- }
226
- var TOOLS = [
227
- {
228
- name: "memory_search",
229
- description: "Search your memories across all conversations and surfaces.",
230
- inputSchema: {
231
- type: "object",
232
- properties: {
233
- query: { type: "string", description: "What to search for" },
234
- limit: { type: "number", description: "Max results (default 5, max 20)" }
235
- },
236
- required: ["query"]
237
- },
238
- annotations: { readOnlyHint: true, openWorldHint: false }
239
- },
240
- {
241
- name: "memory_remember",
242
- description: "Save a fact, preference, or observation to your memory.",
243
- inputSchema: {
244
- type: "object",
245
- properties: {
246
- text: { type: "string", description: "The fact or observation to remember" },
247
- category: {
248
- type: "string",
249
- enum: ["fact", "preference", "event", "opinion", "skill"],
250
- description: "Category of memory (default: fact)"
251
- }
252
- },
253
- required: ["text"]
254
- },
255
- annotations: { readOnlyHint: false, destructiveHint: false, openWorldHint: false }
256
- },
257
- {
258
- name: "memory_forget",
259
- description: "Deprecate a memory by ID.",
260
- inputSchema: {
261
- type: "object",
262
- properties: {
263
- id: { type: "number", description: "Memory ID to deprecate" }
264
- },
265
- required: ["id"]
266
- },
267
- annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true }
268
- },
269
- {
270
- name: "memory_status",
271
- description: "Show your memory status: chunk count, memory count, connected agents.",
272
- inputSchema: { type: "object", properties: {} },
273
- annotations: { readOnlyHint: true, openWorldHint: false }
274
- }
275
- ];
276
- async function handleMCP(request, env, tokenInfo) {
277
- const body = await request.json();
278
- const { method, id, params } = body;
279
- const crystal = new CloudCrystal(env.DB, env.VECTORIZE, env.OPENAI_API_KEY);
280
- let result;
281
- switch (method) {
282
- case "initialize":
283
- result = {
284
- protocolVersion: "2025-03-26",
285
- serverInfo: { name: "memory-crystal", version: "0.2.0" },
286
- capabilities: { tools: {} }
287
- };
288
- break;
289
- case "tools/list":
290
- result = { tools: TOOLS };
291
- break;
292
- case "tools/call": {
293
- const toolName = params?.name;
294
- const args = params?.arguments || {};
295
- switch (toolName) {
296
- case "memory_search": {
297
- if (tokenInfo.tier === "sovereign") {
298
- result = {
299
- content: [{
300
- type: "text",
301
- text: "Search is available on your local devices only (Sovereign tier). Your memories from this session have been saved and will be searchable from any device with Memory Crystal installed locally."
302
- }]
303
- };
304
- } else {
305
- const limit = Math.min(args.limit || 5, 20);
306
- const results = await crystal.search(tokenInfo.user_id, args.query, limit);
307
- const formatted = results.map(
308
- (r, i) => `[${i + 1}] (${r.score.toFixed(1)}% match, ${r.agent_id}, ${r.created_at})
309
- ${r.text}`
310
- ).join("\n\n");
311
- result = {
312
- content: [{
313
- type: "text",
314
- text: results.length > 0 ? formatted : `No results for "${args.query}".`
315
- }]
316
- };
317
- }
318
- break;
319
- }
320
- case "memory_remember": {
321
- if (tokenInfo.tier === "sovereign") {
322
- }
323
- const memId = await crystal.remember(tokenInfo.user_id, args.text, args.category || "fact");
324
- result = {
325
- content: [{
326
- type: "text",
327
- text: `Remembered (id: ${memId}, category: ${args.category || "fact"}): ${args.text}`
328
- }]
329
- };
330
- break;
331
- }
332
- case "memory_forget": {
333
- const ok = await crystal.forget(tokenInfo.user_id, args.id);
334
- result = {
335
- content: [{
336
- type: "text",
337
- text: ok ? `Memory ${args.id} deprecated.` : `Memory ${args.id} not found or already deprecated.`
338
- }]
339
- };
340
- break;
341
- }
342
- case "memory_status": {
343
- const status = await crystal.status(tokenInfo.user_id);
344
- result = {
345
- content: [{
346
- type: "text",
347
- text: [
348
- `Chunks: ${status.chunks}`,
349
- `Memories: ${status.memories}`,
350
- `Agents: ${status.agents.join(", ") || "none"}`,
351
- `Tier: ${status.tier}`
352
- ].join("\n")
353
- }]
354
- };
355
- break;
356
- }
357
- default:
358
- return json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown tool: ${toolName}` } });
359
- }
360
- break;
361
- }
362
- case "notifications/initialized":
363
- return new Response(null, { status: 204 });
364
- default:
365
- return json({ jsonrpc: "2.0", id, error: { code: -32601, message: `Unknown method: ${method}` } });
366
- }
367
- return json({ jsonrpc: "2.0", id, result });
368
- }
369
- var worker_mcp_default = {
370
- async fetch(request, env) {
371
- const url = new URL(request.url);
372
- const path = url.pathname;
373
- if (request.method === "OPTIONS") {
374
- return cors(new Response(null, { status: 204 }));
375
- }
376
- if (path === "/health" && request.method === "GET") {
377
- return cors(json({ ok: true, service: "memory-crystal-cloud", version: "0.2.0" }));
378
- }
379
- if (path === "/.well-known/oauth-protected-resource") {
380
- return cors(handleProtectedResourceMetadata(url));
381
- }
382
- if (path === "/.well-known/oauth-authorization-server") {
383
- return cors(handleAuthServerMetadata(url));
384
- }
385
- if (path === "/oauth/register" && request.method === "POST") {
386
- return cors(await handleRegister(request, env));
387
- }
388
- if (path === "/oauth/authorize") {
389
- return await handleAuthorize(request, url, env);
390
- }
391
- if (path === "/oauth/token" && request.method === "POST") {
392
- return cors(await handleToken(request, env));
393
- }
394
- if (path === "/mcp" && request.method === "POST") {
395
- const tokenResult = await verifyToken(request, env);
396
- if (tokenResult instanceof Response) return cors(tokenResult);
397
- return cors(await handleMCP(request, env, tokenResult));
398
- }
399
- return cors(json({ error: "Not found" }, 404));
400
- }
401
- };
402
- export {
403
- worker_mcp_default as default
404
- };
@@ -1,29 +0,0 @@
1
- #!/bin/bash
2
- # Job: crystal-capture
3
- # Continuous capture for Claude Code sessions.
4
- # Reads JSONL files on disk, ingests into Crystal, exports MD sessions, writes daily logs.
5
- # Primary capture path. Runs every minute via cron.
6
- # The Stop hook (cc-hook.ts) is a redundancy check only.
7
- #
8
- # Source of truth: memory-crystal-private/scripts/crystal-capture.sh
9
- # Deployed to: ~/.ldm/bin/crystal-capture.sh (via crystal init)
10
- # Cron entry: * * * * * ~/.ldm/bin/crystal-capture.sh >> /tmp/ldm-dev-tools/crystal-capture.log 2>&1
11
- #
12
- # The Node poller fetches the OpenAI API key internally via opRead() in core.ts.
13
- # opRead uses: op read "op://Agent Secrets/OpenAI API/api key" with the SA token from
14
- # ~/.openclaw/secrets/op-sa-token. Do NOT call op from this shell script... it triggers
15
- # macOS TCC popups when run from cron.
16
-
17
- # Cron provides minimal PATH. Ensure Homebrew binaries (node, op) are findable.
18
- export PATH="/opt/homebrew/bin:$PATH"
19
-
20
- POLLER="$HOME/.ldm/extensions/memory-crystal/dist/cc-poller.js"
21
- NODE="/opt/homebrew/bin/node"
22
-
23
- if [ ! -f "$POLLER" ]; then
24
- echo "ERROR: cc-poller not found at $POLLER"
25
- exit 1
26
- fi
27
-
28
- # Single run: scan all sessions, ingest new turns, export MD, exit.
29
- $NODE "$POLLER" 2>&1
@@ -1,153 +0,0 @@
1
- #!/usr/bin/env bash
2
- #
3
- # deploy-cloud.sh — Deploy Memory Crystal Cloud MCP server to Cloudflare.
4
- # Pulls all credentials from 1Password. No keys in env files.
5
- #
6
- # Usage:
7
- # bash scripts/deploy-cloud.sh # full setup (first time)
8
- # bash scripts/deploy-cloud.sh deploy # just redeploy Worker code
9
- #
10
- # Prerequisites:
11
- # - wrangler CLI installed (npm install -g wrangler)
12
- # - 1Password items populated:
13
- # "Parker - Cloudflare Memory Crystal Keys" (api-token, account-id)
14
- # "OpenAI API" (api key)
15
-
16
- set -euo pipefail
17
-
18
- REPO_DIR="$(cd "$(dirname "$0")/.." && pwd)"
19
- cd "$REPO_DIR"
20
-
21
- # ── Pull credentials from 1Password ──
22
-
23
- echo "Pulling credentials from 1Password..."
24
-
25
- OP_TOKEN=$(cat ~/.openclaw/secrets/op-sa-token)
26
-
27
- CF_API_TOKEN=$(OP_SERVICE_ACCOUNT_TOKEN="$OP_TOKEN" op item get "Parker - Cloudflare Memory Crystal Keys" \
28
- --vault="Agent Secrets" --fields label=api-token --reveal)
29
-
30
- CF_ACCOUNT_ID=$(OP_SERVICE_ACCOUNT_TOKEN="$OP_TOKEN" op item get "Parker - Cloudflare Memory Crystal Keys" \
31
- --vault="Agent Secrets" --fields label=account-id --reveal)
32
-
33
- OPENAI_API_KEY=$(OP_SERVICE_ACCOUNT_TOKEN="$OP_TOKEN" op item get "OpenAI API" \
34
- --vault="Agent Secrets" --fields label="api key" --reveal)
35
-
36
- if [[ "$CF_API_TOKEN" == "REPLACE_WITH_CLOUDFLARE_API_TOKEN" || "$CF_ACCOUNT_ID" == "REPLACE_WITH_CLOUDFLARE_ACCOUNT_ID" ]]; then
37
- echo "Error: Cloudflare credentials not yet filled in 1Password."
38
- echo "Update 'Parker - Cloudflare Memory Crystal Keys' in Agent Secrets vault."
39
- exit 1
40
- fi
41
-
42
- export CLOUDFLARE_API_TOKEN="$CF_API_TOKEN"
43
- export CLOUDFLARE_ACCOUNT_ID="$CF_ACCOUNT_ID"
44
-
45
- echo " Cloudflare Account ID: ${CF_ACCOUNT_ID:0:8}..."
46
- echo " Cloudflare API Token: ${CF_API_TOKEN:0:8}..."
47
- echo " OpenAI API Key: ${OPENAI_API_KEY:0:8}..."
48
-
49
- # ── Deploy only? ──
50
-
51
- if [[ "${1:-}" == "deploy" ]]; then
52
- echo ""
53
- echo "Building and deploying Worker..."
54
- npm run build:cloud
55
- npx wrangler deploy --config wrangler-mcp.toml
56
- echo "Done. Worker deployed."
57
- exit 0
58
- fi
59
-
60
- # ── Full setup (first time) ──
61
-
62
- echo ""
63
- echo "=== Step 1: Create D1 database ==="
64
-
65
- # Check if database already exists
66
- DB_ID=$(npx wrangler d1 list --json 2>/dev/null | python3 -c "
67
- import sys, json
68
- dbs = json.load(sys.stdin)
69
- for db in dbs:
70
- if db['name'] == 'memory-crystal-cloud':
71
- print(db['uuid'])
72
- break
73
- " 2>/dev/null || echo "")
74
-
75
- if [[ -z "$DB_ID" ]]; then
76
- echo "Creating D1 database: memory-crystal-cloud"
77
- DB_OUTPUT=$(npx wrangler d1 create memory-crystal-cloud 2>&1)
78
- DB_ID=$(echo "$DB_OUTPUT" | grep -oE '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}' | head -1)
79
- echo " Created: $DB_ID"
80
- else
81
- echo " Already exists: $DB_ID"
82
- fi
83
-
84
- if [[ -z "$DB_ID" ]]; then
85
- echo "Error: Could not get D1 database ID"
86
- exit 1
87
- fi
88
-
89
- # Update wrangler-mcp.toml with database ID
90
- if grep -q 'database_id = ""' wrangler-mcp.toml; then
91
- sed -i.bak "s/database_id = \"\"/database_id = \"$DB_ID\"/" wrangler-mcp.toml
92
- rm -f wrangler-mcp.toml.bak
93
- echo " Updated wrangler-mcp.toml with database_id"
94
- fi
95
-
96
- echo ""
97
- echo "=== Step 2: Create Vectorize index ==="
98
-
99
- VEC_EXISTS=$(npx wrangler vectorize list --json 2>/dev/null | python3 -c "
100
- import sys, json
101
- indexes = json.load(sys.stdin)
102
- for idx in indexes:
103
- if idx['name'] == 'memory-crystal-chunks':
104
- print('yes')
105
- break
106
- " 2>/dev/null || echo "")
107
-
108
- if [[ "$VEC_EXISTS" != "yes" ]]; then
109
- echo "Creating Vectorize index: memory-crystal-chunks (1024 dims, cosine)"
110
- npx wrangler vectorize create memory-crystal-chunks --dimensions 1024 --metric cosine
111
- echo " Created."
112
- else
113
- echo " Already exists."
114
- fi
115
-
116
- echo ""
117
- echo "=== Step 3: Run D1 migrations ==="
118
-
119
- npx wrangler d1 migrations apply memory-crystal-cloud --config wrangler-mcp.toml
120
- echo " Migrations applied."
121
-
122
- echo ""
123
- echo "=== Step 4: Set Worker secrets ==="
124
-
125
- echo "$OPENAI_API_KEY" | npx wrangler secret put OPENAI_API_KEY --config wrangler-mcp.toml
126
- echo " OPENAI_API_KEY set."
127
-
128
- # Generate signing key for OAuth tokens
129
- MCP_SIGNING_KEY=$(openssl rand -hex 32)
130
- echo "$MCP_SIGNING_KEY" | npx wrangler secret put MCP_SIGNING_KEY --config wrangler-mcp.toml
131
- echo " MCP_SIGNING_KEY set (generated)."
132
-
133
- # Generate relay encryption key (base64, 32 bytes)
134
- RELAY_KEY=$(openssl rand -base64 32)
135
- echo "$RELAY_KEY" | npx wrangler secret put RELAY_ENCRYPTION_KEY --config wrangler-mcp.toml
136
- echo " RELAY_ENCRYPTION_KEY set (generated)."
137
-
138
- echo ""
139
- echo "=== Step 5: Build and deploy ==="
140
-
141
- npm run build:cloud
142
- npx wrangler deploy --config wrangler-mcp.toml
143
-
144
- echo ""
145
- echo "=== Done ==="
146
- echo ""
147
- echo "Memory Crystal Cloud MCP server deployed."
148
- echo "Worker URL: https://memory-crystal-cloud.<your-subdomain>.workers.dev"
149
- echo ""
150
- echo "Next steps:"
151
- echo " 1. Test: curl https://memory-crystal-cloud.<subdomain>.workers.dev/health"
152
- echo " 2. Test OAuth: GET /.well-known/oauth-authorization-server"
153
- echo " 3. Connect from ChatGPT or Claude"