@totalreclaw/totalreclaw 3.3.12-rc.9 → 3.3.12

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 (79) hide show
  1. package/SKILL.md +33 -27
  2. package/api-client.ts +17 -9
  3. package/batch-gate.ts +42 -0
  4. package/billing-cache.ts +72 -23
  5. package/claims-helper.ts +2 -1
  6. package/config.ts +95 -13
  7. package/consolidation.ts +6 -13
  8. package/contradiction-sync.ts +19 -14
  9. package/credential-provider.ts +184 -0
  10. package/crypto.ts +27 -160
  11. package/dist/api-client.js +17 -9
  12. package/dist/batch-gate.js +40 -0
  13. package/dist/billing-cache.js +54 -24
  14. package/dist/claims-helper.js +2 -1
  15. package/dist/config.js +91 -13
  16. package/dist/consolidation.js +6 -15
  17. package/dist/contradiction-sync.js +15 -15
  18. package/dist/credential-provider.js +145 -0
  19. package/dist/crypto.js +17 -137
  20. package/dist/download-ux.js +11 -7
  21. package/dist/embedder-loader.js +266 -0
  22. package/dist/embedding.js +36 -3
  23. package/dist/entry.js +123 -0
  24. package/dist/fs-helpers.js +75 -379
  25. package/dist/import-adapters/gemini-adapter.js +29 -159
  26. package/dist/index.js +864 -2631
  27. package/dist/memory-runtime.js +459 -0
  28. package/dist/native-memory.js +123 -0
  29. package/dist/onboarding-cli.js +4 -8
  30. package/dist/pair-cli-relay.js +1 -8
  31. package/dist/pair-cli.js +1 -1
  32. package/dist/pair-crypto.js +16 -358
  33. package/dist/pair-http.js +147 -4
  34. package/dist/relay.js +140 -0
  35. package/dist/reranker.js +13 -8
  36. package/dist/semantic-dedup.js +5 -7
  37. package/dist/skill-register.js +97 -0
  38. package/dist/subgraph-search.js +3 -1
  39. package/dist/subgraph-store.js +348 -290
  40. package/dist/tool-gating.js +39 -26
  41. package/dist/tools.js +367 -0
  42. package/dist/tr-cli-export-helper.js +3 -3
  43. package/dist/tr-cli.js +65 -156
  44. package/dist/trajectory-poller.js +155 -9
  45. package/dist/vault-crypto.js +551 -0
  46. package/download-ux.ts +12 -6
  47. package/embedder-loader.ts +293 -1
  48. package/embedding.ts +43 -3
  49. package/entry.ts +132 -0
  50. package/fs-helpers.ts +93 -458
  51. package/import-adapters/gemini-adapter.ts +38 -183
  52. package/index.ts +912 -2917
  53. package/memory-runtime.ts +723 -0
  54. package/native-memory.ts +196 -0
  55. package/onboarding-cli.ts +3 -9
  56. package/openclaw.plugin.json +5 -17
  57. package/package.json +6 -3
  58. package/pair-cli-relay.ts +0 -9
  59. package/pair-cli.ts +1 -1
  60. package/pair-crypto.ts +41 -483
  61. package/pair-http.ts +194 -5
  62. package/postinstall.mjs +138 -0
  63. package/relay.ts +172 -0
  64. package/reranker.ts +13 -8
  65. package/semantic-dedup.ts +5 -6
  66. package/skill-register.ts +146 -0
  67. package/skill.json +1 -1
  68. package/subgraph-search.ts +3 -1
  69. package/subgraph-store.ts +367 -307
  70. package/tool-gating.ts +39 -26
  71. package/tools.ts +499 -0
  72. package/tr-cli-export-helper.ts +3 -3
  73. package/tr-cli.ts +69 -182
  74. package/trajectory-poller.ts +162 -10
  75. package/vault-crypto.ts +705 -0
  76. package/auto-pair-on-load.ts +0 -308
  77. package/dist/auto-pair-on-load.js +0 -197
  78. package/dist/pair-pending-injection.js +0 -125
  79. package/pair-pending-injection.ts +0 -205
@@ -1,38 +1,19 @@
1
1
  import { BaseImportAdapter } from './base-adapter.js';
2
2
  import fs from 'node:fs';
3
3
  import os from 'node:os';
