@totalreclaw/totalreclaw 1.0.1 → 1.0.2
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/dist/index.js +32099 -0
- package/package.json +17 -4
- package/.github/workflows/ci.yml +0 -27
- package/.github/workflows/publish.yml +0 -41
- package/api-client.ts +0 -300
- package/crypto.ts +0 -351
- package/embedding.ts +0 -84
- package/extractor.ts +0 -210
- package/generate-mnemonic.ts +0 -14
- package/hot-cache-wrapper.ts +0 -126
- package/index.ts +0 -1885
- package/llm-client.ts +0 -418
- package/lsh.test.ts +0 -463
- package/lsh.ts +0 -257
- package/reranker.test.ts +0 -594
- package/reranker.ts +0 -537
- package/semantic-dedup.test.ts +0 -392
- package/semantic-dedup.ts +0 -100
- package/subgraph-search.ts +0 -278
- package/subgraph-store.ts +0 -342
package/hot-cache-wrapper.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Hot cache wrapper for the plugin.
|
|
3
|
-
*
|
|
4
|
-
* Self-contained AES-256-GCM encrypted cache (same implementation as
|
|
5
|
-
* client/src/cache/hot-cache.ts but without cross-package import).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import crypto from 'node:crypto';
|
|
9
|
-
import fs from 'node:fs';
|
|
10
|
-
import path from 'node:path';
|
|
11
|
-
|
|
12
|
-
export interface HotFact {
|
|
13
|
-
id: string;
|
|
14
|
-
text: string;
|
|
15
|
-
importance: number;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
interface CachePayload {
|
|
19
|
-
hotFacts: HotFact[];
|
|
20
|
-
factCount: number;
|
|
21
|
-
lastSyncedBlock: number;
|
|
22
|
-
smartAccountAddress: string;
|
|
23
|
-
lastUpdatedAt?: number; // Unix timestamp (ms) of last cache update
|
|
24
|
-
lastQueryEmbedding?: number[]; // Embedding of last search query
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const MAX_HOT_FACTS = 30;
|
|
28
|
-
const IV_LENGTH = 12;
|
|
29
|
-
const TAG_LENGTH = 16;
|
|
30
|
-
|
|
31
|
-
export class PluginHotCache {
|
|
32
|
-
private hotFacts: HotFact[] = [];
|
|
33
|
-
private factCount = 0;
|
|
34
|
-
private lastSyncedBlock = 0;
|
|
35
|
-
private smartAccountAddress = '';
|
|
36
|
-
private lastUpdatedAt = 0;
|
|
37
|
-
private lastQueryEmbedding: number[] | null = null;
|
|
38
|
-
private key: Buffer;
|
|
39
|
-
|
|
40
|
-
constructor(private cachePath: string, hexKey: string) {
|
|
41
|
-
this.key = Buffer.from(hexKey, 'hex');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getHotFacts(): HotFact[] { return [...this.hotFacts]; }
|
|
45
|
-
getFactCount(): number { return this.factCount; }
|
|
46
|
-
getLastSyncedBlock(): number { return this.lastSyncedBlock; }
|
|
47
|
-
getSmartAccountAddress(): string { return this.smartAccountAddress; }
|
|
48
|
-
getLastUpdatedAt(): number { return this.lastUpdatedAt; }
|
|
49
|
-
getLastQueryEmbedding(): number[] | null { return this.lastQueryEmbedding ? [...this.lastQueryEmbedding] : null; }
|
|
50
|
-
|
|
51
|
-
setHotFacts(facts: HotFact[]): void {
|
|
52
|
-
const sorted = [...facts].sort((a, b) => b.importance - a.importance);
|
|
53
|
-
this.hotFacts = sorted.slice(0, MAX_HOT_FACTS);
|
|
54
|
-
this.lastUpdatedAt = Date.now();
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
setFactCount(count: number): void { this.factCount = count; }
|
|
58
|
-
setLastSyncedBlock(block: number): void { this.lastSyncedBlock = block; }
|
|
59
|
-
setSmartAccountAddress(addr: string): void { this.smartAccountAddress = addr; }
|
|
60
|
-
setLastUpdatedAt(ts: number): void { this.lastUpdatedAt = ts; }
|
|
61
|
-
setLastQueryEmbedding(embedding: number[] | null): void { this.lastQueryEmbedding = embedding ? [...embedding] : null; }
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Check if the cache is fresh (within TTL).
|
|
65
|
-
* @param ttlMs TTL in milliseconds (default: 5 minutes)
|
|
66
|
-
*/
|
|
67
|
-
isFresh(ttlMs: number = 300_000): boolean {
|
|
68
|
-
if (this.lastUpdatedAt === 0) return false;
|
|
69
|
-
return (Date.now() - this.lastUpdatedAt) < ttlMs;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
flush(): void {
|
|
73
|
-
const payload: CachePayload = {
|
|
74
|
-
hotFacts: this.hotFacts,
|
|
75
|
-
factCount: this.factCount,
|
|
76
|
-
lastSyncedBlock: this.lastSyncedBlock,
|
|
77
|
-
smartAccountAddress: this.smartAccountAddress,
|
|
78
|
-
lastUpdatedAt: this.lastUpdatedAt,
|
|
79
|
-
lastQueryEmbedding: this.lastQueryEmbedding,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const plaintext = Buffer.from(JSON.stringify(payload), 'utf-8');
|
|
83
|
-
const iv = crypto.randomBytes(IV_LENGTH);
|
|
84
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', this.key, iv);
|
|
85
|
-
const encrypted = Buffer.concat([cipher.update(plaintext), cipher.final()]);
|
|
86
|
-
const tag = cipher.getAuthTag();
|
|
87
|
-
|
|
88
|
-
const output = Buffer.concat([iv, tag, encrypted]);
|
|
89
|
-
|
|
90
|
-
const dir = path.dirname(this.cachePath);
|
|
91
|
-
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
92
|
-
fs.writeFileSync(this.cachePath, output);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
load(): void {
|
|
96
|
-
if (!fs.existsSync(this.cachePath)) return;
|
|
97
|
-
|
|
98
|
-
try {
|
|
99
|
-
const data = fs.readFileSync(this.cachePath);
|
|
100
|
-
if (data.length < IV_LENGTH + TAG_LENGTH) return;
|
|
101
|
-
|
|
102
|
-
const iv = data.subarray(0, IV_LENGTH);
|
|
103
|
-
const tag = data.subarray(IV_LENGTH, IV_LENGTH + TAG_LENGTH);
|
|
104
|
-
const ciphertext = data.subarray(IV_LENGTH + TAG_LENGTH);
|
|
105
|
-
|
|
106
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', this.key, iv);
|
|
107
|
-
decipher.setAuthTag(tag);
|
|
108
|
-
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
109
|
-
|
|
110
|
-
const payload: CachePayload = JSON.parse(decrypted.toString('utf-8'));
|
|
111
|
-
this.hotFacts = payload.hotFacts || [];
|
|
112
|
-
this.factCount = payload.factCount || 0;
|
|
113
|
-
this.lastSyncedBlock = payload.lastSyncedBlock || 0;
|
|
114
|
-
this.smartAccountAddress = payload.smartAccountAddress || '';
|
|
115
|
-
this.lastUpdatedAt = payload.lastUpdatedAt || 0;
|
|
116
|
-
this.lastQueryEmbedding = payload.lastQueryEmbedding || null;
|
|
117
|
-
} catch {
|
|
118
|
-
this.hotFacts = [];
|
|
119
|
-
this.factCount = 0;
|
|
120
|
-
this.lastSyncedBlock = 0;
|
|
121
|
-
this.smartAccountAddress = '';
|
|
122
|
-
this.lastUpdatedAt = 0;
|
|
123
|
-
this.lastQueryEmbedding = null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|