@totalreclaw/mcp-server 2.3.0 → 2.5.0

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.
@@ -0,0 +1,151 @@
1
+ /**
2
+ * TotalReclaw MCP server — Knowledge Graph helpers for the write + read path.
3
+ *
4
+ * Mirrors `skill/plugin/claims-helper.ts` in behavior. Builds canonical Claim
5
+ * JSON from an MCP-tool fact input, computes entity trapdoors, and decodes
6
+ * decrypted blobs uniformly for both the new Claim shape and the legacy
7
+ * {text, metadata} shape.
8
+ *
9
+ * MCP-specific differences vs the OpenClaw plugin helper:
10
+ * - No LLM compilation in MCP (plan §15.5): we ship digest READ only.
11
+ * Compilation is delegated to OpenClaw/Hermes on the shared vault.
12
+ * - No `hoursSince` / `shouldRecompile` / `DIGEST_CLAIM_CAP` guards.
13
+ * - No dependency on a plugin-local `ExtractedFact` type — MCP accepts
14
+ * raw tool arguments, so the builder takes a small `ClaimInput` struct.
15
+ */
16
+ export type FactType = 'fact' | 'preference' | 'decision' | 'episodic' | 'goal' | 'context' | 'summary';
17
+ export type EntityType = 'person' | 'project' | 'tool' | 'company' | 'concept' | 'place';
18
+ export interface ExtractedEntity {
19
+ name: string;
20
+ type: EntityType;
21
+ role?: string;
22
+ }
23
+ export interface ClaimInput {
24
+ /** Human-readable fact text. */
25
+ text: string;
26
+ /** One of the 7 memory types. Defaults to `fact` when absent. */
27
+ type?: FactType;
28
+ /** LLM-assessed confidence (0.0-1.0). Defaults to 0.85. */
29
+ confidence?: number;
30
+ /** Optional structured entities that surface on search. */
31
+ entities?: ExtractedEntity[];
32
+ }
33
+ export type ClaimFormat = 'claim' | 'legacy';
34
+ /**
35
+ * Resolve the claim-format mode from the TOTALRECLAW_CLAIM_FORMAT env var.
36
+ *
37
+ * - `claim` (default, or unset): new canonical Claim blob, entity trapdoors added.
38
+ * - `legacy`: old {text, metadata} doc shape; entity trapdoors still added.
39
+ *
40
+ * Read on every call so tests can toggle via env without module reload.
41
+ */
42
+ export declare function resolveClaimFormat(): ClaimFormat;
43
+ export declare function mapTypeToCategory(type: FactType | undefined): string;
44
+ export interface BuildClaimInput {
45
+ fact: ClaimInput;
46
+ /** Integer 1-10; may differ from fact input after store-time dedup supersede. */
47
+ importance: number;
48
+ /** Who is writing this claim, e.g. `mcp-server` or `mcp-server:debrief`. */
49
+ sourceAgent: string;
50
+ /** ISO 8601 extracted-at timestamp; defaults to now. */
51
+ extractedAt?: string;
52
+ }
53
+ /**
54
+ * Construct a canonical Claim JSON string from a ClaimInput.
55
+ *
56
+ * The output is byte-identical to what the Rust/Python/plugin clients would
57
+ * produce for the same logical claim (field order, default-omission rules,
58
+ * etc.). Encrypt this string directly — do not re-stringify it.
59
+ */
60
+ export declare function buildCanonicalClaim(input: BuildClaimInput): string;
61
+ export interface BuildLegacyDocInput {
62
+ fact: ClaimInput;
63
+ importance: number;
64
+ source: string;
65
+ createdAt?: string;
66
+ }
67
+ /**
68
+ * Build the legacy `{text, metadata}` document shape.
69
+ *
70
+ * Kept so the TOTALRECLAW_CLAIM_FORMAT=legacy fallback writes blobs that
71
+ * the existing parseClaimOrLegacy read path has always handled.
72
+ */
73
+ export declare function buildLegacyDoc(input: BuildLegacyDocInput): string;
74
+ /**
75
+ * Well-known blind index marker used to locate digest claims on the subgraph.
76
+ * Computed as plain SHA-256("type:digest") — same primitive as word trapdoors
77
+ * so it lives in the existing `blindIndices` array. The `type:` namespace
78
+ * prefix keeps it distinct from any user word trapdoor.
79
+ */
80
+ export declare const DIGEST_TRAPDOOR: string;
81
+ /** Compact category short key for digest claims (ClaimCategory::Digest). */
82
+ export declare const DIGEST_CATEGORY = "dig";
83
+ /** Distinctive source marker so operators can grep for digest writes. */
84
+ export declare const DIGEST_SOURCE_AGENT = "mcp-server-digest";
85
+ export type DigestMode = 'on' | 'off' | 'template';
86
+ /**
87
+ * Resolve TOTALRECLAW_DIGEST_MODE.
88
+ *
89
+ * - `on` (default, unset, unknown): digest injection when a compiled digest
90
+ * is available in the vault.
91
+ * - `off`: legacy individual-fact search path, no digest injection.
92
+ * - `template`: same as `on` for MCP (MCP never compiles digests — the flag
93
+ * is accepted for parity with the plugin so operators can use the same env
94
+ * var across clients).
95
+ *
96
+ * Read per-call so tests can toggle via env without module reload.
97
+ */
98
+ export declare function resolveDigestMode(): DigestMode;
99
+ export interface BlobReadResult {
100
+ text: string;
101
+ importance: number;
102
+ category: string;
103
+ metadata: Record<string, unknown>;
104
+ }
105
+ export declare function readClaimFromBlob(decryptedJson: string): BlobReadResult;
106
+ export interface BuildDigestClaimInput {
107
+ digestJson: string;
108
+ compiledAt: string;
109
+ }
110
+ /**
111
+ * Wrap a serialized Digest JSON as a canonical Claim.
112
+ *
113
+ * MCP does not compile digests (no LLM access). This helper exists solely so
114
+ * tests can round-trip digest claims through the read path, and so any
115
+ * future MCP compilation route would use a shared helper.
116
+ */
117
+ export declare function buildDigestClaim(input: BuildDigestClaimInput): string;
118
+ /**
119
+ * Parse a canonical Claim JSON and, if it is a digest claim, return the
120
+ * wrapped Digest object. Returns null for non-digest claims or parse errors.
121
+ */
122
+ export declare function extractDigestFromClaim(canonicalClaimJson: string): any | null;
123
+ /**
124
+ * Lightweight check: does this decrypted blob look like a digest claim?
125
+ * Used to filter digest blobs out of user-facing recall results.
126
+ *
127
+ * Accepts canonical Claim JSON (`{c:"dig",...}`). Returns false for legacy
128
+ * `{text, metadata}` docs and any parse error.
129
+ */
130
+ export declare function isDigestBlob(decrypted: string): boolean;
131
+ /**
132
+ * Compute a single entity trapdoor: sha256("entity:" + normalized_name) as hex.
133
+ *
134
+ * Uses the same primitive (plain SHA-256, not HMAC) as word / stem trapdoors.
135
+ * The `entity:` prefix namespaces the result so a user called "postgresql"
136
+ * never collides with the word trapdoor for the token "postgresql". The
137
+ * search path must construct queries with the same prefix.
138
+ *
139
+ * Rationale for plain SHA-256 vs HMAC: the existing word trapdoor
140
+ * implementation in `rust/totalreclaw-core/src/blind.rs` uses plain SHA-256
141
+ * of the normalized token. For entity trapdoors to appear in the same
142
+ * blindIndices array and be findable by the current search pipeline, they
143
+ * must use the same primitive. This matches the plugin's decision byte-for-byte.
144
+ */
145
+ export declare function computeEntityTrapdoor(name: string): string;
146
+ /**
147
+ * Compute entity trapdoors for every entity on a fact, deduplicated.
148
+ * Returns an empty array when the fact has no entities.
149
+ */
150
+ export declare function computeEntityTrapdoors(entities: readonly ExtractedEntity[] | undefined): string[];
151
+ //# sourceMappingURL=claims-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claims-helper.d.ts","sourceRoot":"","sources":["../src/claims-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAsBH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,YAAY,GACZ,UAAU,GACV,UAAU,GACV,MAAM,GACN,SAAS,GACT,SAAS,CAAC;AAEd,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAEzF,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,UAAU;IACzB,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,2DAA2D;IAC3D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2DAA2D;IAC3D,QAAQ,CAAC,EAAE,eAAe,EAAE,CAAC;CAC9B;AAMD,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE7C;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,IAAI,WAAW,CAGhD;AAgBD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,GAAG,MAAM,CAGpE;AAMD,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE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B,sBAAsB,CAAC,kBAAkB,EAAE,MAAM,GAAG,GAAG,GAAG,IAAI,CAgB7E;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAOvD;AAMD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,SAAS,GAC/C,MAAM,EAAE,CAYV"}
@@ -0,0 +1,298 @@
1
+ "use strict";
2
+ /**
3
+ * TotalReclaw MCP server — Knowledge Graph helpers for the write + read path.
4
+ *
5
+ * Mirrors `skill/plugin/claims-helper.ts` in behavior. Builds canonical Claim
6
+ * JSON from an MCP-tool fact input, computes entity trapdoors, and decodes
7
+ * decrypted blobs uniformly for both the new Claim shape and the legacy
8
+ * {text, metadata} shape.
9
+ *
10
+ * MCP-specific differences vs the OpenClaw plugin helper:
11
+ * - No LLM compilation in MCP (plan §15.5): we ship digest READ only.
12
+ * Compilation is delegated to OpenClaw/Hermes on the shared vault.
13
+ * - No `hoursSince` / `shouldRecompile` / `DIGEST_CLAIM_CAP` guards.
14
+ * - No dependency on a plugin-local `ExtractedFact` type — MCP accepts
15
+ * raw tool arguments, so the builder takes a small `ClaimInput` struct.
16
+ */
17
+ var __importDefault = (this && this.__importDefault) || function (mod) {
18
+ return (mod && mod.__esModule) ? mod : { "default": mod };
19
+ };
20
+ Object.defineProperty(exports, "__esModule", { value: true });
21
+ exports.DIGEST_SOURCE_AGENT = exports.DIGEST_CATEGORY = exports.DIGEST_TRAPDOOR = void 0;
22
+ exports.resolveClaimFormat = resolveClaimFormat;
23
+ exports.mapTypeToCategory = mapTypeToCategory;
24
+ exports.buildCanonicalClaim = buildCanonicalClaim;
25
+ exports.buildLegacyDoc = buildLegacyDoc;
26
+ exports.resolveDigestMode = resolveDigestMode;
27
+ exports.readClaimFromBlob = readClaimFromBlob;
28
+ exports.buildDigestClaim = buildDigestClaim;
29
+ exports.extractDigestFromClaim = extractDigestFromClaim;
30
+ exports.isDigestBlob = isDigestBlob;
31
+ exports.computeEntityTrapdoor = computeEntityTrapdoor;
32
+ exports.computeEntityTrapdoors = computeEntityTrapdoors;
33
+ const node_crypto_1 = __importDefault(require("node:crypto"));
34
+ // The core WASM package ships as CJS. Jest (ts-jest) compiles MCP sources to
35
+ // commonjs so a plain `require` works there; TSC with `NodeNext` rewrites
36
+ // this to a dynamic import in ESM. Lazy-init so tests can spin up without
37
+ // paying WASM cost at module load.
38
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
39
+ let _wasm = null;
40
+ function getWasm() {
41
+ if (!_wasm) {
42
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
43
+ _wasm = require('@totalreclaw/core');
44
+ }
45
+ return _wasm;
46
+ }
47
+ /**
48
+ * Resolve the claim-format mode from the TOTALRECLAW_CLAIM_FORMAT env var.
49
+ *
50
+ * - `claim` (default, or unset): new canonical Claim blob, entity trapdoors added.
51
+ * - `legacy`: old {text, metadata} doc shape; entity trapdoors still added.
52
+ *
53
+ * Read on every call so tests can toggle via env without module reload.
54
+ */
55
+ function resolveClaimFormat() {
56
+ const raw = (process.env.TOTALRECLAW_CLAIM_FORMAT ?? '').trim().toLowerCase();
57
+ return raw === 'legacy' ? 'legacy' : 'claim';
58
+ }
59
+ // ---------------------------------------------------------------------------
60
+ // Category mapping (fact type → compact Claim category short key)
61
+ // ---------------------------------------------------------------------------
62
+ const TYPE_TO_CATEGORY = {
63
+ fact: 'fact',
64
+ preference: 'pref',
65
+ decision: 'dec',
66
+ episodic: 'epi',
67
+ goal: 'goal',
68
+ context: 'ctx',
69
+ summary: 'sum',
70
+ };
71
+ function mapTypeToCategory(type) {
72
+ if (!type)
73
+ return 'fact';
74
+ return TYPE_TO_CATEGORY[type] ?? 'fact';
75
+ }
76
+ /**
77
+ * Construct a canonical Claim JSON string from a ClaimInput.
78
+ *
79
+ * The output is byte-identical to what the Rust/Python/plugin clients would
80
+ * produce for the same logical claim (field order, default-omission rules,
81
+ * etc.). Encrypt this string directly — do not re-stringify it.
82
+ */
83
+ function buildCanonicalClaim(input) {
84
+ const { fact, importance, sourceAgent, extractedAt } = input;
85
+ const claim = {
86
+ t: fact.text,
87
+ c: mapTypeToCategory(fact.type),
88
+ cf: fact.confidence ?? 0.85,
89
+ i: importance,
90
+ sa: sourceAgent,
91
+ ea: extractedAt ?? new Date().toISOString(),
92
+ };
93
+ if (fact.entities && fact.entities.length > 0) {
94
+ claim.e = fact.entities.map((e) => {
95
+ const entity = { n: e.name, tp: e.type };
96
+ if (e.role)
97
+ entity.r = e.role;
98
+ return entity;
99
+ });
100
+ }
101
+ return getWasm().canonicalizeClaim(JSON.stringify(claim));
102
+ }
103
+ /**
104
+ * Build the legacy `{text, metadata}` document shape.
105
+ *
106
+ * Kept so the TOTALRECLAW_CLAIM_FORMAT=legacy fallback writes blobs that
107
+ * the existing parseClaimOrLegacy read path has always handled.
108
+ */
109
+ function buildLegacyDoc(input) {
110
+ const { fact, importance, source, createdAt } = input;
111
+ return JSON.stringify({
112
+ text: fact.text,
113
+ metadata: {
114
+ type: fact.type ?? 'fact',
115
+ importance: importance / 10,
116
+ source,
117
+ created_at: createdAt ?? new Date().toISOString(),
118
+ },
119
+ });
120
+ }
121
+ // ---------------------------------------------------------------------------
122
+ // Digest helpers (read-only in MCP scope)
123
+ // ---------------------------------------------------------------------------
124
+ /**
125
+ * Well-known blind index marker used to locate digest claims on the subgraph.
126
+ * Computed as plain SHA-256("type:digest") — same primitive as word trapdoors
127
+ * so it lives in the existing `blindIndices` array. The `type:` namespace
128
+ * prefix keeps it distinct from any user word trapdoor.
129
+ */
130
+ exports.DIGEST_TRAPDOOR = node_crypto_1.default
131
+ .createHash('sha256')
132
+ .update('type:digest')
133
+ .digest('hex');
134
+ /** Compact category short key for digest claims (ClaimCategory::Digest). */
135
+ exports.DIGEST_CATEGORY = 'dig';
136
+ /** Distinctive source marker so operators can grep for digest writes. */
137
+ exports.DIGEST_SOURCE_AGENT = 'mcp-server-digest';
138
+ /**
139
+ * Resolve TOTALRECLAW_DIGEST_MODE.
140
+ *
141
+ * - `on` (default, unset, unknown): digest injection when a compiled digest
142
+ * is available in the vault.
143
+ * - `off`: legacy individual-fact search path, no digest injection.
144
+ * - `template`: same as `on` for MCP (MCP never compiles digests — the flag
145
+ * is accepted for parity with the plugin so operators can use the same env
146
+ * var across clients).
147
+ *
148
+ * Read per-call so tests can toggle via env without module reload.
149
+ */
150
+ function resolveDigestMode() {
151
+ const raw = (process.env.TOTALRECLAW_DIGEST_MODE ?? '').trim().toLowerCase();
152
+ if (raw === 'off')
153
+ return 'off';
154
+ if (raw === 'template')
155
+ return 'template';
156
+ return 'on';
157
+ }
158
+ function readClaimFromBlob(decryptedJson) {
159
+ try {
160
+ const obj = JSON.parse(decryptedJson);
161
+ // New canonical Claim format: short keys
162
+ if (typeof obj.t === 'string' && typeof obj.c === 'string') {
163
+ const importance = typeof obj.i === 'number' ? Math.max(1, Math.min(10, Math.round(obj.i))) : 5;
164
+ return {
165
+ text: obj.t,
166
+ importance,
167
+ category: obj.c,
168
+ metadata: {
169
+ type: obj.c,
170
+ importance: importance / 10,
171
+ source: typeof obj.sa === 'string' ? obj.sa : 'mcp_remember',
172
+ created_at: typeof obj.ea === 'string' ? obj.ea : '',
173
+ },
174
+ };
175
+ }
176
+ // Legacy plugin {text, metadata: {importance: 0-1}} format
177
+ if (typeof obj.text === 'string') {
178
+ const meta = obj.metadata ?? {};
179
+ const impFloat = typeof meta.importance === 'number' ? meta.importance : 0.5;
180
+ const importance = Math.max(1, Math.min(10, Math.round(impFloat * 10)));
181
+ return {
182
+ text: obj.text,
183
+ importance,
184
+ category: typeof meta.type === 'string' ? meta.type : 'fact',
185
+ metadata: meta,
186
+ };
187
+ }
188
+ }
189
+ catch {
190
+ // fall through
191
+ }
192
+ return { text: decryptedJson, importance: 5, category: 'fact', metadata: {} };
193
+ }
194
+ /**
195
+ * Wrap a serialized Digest JSON as a canonical Claim.
196
+ *
197
+ * MCP does not compile digests (no LLM access). This helper exists solely so
198
+ * tests can round-trip digest claims through the read path, and so any
199
+ * future MCP compilation route would use a shared helper.
200
+ */
201
+ function buildDigestClaim(input) {
202
+ const { digestJson, compiledAt } = input;
203
+ const claim = {
204
+ t: digestJson,
205
+ c: exports.DIGEST_CATEGORY,
206
+ cf: 1.0,
207
+ i: 10,
208
+ sa: exports.DIGEST_SOURCE_AGENT,
209
+ ea: compiledAt,
210
+ };
211
+ return getWasm().canonicalizeClaim(JSON.stringify(claim));
212
+ }
213
+ /**
214
+ * Parse a canonical Claim JSON and, if it is a digest claim, return the
215
+ * wrapped Digest object. Returns null for non-digest claims or parse errors.
216
+ */
217
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
218
+ function extractDigestFromClaim(canonicalClaimJson) {
219
+ let claim;
220
+ try {
221
+ claim = JSON.parse(canonicalClaimJson);
222
+ }
223
+ catch {
224
+ return null;
225
+ }
226
+ if (claim.c !== exports.DIGEST_CATEGORY || typeof claim.t !== 'string')
227
+ return null;
228
+ try {
229
+ const digest = JSON.parse(claim.t);
230
+ if (typeof digest !== 'object' || digest === null)
231
+ return null;
232
+ if (typeof digest.prompt_text !== 'string')
233
+ return null;
234
+ return digest;
235
+ }
236
+ catch {
237
+ return null;
238
+ }
239
+ }
240
+ /**
241
+ * Lightweight check: does this decrypted blob look like a digest claim?
242
+ * Used to filter digest blobs out of user-facing recall results.
243
+ *
244
+ * Accepts canonical Claim JSON (`{c:"dig",...}`). Returns false for legacy
245
+ * `{text, metadata}` docs and any parse error.
246
+ */
247
+ function isDigestBlob(decrypted) {
248
+ try {
249
+ const obj = JSON.parse(decrypted);
250
+ return obj && typeof obj === 'object' && obj.c === exports.DIGEST_CATEGORY;
251
+ }
252
+ catch {
253
+ return false;
254
+ }
255
+ }
256
+ // ---------------------------------------------------------------------------
257
+ // Entity trapdoors
258
+ // ---------------------------------------------------------------------------
259
+ /**
260
+ * Compute a single entity trapdoor: sha256("entity:" + normalized_name) as hex.
261
+ *
262
+ * Uses the same primitive (plain SHA-256, not HMAC) as word / stem trapdoors.
263
+ * The `entity:` prefix namespaces the result so a user called "postgresql"
264
+ * never collides with the word trapdoor for the token "postgresql". The
265
+ * search path must construct queries with the same prefix.
266
+ *
267
+ * Rationale for plain SHA-256 vs HMAC: the existing word trapdoor
268
+ * implementation in `rust/totalreclaw-core/src/blind.rs` uses plain SHA-256
269
+ * of the normalized token. For entity trapdoors to appear in the same
270
+ * blindIndices array and be findable by the current search pipeline, they
271
+ * must use the same primitive. This matches the plugin's decision byte-for-byte.
272
+ */
273
+ function computeEntityTrapdoor(name) {
274
+ const normalized = getWasm().normalizeEntityName(name);
275
+ return node_crypto_1.default
276
+ .createHash('sha256')
277
+ .update('entity:' + normalized)
278
+ .digest('hex');
279
+ }
280
+ /**
281
+ * Compute entity trapdoors for every entity on a fact, deduplicated.
282
+ * Returns an empty array when the fact has no entities.
283
+ */
284
+ function computeEntityTrapdoors(entities) {
285
+ if (!entities || entities.length === 0)
286
+ return [];
287
+ const seen = new Set();
288
+ const out = [];
289
+ for (const e of entities) {
290
+ const td = computeEntityTrapdoor(e.name);
291
+ if (!seen.has(td)) {
292
+ seen.add(td);
293
+ out.push(td);
294
+ }
295
+ }
296
+ return out;
297
+ }
298
+ //# sourceMappingURL=claims-helper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"claims-helper.js","sourceRoot":"","sources":["../src/claims-helper.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;AAgEH,gDAGC;AAgBD,8CAGC;AAuBD,kDAqBC;AAmBD,wCAWC;AAqCD,8CAKC;AAeD,8CAmCC;AAcD,4CAWC;AAOD,wDAgBC;AASD,oCAOC;AAoBD,sDAMC;AAMD,wDAcC;AAxWD,8DAAiC;AAEjC,6EAA6E;AAC7E,0EAA0E;AAC1E,0EAA0E;AAC1E,mCAAm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