4
- /** Maximum messages per conversation chunk for LLM extraction. */
5
- const CHUNK_SIZE = 20;
6
- /** Gap (in minutes) between entries that starts a new pseudo-session. */
7
- const SESSION_GAP_MINUTES = 30;
8
- // ── Timestamp Parsing ────────────────────────────────────────────────────────
9
- const MONTHS = {
10
- Jan: 0, Feb: 1, Mar: 2, Apr: 3, May: 4, Jun: 5,
11
- Jul: 6, Aug: 7, Sep: 8, Oct: 9, Nov: 10, Dec: 11,
12
- };
13
- /**
14
- * Parse Gemini timestamp: "1 Apr 2026, 18:39:35 WEST" → ISO 8601.
15
- * Timezone is treated as UTC (all entries use the same TZ, preserving order).
16
- */
17
- function parseTimestamp(raw) {
18
- const m = raw.match(/^(\d{1,2})\s+(\w{3})\s+(\d{4}),\s+(\d{2}):(\d{2}):(\d{2})\s+/);
19
- if (!m || MONTHS[m[2]] === undefined)
20
- return undefined;
21
- const d = new Date(Date.UTC(+m[3], MONTHS[m[2]], +m[1], +m[4], +m[5], +m[6]));
22
- return d.toISOString();
4
+ import { createRequire } from 'node:module';
5
+ // All Gemini format parsing (MyActivity.json, legacy HTML, Saved-info paste)
6
+ // lives in the shared Rust core (`@totalreclaw/core` WASM) so the logic —
7
+ // including the locale-robust, lossless timestamp handling — is identical across
8
+ // every client (Python/Hermes via PyO3, TS via WASM). This adapter is a thin
9
+ // shim: it owns only file I/O + the size/RAM preflight, then delegates parsing.
10
+ const requireWasm = createRequire(import.meta.url);
11
+ let _wasm = null;
12
+ function getWasm() {
13
+ if (!_wasm)
14
+ _wasm = requireWasm('@totalreclaw/core');
15
+ return _wasm;
23
16
  }
24
- // ── HTML Helpers ─────────────────────────────────────────────────────────────
25
- function decodeEntities(t) {
26
- return t.replace(/'/g, "'").replace(/"/g, '"').replace(/&/g, '&')
27
- .replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ');
28
- }
29
- function stripHTML(html) {
30
- return html.replace(/<br\s*\/?>/gi, '\n').replace(/<\/p>/gi, '\n')
31
- .replace(/<\/li>/gi, '\n').replace(/<\/h[1-6]>/gi, '\n')
32
- .replace(/<hr\s*\/?>/gi, '\n---\n').replace(/<[^>]+>/g, '')
33
- .replace(/\n{3,}/g, '\n\n').trim();
34
- }
35
- // ── Gemini Adapter ───────────────────────────────────────────────────────────
36
17
  export class GeminiAdapter extends BaseImportAdapter {
37
18
  source = 'gemini';
38
19
  displayName = 'Google Gemini';
@@ -69,147 +50,36 @@ export class GeminiAdapter extends BaseImportAdapter {
69
50
  }
70
51
  else {
71
52
  errors.push('Gemini import requires either content or file_path. ' +
72
- 'Export from Google Takeout: takeout.google.com → select Gemini Apps → export. ' +
73
- 'Provide the "My Activity.html" file path.');
53
+ 'Export from Google Takeout: takeout.google.com → "My Activity" → "Gemini Apps". ' +
54
+ 'Provide the "My Activity.html" (or MyActivity.json) file path, or paste your Saved info.');
74
55
  return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
75
56
  }
76
57
  if (onProgress) {
77
- onProgress({ current: 0, total: 0, phase: 'parsing', message: 'Parsing Gemini HTML...' });
78
- }
79
- // Parse HTML into entries
80
- const entries = this.parseHTML(content);
81
- if (entries.length === 0) {
82
- warnings.push('No conversation entries found in the HTML file.');
83
- return { facts: [], chunks: [], totalMessages: 0, warnings, errors };
58
+ onProgress({ current: 0, total: 0, phase: 'parsing', message: 'Parsing Gemini export...' });
84
59
  }
85
- // Group into pseudo-sessions by temporal proximity
86
- const sessions = this.groupSessions(entries);
60
+ // Delegate ALL format parsing to the shared core.
61
+ const result = getWasm().parseGemini(content);
87
62
  if (onProgress) {
88
63
  onProgress({
89
- current: 0,
90
- total: sessions.length,
64
+ current: result.chunks.length,
65
+ total: result.chunks.length,
91
66
  phase: 'parsing',
92
- message: `Parsed ${entries.length} entries into ${sessions.length} sessions`,
67
+ message: `Parsed ${result.total_messages} messages into ${result.chunks.length} chunks`,
93
68
  });
94
69
  }
95
- // Build conversation chunks from sessions
96
- const chunks = [];
97
- let totalMessages = 0;
98
- for (const session of sessions) {
99
- const messages = [];
100
- for (const entry of session) {
101
- if (entry.userPrompt)
102
- messages.push({ role: 'user', text: entry.userPrompt });
103
- if (entry.aiResponse)
104
- messages.push({ role: 'assistant', text: entry.aiResponse });
105
- }
106
- if (messages.length === 0)
107
- continue;
108
- totalMessages += messages.length;
109
- const timestamp = session[0].timestampISO;
110
- // Sub-chunk large sessions
111
- for (let i = 0; i < messages.length; i += CHUNK_SIZE) {
112
- const batch = messages.slice(i, i + CHUNK_SIZE);
113
- const chunkIdx = Math.floor(i / CHUNK_SIZE) + 1;
114
- const totalChunks = Math.ceil(messages.length / CHUNK_SIZE);
115
- const title = totalChunks > 1
116
- ? `Gemini session (part ${chunkIdx}/${totalChunks})`
117
- : 'Gemini session';
118
- chunks.push({ title, messages: batch, timestamp });
119
- }
120
- }
121
70
  return {
122
71
  facts: [],
123
- chunks,
124
- totalMessages,
125
- warnings,
126
- errors,
72
+ chunks: result.chunks,
73
+ totalMessages: result.total_messages,
74
+ warnings: [...warnings, ...result.warnings],
75
+ errors: [...errors, ...result.errors],
127
76
  source_metadata: {
128
- format: 'gemini-takeout-html',
129
- total_entries: entries.length,
130
- sessions_count: sessions.length,
131
- chunks_count: chunks.length,
132
- total_messages: totalMessages,
133
- date_range: {
134
- earliest: entries[0]?.timestampISO,
135
- latest: entries[entries.length - 1]?.timestampISO,
136
- },
77
+ format: result.format,
78
+ chunks_count: result.chunks.length,
79
+ total_messages: result.total_messages,
80
+ ...(result.records_count ? { records_count: result.records_count } : {}),
81
+ ...(result.skipped ? { skipped_non_gemini: result.skipped } : {}),
137
82
  },
138
83
  };
139
84
  }
