@wipcomputer/memory-crystal 0.7.32 → 0.7.34-alpha.1
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.
- package/SKILL.md +1 -1
- package/cloud/wrangler.toml +30 -0
- package/dist/bridge.d.ts +7 -0
- package/dist/bridge.js +14 -0
- package/dist/bulk-copy.d.ts +17 -0
- package/dist/bulk-copy.js +90 -0
- package/dist/cc-hook.d.ts +8 -0
- package/dist/cc-hook.js +368 -0
- package/dist/cc-poller.d.ts +1 -0
- package/dist/cc-poller.js +550 -0
- package/dist/chunk-25LXQJ4Z.js +110 -0
- package/dist/chunk-2DRXIRQW.js +97 -0
- package/dist/chunk-2GBYLMEF.js +1385 -0
- package/dist/chunk-2ZNH5F6E.js +1281 -0
- package/dist/chunk-3G3SFYYI.js +288 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3S6TI23B.js +97 -0
- package/dist/chunk-3VFIJYS4.js +818 -0
- package/dist/chunk-437F27T6.js +97 -0
- package/dist/chunk-52QE3YI3.js +1169 -0
- package/dist/chunk-57RP3DIN.js +1205 -0
- package/dist/chunk-5HSZ4W2P.js +62 -0
- package/dist/chunk-5I7GMRDN.js +146 -0
- package/dist/chunk-645IPXW3.js +290 -0
- package/dist/chunk-7A7ELD4C.js +1205 -0
- package/dist/chunk-7FYY4GZM.js +1205 -0
- package/dist/chunk-7IUE7ODU.js +254 -0
- package/dist/chunk-7RMLKZIS.js +108 -0
- package/dist/chunk-AA3OPP4Z.js +432 -0
- package/dist/chunk-AEWLSYPH.js +72 -0
- package/dist/chunk-ASSZDR6I.js +108 -0
- package/dist/chunk-AYRJVWUC.js +1205 -0
- package/dist/chunk-CCYI5O3D.js +148 -0
- package/dist/chunk-CGIDSAJB.js +288 -0
- package/dist/chunk-D3I3ZSE2.js +411 -0
- package/dist/chunk-D3MACYZ4.js +108 -0
- package/dist/chunk-DACSKLY6.js +219 -0
- package/dist/chunk-DFQ72B7M.js +248 -0
- package/dist/chunk-DW5B4BL7.js +108 -0
- package/dist/chunk-EKSACBTJ.js +1070 -0
- package/dist/chunk-EXEZZADG.js +248 -0
- package/dist/chunk-F3Y7EL7K.js +83 -0
- package/dist/chunk-FBQWSDPC.js +1328 -0
- package/dist/chunk-FHRZNOMW.js +1205 -0
- package/dist/chunk-IM7N24MT.js +129 -0
- package/dist/chunk-IPNYIXFK.js +1178 -0
- package/dist/chunk-J7MRSZIO.js +167 -0
- package/dist/chunk-JITKI2OI.js +106 -0
- package/dist/chunk-JWZXYVET.js +1068 -0
- package/dist/chunk-KCQUXVYT.js +108 -0
- package/dist/chunk-KOQ43OX6.js +1281 -0
- package/dist/chunk-KYVWO6ZM.js +1069 -0
- package/dist/chunk-L3VHARQH.js +413 -0
- package/dist/chunk-LBWDS6BE.js +288 -0
- package/dist/chunk-LOVAHSQV.js +411 -0
- package/dist/chunk-LQOYCAGG.js +446 -0
- package/dist/chunk-LWAIPJ2W.js +146 -0
- package/dist/chunk-M5DHKW7M.js +127 -0
- package/dist/chunk-MBKCIJHM.js +1328 -0
- package/dist/chunk-MK42FMEG.js +147 -0
- package/dist/chunk-MOBMYHKL.js +1205 -0
- package/dist/chunk-MPLTNMRG.js +67 -0
- package/dist/chunk-NIJCVN3O.js +147 -0
- package/dist/chunk-NX647OM3.js +310 -0
- package/dist/chunk-NZCFSZQ7.js +1205 -0
- package/dist/chunk-O2UITJGH.js +465 -0
- package/dist/chunk-OCRA44AZ.js +108 -0
- package/dist/chunk-P3KJR66H.js +117 -0
- package/dist/chunk-PEK6JH65.js +432 -0
- package/dist/chunk-PJ6FFKEX.js +77 -0
- package/dist/chunk-PLUBBZYR.js +800 -0
- package/dist/chunk-PNKVD2UK.js +26 -0
- package/dist/chunk-PSQZURHO.js +229 -0
- package/dist/chunk-SGL6ISBJ.js +1061 -0
- package/dist/chunk-SJABZZT5.js +97 -0
- package/dist/chunk-TD3P3K32.js +1199 -0
- package/dist/chunk-TMDZJJKV.js +288 -0
- package/dist/chunk-UNHVZB5G.js +411 -0
- package/dist/chunk-VAFTWSTE.js +1061 -0
- package/dist/chunk-VNFXFQBB.js +217 -0
- package/dist/chunk-X3GVFKSJ.js +1205 -0
- package/dist/chunk-XZ3S56RQ.js +1061 -0
- package/dist/chunk-Y72C7F6O.js +148 -0
- package/dist/chunk-YLICP577.js +1205 -0
- package/dist/chunk-YX6AXLVK.js +159 -0
- package/dist/chunk-ZCQYHTNU.js +146 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +1160 -0
- package/dist/cloud-crystal.js +6 -0
- package/dist/core.d.ts +252 -0
- package/dist/core.js +12 -0
- package/dist/crypto.d.ts +20 -0
- package/dist/crypto.js +27 -0
- package/dist/crystal-capture.sh +29 -0
- package/dist/crystal-serve.d.ts +4 -0
- package/dist/crystal-serve.js +252 -0
- package/dist/dev-update-SZ2Z4WCQ.js +6 -0
- package/dist/discover.d.ts +30 -0
- package/dist/discover.js +177 -0
- package/dist/doctor.d.ts +9 -0
- package/dist/doctor.js +342 -0
- package/dist/dream-weaver.d.ts +8 -0
- package/dist/dream-weaver.js +56 -0
- package/dist/file-sync.d.ts +48 -0
- package/dist/file-sync.js +18 -0
- package/dist/installer.d.ts +61 -0
- package/dist/installer.js +772 -0
- package/dist/ldm-backup.sh +116 -0
- package/dist/ldm.d.ts +50 -0
- package/dist/ldm.js +32 -0
- package/dist/llm-XXLYPIOF.js +16 -0
- package/dist/mcp-server.d.ts +1 -0
- package/dist/mcp-server.js +277 -0
- package/dist/migrate.d.ts +1 -0
- package/dist/migrate.js +89 -0
- package/dist/mirror-sync.d.ts +1 -0
- package/dist/mirror-sync.js +159 -0
- package/dist/mlx-setup-XKU67WCT.js +289 -0
- package/dist/oc-backfill.d.ts +19 -0
- package/dist/oc-backfill.js +74 -0
- package/dist/openclaw.d.ts +5 -0
- package/dist/openclaw.js +434 -0
- package/dist/pair.d.ts +4 -0
- package/dist/pair.js +75 -0
- package/dist/poller.d.ts +1 -0
- package/dist/poller.js +634 -0
- package/dist/role.d.ts +24 -0
- package/dist/role.js +13 -0
- package/dist/search-pipeline-4K4OJSSS.js +255 -0
- package/dist/search-pipeline-4PRS6LI7.js +280 -0
- package/dist/search-pipeline-7UJMXPLO.js +280 -0
- package/dist/search-pipeline-CBV25NX7.js +99 -0
- package/dist/search-pipeline-DQTRLGBH.js +74 -0
- package/dist/search-pipeline-HNG37REH.js +282 -0
- package/dist/search-pipeline-IZFPLBUB.js +280 -0
- package/dist/search-pipeline-MID6F26Q.js +73 -0
- package/dist/search-pipeline-N52JZFNN.js +282 -0
- package/dist/search-pipeline-OPB2PRQQ.js +280 -0
- package/dist/search-pipeline-VXTE5HAD.js +262 -0
- package/dist/search-pipeline-XHFKADRG.js +73 -0
- package/dist/staging.d.ts +29 -0
- package/dist/staging.js +21 -0
- package/dist/summarize.d.ts +19 -0
- package/dist/summarize.js +10 -0
- package/dist/worker-demo.js +186 -0
- package/dist/worker-mcp.js +404 -0
- package/dist/worker.js +137 -0
- package/package.json +15 -1
- package/.env.example +0 -20
- package/.publish-skill.json +0 -1
- package/CHANGELOG.md +0 -1372
- package/README-ENTERPRISE.md +0 -226
- package/RELAY.md +0 -199
- package/wrangler-demo.toml +0 -8
- package/wrangler-mcp.toml +0 -24
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
interface CrystalConfig {
|
|
2
|
+
/** Root directory for all crystal data */
|
|
3
|
+
dataDir: string;
|
|
4
|
+
/** Embedding provider: 'openai' | 'ollama' | 'google' */
|
|
5
|
+
embeddingProvider: 'openai' | 'ollama' | 'google';
|
|
6
|
+
/** OpenAI API key (required if provider is 'openai') */
|
|
7
|
+
openaiApiKey?: string;
|
|
8
|
+
/** OpenAI embedding model (default: text-embedding-3-small) */
|
|
9
|
+
openaiModel?: string;
|
|
10
|
+
/** Ollama host (default: http://localhost:11434) */
|
|
11
|
+
ollamaHost?: string;
|
|
12
|
+
/** Ollama model (default: nomic-embed-text) */
|
|
13
|
+
ollamaModel?: string;
|
|
14
|
+
/** Google API key (required if provider is 'google') */
|
|
15
|
+
googleApiKey?: string;
|
|
16
|
+
/** Google embedding model (default: text-embedding-004) */
|
|
17
|
+
googleModel?: string;
|
|
18
|
+
/** Remote Worker URL for cloud mirror mode */
|
|
19
|
+
remoteUrl?: string;
|
|
20
|
+
/** Remote auth token */
|
|
21
|
+
remoteToken?: string;
|
|
22
|
+
}
|
|
23
|
+
interface Chunk {
|
|
24
|
+
id?: number;
|
|
25
|
+
text: string;
|
|
26
|
+
embedding?: number[];
|
|
27
|
+
role: 'user' | 'assistant' | 'system';
|
|
28
|
+
source_type: string;
|
|
29
|
+
source_id: string;
|
|
30
|
+
agent_id: string;
|
|
31
|
+
token_count: number;
|
|
32
|
+
created_at: string;
|
|
33
|
+
}
|
|
34
|
+
/** Pre-embedded chunk for delta sync. Includes embedding vector so Nodes don't re-embed. */
|
|
35
|
+
interface ExportedChunk {
|
|
36
|
+
id: number;
|
|
37
|
+
text: string;
|
|
38
|
+
text_hash: string;
|
|
39
|
+
role: string;
|
|
40
|
+
source_type: string;
|
|
41
|
+
source_id: string;
|
|
42
|
+
agent_id: string;
|
|
43
|
+
token_count: number;
|
|
44
|
+
created_at: string;
|
|
45
|
+
embedding: number[] | null;
|
|
46
|
+
}
|
|
47
|
+
interface Memory {
|
|
48
|
+
id?: number;
|
|
49
|
+
text: string;
|
|
50
|
+
embedding?: number[];
|
|
51
|
+
category: 'fact' | 'preference' | 'event' | 'opinion' | 'skill' | 'user' | 'feedback' | 'project' | 'reference';
|
|
52
|
+
confidence: number;
|
|
53
|
+
source_ids: string;
|
|
54
|
+
status: 'active' | 'deprecated' | 'deleted';
|
|
55
|
+
created_at: string;
|
|
56
|
+
updated_at: string;
|
|
57
|
+
}
|
|
58
|
+
interface SearchResult {
|
|
59
|
+
text: string;
|
|
60
|
+
role: string;
|
|
61
|
+
score: number;
|
|
62
|
+
source_type: string;
|
|
63
|
+
source_id: string;
|
|
64
|
+
agent_id: string;
|
|
65
|
+
created_at: string;
|
|
66
|
+
freshness?: "fresh" | "recent" | "aging" | "stale";
|
|
67
|
+
}
|
|
68
|
+
/** Pre-expanded query for unified search API. Skip LLM expansion when you know what you want. */
|
|
69
|
+
interface StructuredQuery {
|
|
70
|
+
type: 'lex' | 'vec' | 'hyde';
|
|
71
|
+
text: string;
|
|
72
|
+
}
|
|
73
|
+
interface CrystalStatus {
|
|
74
|
+
chunks: number;
|
|
75
|
+
memories: number;
|
|
76
|
+
sources: number;
|
|
77
|
+
agents: string[];
|
|
78
|
+
oldestChunk: string | null;
|
|
79
|
+
newestChunk: string | null;
|
|
80
|
+
embeddingProvider: string;
|
|
81
|
+
dataDir: string;
|
|
82
|
+
capturedSessions: number;
|
|
83
|
+
latestCapture: string | null;
|
|
84
|
+
}
|
|
85
|
+
interface SourceCollection {
|
|
86
|
+
id?: number;
|
|
87
|
+
name: string;
|
|
88
|
+
root_path: string;
|
|
89
|
+
glob_patterns: string;
|
|
90
|
+
ignore_patterns: string;
|
|
91
|
+
file_count: number;
|
|
92
|
+
chunk_count: number;
|
|
93
|
+
last_sync_at: string | null;
|
|
94
|
+
created_at: string;
|
|
95
|
+
}
|
|
96
|
+
interface SourceFile {
|
|
97
|
+
id?: number;
|
|
98
|
+
collection_id: number;
|
|
99
|
+
file_path: string;
|
|
100
|
+
file_hash: string;
|
|
101
|
+
file_size: number;
|
|
102
|
+
chunk_count: number;
|
|
103
|
+
last_indexed_at: string;
|
|
104
|
+
}
|
|
105
|
+
interface SourcesStatus {
|
|
106
|
+
collections: Array<{
|
|
107
|
+
name: string;
|
|
108
|
+
root_path: string;
|
|
109
|
+
file_count: number;
|
|
110
|
+
chunk_count: number;
|
|
111
|
+
last_sync_at: string | null;
|
|
112
|
+
}>;
|
|
113
|
+
total_files: number;
|
|
114
|
+
total_chunks: number;
|
|
115
|
+
}
|
|
116
|
+
interface SyncResult {
|
|
117
|
+
collection: string;
|
|
118
|
+
added: number;
|
|
119
|
+
updated: number;
|
|
120
|
+
removed: number;
|
|
121
|
+
chunks_added: number;
|
|
122
|
+
duration_ms: number;
|
|
123
|
+
}
|
|
124
|
+
declare class Crystal {
|
|
125
|
+
private config;
|
|
126
|
+
private lanceDb;
|
|
127
|
+
private sqliteDb;
|
|
128
|
+
private chunksTable;
|
|
129
|
+
private vecDimensions;
|
|
130
|
+
constructor(config: CrystalConfig);
|
|
131
|
+
init(): Promise<void>;
|
|
132
|
+
private initSqliteTables;
|
|
133
|
+
private initChunksTables;
|
|
134
|
+
private ensureVecTable;
|
|
135
|
+
private initLanceTables;
|
|
136
|
+
embed(texts: string[]): Promise<number[][]>;
|
|
137
|
+
chunkText(text: string, targetTokens?: number, overlapTokens?: number): string[];
|
|
138
|
+
ingest(chunks: Chunk[]): Promise<number>;
|
|
139
|
+
/** Export interface for delta sync payloads. */
|
|
140
|
+
static readonly DELTA_VERSION = 1;
|
|
141
|
+
/** Export chunks with IDs greater than sinceId. Returns pre-embedded chunks for delta sync.
|
|
142
|
+
* Core calls this to build delta payloads for Nodes. */
|
|
143
|
+
exportChunksSince(sinceId: number): ExportedChunk[];
|
|
144
|
+
/** Get the highest chunk ID in the database. Used for watermark tracking. */
|
|
145
|
+
getMaxChunkId(): number;
|
|
146
|
+
/** Import pre-embedded chunks from Core. Node calls this to apply delta payloads.
|
|
147
|
+
* Skips chunks that already exist (by text_hash). Does NOT re-embed. */
|
|
148
|
+
importChunks(exported: ExportedChunk[]): number;
|
|
149
|
+
private recencyWeight;
|
|
150
|
+
/** Parse relative time strings ("24h", "7d", "30d") or ISO dates into ISO date strings. */
|
|
151
|
+
private parseSince;
|
|
152
|
+
private freshnessLabel;
|
|
153
|
+
search(query: string, limit?: number, filter?: {
|
|
154
|
+
agent_id?: string;
|
|
155
|
+
source_type?: string;
|
|
156
|
+
since?: string;
|
|
157
|
+
until?: string;
|
|
158
|
+
}): Promise<SearchResult[]>;
|
|
159
|
+
/** Deep search: query expansion + LLM re-ranking + position-aware blending.
|
|
160
|
+
* Falls back to standard search if no LLM provider is available.
|
|
161
|
+
* Supports intent disambiguation, candidateLimit tuning, and explain traces. */
|
|
162
|
+
deepSearch(query: string, limit?: number, filter?: {
|
|
163
|
+
agent_id?: string;
|
|
164
|
+
source_type?: string;
|
|
165
|
+
since?: string;
|
|
166
|
+
until?: string;
|
|
167
|
+
}, options?: {
|
|
168
|
+
intent?: string;
|
|
169
|
+
candidateLimit?: number;
|
|
170
|
+
explain?: boolean;
|
|
171
|
+
}): Promise<SearchResult[]>;
|
|
172
|
+
/** Structured search: pass pre-expanded queries to skip LLM expansion.
|
|
173
|
+
* Each query is typed (lex, vec, hyde) and searched independently, then fused with RRF. */
|
|
174
|
+
structuredSearch(queries: StructuredQuery[], limit?: number, filter?: {
|
|
175
|
+
agent_id?: string;
|
|
176
|
+
source_type?: string;
|
|
177
|
+
since?: string;
|
|
178
|
+
until?: string;
|
|
179
|
+
}): Promise<SearchResult[]>;
|
|
180
|
+
/** Vector search via sqlite-vec. Two-step pattern: MATCH first, then JOIN. */
|
|
181
|
+
private searchVec;
|
|
182
|
+
/** Full-text search via FTS5 with BM25 scoring. */
|
|
183
|
+
private searchFTS;
|
|
184
|
+
/** Build a safe FTS5 query from user input. */
|
|
185
|
+
private buildFTS5Query;
|
|
186
|
+
/**
|
|
187
|
+
* Reciprocal Rank Fusion. Ported from QMD (MIT License, Tobi Lutke, 2024-2026).
|
|
188
|
+
* Fuses multiple ranked result lists into one using RRF scoring.
|
|
189
|
+
* Uses text content as dedup key (instead of QMD's file path).
|
|
190
|
+
*/
|
|
191
|
+
private reciprocalRankFusion;
|
|
192
|
+
/** LanceDB fallback for search (used when sqlite-vec tables are empty, pre-migration). */
|
|
193
|
+
private searchLanceFallback;
|
|
194
|
+
remember(text: string, category?: Memory['category']): Promise<number>;
|
|
195
|
+
forget(memoryId: number): boolean;
|
|
196
|
+
status(): Promise<CrystalStatus>;
|
|
197
|
+
getCaptureState(agentId: string, sourceId: string): {
|
|
198
|
+
lastMessageCount: number;
|
|
199
|
+
captureCount: number;
|
|
200
|
+
};
|
|
201
|
+
setCaptureState(agentId: string, sourceId: string, messageCount: number, captureCount: number): void;
|
|
202
|
+
private static readonly DEFAULT_INCLUDE;
|
|
203
|
+
private static readonly DEFAULT_IGNORE;
|
|
204
|
+
/** Add a directory as a source collection for indexing. */
|
|
205
|
+
sourcesAdd(rootPath: string, name: string, options?: {
|
|
206
|
+
include?: string[];
|
|
207
|
+
ignore?: string[];
|
|
208
|
+
}): Promise<SourceCollection>;
|
|
209
|
+
/** Remove a source collection and its file records. Chunks remain in LanceDB. */
|
|
210
|
+
sourcesRemove(name: string): boolean;
|
|
211
|
+
/** Sync a collection: scan files, detect changes, re-index what changed. */
|
|
212
|
+
sourcesSync(name: string, options?: {
|
|
213
|
+
dryRun?: boolean;
|
|
214
|
+
batchSize?: number;
|
|
215
|
+
}): Promise<SyncResult>;
|
|
216
|
+
/** Get status of all source collections. */
|
|
217
|
+
sourcesStatus(): SourcesStatus;
|
|
218
|
+
/** Scan a directory recursively, matching include/ignore patterns. */
|
|
219
|
+
private scanDirectory;
|
|
220
|
+
/** Clean orphaned entries in chunks_vec and chunks_fts that no longer have
|
|
221
|
+
* corresponding rows in the chunks table. Returns counts of what was found/cleaned. */
|
|
222
|
+
cleanOrphans(options?: {
|
|
223
|
+
dryRun?: boolean;
|
|
224
|
+
}): {
|
|
225
|
+
orphanedVec: number;
|
|
226
|
+
orphanedFts: number;
|
|
227
|
+
cleanedVec: number;
|
|
228
|
+
cleanedFts: number;
|
|
229
|
+
dryRun: boolean;
|
|
230
|
+
};
|
|
231
|
+
close(): void;
|
|
232
|
+
}
|
|
233
|
+
declare function resolveConfig(overrides?: Partial<CrystalConfig>): CrystalConfig;
|
|
234
|
+
declare class RemoteCrystal {
|
|
235
|
+
private url;
|
|
236
|
+
private token;
|
|
237
|
+
constructor(url: string, token: string);
|
|
238
|
+
init(): Promise<void>;
|
|
239
|
+
private request;
|
|
240
|
+
search(query: string, limit?: number, filter?: {
|
|
241
|
+
agent_id?: string;
|
|
242
|
+
}): Promise<SearchResult[]>;
|
|
243
|
+
ingest(chunks: Chunk[]): Promise<number>;
|
|
244
|
+
remember(text: string, category?: Memory['category']): Promise<number>;
|
|
245
|
+
forget(memoryId: number): Promise<boolean>;
|
|
246
|
+
status(): Promise<CrystalStatus>;
|
|
247
|
+
chunkText(text: string): string[];
|
|
248
|
+
}
|
|
249
|
+
/** Create the appropriate Crystal instance based on config. */
|
|
250
|
+
declare function createCrystal(config: CrystalConfig): Crystal | RemoteCrystal;
|
|
251
|
+
|
|
252
|
+
export { type Chunk, Crystal, type CrystalConfig, type CrystalStatus, type ExportedChunk, type Memory, RemoteCrystal, type SearchResult, type SourceCollection, type SourceFile, type SourcesStatus, type StructuredQuery, type SyncResult, createCrystal, resolveConfig };
|
package/dist/core.js
ADDED
package/dist/crypto.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare function loadRelayKey(): Buffer;
|
|
2
|
+
interface EncryptedPayload {
|
|
3
|
+
v: 1;
|
|
4
|
+
nonce: string;
|
|
5
|
+
ciphertext: string;
|
|
6
|
+
tag: string;
|
|
7
|
+
hmac: string;
|
|
8
|
+
}
|
|
9
|
+
declare function encrypt(plaintext: Buffer, masterKey: Buffer): EncryptedPayload;
|
|
10
|
+
declare function decrypt(payload: EncryptedPayload, masterKey: Buffer): Buffer;
|
|
11
|
+
declare function encryptJSON(data: unknown, masterKey: Buffer): EncryptedPayload;
|
|
12
|
+
declare function decryptJSON<T = unknown>(payload: EncryptedPayload, masterKey: Buffer): T;
|
|
13
|
+
declare function encryptFile(filePath: string, masterKey: Buffer): EncryptedPayload;
|
|
14
|
+
declare const RELAY_KEY_PATH: string;
|
|
15
|
+
declare function generateRelayKey(): Buffer;
|
|
16
|
+
declare function encodePairingString(key: Buffer): string;
|
|
17
|
+
declare function decodePairingString(str: string): Buffer;
|
|
18
|
+
declare function hashBuffer(data: Buffer): string;
|
|
19
|
+
|
|
20
|
+
export { type EncryptedPayload, RELAY_KEY_PATH, decodePairingString, decrypt, decryptJSON, encodePairingString, encrypt, encryptFile, encryptJSON, generateRelayKey, hashBuffer, loadRelayKey };
|
package/dist/crypto.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
RELAY_KEY_PATH,
|
|
3
|
+
decodePairingString,
|
|
4
|
+
decrypt,
|
|
5
|
+
decryptJSON,
|
|
6
|
+
encodePairingString,
|
|
7
|
+
encrypt,
|
|
8
|
+
encryptFile,
|
|
9
|
+
encryptJSON,
|
|
10
|
+
generateRelayKey,
|
|
11
|
+
hashBuffer,
|
|
12
|
+
loadRelayKey
|
|
13
|
+
} from "./chunk-D3MACYZ4.js";
|
|
14
|
+
import "./chunk-DFQ72B7M.js";
|
|
15
|
+
export {
|
|
16
|
+
RELAY_KEY_PATH,
|
|
17
|
+
decodePairingString,
|
|
18
|
+
decrypt,
|
|
19
|
+
decryptJSON,
|
|
20
|
+
encodePairingString,
|
|
21
|
+
encrypt,
|
|
22
|
+
encryptFile,
|
|
23
|
+
encryptJSON,
|
|
24
|
+
generateRelayKey,
|
|
25
|
+
hashBuffer,
|
|
26
|
+
loadRelayKey
|
|
27
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
ldmPaths
|
|
4
|
+
} from "./chunk-DFQ72B7M.js";
|
|
5
|
+
|
|
6
|
+
// src/crystal-serve.ts
|
|
7
|
+
import { createServer } from "http";
|
|
8
|
+
import { spawn } from "child_process";
|
|
9
|
+
import { existsSync, readFileSync } from "fs";
|
|
10
|
+
import { join } from "path";
|
|
11
|
+
var DEFAULT_PORT = 18790;
|
|
12
|
+
var AUTH_TOKEN = process.env.CRYSTAL_SERVE_TOKEN || "";
|
|
13
|
+
function checkAuth(req) {
|
|
14
|
+
if (!AUTH_TOKEN) return true;
|
|
15
|
+
const authHeader = req.headers.authorization;
|
|
16
|
+
if (!authHeader) return false;
|
|
17
|
+
return authHeader === `Bearer ${AUTH_TOKEN}`;
|
|
18
|
+
}
|
|
19
|
+
function sendJson(res, status, body) {
|
|
20
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
21
|
+
res.end(JSON.stringify(body));
|
|
22
|
+
}
|
|
23
|
+
function send401(res) {
|
|
24
|
+
sendJson(res, 401, { error: "Unauthorized" });
|
|
25
|
+
}
|
|
26
|
+
function readBody(req) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
let body = "";
|
|
29
|
+
req.on("data", (chunk) => {
|
|
30
|
+
body += chunk;
|
|
31
|
+
});
|
|
32
|
+
req.on("end", () => resolve(body));
|
|
33
|
+
req.on("error", reject);
|
|
34
|
+
req.on("data", () => {
|
|
35
|
+
if (body.length > 1e6) {
|
|
36
|
+
req.destroy();
|
|
37
|
+
reject(new Error("Request body too large"));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
async function handleChatCompletions(req, res) {
|
|
43
|
+
const raw = await readBody(req);
|
|
44
|
+
let parsed;
|
|
45
|
+
try {
|
|
46
|
+
parsed = JSON.parse(raw);
|
|
47
|
+
} catch {
|
|
48
|
+
sendJson(res, 400, { error: "Invalid JSON" });
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const messages = parsed.messages;
|
|
52
|
+
if (!messages || !Array.isArray(messages) || messages.length === 0) {
|
|
53
|
+
sendJson(res, 400, { error: "messages array required" });
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const lastUser = [...messages].reverse().find((m) => m.role === "user");
|
|
57
|
+
if (!lastUser) {
|
|
58
|
+
sendJson(res, 400, { error: "No user message found" });
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const prompt = typeof lastUser.content === "string" ? lastUser.content : Array.isArray(lastUser.content) ? lastUser.content.filter((b) => b.type === "text").map((b) => b.text).join("\n") : "";
|
|
62
|
+
if (!prompt) {
|
|
63
|
+
sendJson(res, 400, { error: "Empty prompt" });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const systemMsg = messages.find((m) => m.role === "system");
|
|
67
|
+
const systemPrompt = systemMsg ? typeof systemMsg.content === "string" ? systemMsg.content : "" : void 0;
|
|
68
|
+
try {
|
|
69
|
+
const args2 = ["-p", prompt];
|
|
70
|
+
if (systemPrompt) args2.push("--system", systemPrompt);
|
|
71
|
+
args2.push("--output-format", "text");
|
|
72
|
+
const result = await new Promise((resolve, reject) => {
|
|
73
|
+
const proc = spawn("claude", args2, {
|
|
74
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
75
|
+
env: { ...process.env },
|
|
76
|
+
timeout: 3e5
|
|
77
|
+
});
|
|
78
|
+
let stdout = "";
|
|
79
|
+
let stderr = "";
|
|
80
|
+
proc.stdout.on("data", (data) => {
|
|
81
|
+
stdout += data.toString();
|
|
82
|
+
});
|
|
83
|
+
proc.stderr.on("data", (data) => {
|
|
84
|
+
stderr += data.toString();
|
|
85
|
+
});
|
|
86
|
+
proc.on("close", (code) => {
|
|
87
|
+
if (code === 0) resolve(stdout.trim());
|
|
88
|
+
else reject(new Error(`claude exited ${code}: ${stderr.slice(0, 300)}`));
|
|
89
|
+
});
|
|
90
|
+
proc.on("error", reject);
|
|
91
|
+
});
|
|
92
|
+
sendJson(res, 200, {
|
|
93
|
+
id: `crystal-${Date.now()}`,
|
|
94
|
+
object: "chat.completion",
|
|
95
|
+
created: Math.floor(Date.now() / 1e3),
|
|
96
|
+
model: "claude-opus-4-6",
|
|
97
|
+
choices: [{
|
|
98
|
+
index: 0,
|
|
99
|
+
message: { role: "assistant", content: result },
|
|
100
|
+
finish_reason: "stop"
|
|
101
|
+
}]
|
|
102
|
+
});
|
|
103
|
+
} catch (err) {
|
|
104
|
+
sendJson(res, 500, { error: err.message });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function handleProcess(req, res) {
|
|
108
|
+
const raw = await readBody(req);
|
|
109
|
+
let parsed;
|
|
110
|
+
try {
|
|
111
|
+
parsed = JSON.parse(raw);
|
|
112
|
+
} catch {
|
|
113
|
+
sendJson(res, 400, { error: "Invalid JSON" });
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const agentId = parsed.agent_id || parsed.agentId;
|
|
117
|
+
const action = parsed.action || "dream-weave";
|
|
118
|
+
if (!agentId) {
|
|
119
|
+
sendJson(res, 400, { error: "agent_id required" });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const args2 = [];
|
|
123
|
+
if (action === "backfill") {
|
|
124
|
+
args2.push("backfill", "--agent", agentId);
|
|
125
|
+
} else if (action === "dream-weave") {
|
|
126
|
+
args2.push("dream-weave", "--agent", agentId, "--mode", parsed.mode || "incremental");
|
|
127
|
+
} else {
|
|
128
|
+
sendJson(res, 400, { error: `Unknown action: ${action}` });
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const proc = spawn("crystal", args2, {
|
|
133
|
+
stdio: "ignore",
|
|
134
|
+
detached: true,
|
|
135
|
+
env: { ...process.env }
|
|
136
|
+
});
|
|
137
|
+
proc.unref();
|
|
138
|
+
sendJson(res, 202, {
|
|
139
|
+
status: "accepted",
|
|
140
|
+
action,
|
|
141
|
+
agent_id: agentId,
|
|
142
|
+
message: `${action} started for ${agentId}`
|
|
143
|
+
});
|
|
144
|
+
} catch (err) {
|
|
145
|
+
sendJson(res, 500, { error: err.message });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function handleStatus(_req, res) {
|
|
149
|
+
const paths = ldmPaths();
|
|
150
|
+
const hasDb = existsSync(paths.crystalDb);
|
|
151
|
+
let lastDreamWeaver = null;
|
|
152
|
+
const agentId = process.env.CRYSTAL_AGENT_ID || "cc-mini";
|
|
153
|
+
const wmPath = join(paths.state, `dream-weaver-${agentId}.json`);
|
|
154
|
+
if (existsSync(wmPath)) {
|
|
155
|
+
try {
|
|
156
|
+
const wm = JSON.parse(readFileSync(wmPath, "utf-8"));
|
|
157
|
+
lastDreamWeaver = wm.lastRunAt || null;
|
|
158
|
+
} catch {
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
let role = "core";
|
|
162
|
+
const rolePath = join(paths.state, "role.json");
|
|
163
|
+
if (existsSync(rolePath)) {
|
|
164
|
+
try {
|
|
165
|
+
const r = JSON.parse(readFileSync(rolePath, "utf-8"));
|
|
166
|
+
role = r.role || "core";
|
|
167
|
+
} catch {
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
sendJson(res, 200, {
|
|
171
|
+
status: "ok",
|
|
172
|
+
role,
|
|
173
|
+
agentId,
|
|
174
|
+
hasDatabase: hasDb,
|
|
175
|
+
lastDreamWeaver,
|
|
176
|
+
uptime: process.uptime(),
|
|
177
|
+
version: "0.6.0"
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function startServer(port2 = DEFAULT_PORT) {
|
|
181
|
+
const server = createServer(async (req, res) => {
|
|
182
|
+
const url = req.url || "";
|
|
183
|
+
const method = req.method || "GET";
|
|
184
|
+
res.setHeader("Access-Control-Allow-Origin", "http://localhost:*");
|
|
185
|
+
res.setHeader("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
|
|
186
|
+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
|
|
187
|
+
if (method === "OPTIONS") {
|
|
188
|
+
res.writeHead(204);
|
|
189
|
+
res.end();
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (url !== "/status" && !checkAuth(req)) {
|
|
193
|
+
send401(res);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
if (method === "POST" && url === "/v1/chat/completions") {
|
|
198
|
+
await handleChatCompletions(req, res);
|
|
199
|
+
} else if (method === "POST" && url === "/process") {
|
|
200
|
+
await handleProcess(req, res);
|
|
201
|
+
} else if (method === "GET" && url === "/status") {
|
|
202
|
+
handleStatus(req, res);
|
|
203
|
+
} else {
|
|
204
|
+
sendJson(res, 404, { error: "Not found" });
|
|
205
|
+
}
|
|
206
|
+
} catch (err) {
|
|
207
|
+
sendJson(res, 500, { error: err.message });
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
server.listen(port2, "127.0.0.1", () => {
|
|
211
|
+
console.log(`Crystal Core gateway listening on http://127.0.0.1:${port2}`);
|
|
212
|
+
console.log(` POST /v1/chat/completions (OpenAI-compatible)`);
|
|
213
|
+
console.log(` POST /process (trigger backfill/dream-weaver)`);
|
|
214
|
+
console.log(` GET /status (health check)`);
|
|
215
|
+
if (AUTH_TOKEN) {
|
|
216
|
+
console.log(` Auth: bearer token required`);
|
|
217
|
+
} else {
|
|
218
|
+
console.log(` Auth: none (set CRYSTAL_SERVE_TOKEN to enable)`);
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
process.on("SIGTERM", () => {
|
|
222
|
+
console.log("Crystal Core gateway shutting down...");
|
|
223
|
+
server.close();
|
|
224
|
+
process.exit(0);
|
|
225
|
+
});
|
|
226
|
+
process.on("SIGINT", () => {
|
|
227
|
+
console.log("Crystal Core gateway shutting down...");
|
|
228
|
+
server.close();
|
|
229
|
+
process.exit(0);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
var args = process.argv.slice(2);
|
|
233
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
234
|
+
console.log(`crystal serve [--port <port>]
|
|
235
|
+
|
|
236
|
+
Crystal Core gateway. Localhost-only HTTP server.
|
|
237
|
+
|
|
238
|
+
Options:
|
|
239
|
+
--port <port> Port to listen on (default: ${DEFAULT_PORT})
|
|
240
|
+
|
|
241
|
+
Environment:
|
|
242
|
+
CRYSTAL_SERVE_TOKEN Bearer token for auth (optional)
|
|
243
|
+
CRYSTAL_AGENT_ID Agent identifier (default: cc-mini)
|
|
244
|
+
`);
|
|
245
|
+
process.exit(0);
|
|
246
|
+
}
|
|
247
|
+
var portFlag = args.indexOf("--port");
|
|
248
|
+
var port = portFlag >= 0 ? parseInt(args[portFlag + 1], 10) : DEFAULT_PORT;
|
|
249
|
+
startServer(port);
|
|
250
|
+
export {
|
|
251
|
+
startServer
|
|
252
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
interface HarnessInfo {
|
|
2
|
+
platform: 'claude-code' | 'openclaw';
|
|
3
|
+
sessionDir: string;
|
|
4
|
+
workspaceDir?: string;
|
|
5
|
+
filePattern: string;
|
|
6
|
+
agentIdDefault: string;
|
|
7
|
+
}
|
|
8
|
+
interface DiscoveryBreakdown {
|
|
9
|
+
platform: string;
|
|
10
|
+
files: number;
|
|
11
|
+
sizeBytes: number;
|
|
12
|
+
sessionPaths: string[];
|
|
13
|
+
}
|
|
14
|
+
interface DiscoveryResult {
|
|
15
|
+
harnesses: HarnessInfo[];
|
|
16
|
+
totalFiles: number;
|
|
17
|
+
totalSizeBytes: number;
|
|
18
|
+
breakdown: DiscoveryBreakdown[];
|
|
19
|
+
}
|
|
20
|
+
/** Detect which agent platforms are installed on this machine. */
|
|
21
|
+
declare function discoverHarnesses(): HarnessInfo[];
|
|
22
|
+
/** Discover all session JSONL files for a given harness. */
|
|
23
|
+
declare function discoverSessionFiles(harness: HarnessInfo): string[];
|
|
24
|
+
/** Discover workspace .md files for OpenClaw harness. */
|
|
25
|
+
declare function discoverWorkspaceFiles(harness: HarnessInfo): string[];
|
|
26
|
+
/** Run full discovery: detect harnesses, find all files, compute sizes. */
|
|
27
|
+
declare function discoverAll(): DiscoveryResult;
|
|
28
|
+
declare function formatBytes(bytes: number): string;
|
|
29
|
+
|
|
30
|
+
export { type DiscoveryBreakdown, type DiscoveryResult, type HarnessInfo, discoverAll, discoverHarnesses, discoverSessionFiles, discoverWorkspaceFiles, formatBytes };
|