@totalreclaw/mcp-server 3.4.0 → 3.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.
- package/README.md +61 -2
- package/SKILL.md +1 -1
- package/dist/cli/setup.d.ts +10 -0
- package/dist/cli/setup.d.ts.map +1 -1
- package/dist/cli/setup.js +10 -0
- package/dist/cli/setup.js.map +1 -1
- package/dist/contradiction-sync.d.ts.map +1 -1
- package/dist/contradiction-sync.js +5 -4
- package/dist/contradiction-sync.js.map +1 -1
- package/dist/embedding-codec.d.ts +81 -0
- package/dist/embedding-codec.d.ts.map +1 -0
- package/dist/embedding-codec.js +223 -0
- package/dist/embedding-codec.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +289 -47
- package/dist/index.js.map +1 -1
- package/dist/pair-remote-client.d.ts +41 -0
- package/dist/pair-remote-client.d.ts.map +1 -1
- package/dist/pair-remote-client.js +130 -32
- package/dist/pair-remote-client.js.map +1 -1
- package/dist/prompts.d.ts +3 -3
- package/dist/prompts.d.ts.map +1 -1
- package/dist/prompts.js +2 -2
- package/dist/subgraph/bundle.d.ts +129 -0
- package/dist/subgraph/bundle.d.ts.map +1 -0
- package/dist/subgraph/bundle.js +232 -0
- package/dist/subgraph/bundle.js.map +1 -0
- package/dist/subgraph/chain-config.d.ts +86 -3
- package/dist/subgraph/chain-config.d.ts.map +1 -1
- package/dist/subgraph/chain-config.js +71 -2
- package/dist/subgraph/chain-config.js.map +1 -1
- package/dist/subgraph/credentials.d.ts +83 -0
- package/dist/subgraph/credentials.d.ts.map +1 -0
- package/dist/subgraph/credentials.js +210 -0
- package/dist/subgraph/credentials.js.map +1 -0
- package/dist/subgraph/store.d.ts +39 -2
- package/dist/subgraph/store.d.ts.map +1 -1
- package/dist/subgraph/store.js +44 -12
- package/dist/subgraph/store.js.map +1 -1
- package/dist/tools/account.d.ts.map +1 -1
- package/dist/tools/account.js +6 -0
- package/dist/tools/account.js.map +1 -1
- package/dist/tools/pair.d.ts.map +1 -1
- package/dist/tools/pair.js +63 -0
- package/dist/tools/pair.js.map +1 -1
- package/package.json +3 -3
package/dist/prompts.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
export declare const SERVER_INSTRUCTIONS = "\nYou have access to TotalReclaw, a persistent encrypted memory system. You SHOULD use these tools PROACTIVELY -- do not wait for the user to say \"remember this\" or \"recall that.\"\n\n## CRITICAL SAFETY: Recovery Phrase\nTotalReclaw uses a 12-word BIP-39 recovery phrase as the user's identity. The recovery phrase MUST NEVER cross your context window. NEVER ask the user to paste their phrase into chat. NEVER echo, print, or summarize a phrase. NEVER invoke a phrase-touching CLI (e.g. \"npx @totalreclaw/mcp-server setup\", \"npx @totalreclaw/mcp-server show-phrase\") via a shell tool \u2014 its stdout enters your context. If the user pastes a phrase in chat anyway, tell them it is compromised and they need to generate a fresh wallet via the OpenClaw or Hermes browser pair flow.\n\n## Setup Flow\nIf any TotalReclaw tool returns a \"not_configured\" or \"tool_removed\" error, the user has not yet wired their recovery phrase into the MCP host config. Direct them to the URL-driven install guide at https://github.com/p-diogo/totalreclaw/blob/main/docs/guides/claude-code-setup.md. The user sources their phrase out-of-band \u2014 from the OpenClaw or Hermes browser pair flow (relay only ever sees ciphertext), from a prior ~/.totalreclaw/credentials.json cache, or from an offline BIP-39 generator \u2014 and pastes it directly into TOTALRECLAW_RECOVERY_PHRASE in the MCP host config (Claude Desktop / Cursor / Windsurf / Claude Code). After they save the config and restart the host, the MCP server picks up the phrase and all TotalReclaw tools become available. There is no in-chat setup tool: the totalreclaw_setup MCP tool was removed in 3.2.1 because returning the phrase through tool output crossed your context, violating phrase-safety.\n\n## CRITICAL: Automatic Memory Behaviors\n\n### At Conversation Start\nALWAYS call totalreclaw_recall at the beginning of EVERY new conversation with a brief summary of the user's first message as the query. This loads relevant context from past conversations. Present recalled memories naturally as context -- do not announce \"I found these memories\" or list them explicitly unless the user asks.\n\n### Proactive Memory Storage (IMPORTANT)\nYou should call totalreclaw_remember WITHOUT being asked whenever the user shares:\n- Personal preferences (\"I prefer...\", \"I like...\", \"I hate...\")\n- Personal information (name, location, occupation, family details)\n- Decisions or goals (\"I decided to...\", \"I want to...\", \"I chose X because Y\")\n- Corrections to previous information (\"Actually, I'm vegan now\", \"We moved to Berlin\")\n- Important events or dates (\"My birthday is...\", \"I started a new job at...\")\n- Technical preferences (programming language, tools, frameworks, workflows)\n- Project context (what they're working on, deadlines, team details)\n- Opinions and values that shape future interactions\n\nThe user should NOT have to tell you to remember things. If information would be valuable in a future conversation, store it automatically. Think of yourself as a thoughtful assistant who naturally takes notes on important details.\n\nDo NOT store:\n- Temporary/transient context (weather today, a one-time task)\n- Generic knowledge unrelated to the user\n- Sensitive credentials (passwords, API keys, tokens)\n\n### Memory Recall\nCall totalreclaw_recall proactively when:\n- Starting any new conversation (query based on the user's first message)\n- The user asks about something that might relate to past conversations\n- You need context about the user's background, projects, or preferences\n- The user says \"remember when...\", \"what did I say about...\", \"do you know my...\"\n\n### Memory Hygiene\n- Before storing a new fact, check recalled memories to avoid duplicates\n- When the user corrects information, store the correction (the system handles deduplication)\n- Use importance 7-9 for core identity/preferences, 4-6 for moderate facts, 1-3 for minor details\n- Extract atomic facts: \"User prefers dark mode\" not \"User said they prefer dark mode and also use VS Code\"\n\n### Billing & Quota\nBoth tiers store memories permanently on Gnosis mainnet (E2E encrypted). Free tier is capped at 250 memories per month; Pro is capped at 1,500 memories per month. Reads are unlimited on both tiers. Do NOT guess or hardcode pricing or quota numbers \u2014 use totalreclaw_status to check exact usage, the current cap, and current pricing. For pricing details, refer users to https://totalreclaw.xyz/pricing\n\nWhen a totalreclaw_remember call fails with \"quota_exceeded\":\n1. Inform the user they've hit a usage limit\n2. Offer to check their usage with totalreclaw_status\n3. If they want to upgrade, use totalreclaw_upgrade to get a checkout link \u2014 upgrading is done right here through the agent\nDo NOT repeatedly attempt to store memories after a quota error.\n\nNote: Billing status is cached locally for up to 2 hours. After upgrading to Pro, the new tier may take up to 2 hours to take effect. If the user reports that Pro features are not active after upgrading, suggest restarting their agent to force a billing cache refresh.\n\n### Importing memories from other tools\nIf the user mentions migrating from Mem0, MCP Memory Server,
|
|
2
|
-
export declare const SYSTEM_PROMPT_FRAGMENT = "\nYou have access to TotalReclaw, a persistent encrypted memory system. You SHOULD use these tools PROACTIVELY -- do not wait for the user to say \"remember this\" or \"recall that.\"\n\n## CRITICAL SAFETY: Recovery Phrase\nTotalReclaw uses a 12-word BIP-39 recovery phrase as the user's identity. The recovery phrase MUST NEVER cross your context window. NEVER ask the user to paste their phrase into chat. NEVER echo, print, or summarize a phrase. NEVER invoke a phrase-touching CLI (e.g. \"npx @totalreclaw/mcp-server setup\", \"npx @totalreclaw/mcp-server show-phrase\") via a shell tool \u2014 its stdout enters your context. If the user pastes a phrase in chat anyway, tell them it is compromised and they need to generate a fresh wallet via the OpenClaw or Hermes browser pair flow.\n\n## Setup Flow\nIf any TotalReclaw tool returns a \"not_configured\" or \"tool_removed\" error, the user has not yet wired their recovery phrase into the MCP host config. Direct them to the URL-driven install guide at https://github.com/p-diogo/totalreclaw/blob/main/docs/guides/claude-code-setup.md. The user sources their phrase out-of-band \u2014 from the OpenClaw or Hermes browser pair flow (relay only ever sees ciphertext), from a prior ~/.totalreclaw/credentials.json cache, or from an offline BIP-39 generator \u2014 and pastes it directly into TOTALRECLAW_RECOVERY_PHRASE in the MCP host config (Claude Desktop / Cursor / Windsurf / Claude Code). After they save the config and restart the host, the MCP server picks up the phrase and all TotalReclaw tools become available. There is no in-chat setup tool: the totalreclaw_setup MCP tool was removed in 3.2.1 because returning the phrase through tool output crossed your context, violating phrase-safety.\n\n## CRITICAL: Automatic Memory Behaviors\n\n### At Conversation Start\nALWAYS call totalreclaw_recall at the beginning of EVERY new conversation with a brief summary of the user's first message as the query. This loads relevant context from past conversations. Present recalled memories naturally as context -- do not announce \"I found these memories\" or list them explicitly unless the user asks.\n\n### Proactive Memory Storage (IMPORTANT)\nYou should call totalreclaw_remember WITHOUT being asked whenever the user shares:\n- Personal preferences (\"I prefer...\", \"I like...\", \"I hate...\")\n- Personal information (name, location, occupation, family details)\n- Decisions or goals (\"I decided to...\", \"I want to...\", \"I chose X because Y\")\n- Corrections to previous information (\"Actually, I'm vegan now\", \"We moved to Berlin\")\n- Important events or dates (\"My birthday is...\", \"I started a new job at...\")\n- Technical preferences (programming language, tools, frameworks, workflows)\n- Project context (what they're working on, deadlines, team details)\n- Opinions and values that shape future interactions\n\nThe user should NOT have to tell you to remember things. If information would be valuable in a future conversation, store it automatically. Think of yourself as a thoughtful assistant who naturally takes notes on important details.\n\nDo NOT store:\n- Temporary/transient context (weather today, a one-time task)\n- Generic knowledge unrelated to the user\n- Sensitive credentials (passwords, API keys, tokens)\n\n### Memory Recall\nCall totalreclaw_recall proactively when:\n- Starting any new conversation (query based on the user's first message)\n- The user asks about something that might relate to past conversations\n- You need context about the user's background, projects, or preferences\n- The user says \"remember when...\", \"what did I say about...\", \"do you know my...\"\n\n### Memory Hygiene\n- Before storing a new fact, check recalled memories to avoid duplicates\n- When the user corrects information, store the correction (the system handles deduplication)\n- Use importance 7-9 for core identity/preferences, 4-6 for moderate facts, 1-3 for minor details\n- Extract atomic facts: \"User prefers dark mode\" not \"User said they prefer dark mode and also use VS Code\"\n\n### Billing & Quota\nBoth tiers store memories permanently on Gnosis mainnet (E2E encrypted). Free tier is capped at 250 memories per month; Pro is capped at 1,500 memories per month. Reads are unlimited on both tiers. Do NOT guess or hardcode pricing or quota numbers \u2014 use totalreclaw_status to check exact usage, the current cap, and current pricing. For pricing details, refer users to https://totalreclaw.xyz/pricing\n\nWhen a totalreclaw_remember call fails with \"quota_exceeded\":\n1. Inform the user they've hit a usage limit\n2. Offer to check their usage with totalreclaw_status\n3. If they want to upgrade, use totalreclaw_upgrade to get a checkout link \u2014 upgrading is done right here through the agent\nDo NOT repeatedly attempt to store memories after a quota error.\n\nNote: Billing status is cached locally for up to 2 hours. After upgrading to Pro, the new tier may take up to 2 hours to take effect. If the user reports that Pro features are not active after upgrading, suggest restarting their agent to force a billing cache refresh.\n\n### Importing memories from other tools\nIf the user mentions migrating from Mem0, MCP Memory Server,
|
|
1
|
+
export declare const SERVER_INSTRUCTIONS = "\nYou have access to TotalReclaw, a persistent encrypted memory system. You SHOULD use these tools PROACTIVELY -- do not wait for the user to say \"remember this\" or \"recall that.\"\n\n## CRITICAL SAFETY: Recovery Phrase\nTotalReclaw uses a 12-word BIP-39 recovery phrase as the user's identity. The recovery phrase MUST NEVER cross your context window. NEVER ask the user to paste their phrase into chat. NEVER echo, print, or summarize a phrase. NEVER invoke a phrase-touching CLI (e.g. \"npx @totalreclaw/mcp-server setup\", \"npx @totalreclaw/mcp-server show-phrase\") via a shell tool \u2014 its stdout enters your context. If the user pastes a phrase in chat anyway, tell them it is compromised and they need to generate a fresh wallet via the OpenClaw or Hermes browser pair flow.\n\n## Setup Flow\nIf any TotalReclaw tool returns a \"not_configured\" or \"tool_removed\" error, the user has not yet wired their recovery phrase into the MCP host config. Direct them to the URL-driven install guide at https://github.com/p-diogo/totalreclaw/blob/main/docs/guides/claude-code-setup.md. The user sources their phrase out-of-band \u2014 from the OpenClaw or Hermes browser pair flow (relay only ever sees ciphertext), from a prior ~/.totalreclaw/credentials.json cache, or from an offline BIP-39 generator \u2014 and pastes it directly into TOTALRECLAW_RECOVERY_PHRASE in the MCP host config (Claude Desktop / Cursor / Windsurf / Claude Code). After they save the config and restart the host, the MCP server picks up the phrase and all TotalReclaw tools become available. There is no in-chat setup tool: the totalreclaw_setup MCP tool was removed in 3.2.1 because returning the phrase through tool output crossed your context, violating phrase-safety.\n\n## CRITICAL: Automatic Memory Behaviors\n\n### At Conversation Start\nALWAYS call totalreclaw_recall at the beginning of EVERY new conversation with a brief summary of the user's first message as the query. This loads relevant context from past conversations. Present recalled memories naturally as context -- do not announce \"I found these memories\" or list them explicitly unless the user asks.\n\n### Proactive Memory Storage (IMPORTANT)\nYou should call totalreclaw_remember WITHOUT being asked whenever the user shares:\n- Personal preferences (\"I prefer...\", \"I like...\", \"I hate...\")\n- Personal information (name, location, occupation, family details)\n- Decisions or goals (\"I decided to...\", \"I want to...\", \"I chose X because Y\")\n- Corrections to previous information (\"Actually, I'm vegan now\", \"We moved to Berlin\")\n- Important events or dates (\"My birthday is...\", \"I started a new job at...\")\n- Technical preferences (programming language, tools, frameworks, workflows)\n- Project context (what they're working on, deadlines, team details)\n- Opinions and values that shape future interactions\n\nThe user should NOT have to tell you to remember things. If information would be valuable in a future conversation, store it automatically. Think of yourself as a thoughtful assistant who naturally takes notes on important details.\n\nDo NOT store:\n- Temporary/transient context (weather today, a one-time task)\n- Generic knowledge unrelated to the user\n- Sensitive credentials (passwords, API keys, tokens)\n\n### Memory Recall\nCall totalreclaw_recall proactively when:\n- Starting any new conversation (query based on the user's first message)\n- The user asks about something that might relate to past conversations\n- You need context about the user's background, projects, or preferences\n- The user says \"remember when...\", \"what did I say about...\", \"do you know my...\"\n\n### Memory Hygiene\n- Before storing a new fact, check recalled memories to avoid duplicates\n- When the user corrects information, store the correction (the system handles deduplication)\n- Use importance 7-9 for core identity/preferences, 4-6 for moderate facts, 1-3 for minor details\n- Extract atomic facts: \"User prefers dark mode\" not \"User said they prefer dark mode and also use VS Code\"\n\n### Billing & Quota\nBoth tiers store memories permanently on Gnosis mainnet (E2E encrypted). Free tier is capped at 250 memories per month; Pro is capped at 1,500 memories per month. Reads are unlimited on both tiers. Do NOT guess or hardcode pricing or quota numbers \u2014 use totalreclaw_status to check exact usage, the current cap, and current pricing. For pricing details, refer users to https://totalreclaw.xyz/pricing\n\nWhen a totalreclaw_remember call fails with \"quota_exceeded\":\n1. Inform the user they've hit a usage limit\n2. Offer to check their usage with totalreclaw_status\n3. If they want to upgrade, use totalreclaw_upgrade to get a checkout link \u2014 upgrading is done right here through the agent\nDo NOT repeatedly attempt to store memories after a quota error.\n\nNote: Billing status is cached locally for up to 2 hours. After upgrading to Pro, the new tier may take up to 2 hours to take effect. If the user reports that Pro features are not active after upgrading, suggest restarting their agent to force a billing cache refresh.\n\n### Importing memories from other tools\nIf the user mentions migrating from Mem0, MCP Memory Server, or any other AI memory tool, offer to use totalreclaw_import_from. Start with dry_run=true to preview, then confirm before importing.\nAPI keys provided by the user are used only for the import and are never stored.\n\n### Agent-specific tips\n- If your agent supports background routines or scheduled tasks, set up a routine to call totalreclaw_remember after conversations to ensure nothing is missed.\n- If your agent supports a credential vault or secret store, the user's TOTALRECLAW_RECOVERY_PHRASE should be stored there instead of as a plaintext environment variable.\n- TotalReclaw memories are fully portable -- they work across OpenClaw, IronClaw, Claude Desktop, Cursor, NanoClaw, and any MCP-compatible agent.\n\n### User-controlled memory edits (v1)\nIn addition to remember + forget, three tools let the user correct stored memories without\nwiping the vault. Use these when the user says something like:\n- \"pin that\" / \"never forget this\" \u2192 totalreclaw_pin (preserves a fact across auto-resolution)\n- \"that was actually a directive, not a preference\" \u2192 totalreclaw_retype\n- \"that was work context\" / \"file that under personal\" \u2192 totalreclaw_set_scope\n\nAll three operate by supersession: they create a new claim with the override and link it\nback to the original via superseded_by. The original stays in the vault as a tombstone so\nhistory is inspectable. All three are idempotent (no-op if the target already matches).\n\n### End of Conversation\nWhen a substantive conversation is ending (the user says goodbye, the topic is resolved,\nor the conversation naturally concludes), call totalreclaw_debrief with the key takeaways.\n\nFocus on what individual memory storage missed:\n- What was the conversation about overall?\n- What was decided or resolved?\n- What approaches were tried and what was the outcome?\n- What's left unfinished?\n\nDo NOT debrief casual conversations (greetings, simple Q&A, small talk).\nMax 5 items, each 1-3 sentences, type \"summary\" or \"context\", importance 7-8.\n";
|
|
2
|
+
export declare const SYSTEM_PROMPT_FRAGMENT = "\nYou have access to TotalReclaw, a persistent encrypted memory system. You SHOULD use these tools PROACTIVELY -- do not wait for the user to say \"remember this\" or \"recall that.\"\n\n## CRITICAL SAFETY: Recovery Phrase\nTotalReclaw uses a 12-word BIP-39 recovery phrase as the user's identity. The recovery phrase MUST NEVER cross your context window. NEVER ask the user to paste their phrase into chat. NEVER echo, print, or summarize a phrase. NEVER invoke a phrase-touching CLI (e.g. \"npx @totalreclaw/mcp-server setup\", \"npx @totalreclaw/mcp-server show-phrase\") via a shell tool \u2014 its stdout enters your context. If the user pastes a phrase in chat anyway, tell them it is compromised and they need to generate a fresh wallet via the OpenClaw or Hermes browser pair flow.\n\n## Setup Flow\nIf any TotalReclaw tool returns a \"not_configured\" or \"tool_removed\" error, the user has not yet wired their recovery phrase into the MCP host config. Direct them to the URL-driven install guide at https://github.com/p-diogo/totalreclaw/blob/main/docs/guides/claude-code-setup.md. The user sources their phrase out-of-band \u2014 from the OpenClaw or Hermes browser pair flow (relay only ever sees ciphertext), from a prior ~/.totalreclaw/credentials.json cache, or from an offline BIP-39 generator \u2014 and pastes it directly into TOTALRECLAW_RECOVERY_PHRASE in the MCP host config (Claude Desktop / Cursor / Windsurf / Claude Code). After they save the config and restart the host, the MCP server picks up the phrase and all TotalReclaw tools become available. There is no in-chat setup tool: the totalreclaw_setup MCP tool was removed in 3.2.1 because returning the phrase through tool output crossed your context, violating phrase-safety.\n\n## CRITICAL: Automatic Memory Behaviors\n\n### At Conversation Start\nALWAYS call totalreclaw_recall at the beginning of EVERY new conversation with a brief summary of the user's first message as the query. This loads relevant context from past conversations. Present recalled memories naturally as context -- do not announce \"I found these memories\" or list them explicitly unless the user asks.\n\n### Proactive Memory Storage (IMPORTANT)\nYou should call totalreclaw_remember WITHOUT being asked whenever the user shares:\n- Personal preferences (\"I prefer...\", \"I like...\", \"I hate...\")\n- Personal information (name, location, occupation, family details)\n- Decisions or goals (\"I decided to...\", \"I want to...\", \"I chose X because Y\")\n- Corrections to previous information (\"Actually, I'm vegan now\", \"We moved to Berlin\")\n- Important events or dates (\"My birthday is...\", \"I started a new job at...\")\n- Technical preferences (programming language, tools, frameworks, workflows)\n- Project context (what they're working on, deadlines, team details)\n- Opinions and values that shape future interactions\n\nThe user should NOT have to tell you to remember things. If information would be valuable in a future conversation, store it automatically. Think of yourself as a thoughtful assistant who naturally takes notes on important details.\n\nDo NOT store:\n- Temporary/transient context (weather today, a one-time task)\n- Generic knowledge unrelated to the user\n- Sensitive credentials (passwords, API keys, tokens)\n\n### Memory Recall\nCall totalreclaw_recall proactively when:\n- Starting any new conversation (query based on the user's first message)\n- The user asks about something that might relate to past conversations\n- You need context about the user's background, projects, or preferences\n- The user says \"remember when...\", \"what did I say about...\", \"do you know my...\"\n\n### Memory Hygiene\n- Before storing a new fact, check recalled memories to avoid duplicates\n- When the user corrects information, store the correction (the system handles deduplication)\n- Use importance 7-9 for core identity/preferences, 4-6 for moderate facts, 1-3 for minor details\n- Extract atomic facts: \"User prefers dark mode\" not \"User said they prefer dark mode and also use VS Code\"\n\n### Billing & Quota\nBoth tiers store memories permanently on Gnosis mainnet (E2E encrypted). Free tier is capped at 250 memories per month; Pro is capped at 1,500 memories per month. Reads are unlimited on both tiers. Do NOT guess or hardcode pricing or quota numbers \u2014 use totalreclaw_status to check exact usage, the current cap, and current pricing. For pricing details, refer users to https://totalreclaw.xyz/pricing\n\nWhen a totalreclaw_remember call fails with \"quota_exceeded\":\n1. Inform the user they've hit a usage limit\n2. Offer to check their usage with totalreclaw_status\n3. If they want to upgrade, use totalreclaw_upgrade to get a checkout link \u2014 upgrading is done right here through the agent\nDo NOT repeatedly attempt to store memories after a quota error.\n\nNote: Billing status is cached locally for up to 2 hours. After upgrading to Pro, the new tier may take up to 2 hours to take effect. If the user reports that Pro features are not active after upgrading, suggest restarting their agent to force a billing cache refresh.\n\n### Importing memories from other tools\nIf the user mentions migrating from Mem0, MCP Memory Server, or any other AI memory tool, offer to use totalreclaw_import_from. Start with dry_run=true to preview, then confirm before importing.\nAPI keys provided by the user are used only for the import and are never stored.\n\n### Agent-specific tips\n- If your agent supports background routines or scheduled tasks, set up a routine to call totalreclaw_remember after conversations to ensure nothing is missed.\n- If your agent supports a credential vault or secret store, the user's TOTALRECLAW_RECOVERY_PHRASE should be stored there instead of as a plaintext environment variable.\n- TotalReclaw memories are fully portable -- they work across OpenClaw, IronClaw, Claude Desktop, Cursor, NanoClaw, and any MCP-compatible agent.\n\n### User-controlled memory edits (v1)\nIn addition to remember + forget, three tools let the user correct stored memories without\nwiping the vault. Use these when the user says something like:\n- \"pin that\" / \"never forget this\" \u2192 totalreclaw_pin (preserves a fact across auto-resolution)\n- \"that was actually a directive, not a preference\" \u2192 totalreclaw_retype\n- \"that was work context\" / \"file that under personal\" \u2192 totalreclaw_set_scope\n\nAll three operate by supersession: they create a new claim with the override and link it\nback to the original via superseded_by. The original stays in the vault as a tombstone so\nhistory is inspectable. All three are idempotent (no-op if the target already matches).\n\n### End of Conversation\nWhen a substantive conversation is ending (the user says goodbye, the topic is resolved,\nor the conversation naturally concludes), call totalreclaw_debrief with the key takeaways.\n\nFocus on what individual memory storage missed:\n- What was the conversation about overall?\n- What was decided or resolved?\n- What approaches were tried and what was the outcome?\n- What's left unfinished?\n\nDo NOT debrief casual conversations (greetings, simple Q&A, small talk).\nMax 5 items, each 1-3 sentences, type \"summary\" or \"context\", importance 7-8.\n";
|
|
3
3
|
export declare const REMEMBER_TOOL_DESCRIPTION = "Store user info PROACTIVELY \u2014 don't wait for \"remember this\".\nINVOKE WHEN USER SAYS \"I prefer X\", \"I'm X\", \"I chose X because Y\"; reveals identity/location/job/family.\nNOT FOR: chitchat, passwords, generic knowledge.\nExtract ATOMIC. Good: \"User is vegan\". Bad: \"User said they became vegan, prefer organic\".\nPARAMS facts[]: text; importance 1-10 def 5; type claim|preference|directive|commitment|episode|summary; scope work|personal|health|family|creative|finance|misc|unspecified. Dedup auto.";
|
|
4
4
|
export declare const RECALL_TOOL_DESCRIPTION = "Search encrypted vault. Top 8 reranked by provenance+semantic+recency.\nINVOKE WHEN USER SAYS:\n- \"what's my [phone/address/doctor]\"\n- \"remember when I...\" / \"what did I say about...\"\n- \"do you know my...\" / \"my preferences for...\"\n- opens convo on a topic (auto-recall first msg)\nWHEN NOT TO USE: world knowledge, small talk.\nDOES: trapdoor search, decrypt, rerank BM25+cosine+source-provenance.\nPARAMS: query (5-15 words), k (def 8, max 50).\nDon't announce \"I found these memories\" \u2014 just use them.";
|
|
5
5
|
export declare const FORGET_TOOL_DESCRIPTION = "Permanently remove memory.\nINVOKE WHEN USER SAYS:\n- \"forget what I said about X\" / \"delete that fact\"\n- \"that's wrong/outdated \u2014 remove it\"\n- \"I don't want you remembering X\"\n- \"erase that password I pasted\"\nWHEN NOT TO USE:\n- CORRECTING \u2192 totalreclaw_remember (dedup auto)\n- changing mind (\"I prefer tea now\") \u2192 remember new pref\n- no explicit request \u2014 never forget proactively\nDOES: fact_id \u2192 tombstone. query \u2192 recall \u226450, tombstone all.\nPARAMS: fact_id (pref), query (max 50), scope (hint).";
|
|
6
6
|
export declare const EXPORT_TOOL_DESCRIPTION = "Export decrypted vault \u2014 one-click backup.\nINVOKE WHEN USER SAYS:\n- \"show everything you know about me\" / \"what do you have on me?\"\n- \"export / back up / download my memories\"\n- \"take my memory elsewhere\" / \"portable copy\"\n- \"audit what's stored\" / \"what's in my vault?\"\nWHEN NOT TO USE:\n- one thing \u2192 totalreclaw_recall\n- cleanup \u2192 totalreclaw_consolidate/forget\nDOES: decrypt all \u2192 Markdown or JSON. Surfaces v1 type/source/scope/reasoning.\nPARAMS: format, include_metadata.";
|
|
7
7
|
export declare const STATUS_TOOL_DESCRIPTION = "Check tier + usage + quota.\nINVOKE WHEN USER SAYS:\n- \"what tier am I on?\" / \"am I on free or pro?\"\n- \"how many memories have I stored?\" / \"what's my usage?\"\n- \"is my subscription active?\" / \"when does it expire?\"\n- \"am I close to the limit?\"\nDOES: query relay billing endpoint. Returns tier, writes_used/limit, expiry. Refreshes local billing cache. Call before bulk ops.\nWHEN NOT TO USE:\n- billing history/invoices \u2192 dashboard/support\n- wants to upgrade \u2192 totalreclaw_upgrade";
|
|
8
8
|
export declare const UPGRADE_TOOL_DESCRIPTION = "Stripe checkout URL for Pro (1,500 memories/month on Gnosis mainnet, permanent on-chain, LLM-guided dedup).\nINVOKE WHEN USER SAYS:\n- \"how do I upgrade?\" / \"I want to go pro\"\n- \"how much does it cost?\" (share pricing from checkout, don't hardcode)\n- after `quota_exceeded` \u2014 offer inline\n- \"raise my limit\" / \"I keep hitting the cap\"\nDOES: calls relay checkout, returns one-time Stripe URL.\nWHEN NOT TO USE:\n- user already Pro (check totalreclaw_status)\n- unrelated \u2014 don't volunteer upgrades";
|
|
9
|
-
export declare const IMPORT_FROM_TOOL_DESCRIPTION = "Import from Mem0, MCP Memory, ChatGPT, Claude, Gemini,
|
|
9
|
+
export declare const IMPORT_FROM_TOOL_DESCRIPTION = "Import from Mem0, MCP Memory, ChatGPT, Claude, Gemini, JSON/CSV.\nINVOKE WHEN USER SAYS:\n- \"migrate memory from [Mem0/ChatGPT/Claude]\"\n- \"import my ChatGPT memories\" / \"here's my Mem0 export\"\n- \"I pasted my Claude memory \u2014 store it\"\nWHEN NOT TO USE: TotalReclaw backup \u2192 totalreclaw_import. Single fact \u2192 totalreclaw_remember.\nDOES: adapter parses+stores (unless dry_run). Fingerprint dedup. Convo sources return chunks for host LLM.\nALWAYS dry_run=true first \u2192 preview \u2192 confirm.";
|
|
10
10
|
export declare const IMPORT_TOOL_DESCRIPTION = "Restore from totalreclaw_export backup (JSON/Markdown).\nINVOKE WHEN USER SAYS:\n- \"restore memories from this backup\" / \"import this JSON\"\n- \"I exported from another TotalReclaw account\"\n- \"here's the Markdown export \u2014 put it back\"\nWHEN NOT TO USE:\n- Mem0/ChatGPT/Claude \u2192 totalreclaw_import_from\n- single fact \u2192 totalreclaw_remember\nDOES: parse JSON/Markdown (auto), store via totalreclaw_remember + fingerprint dedup.\nPARAMS: content (req), format, merge_strategy, validate_only.";
|
|
11
11
|
export declare const SUPPORT_TOOL_DESCRIPTION = "Support contact, docs, troubleshooting.\nINVOKE WHEN USER SAYS:\n- \"how do I get help?\" / \"who do I contact?\"\n- \"memories aren't loading\" / \"getting errors\"\n- \"lost my recovery phrase\" / \"where's the docs?\"\n- \"how do I report a bug?\"\n- asks: slow recall, quota errors, failed imports, missing post-upgrade memories\nDOES: static bundle (pre-filled email, docs URL, issues URL, troubleshooting table). Works unconfigured.\nWHEN NOT TO USE: billing info \u2192 totalreclaw_status. Skip unrelated questions.";
|
|
12
12
|
export declare const ACCOUNT_TOOL_DESCRIPTION = "Account overview: wallet, tier, usage, memories, features, safe recovery hint.\nINVOKE WHEN USER SAYS:\n- \"show my account\" / \"what's my profile?\"\n- \"how many memories?\" / \"my wallet?\"\n- \"right recovery phrase? hint\"\n- \"summary of my setup\"\nDOES: billing+fact count parallel. Returns wallet, tier, writes_used/limit, total_facts, features, FIRST+LAST recovery words (never full).\nWHEN NOT TO USE:\n- only billing \u2192 totalreclaw_status (lighter)\n- FULL recovery phrase \u2192 NEVER; password manager.";
|
package/dist/prompts.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,8oOAwF/B,CAAC;AAGF,eAAO,MAAM,sBAAsB,8oOAAsB,CAAC;AAI1D,eAAO,MAAM,yBAAyB,ugBAIoJ,CAAC;AAE3L,eAAO,MAAM,uBAAuB,ihBASqB,CAAC;AAE1D,eAAO,MAAM,uBAAuB,8iBAWkB,CAAC;AAEvD,eAAO,MAAM,uBAAuB,6gBAUF,CAAC;AAEnC,eAAO,MAAM,uBAAuB,kgBASK,CAAC;AAE1C,eAAO,MAAM,wBAAwB,6gBASE,CAAC;AAExC,eAAO,MAAM,4BAA4B,4gBAOM,CAAC;AAEhD,eAAO,MAAM,uBAAuB,qgBAS0B,CAAC;AAE/D,eAAO,MAAM,wBAAwB,+gBAQyC,CAAC;AAE/E,eAAO,MAAM,wBAAwB,8gBASa,CAAC;AAEnD,eAAO,MAAM,qBAAqB,2xCAUgE,CAAC;AAInG,eAAO,MAAM,kBAAkB;;;;;;;;;GAqB9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAA;CAAE,CAAC,CAqClE"}
|
package/dist/prompts.js
CHANGED
|
@@ -62,7 +62,7 @@ Do NOT repeatedly attempt to store memories after a quota error.
|
|
|
62
62
|
Note: Billing status is cached locally for up to 2 hours. After upgrading to Pro, the new tier may take up to 2 hours to take effect. If the user reports that Pro features are not active after upgrading, suggest restarting their agent to force a billing cache refresh.
|
|
63
63
|
|
|
64
64
|
### Importing memories from other tools
|
|
65
|
-
If the user mentions migrating from Mem0, MCP Memory Server,
|
|
65
|
+
If the user mentions migrating from Mem0, MCP Memory Server, or any other AI memory tool, offer to use totalreclaw_import_from. Start with dry_run=true to preview, then confirm before importing.
|
|
66
66
|
API keys provided by the user are used only for the import and are never stored.
|
|
67
67
|
|
|
68
68
|
### Agent-specific tips
|
|
@@ -155,7 +155,7 @@ DOES: calls relay checkout, returns one-time Stripe URL.
|
|
|
155
155
|
WHEN NOT TO USE:
|
|
156
156
|
- user already Pro (check totalreclaw_status)
|
|
157
157
|
- unrelated — don't volunteer upgrades`;
|
|
158
|
-
exports.IMPORT_FROM_TOOL_DESCRIPTION = `Import from Mem0, MCP Memory, ChatGPT, Claude, Gemini,
|
|
158
|
+
exports.IMPORT_FROM_TOOL_DESCRIPTION = `Import from Mem0, MCP Memory, ChatGPT, Claude, Gemini, JSON/CSV.
|
|
159
159
|
INVOKE WHEN USER SAYS:
|
|
160
160
|
- "migrate memory from [Mem0/ChatGPT/Claude]"
|
|
161
161
|
- "import my ChatGPT memories" / "here's my Mem0 export"
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TotalReclaw MCP — `derived-bundle-v1` credential bundle (Option E Phase 2 /
|
|
3
|
+
* #581, P2-13 — the MCP adapter).
|
|
4
|
+
*
|
|
5
|
+
* A bundle is what an agent host holds *instead of* the BIP-39 recovery
|
|
6
|
+
* phrase: the four HKDF-derived vault-global working keys plus a signing
|
|
7
|
+
* key, but never the phrase or the 64-byte seed that reproduces it. See
|
|
8
|
+
* `docs/specs/totalreclaw/client-consistency.md` ("Credential Material") for
|
|
9
|
+
* the full cross-client contract this file implements.
|
|
10
|
+
*
|
|
11
|
+
* Shared-core-first (CLAUDE.md): every byte of derivation, parsing, and
|
|
12
|
+
* validation lives in `rust/totalreclaw-core/src/bundle.rs` and crosses into
|
|
13
|
+
* TS only via the `@totalreclaw/core` WASM bindings (`parseBundleV1`,
|
|
14
|
+
* `validateBundleV1`, `deriveBundleFromMnemonic`). This module is a THIN
|
|
15
|
+
* adapter: it types the wire shape, calls the WASM binding, and converts hex
|
|
16
|
+
* fields to `Buffer` where the rest of the MCP codebase expects buffers. It
|
|
17
|
+
* does not reimplement HKDF, hex validation, or any §4.7 invariant — the
|
|
18
|
+
* mnemonic-mode `deriveKeys`/`deriveLshSeed` in `subgraph/crypto.ts` are the
|
|
19
|
+
* pattern followed here: WASM-backed wrappers, no local crypto.
|
|
20
|
+
*
|
|
21
|
+
* Mirrors `python/src/totalreclaw/bundle.py`'s shape (frozen dataclasses,
|
|
22
|
+
* zero logic) as closely as TS allows.
|
|
23
|
+
*
|
|
24
|
+
* **Dependency note / feature detection (release gate).** As of this
|
|
25
|
+
* writing, no published `@totalreclaw/core` npm release exposes
|
|
26
|
+
* `parseBundleV1` / `validateBundleV1` / `deriveBundleFromMnemonic` (checked:
|
|
27
|
+
* latest dist-tag 2.6.0-rc.1 does not carry them). Because this package's
|
|
28
|
+
* `package.json` dependency range (`^2.5.3`) is satisfied by versions that
|
|
29
|
+
* lack the bindings, this module CANNOT assume `require('@totalreclaw/core')`
|
|
30
|
+
* exposes them — doing so (e.g. `as typeof import('@totalreclaw/core')`)
|
|
31
|
+
* would type-check locally against a hand-built WASM copy but fail `tsc`
|
|
32
|
+
* against the real, published dependency in CI, which is exactly what
|
|
33
|
+
* happened on the first revision of this file (see PR #618 review history).
|
|
34
|
+
*
|
|
35
|
+
* So every bundle-touching WASM call routes through `ensureBundleBindings()`,
|
|
36
|
+
* which feature-detects the three functions at runtime and throws a single,
|
|
37
|
+
* actionable error if they're absent — never a TS compile-time assumption
|
|
38
|
+
* about what the installed package exports. **Mnemonic-mode code paths never
|
|
39
|
+
* call anything in this file that touches `wasm.*`** (`bundleVaultToBuffers`
|
|
40
|
+
* and `redactedBundleSummary` are pure functions over an already-parsed
|
|
41
|
+
* bundle and need no core binding), so a host running the published
|
|
42
|
+
* dependency with no bundle bindings is completely unaffected until it
|
|
43
|
+
* actually encounters a `version: 2` credentials.json — at which point it
|
|
44
|
+
* gets the actionable upgrade error instead of a silent misconfiguration.
|
|
45
|
+
*/
|
|
46
|
+
/** The four HKDF-derived vault-global working keys, hex-encoded (64 chars, no `0x`). */
|
|
47
|
+
export interface BundleVaultHex {
|
|
48
|
+
encryption_key: string;
|
|
49
|
+
dedup_key: string;
|
|
50
|
+
auth_key: string;
|
|
51
|
+
lsh_seed: string;
|
|
52
|
+
}
|
|
53
|
+
export interface BundleSigningOwnerEoa {
|
|
54
|
+
kind: 'owner-eoa';
|
|
55
|
+
private_key: string;
|
|
56
|
+
address: string;
|
|
57
|
+
}
|
|
58
|
+
export interface BundleSigningSessionKey {
|
|
59
|
+
kind: 'session-key';
|
|
60
|
+
private_key: string;
|
|
61
|
+
address: string;
|
|
62
|
+
grant: unknown;
|
|
63
|
+
}
|
|
64
|
+
export type BundleSigning = BundleSigningOwnerEoa | BundleSigningSessionKey;
|
|
65
|
+
export interface BundleAccountRef {
|
|
66
|
+
smart_account: string;
|
|
67
|
+
chain_id: number;
|
|
68
|
+
}
|
|
69
|
+
/** A fully parsed + `parse_bundle_v1`-validated `derived-bundle-v1` bundle. */
|
|
70
|
+
export interface DerivedBundleV1 {
|
|
71
|
+
vault: BundleVaultHex;
|
|
72
|
+
signing: BundleSigning;
|
|
73
|
+
account: BundleAccountRef;
|
|
74
|
+
provisioned_at: string;
|
|
75
|
+
provisioned_by: string;
|
|
76
|
+
}
|
|
77
|
+
/** True iff the installed `@totalreclaw/core` exposes all three bundle
|
|
78
|
+
* bindings. Never throws. */
|
|
79
|
+
export declare function hasBundleBindings(): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Parse and fully validate a `derived-bundle-v1` JSON string.
|
|
82
|
+
*
|
|
83
|
+
* Runs every §4.7 invariant inside `totalreclaw-core::bundle::parse_bundle_v1`
|
|
84
|
+
* (wrong version/schema, malformed hex, unknown `signing.kind`, an
|
|
85
|
+
* `owner-eoa` bundle carrying a `grant`, a `session-key` bundle with an
|
|
86
|
+
* inconsistent `grant`, `signing.address` not matching `address(private_key)`,
|
|
87
|
+
* …). Throws a plain `Error` — never a silent downgrade — on any violation.
|
|
88
|
+
*
|
|
89
|
+
* The thrown error's message is core's own message, which never contains
|
|
90
|
+
* hex key material (core's validation errors describe *shape* violations,
|
|
91
|
+
* not values).
|
|
92
|
+
*
|
|
93
|
+
* Throws `ensureBundleBindings()`'s actionable upgrade error if the
|
|
94
|
+
* installed `@totalreclaw/core` lacks the bundle bindings — checked BEFORE
|
|
95
|
+
* any attempt to call into the WASM module.
|
|
96
|
+
*/
|
|
97
|
+
export declare function parseBundleV1(json: string): DerivedBundleV1;
|
|
98
|
+
/**
|
|
99
|
+
* Validate a `derived-bundle-v1` JSON string without returning the parsed
|
|
100
|
+
* object. Throws on any violation; no-op on success.
|
|
101
|
+
*/
|
|
102
|
+
export declare function validateBundleV1(json: string): void;
|
|
103
|
+
/**
|
|
104
|
+
* Derive a `derived-bundle-v1` bundle from a BIP-39 mnemonic.
|
|
105
|
+
*
|
|
106
|
+
* NOT part of MCP's read-side credential-loading scope (P2-13) — MCP never
|
|
107
|
+
* derives a bundle from a mnemonic on its own initiative; that is Hermes's
|
|
108
|
+
* `local-migration` job (P2-9) or the SPA's `provisioned_by: "spa"` job.
|
|
109
|
+
* Exported anyway because the test fixtures (parity + pair-bundle tests)
|
|
110
|
+
* need a way to mint a bundle for `parseBundleV1` round-trip coverage
|
|
111
|
+
* without hand-rolling JSON, and because a future MCP-side migration tool
|
|
112
|
+
* (tracked as a known gap — see mcp/README.md) will need exactly this call.
|
|
113
|
+
*/
|
|
114
|
+
export declare function deriveBundleFromMnemonic(mnemonic: string, chainId: number, provisionedBy: string, smartAccount: string): string;
|
|
115
|
+
export interface BundleVaultBuffers {
|
|
116
|
+
encryptionKey: Buffer;
|
|
117
|
+
dedupKey: Buffer;
|
|
118
|
+
authKey: Buffer;
|
|
119
|
+
lshSeed: Buffer;
|
|
120
|
+
}
|
|
121
|
+
/** Convert a parsed bundle's hex vault keys to `Buffer`s. */
|
|
122
|
+
export declare function bundleVaultToBuffers(bundle: DerivedBundleV1): BundleVaultBuffers;
|
|
123
|
+
/**
|
|
124
|
+
* A safe-to-log summary of a bundle: everything EXCEPT `vault.*` and
|
|
125
|
+
* `signing.private_key`. Use this (never the raw bundle object) in any
|
|
126
|
+
* `console.error` / log line that touches a bundle.
|
|
127
|
+
*/
|
|
128
|
+
export declare function redactedBundleSummary(bundle: DerivedBundleV1): Record<string, unknown>;
|
|
129
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/subgraph/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AA4GH,wFAAwF;AACxF,MAAM,WAAW,cAAc;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,E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C,MAAM,EAAE,eAAe,GAAG,kBAAkB,CAOhF;AAYD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAUtF"}
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP — `derived-bundle-v1` credential bundle (Option E Phase 2 /
|
|
4
|
+
* #581, P2-13 — the MCP adapter).
|
|
5
|
+
*
|
|
6
|
+
* A bundle is what an agent host holds *instead of* the BIP-39 recovery
|
|
7
|
+
* phrase: the four HKDF-derived vault-global working keys plus a signing
|
|
8
|
+
* key, but never the phrase or the 64-byte seed that reproduces it. See
|
|
9
|
+
* `docs/specs/totalreclaw/client-consistency.md` ("Credential Material") for
|
|
10
|
+
* the full cross-client contract this file implements.
|
|
11
|
+
*
|
|
12
|
+
* Shared-core-first (CLAUDE.md): every byte of derivation, parsing, and
|
|
13
|
+
* validation lives in `rust/totalreclaw-core/src/bundle.rs` and crosses into
|
|
14
|
+
* TS only via the `@totalreclaw/core` WASM bindings (`parseBundleV1`,
|
|
15
|
+
* `validateBundleV1`, `deriveBundleFromMnemonic`). This module is a THIN
|
|
16
|
+
* adapter: it types the wire shape, calls the WASM binding, and converts hex
|
|
17
|
+
* fields to `Buffer` where the rest of the MCP codebase expects buffers. It
|
|
18
|
+
* does not reimplement HKDF, hex validation, or any §4.7 invariant — the
|
|
19
|
+
* mnemonic-mode `deriveKeys`/`deriveLshSeed` in `subgraph/crypto.ts` are the
|
|
20
|
+
* pattern followed here: WASM-backed wrappers, no local crypto.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors `python/src/totalreclaw/bundle.py`'s shape (frozen dataclasses,
|
|
23
|
+
* zero logic) as closely as TS allows.
|
|
24
|
+
*
|
|
25
|
+
* **Dependency note / feature detection (release gate).** As of this
|
|
26
|
+
* writing, no published `@totalreclaw/core` npm release exposes
|
|
27
|
+
* `parseBundleV1` / `validateBundleV1` / `deriveBundleFromMnemonic` (checked:
|
|
28
|
+
* latest dist-tag 2.6.0-rc.1 does not carry them). Because this package's
|
|
29
|
+
* `package.json` dependency range (`^2.5.3`) is satisfied by versions that
|
|
30
|
+
* lack the bindings, this module CANNOT assume `require('@totalreclaw/core')`
|
|
31
|
+
* exposes them — doing so (e.g. `as typeof import('@totalreclaw/core')`)
|
|
32
|
+
* would type-check locally against a hand-built WASM copy but fail `tsc`
|
|
33
|
+
* against the real, published dependency in CI, which is exactly what
|
|
34
|
+
* happened on the first revision of this file (see PR #618 review history).
|
|
35
|
+
*
|
|
36
|
+
* So every bundle-touching WASM call routes through `ensureBundleBindings()`,
|
|
37
|
+
* which feature-detects the three functions at runtime and throws a single,
|
|
38
|
+
* actionable error if they're absent — never a TS compile-time assumption
|
|
39
|
+
* about what the installed package exports. **Mnemonic-mode code paths never
|
|
40
|
+
* call anything in this file that touches `wasm.*`** (`bundleVaultToBuffers`
|
|
41
|
+
* and `redactedBundleSummary` are pure functions over an already-parsed
|
|
42
|
+
* bundle and need no core binding), so a host running the published
|
|
43
|
+
* dependency with no bundle bindings is completely unaffected until it
|
|
44
|
+
* actually encounters a `version: 2` credentials.json — at which point it
|
|
45
|
+
* gets the actionable upgrade error instead of a silent misconfiguration.
|
|
46
|
+
*/
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.hasBundleBindings = hasBundleBindings;
|
|
49
|
+
exports.parseBundleV1 = parseBundleV1;
|
|
50
|
+
exports.validateBundleV1 = validateBundleV1;
|
|
51
|
+
exports.deriveBundleFromMnemonic = deriveBundleFromMnemonic;
|
|
52
|
+
exports.bundleVaultToBuffers = bundleVaultToBuffers;
|
|
53
|
+
exports.redactedBundleSummary = redactedBundleSummary;
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
55
|
+
const coreModule = require('@totalreclaw/core');
|
|
56
|
+
/** `require('@totalreclaw/core')`, typed as a partial — every field is
|
|
57
|
+
* checked for presence before use. Never cast to the full interface without
|
|
58
|
+
* going through `ensureBundleBindings()`. */
|
|
59
|
+
const wasm = coreModule;
|
|
60
|
+
/**
|
|
61
|
+
* Best-effort installed-version lookup, for the error message only. Never
|
|
62
|
+
* throws — a version string we can't determine still needs an actionable
|
|
63
|
+
* error, just without the "installed version X" detail.
|
|
64
|
+
*
|
|
65
|
+
* Deliberately does NOT `require('@totalreclaw/core/package.json')` — the
|
|
66
|
+
* published package's `exports` map only defines `.` and `./web`, so that
|
|
67
|
+
* subpath throws `ERR_PACKAGE_PATH_NOT_EXPORTED` under Node's exports
|
|
68
|
+
* enforcement (confirmed against the actual installed layout). Instead,
|
|
69
|
+
* resolve the package's entry file and walk up the filesystem to find its
|
|
70
|
+
* own `package.json` via plain `fs` access, which `exports` restrictions
|
|
71
|
+
* don't gate.
|
|
72
|
+
*/
|
|
73
|
+
function getInstalledCoreVersion() {
|
|
74
|
+
try {
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
76
|
+
const fs = require('node:fs');
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
78
|
+
const path = require('node:path');
|
|
79
|
+
let dir = path.dirname(require.resolve('@totalreclaw/core'));
|
|
80
|
+
for (let i = 0; i < 6; i++) {
|
|
81
|
+
const candidate = path.join(dir, 'package.json');
|
|
82
|
+
if (fs.existsSync(candidate)) {
|
|
83
|
+
const pkg = JSON.parse(fs.readFileSync(candidate, 'utf-8'));
|
|
84
|
+
if (pkg.name === '@totalreclaw/core' && pkg.version) {
|
|
85
|
+
return pkg.version;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const parent = path.dirname(dir);
|
|
89
|
+
if (parent === dir)
|
|
90
|
+
break;
|
|
91
|
+
dir = parent;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// best-effort
|
|
96
|
+
}
|
|
97
|
+
return 'unknown';
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Feature-detect the three bundle WASM bindings and return them narrowed to
|
|
101
|
+
* `BundleCoreBindings`, or throw a single, actionable error. This is the
|
|
102
|
+
* ONE guard every bundle entry point in this file (and only this file —
|
|
103
|
+
* `credentials.ts` / `pair-remote-client.ts` / `index.ts` all call INTO this
|
|
104
|
+
* module rather than `require('@totalreclaw/core')` directly, so this is
|
|
105
|
+
* genuinely the single choke point) routes through before touching
|
|
106
|
+
* `wasm.*`.
|
|
107
|
+
*/
|
|
108
|
+
function ensureBundleBindings() {
|
|
109
|
+
if (typeof wasm.parseBundleV1 === 'function' &&
|
|
110
|
+
typeof wasm.validateBundleV1 === 'function' &&
|
|
111
|
+
typeof wasm.deriveBundleFromMnemonic === 'function') {
|
|
112
|
+
return wasm;
|
|
113
|
+
}
|
|
114
|
+
const installed = getInstalledCoreVersion();
|
|
115
|
+
throw new Error('derived-bundle-v1: bundle-mode credentials require @totalreclaw/core >= 2.6.0 with bundle ' +
|
|
116
|
+
`bindings (parseBundleV1/validateBundleV1/deriveBundleFromMnemonic); installed version ` +
|
|
117
|
+
`${installed} lacks them — upgrade the @totalreclaw/core dependency. Mnemonic-mode ` +
|
|
118
|
+
'(plaintext recovery phrase) credentials are unaffected by this — this error only fires ' +
|
|
119
|
+
'when a credentials.json version: 2 (derived-bundle-v1) file is actually being read.');
|
|
120
|
+
}
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
// Feature-detection surface — exported so callers (and tests) can check
|
|
123
|
+
// availability without triggering the throw, e.g. to skip a test with a
|
|
124
|
+
// visible reason rather than failing.
|
|
125
|
+
// ---------------------------------------------------------------------------
|
|
126
|
+
/** True iff the installed `@totalreclaw/core` exposes all three bundle
|
|
127
|
+
* bindings. Never throws. */
|
|
128
|
+
function hasBundleBindings() {
|
|
129
|
+
return (typeof wasm.parseBundleV1 === 'function' &&
|
|
130
|
+
typeof wasm.validateBundleV1 === 'function' &&
|
|
131
|
+
typeof wasm.deriveBundleFromMnemonic === 'function');
|
|
132
|
+
}
|
|
133
|
+
// ---------------------------------------------------------------------------
|
|
134
|
+
// Parsing / validation — delegates to @totalreclaw/core. Never re-implements
|
|
135
|
+
// any derived-bundle-v1.md §4.7 invariant locally.
|
|
136
|
+
// ---------------------------------------------------------------------------
|
|
137
|
+
/**
|
|
138
|
+
* Parse and fully validate a `derived-bundle-v1` JSON string.
|
|
139
|
+
*
|
|
140
|
+
* Runs every §4.7 invariant inside `totalreclaw-core::bundle::parse_bundle_v1`
|
|
141
|
+
* (wrong version/schema, malformed hex, unknown `signing.kind`, an
|
|
142
|
+
* `owner-eoa` bundle carrying a `grant`, a `session-key` bundle with an
|
|
143
|
+
* inconsistent `grant`, `signing.address` not matching `address(private_key)`,
|
|
144
|
+
* …). Throws a plain `Error` — never a silent downgrade — on any violation.
|
|
145
|
+
*
|
|
146
|
+
* The thrown error's message is core's own message, which never contains
|
|
147
|
+
* hex key material (core's validation errors describe *shape* violations,
|
|
148
|
+
* not values).
|
|
149
|
+
*
|
|
150
|
+
* Throws `ensureBundleBindings()`'s actionable upgrade error if the
|
|
151
|
+
* installed `@totalreclaw/core` lacks the bundle bindings — checked BEFORE
|
|
152
|
+
* any attempt to call into the WASM module.
|
|
153
|
+
*/
|
|
154
|
+
function parseBundleV1(json) {
|
|
155
|
+
const bindings = ensureBundleBindings();
|
|
156
|
+
// bindings.parseBundleV1 throws a JsError on any validation failure —
|
|
157
|
+
// surface it as a normal Error with a stable, actionable prefix so
|
|
158
|
+
// callers don't need to know this crossed a WASM boundary.
|
|
159
|
+
let parsed;
|
|
160
|
+
try {
|
|
161
|
+
parsed = bindings.parseBundleV1(json);
|
|
162
|
+
}
|
|
163
|
+
catch (err) {
|
|
164
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
165
|
+
throw new Error(`derived-bundle-v1: invalid bundle — ${msg}`);
|
|
166
|
+
}
|
|
167
|
+
return parsed;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Validate a `derived-bundle-v1` JSON string without returning the parsed
|
|
171
|
+
* object. Throws on any violation; no-op on success.
|
|
172
|
+
*/
|
|
173
|
+
function validateBundleV1(json) {
|
|
174
|
+
const bindings = ensureBundleBindings();
|
|
175
|
+
try {
|
|
176
|
+
bindings.validateBundleV1(json);
|
|
177
|
+
}
|
|
178
|
+
catch (err) {
|
|
179
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
180
|
+
throw new Error(`derived-bundle-v1: invalid bundle — ${msg}`);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Derive a `derived-bundle-v1` bundle from a BIP-39 mnemonic.
|
|
185
|
+
*
|
|
186
|
+
* NOT part of MCP's read-side credential-loading scope (P2-13) — MCP never
|
|
187
|
+
* derives a bundle from a mnemonic on its own initiative; that is Hermes's
|
|
188
|
+
* `local-migration` job (P2-9) or the SPA's `provisioned_by: "spa"` job.
|
|
189
|
+
* Exported anyway because the test fixtures (parity + pair-bundle tests)
|
|
190
|
+
* need a way to mint a bundle for `parseBundleV1` round-trip coverage
|
|
191
|
+
* without hand-rolling JSON, and because a future MCP-side migration tool
|
|
192
|
+
* (tracked as a known gap — see mcp/README.md) will need exactly this call.
|
|
193
|
+
*/
|
|
194
|
+
function deriveBundleFromMnemonic(mnemonic, chainId, provisionedBy, smartAccount) {
|
|
195
|
+
const bindings = ensureBundleBindings();
|
|
196
|
+
return bindings.deriveBundleFromMnemonic(mnemonic.trim(), BigInt(chainId), provisionedBy, smartAccount);
|
|
197
|
+
}
|
|
198
|
+
/** Convert a parsed bundle's hex vault keys to `Buffer`s. */
|
|
199
|
+
function bundleVaultToBuffers(bundle) {
|
|
200
|
+
return {
|
|
201
|
+
encryptionKey: Buffer.from(bundle.vault.encryption_key, 'hex'),
|
|
202
|
+
dedupKey: Buffer.from(bundle.vault.dedup_key, 'hex'),
|
|
203
|
+
authKey: Buffer.from(bundle.vault.auth_key, 'hex'),
|
|
204
|
+
lshSeed: Buffer.from(bundle.vault.lsh_seed, 'hex'),
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
// ---------------------------------------------------------------------------
|
|
208
|
+
// Redaction — derived-bundle-v1.md §4.6 point 5: no value under `vault` or
|
|
209
|
+
// `signing.private_key` may ever be logged, printed, or included in an
|
|
210
|
+
// exception message. Python's `bundle.py` enforces this with `__repr__`
|
|
211
|
+
// overrides on frozen dataclasses; TS has no dataclass-repr equivalent, so
|
|
212
|
+
// every call site that might log a bundle MUST route through this helper
|
|
213
|
+
// instead of `JSON.stringify(bundle)` / `console.error(bundle)` directly.
|
|
214
|
+
// Also touches no WASM binding — pure function, no feature-detection needed.
|
|
215
|
+
// ---------------------------------------------------------------------------
|
|
216
|
+
/**
|
|
217
|
+
* A safe-to-log summary of a bundle: everything EXCEPT `vault.*` and
|
|
218
|
+
* `signing.private_key`. Use this (never the raw bundle object) in any
|
|
219
|
+
* `console.error` / log line that touches a bundle.
|
|
220
|
+
*/
|
|
221
|
+
function redactedBundleSummary(bundle) {
|
|
222
|
+
return {
|
|
223
|
+
schema: 'derived-bundle-v1',
|
|
224
|
+
signing_kind: bundle.signing.kind,
|
|
225
|
+
signing_address: bundle.signing.address,
|
|
226
|
+
smart_account: bundle.account.smart_account,
|
|
227
|
+
chain_id: bundle.account.chain_id,
|
|
228
|
+
provisioned_at: bundle.provisioned_at,
|
|
229
|
+
provisioned_by: bundle.provisioned_by,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/subgraph/bundle.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;;AAyJH,8CAMC;AAwBD,sCAaC;AAMD,4CAQC;AAaD,4DAQC;AAmBD,oDAOC;AAiBD,sDAUC;AA1RD,8DAA8D;AAC9D,MAAM,UAAU,GAAY,OAA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H,SAAgB,qBAAqB,CAAC,MAAuB;IAC3D,OAAO;QACL,MAAM,EAAE,mBAAmB;QAC3B,YAAY,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI;QACjC,eAAe,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;QACvC,aAAa,EAAE,MAAM,CAAC,OAAO,CAAC,aAAa;QAC3C,QAAQ,EAAE,MAAM,CAAC,OAAO,CAAC,QAAQ;QACjC,cAAc,EAAE,MAAM,CAAC,cAAc;QACrC,cAAc,EAAE,MAAM,CAAC,cAAc;KACtC,CAAC;AACJ,CAAC"}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* (chain 100) after ops-1 — the legacy Free → Base Sepolia (84532) routing
|
|
9
9
|
* was retired, so the local default here is 100, not 84532.
|
|
10
10
|
*/
|
|
11
|
-
import type
|
|
11
|
+
import { type SubgraphStoreConfig } from './store.js';
|
|
12
12
|
export interface ResolvedChainConfig {
|
|
13
13
|
/** Chain to submit the write to (verbatim from billing, else Gnosis 100). */
|
|
14
14
|
chainId: number;
|
|
@@ -21,11 +21,32 @@ export interface ResolvedChainConfig {
|
|
|
21
21
|
* - `chain_id`: used verbatim when a finite number; otherwise Gnosis (100).
|
|
22
22
|
* - `data_edge_address`: used only when a valid `0x…40hex` string; otherwise
|
|
23
23
|
* left undefined so the caller falls through to env / the store default.
|
|
24
|
+
*
|
|
25
|
+
* `onMalformedDataEdge` fires when `data_edge_address` is PRESENT but fails
|
|
26
|
+
* the `0x…40hex` shape check — distinct from the field being simply absent
|
|
27
|
+
* (a legitimate response shape for some relay versions/tiers). A present-
|
|
28
|
+
* but-garbage value is evidence of a relay bug or a tampered response and
|
|
29
|
+
* was previously dropped silently; callers that care (currently
|
|
30
|
+
* `fetchChainConfig` below) should log it loudly rather than let a caller
|
|
31
|
+
* silently fall through to the store's default DataEdge with no trace of
|
|
32
|
+
* why.
|
|
24
33
|
*/
|
|
25
|
-
export declare function resolveChainConfig(billing: Record<string, unknown> | null | undefined): ResolvedChainConfig;
|
|
34
|
+
export declare function resolveChainConfig(billing: Record<string, unknown> | null | undefined, onMalformedDataEdge?: (raw: unknown) => void): ResolvedChainConfig;
|
|
26
35
|
export interface WriteConfigInput {
|
|
27
36
|
relayUrl: string;
|
|
28
|
-
|
|
37
|
+
/**
|
|
38
|
+
* Exactly one of `mnemonic` / `ownerPrivateKeyHex` must be set (Option E
|
|
39
|
+
* Phase 2 / #581, P2-13). Mnemonic-mode clients set `mnemonic`;
|
|
40
|
+
* bundle-mode clients (no mnemonic anywhere in the process — derived-
|
|
41
|
+
* bundle-v1.md §4.6 point 1) set `ownerPrivateKeyHex` from
|
|
42
|
+
* `bundle.signing.private_key` instead. `store.ts`'s
|
|
43
|
+
* `resolveOwnerAccount` prefers `ownerPrivateKeyHex` when both happen to
|
|
44
|
+
* be present (never expected in practice, but privateKey is the more
|
|
45
|
+
* direct source of truth so it wins rather than erroring).
|
|
46
|
+
*/
|
|
47
|
+
mnemonic?: string;
|
|
48
|
+
/** Bundle-mode signing key — 64 lowercase hex chars, no `0x` prefix. */
|
|
49
|
+
ownerPrivateKeyHex?: string;
|
|
29
50
|
authKeyHex: string;
|
|
30
51
|
walletAddress: string;
|
|
31
52
|
chainId: number;
|
|
@@ -42,4 +63,66 @@ export interface WriteConfigInput {
|
|
|
42
63
|
* ordering.
|
|
43
64
|
*/
|
|
44
65
|
export declare function buildSubgraphOverrides(input: WriteConfigInput): Partial<SubgraphStoreConfig>;
|
|
66
|
+
/**
|
|
67
|
+
* `fetchChainConfig`'s result, extended with whether the billing call
|
|
68
|
+
* itself actually succeeded (200 + parseable JSON). Adversarial-review
|
|
69
|
+
* fixup (PR #618): a caller that only inspects `dataEdgeAddress` cannot
|
|
70
|
+
* tell "billing responded but omitted the field" (rare, arguably legitimate)
|
|
71
|
+
* apart from "billing was completely unreachable" (network error, timeout,
|
|
72
|
+
* non-200) — and those two cases need different responses in bundle mode.
|
|
73
|
+
* See `billingResolved`'s own doc comment.
|
|
74
|
+
*/
|
|
75
|
+
export interface FetchedChainConfig extends ResolvedChainConfig {
|
|
76
|
+
/**
|
|
77
|
+
* True iff the billing endpoint responded 200 with parseable JSON —
|
|
78
|
+
* `resolveChainConfig` actually ran against real billing data (even if
|
|
79
|
+
* `chain_id`/`data_edge_address` were absent or malformed within it).
|
|
80
|
+
* False on network failure, timeout, or a non-200 response: the caller
|
|
81
|
+
* fell all the way back to `fallbackChainId` with NO environment
|
|
82
|
+
* information at all. Bundle-mode callers (`index.ts`'s
|
|
83
|
+
* `initSubgraphStateFromBundle`) MUST check this before proceeding — see
|
|
84
|
+
* that function's fail-closed guard.
|
|
85
|
+
*/
|
|
86
|
+
billingResolved: boolean;
|
|
87
|
+
}
|
|
88
|
+
export interface FetchChainConfigOptions {
|
|
89
|
+
serverUrl: string;
|
|
90
|
+
smartAccountAddress: string;
|
|
91
|
+
authKeyHex: string;
|
|
92
|
+
/** Extra headers (client id, session tag, …) merged with Authorization. */
|
|
93
|
+
headers?: Record<string, string>;
|
|
94
|
+
/** Chain id to return when the billing call fails/is unreachable. */
|
|
95
|
+
fallbackChainId: number;
|
|
96
|
+
timeoutMs?: number;
|
|
97
|
+
/** Injectable for tests; defaults to the global `fetch`. */
|
|
98
|
+
fetchImpl?: typeof fetch;
|
|
99
|
+
/** Best-effort logger for the tier/chain line other init paths already print. */
|
|
100
|
+
onResolved?: (billing: Record<string, unknown>, resolved: ResolvedChainConfig) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Fires whenever the billing call did NOT succeed — network error,
|
|
103
|
+
* timeout, or a non-200 response — right before falling back to
|
|
104
|
+
* `fallbackChainId` / no DataEdge. `reason` is a short, human-readable
|
|
105
|
+
* description (never contains key material — it only ever describes
|
|
106
|
+
* transport-level failure, ``err.message``/HTTP status).
|
|
107
|
+
*/
|
|
108
|
+
onBillingUnavailable?: (reason: string) => void;
|
|
109
|
+
}
|
|
110
|
+
export declare function fetchChainConfig(opts: FetchChainConfigOptions): Promise<FetchedChainConfig>;
|
|
111
|
+
export interface AssertDataEdgeResolvableOptions {
|
|
112
|
+
/** From `fetchChainConfig`'s result. */
|
|
113
|
+
billingResolved: boolean;
|
|
114
|
+
/** `process.env.TOTALRECLAW_DATA_EDGE_ADDRESS` (or the test override). */
|
|
115
|
+
envDataEdgeOverride: string | undefined;
|
|
116
|
+
/** Relay base URL, for the error message only. */
|
|
117
|
+
serverUrl: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Throws an actionable error when bundle-mode state construction has no
|
|
121
|
+
* confirmed DataEdge for this environment (billing failed, no env
|
|
122
|
+
* override). No-op (returns) when either `billingResolved` is true (the
|
|
123
|
+
* billing call succeeded — even if it happened not to carry a
|
|
124
|
+
* `data_edge_address`, that's `resolveChainConfig`'s concern, not this
|
|
125
|
+
* guard's) or an explicit env override is present.
|
|
126
|
+
*/
|
|
127
|
+
export declare function assertDataEdgeResolvable(opts: AssertDataEdgeResolvableOptions): void;
|
|
45
128
|
//# sourceMappingURL=chain-config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chain-config.d.ts","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"chain-config.d.ts","sourceRoot":"","sources":["../../src/subgraph/chain-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAA6B,KAAK,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAQjF,MAAM,WAAW,mBAAmB;IAClC,6EAA6E;IAC7E,OAAO,EAAE,MAAM,CAAC;IAChB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,EACnD,mBAAmB,CAAC,EAAE,CAAC,GAAG,E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