140
- /**
141
- * Parse Gemini Takeout HTML into structured entries.
142
- *
143
- * Each outer-cell div contains: "Prompted USER_TEXT<br>TIMESTAMP<br>RESPONSE_HTML"
144
- * all within one content-cell.
145
- */
146
- parseHTML(html) {
147
- const entries = [];
148
- const cellPattern = /<div class="outer-cell[^"]*">([\s\S]*?)(?=<div class="outer-cell|$)/g;
149
- let match;
150
- while ((match = cellPattern.exec(html)) !== null) {
151
- const cell = match[1];
152
- // Only process "Prompted" entries (skip canvas, feedback)
153
- const promptedIdx = cell.indexOf('Prompted\u00a0');
154
- if (promptedIdx === -1)
155
- continue;
156
- // Extract timestamp
157
- const tsMatch = cell.match(/(\d{1,2}\s+\w{3}\s+\d{4},\s+\d{2}:\d{2}:\d{2}\s+\w+)/);
158
- if (!tsMatch)
159
- continue;
160
- const timestampISO = parseTimestamp(tsMatch[1]);
161
- if (!timestampISO)
162
- continue;
163
- // Split on timestamp to separate user prompt from AI response
164
- const afterPrompted = cell.substring(promptedIdx + 'Prompted\u00a0'.length);
165
- const tsPattern = /(\d{1,2}\s+\w{3}\s+\d{4},\s+\d{2}:\d{2}:\d{2}\s+\w+)/;
166
- const tsIdx = afterPrompted.search(tsPattern);
167
- let userPrompt = '';
168
- let aiResponse = '';
169
- if (tsIdx > 0) {
170
- userPrompt = stripHTML(decodeEntities(afterPrompted.substring(0, tsIdx))).trim();
171
- const tsInner = afterPrompted.match(tsPattern);
172
- if (tsInner) {
173
- const afterTs = afterPrompted.substring(tsIdx + tsInner[0].length)
174
- .replace(/^\s*<br\s*\/?>\s*/i, '');
175
- const endDiv = afterTs.search(/<\/div>\s*<div class="content-cell/);
176
- const rawResp = endDiv !== -1 ? afterTs.substring(0, endDiv) : afterTs;
177
- aiResponse = stripHTML(decodeEntities(rawResp)).trim();
178
- }
179
- }
180
- if (userPrompt.length < 3 && aiResponse.length < 3)
181
- continue;
182
- entries.push({
183
- userPrompt,
184
- aiResponse,
185
- timestampISO,
186
- timestampUnix: Math.floor(new Date(timestampISO).getTime() / 1000),
187
- });
188
- }
189
- // Sort chronologically (HTML is newest-first)
190
- entries.sort((a, b) => a.timestampUnix - b.timestampUnix);
191
- return entries;
192
- }
193
- /**
194
- * Group entries into pseudo-sessions by temporal proximity.
195
- */
196
- groupSessions(entries) {
197
- if (entries.length === 0)
198
- return [];
199
- const sessions = [];
200
- let current = [entries[0]];
201
- for (let i = 1; i < entries.length; i++) {
202
- const gap = entries[i].timestampUnix - entries[i - 1].timestampUnix;
203
- if (gap > SESSION_GAP_MINUTES * 60) {
204
- sessions.push(current);
205
- current = [entries[i]];
206
- }
207
- else {
208
- current.push(entries[i]);
209
- }
210
- }
211
- if (current.length > 0)
212
- sessions.push(current);
213
- return sessions;
214
- }
215
85
  }