@totalreclaw/mcp-server 3.2.1 → 3.3.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,355 @@
1
+ "use strict";
2
+ /**
3
+ * pair-remote-client — gateway-side WebSocket client for the relay-brokered
4
+ * pair flow.
5
+ *
6
+ * Ported from the plugin's `skill/plugin/pair-remote-client.ts` (TotalReclaw
7
+ * plugin v3.3.1-rc.11+) so the MCP server's `totalreclaw_pair` tool emits the
8
+ * same URL/PIN format the browser pair-page already understands.
9
+ *
10
+ * Flow (gateway side):
11
+ * 1. Generate ephemeral x25519 keypair.
12
+ * 2. Open WS to `wss://<relay>/pair/session/open`.
13
+ * 3. Send `{type:"open", gateway_pubkey, pin, client_id, mode}`.
14
+ * 4. Receive `{type:"opened", token, expires_at}` — build the user URL.
15
+ * 5. Block on the WS until the relay pushes `{type:"forward", client_pubkey, nonce, ciphertext}`.
16
+ * 6. Decrypt locally via x25519 ECDH + AES-256-GCM.
17
+ * 7. Hand the decrypted phrase to the caller's completePairing handler
18
+ * (writes credentials.json) and ack/nack the relay.
19
+ *
20
+ * Phrase-safety:
21
+ * - Relay sees only ciphertext.
22
+ * - Phrase NEVER touches logs / stdout / agent context.
23
+ * - PIN is on the tool return payload (required for the user to type into
24
+ * the browser) but is never logged.
25
+ *
26
+ * Scope:
27
+ * - No `fs.*` calls — caller passes a completePairing handler.
28
+ * - No env-var reads — caller passes the relay base URL.
29
+ *
30
+ * See pair-crypto.ts for the cipher-suite header comment.
31
+ */
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.DEFAULT_RELAY_URL = void 0;
37
+ exports.openRemotePairSession = openRemotePairSession;
38
+ exports.awaitPhraseUpload = awaitPhraseUpload;
39
+ exports.pairViaRelay = pairViaRelay;
40
+ const node_crypto_1 = require("node:crypto");
41
+ const ws_1 = __importDefault(require("ws"));
42
+ const pair_crypto_js_1 = require("./pair-crypto.js");
43
+ // ---------------------------------------------------------------------------
44
+ // Constants
45
+ // ---------------------------------------------------------------------------
46
+ exports.DEFAULT_RELAY_URL = 'wss://api.totalreclaw.xyz';
47
+ const OPEN_TIMEOUT_MS = 10_000;
48
+ const DEFAULT_AWAIT_TIMEOUT_MS = 5 * 60_000;
49
+ function defaultBip39CountValidator(phrase) {
50
+ const words = phrase.split(' ');
51
+ if (words.length !== 12 && words.length !== 24)
52
+ return false;
53
+ return words.every((w) => /^[a-z]+$/.test(w));
54
+ }
55
+ function defaultPin() {
56
+ const n = (0, node_crypto_1.randomInt)(0, 1_000_000);
57
+ return n.toString(10).padStart(6, '0');
58
+ }
59
+ function defaultClientId() {
60
+ return 'mcp-' + (0, node_crypto_1.randomBytes)(8).toString('hex');
61
+ }
62
+ function buildUserUrl(relayBase, token, pkB64) {
63
+ let httpBase = relayBase;
64
+ if (httpBase.startsWith('wss://')) {
65
+ httpBase = 'https://' + httpBase.slice('wss://'.length);
66
+ }
67
+ else if (httpBase.startsWith('ws://')) {
68
+ httpBase = 'http://' + httpBase.slice('ws://'.length);
69
+ }
70
+ return `${httpBase}/pair/p/${token}#pk=${pkB64}`;
71
+ }
72
+ function wsConnectBase(relayBase) {
73
+ let base = relayBase.replace(/\/+$/, '');
74
+ if (base.startsWith('https://')) {
75
+ base = 'wss://' + base.slice('https://'.length);
76
+ }
77
+ else if (base.startsWith('http://')) {
78
+ base = 'ws://' + base.slice('http://'.length);
79
+ }
80
+ return base;
81
+ }
82
+ // ---------------------------------------------------------------------------
83
+ // Open
84
+ // ---------------------------------------------------------------------------
85
+ async function openRemotePairSession(opts = {}) {
86
+ const relayBase = (opts.relayBaseUrl ?? exports.DEFAULT_RELAY_URL).replace(/\/+$/, '');
87
+ const wsBase = wsConnectBase(relayBase);
88
+ const wsUrl = `${wsBase}/pair/session/open`;
89
+ const WebSocketImpl = opts.webSocketImpl ?? ws_1.default;
90
+ const keypair = opts.keypair ?? (0, pair_crypto_js_1.generateGatewayKeypair)();
91
+ const pin = opts.pin ?? defaultPin();
92
+ const clientId = opts.clientId ?? defaultClientId();
93
+ const mode = opts.mode ?? 'either';
94
+ const ws = new WebSocketImpl(wsUrl, {
95
+ handshakeTimeout: OPEN_TIMEOUT_MS,
96
+ });
97
+ try {
98
+ await waitOpen(ws, OPEN_TIMEOUT_MS);
99
+ }
100
+ catch (err) {
101
+ safeClose(ws);
102
+ throw err;
103
+ }
104
+ try {
105
+ ws.send(JSON.stringify({
106
+ type: 'open',
107
+ gateway_pubkey: keypair.pkB64,
108
+ pin,
109
+ client_id: clientId,
110
+ mode,
111
+ }));
112
+ }
113
+ catch (err) {
114
+ safeClose(ws);
115
+ throw err instanceof Error ? err : new Error(String(err));
116
+ }
117
+ let raw;
118
+ try {
119
+ raw = await waitNextMessage(ws, OPEN_TIMEOUT_MS);
120
+ }
121
+ catch (err) {
122
+ safeClose(ws);
123
+ throw err;
124
+ }
125
+ let msg;
126
+ try {
127
+ const text = typeof raw === 'string' ? raw : Buffer.from(raw).toString('utf-8');
128
+ msg = JSON.parse(text);
129
+ }
130
+ catch {
131
+ safeClose(ws);
132
+ throw new Error('pair-remote-client: opened frame not valid JSON');
133
+ }
134
+ if (msg.type === 'error') {
135
+ const errStr = typeof msg.error === 'string' ? msg.error : 'relay_error';
136
+ safeClose(ws);
137
+ throw new Error(`pair-remote-client: session/open failed: ${errStr}`);
138
+ }
139
+ if (msg.type !== 'opened') {
140
+ safeClose(ws);
141
+ throw new Error(`pair-remote-client: unexpected response type '${String(msg.type)}'`);
142
+ }
143
+ const token = typeof msg.token === 'string' ? msg.token : '';
144
+ const expiresAt = typeof msg.expires_at === 'string' ? msg.expires_at : '';
145
+ if (!token || !expiresAt) {
146
+ safeClose(ws);
147
+ throw new Error('pair-remote-client: opened frame missing token or expires_at');
148
+ }
149
+ const url = buildUserUrl(relayBase, token, keypair.pkB64);
150
+ return {
151
+ url,
152
+ pin,
153
+ token,
154
+ expiresAt,
155
+ keypair,
156
+ mode,
157
+ _ws: ws,
158
+ };
159
+ }
160
+ // ---------------------------------------------------------------------------
161
+ // Await + decrypt + ack
162
+ // ---------------------------------------------------------------------------
163
+ async function awaitPhraseUpload(session, opts) {
164
+ const validate = opts.phraseValidator ?? defaultBip39CountValidator;
165
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_AWAIT_TIMEOUT_MS;
166
+ const ws = session._ws;
167
+ let raw;
168
+ try {
169
+ raw = await waitNextMessage(ws, timeoutMs);
170
+ }
171
+ catch (err) {
172
+ safeClose(ws);
173
+ throw err;
174
+ }
175
+ let msg;
176
+ try {
177
+ const text = typeof raw === 'string' ? raw : Buffer.from(raw).toString('utf-8');
178
+ msg = JSON.parse(text);
179
+ }
180
+ catch {
181
+ safeSend(ws, { type: 'nack', error: 'bad_json' });
182
+ safeClose(ws);
183
+ throw new Error('pair-remote-client: forward frame not valid JSON');
184
+ }
185
+ if (msg.type !== 'forward') {
186
+ safeSend(ws, { type: 'nack', error: 'expected_forward' });
187
+ safeClose(ws);
188
+ throw new Error(`pair-remote-client: unexpected frame '${String(msg.type)}'`);
189
+ }
190
+ const clientPubkey = typeof msg.client_pubkey === 'string' ? msg.client_pubkey : '';
191
+ const nonce = typeof msg.nonce === 'string' ? msg.nonce : '';
192
+ const ciphertext = typeof msg.ciphertext === 'string' ? msg.ciphertext : '';
193
+ if (!clientPubkey || !nonce || !ciphertext) {
194
+ safeSend(ws, { type: 'nack', error: 'bad_forward_body' });
195
+ safeClose(ws);
196
+ throw new Error('pair-remote-client: forward frame missing required fields');
197
+ }
198
+ let plaintext;
199
+ try {
200
+ plaintext = (0, pair_crypto_js_1.decryptPairingPayload)({
201
+ skGatewayB64: session.keypair.skB64,
202
+ pkDeviceB64: clientPubkey,
203
+ sid: session.token,
204
+ nonceB64: nonce,
205
+ ciphertextB64: ciphertext,
206
+ });
207
+ }
208
+ catch (err) {
209
+ safeSend(ws, { type: 'nack', error: 'decrypt_failed' });
210
+ safeClose(ws);
211
+ throw err instanceof Error ? err : new Error(String(err));
212
+ }
213
+ let mnemonic;
214
+ try {
215
+ mnemonic = plaintext
216
+ .toString('utf-8')
217
+ .normalize('NFKC')
218
+ .toLowerCase()
219
+ .trim()
220
+ .split(/\s+/)
221
+ .join(' ');
222
+ }
223
+ catch (err) {
224
+ safeSend(ws, { type: 'nack', error: 'bad_utf8' });
225
+ safeClose(ws);
226
+ throw err instanceof Error ? err : new Error(String(err));
227
+ }
228
+ finally {
229
+ plaintext.fill(0);
230
+ }
231
+ if (!validate(mnemonic)) {
232
+ safeSend(ws, { type: 'nack', error: 'invalid_mnemonic' });
233
+ safeClose(ws);
234
+ throw new Error('pair-remote-client: phrase failed BIP-39 validation');
235
+ }
236
+ let result;
237
+ try {
238
+ result = await opts.completePairing({ mnemonic, session });
239
+ }
240
+ catch (err) {
241
+ safeSend(ws, { type: 'nack', error: 'completion_failed' });
242
+ safeClose(ws);
243
+ throw err instanceof Error ? err : new Error(String(err));
244
+ }
245
+ finally {
246
+ mnemonic = '';
247
+ }
248
+ if (result.state !== 'active') {
249
+ safeSend(ws, { type: 'nack', error: result.error ?? 'completion_failed' });
250
+ safeClose(ws);
251
+ return result;
252
+ }
253
+ safeSend(ws, { type: 'ack' });
254
+ safeClose(ws);
255
+ return result;
256
+ }
257
+ async function pairViaRelay(opts) {
258
+ const session = await openRemotePairSession({
259
+ relayBaseUrl: opts.relayBaseUrl,
260
+ pin: opts.pin,
261
+ mode: opts.mode,
262
+ });
263
+ return awaitPhraseUpload(session, {
264
+ completePairing: opts.completePairing,
265
+ phraseValidator: opts.phraseValidator,
266
+ timeoutMs: opts.timeoutMs,
267
+ });
268
+ }
269
+ // ---------------------------------------------------------------------------
270
+ // WS helpers
271
+ // ---------------------------------------------------------------------------
272
+ function waitOpen(ws, timeoutMs) {
273
+ return new Promise((resolve, reject) => {
274
+ if (ws.readyState === ws_1.default.OPEN) {
275
+ resolve();
276
+ return;
277
+ }
278
+ const onOpen = () => {
279
+ cleanup();
280
+ resolve();
281
+ };
282
+ const onError = (err) => {
283
+ cleanup();
284
+ reject(err instanceof Error ? err : new Error(String(err)));
285
+ };
286
+ const onClose = (code) => {
287
+ cleanup();
288
+ reject(new Error(`pair-remote-client: ws closed before open (${code})`));
289
+ };
290
+ const timer = setTimeout(() => {
291
+ cleanup();
292
+ reject(new Error('pair-remote-client: ws open timeout'));
293
+ }, timeoutMs);
294
+ const cleanup = () => {
295
+ clearTimeout(timer);
296
+ ws.off('open', onOpen);
297
+ ws.off('error', onError);
298
+ ws.off('close', onClose);
299
+ };
300
+ ws.on('open', onOpen);
301
+ ws.on('error', onError);
302
+ ws.on('close', onClose);
303
+ });
304
+ }
305
+ function waitNextMessage(ws, timeoutMs) {
306
+ return new Promise((resolve, reject) => {
307
+ const onMessage = (data) => {
308
+ cleanup();
309
+ resolve(data);
310
+ };
311
+ const onError = (err) => {
312
+ cleanup();
313
+ reject(err instanceof Error ? err : new Error(String(err)));
314
+ };
315
+ const onClose = (code) => {
316
+ cleanup();
317
+ reject(new Error(`pair-remote-client: ws closed before message (${code})`));
318
+ };
319
+ const timer = setTimeout(() => {
320
+ cleanup();
321
+ reject(new Error('pair-remote-client: ws message timeout'));
322
+ }, timeoutMs);
323
+ const cleanup = () => {
324
+ clearTimeout(timer);
325
+ ws.off('message', onMessage);
326
+ ws.off('error', onError);
327
+ ws.off('close', onClose);
328
+ };
329
+ ws.on('message', onMessage);
330
+ ws.on('error', onError);
331
+ ws.on('close', onClose);
332
+ });
333
+ }
334
+ function safeSend(ws, msg) {
335
+ try {
336
+ if (ws.readyState === ws_1.default.OPEN) {
337
+ ws.send(JSON.stringify(msg));
338
+ }
339
+ }
340
+ catch {
341
+ /* swallow */
342
+ }
343
+ }
344
+ function safeClose(ws) {
345
+ try {
346
+ if (ws.readyState === ws_1.default.OPEN ||
347
+ ws.readyState === ws_1.default.CONNECTING) {
348
+ ws.close();
349
+ }
350
+ }
351
+ catch {
352
+ /* swallow */
353
+ }
354
+ }
355
+ //# sourceMappingURL=pair-remote-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pair-remote-client.js","sourceRoot":"","sources":["../src/pair-remote-client.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;;;;;;AA8GH,sDAoFC;AAMD,8CAmGC;AAED,oCAkBC;AA7TD,6CAAqD;AAErD,4CAA2B;AAE3B,qDAI0B;AAE1B,8EAA8E;AAC9E,YAAY;AACZ,8EAA8E;AAEjE,QAAA,iBAAiB,GAAG,2BAA2B,CAAC;AAE7D,MAAM,eAAe,GAAG,MAAM,CAAC;AAE/B,MAAM,wBAAwB,GAAG,CAAC,GAAG,MAAM,CAAC;AA+B5C,SAAS,0BAA0B,CAAC,MAAc;IAChD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAChC,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE,IAAI,KAAK,CAAC,MAAM,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAC7D,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,SAAS,UAAU;IACjB,MAAM,CAAC,GAAG,IAAA,uBAAS,EAAC,CAAC,EAAE,SAAS,CAAC,CAAC;IAClC,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AACzC,CAAC;AAED,SAAS,eAAe;IACtB,OAAO,MAAM,GAAG,IAAA,yBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACjD,CAAC;AAED,SAAS,YAAY,CAAC,SAAiB,EAAE,KAAa,EAAE,KAAa;IACnE,IAAI,QAAQ,GAAG,SAAS,CAAC;IACzB,IAAI,QAA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AAS,CAAC,CAAC;QAC5B,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACxB,EAAE,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1B,CAAC,CAAC,CAAC;AACL,CAAC;AAED,SAAS,QAAQ,CAAC,EAAa,EAAE,GAAY;IAC3C,IAAI,CAAC;QACH,IAAI,EAAE,CAAC,UAAU,KAAK,YAAS,CAAC,IAAI,EAAE,CAAC;YACrC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,aAAa;IACf,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,EAAa;IAC9B,IAAI,CAAC;QACH,IACE,EAAE,CAAC,UAAU,KAAK,YAAS,CAAC,IAAI;YAChC,EAAE,CAAC,UAAU,KAAK,YAAS,CAAC,UAAU,EACtC,CAAC;YACD,EAAE,CAAC,KAAK,EAAE,CAAC;QACb,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,aAAa;IACf,CAAC;AACH,CAAC"}
package/dist/prompts.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare const IMPORT_FROM_TOOL_DESCRIPTION = "Import from Mem0, MCP Memor
11
11
  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.";
12
12
  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.";
13
13
  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.";
14
+ export declare const PAIR_TOOL_DESCRIPTION = "Set up the user's TotalReclaw account (browser-side recovery-phrase generation or import).\nINVOKE WHEN USER SAYS:\n- \"set up totalreclaw\" / \"set up my account\"\n- \"I don't have a totalreclaw recovery phrase yet\" / \"create a totalreclaw account\"\n- ANY tool returns \"not_configured\" \u2014 propose this tool BEFORE asking the user to edit MCP config.\nDOES: opens a brief relay session, returns {url, pin, expires_at_ms}. Hand the URL + PIN to the user \u2014 they open the URL in any browser, the BROWSER generates (or imports) a 12-word phrase, encrypts it, uploads ciphertext to this MCP server. Server decrypts in-memory, writes ~/.totalreclaw/credentials.json (mode 0600). Phrase NEVER touches LLM context, chat transcript, stdout, or logs.\nAFTER PAIRING: tell the user to RESTART their MCP host (Claude Desktop / Cursor / Claude Code) so the server re-reads credentials.json and switches out of unconfigured mode.\nWHEN NOT TO USE:\n- user already has TOTALRECLAW_RECOVERY_PHRASE in env \u2192 tool will return URL but pairing is unnecessary\n- user explicitly wants terminal-only setup \u2192 point them at `npx @totalreclaw/mcp-server setup` (CLI wizard, runs OUTSIDE your shell tool)\n- NEVER ask the user to paste their phrase in chat. NEVER echo or print a phrase from any source.";
14
15
  export declare const PROMPT_DEFINITIONS: {
15
16
  name: string;
16
17
  title: string;
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,wkOAwF/B,CAAC;AAGF,eAAO,MAAM,sBAAsB,wkOAAsB,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,ohBASE,CAAC;AAExC,eAAO,MAAM,wBAAwB,mfAKwD,CAAC;AAE9F,eAAO,MAAM,4BAA4B,shBAOM,CAAC;AAEhD,eAAO,MAAM,uBAAuB,qgBAS0B,CAAC;AAE/D,eAAO,MAAM,wBAAwB,+gBAQyC,CAAC;AAE/E,eAAO,MAAM,wBAAwB,8gBASa,CAAC;AAInD,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"}
1
+ {"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,wkOAwF/B,CAAC;AAGF,eAAO,MAAM,sBAAsB,wkOAAsB,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,ohBASE,CAAC;AAExC,eAAO,MAAM,wBAAwB,mfAKwD,CAAC;AAE9F,eAAO,MAAM,4BAA4B,shBAOM,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
@@ -3,7 +3,7 @@
3
3
  // Returned in the MCP `initialize` response. Clients SHOULD inject this into the
4
4
  // system prompt, giving the LLM persistent behavioral guidance for the session.
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.PROMPT_DEFINITIONS = exports.ACCOUNT_TOOL_DESCRIPTION = exports.SUPPORT_TOOL_DESCRIPTION = exports.IMPORT_TOOL_DESCRIPTION = exports.IMPORT_FROM_TOOL_DESCRIPTION = exports.MIGRATE_TOOL_DESCRIPTION = exports.UPGRADE_TOOL_DESCRIPTION = exports.STATUS_TOOL_DESCRIPTION = exports.EXPORT_TOOL_DESCRIPTION = exports.FORGET_TOOL_DESCRIPTION = exports.RECALL_TOOL_DESCRIPTION = exports.REMEMBER_TOOL_DESCRIPTION = exports.SYSTEM_PROMPT_FRAGMENT = exports.SERVER_INSTRUCTIONS = void 0;
6
+ exports.PROMPT_DEFINITIONS = exports.PAIR_TOOL_DESCRIPTION = exports.ACCOUNT_TOOL_DESCRIPTION = exports.SUPPORT_TOOL_DESCRIPTION = exports.IMPORT_TOOL_DESCRIPTION = exports.IMPORT_FROM_TOOL_DESCRIPTION = exports.MIGRATE_TOOL_DESCRIPTION = exports.UPGRADE_TOOL_DESCRIPTION = exports.STATUS_TOOL_DESCRIPTION = exports.EXPORT_TOOL_DESCRIPTION = exports.FORGET_TOOL_DESCRIPTION = exports.RECALL_TOOL_DESCRIPTION = exports.REMEMBER_TOOL_DESCRIPTION = exports.SYSTEM_PROMPT_FRAGMENT = exports.SERVER_INSTRUCTIONS = void 0;
7
7
  exports.getPromptMessages = getPromptMessages;
8
8
  exports.SERVER_INSTRUCTIONS = `
9
9
  You 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."
@@ -198,6 +198,17 @@ DOES: billing+fact count parallel. Returns wallet, tier, writes_used/limit, tota
198
198
  WHEN NOT TO USE:
199
199
  - only billing → totalreclaw_status (lighter)
200
200
  - FULL recovery phrase → NEVER; password manager.`;
201
+ exports.PAIR_TOOL_DESCRIPTION = `Set up the user's TotalReclaw account (browser-side recovery-phrase generation or import).
202
+ INVOKE WHEN USER SAYS:
203
+ - "set up totalreclaw" / "set up my account"
204
+ - "I don't have a totalreclaw recovery phrase yet" / "create a totalreclaw account"
205
+ - ANY tool returns "not_configured" — propose this tool BEFORE asking the user to edit MCP config.
206
+ DOES: opens a brief relay session, returns {url, pin, expires_at_ms}. Hand the URL + PIN to the user — they open the URL in any browser, the BROWSER generates (or imports) a 12-word phrase, encrypts it, uploads ciphertext to this MCP server. Server decrypts in-memory, writes ~/.totalreclaw/credentials.json (mode 0600). Phrase NEVER touches LLM context, chat transcript, stdout, or logs.
207
+ AFTER PAIRING: tell the user to RESTART their MCP host (Claude Desktop / Cursor / Claude Code) so the server re-reads credentials.json and switches out of unconfigured mode.
208
+ WHEN NOT TO USE:
209
+ - user already has TOTALRECLAW_RECOVERY_PHRASE in env → tool will return URL but pairing is unnecessary
210
+ - user explicitly wants terminal-only setup → point them at \`npx @totalreclaw/mcp-server setup\` (CLI wizard, runs OUTSIDE your shell tool)
211
+ - NEVER ask the user to paste their phrase in chat. NEVER echo or print a phrase from any source.`;
201
212
  // ── Layer 5: Prompt Fallback Templates ───────────────────────────────────────
202
213
  exports.PROMPT_DEFINITIONS = [
203
214
  {
@@ -1 +1 @@
1
- {"version":3,"file":"prompts.js","sourceRoot":"","sources":["../src/prompts.ts"],"names":[],"mappings":";AAAA,iFAAiF;AACjF,iFAAiF;AACjF,gFAAgF;;;AA0OhF,8CAwCC;AAhRY,QAAA,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwFlC,CAAC;AAEF,yEAAyE;AAC5D,QAAA,sBAAsB,GAAG,2BAAmB,CAAC;AAE1D,gFAAgF;AAEnE,QAAA,yBAAyB,GAAG;;;;0LAIiJ,CAAC;AAE9K,QAAA,uBAAuB,GAAG;;;;;;;;;yDASkB,CAAC;AAE7C,QAAA,uBAAuB,GAAG;;;;;;;;;;;sDAWe,CAAC;AAE1C,QAAA,uBAAuB,GAAG;;;;;;;;;;kCAUL,CAAC;AAEtB,QAAA,uBAAuB,GAAG;;;;;;;;;yCASE,CAAC;AAE7B,QAAA,wBAAwB,GAAG;;;;;;;;;uCASD,CAAC;AAE3B,QAAA,wBAAwB,GAAG;;;;;6FAKqD,CAAC;AAEjF,QAAA,4BAA4B,GAAG;;;;;;;+CAOG,CAAC;AAEnC,QAAA,uBAAuB,GAAG;;;;;;;;;8DASuB,CAAC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gB;QACvB,WAAW,EACT,+EAA+E;QACjF,SAAS,EAAE,EAAqE;KACjF;CACF,CAAC;AAEF,SAAgB,iBAAiB,CAC/B,UAAkB,EAClB,IAA6B;IAE7B,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,mBAAmB,CAAC,CAAC,CAAC;YACzB,MAAM,KAAK,GAAG,IAAI,EAAE,KAAK,IAAI,gBAAgB,CAAC;YAC9C,OAAO;gBACL;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,4CAA4C,KAAK,gDAAgD;qBACxG;iBACF;aACF,CAAC;QACJ,CAAC;QAED,KAAK,kBAAkB;YACrB,OAAO;gBACL;oBACE,IAAI,EAAE,MAAM;oBACZ,OAAO,EAAE;wBACP,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,uOAAuO;qBAC9O;iBACF;aACF,CAAC;QAEJ,KAAK,0BAA0B;YAC7B,OAAO;gBACL;oBACE,IAAI,EAAE,WAAW;oBACjB,OAAO,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,2BAAmB,EAAE;iBACrD;aACF,CAAC;QAEJ;YACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,UAAU,EAAE,CAAC,CAAC;IACrD,CAAC;AACH,CAAC"}
@@ -12,6 +12,7 @@ export { migrateToolDefinition } from './migrate.js';
12
12
  export { debriefToolDefinition, handleDebrief, parseDebriefResponse, DEBRIEF_SYSTEM_PROMPT, type DebriefItem } from './debrief.js';
13
13
  export { supportToolDefinition, handleSupport } from './support.js';
14
14
  export { accountToolDefinition, handleAccount } from './account.js';
15
+ export { pairToolDefinition, handlePair, runPairBackgroundTask, resolvePairRelayUrl, } from './pair.js';
15
16
  export { pinToolDefinition, unpinToolDefinition, handlePin, handleUnpin, executePinOperation, type PinOpDeps, type PinOpResult, type HumanStatus, } from './pin.js';
16
17
  export { retypeToolDefinition, handleRetype, handleRetypeWithDeps, executeRetype, executeMetadataOp, extractV1Fields, validateRetypeArgs, type MetadataOpDeps, type MetadataOpResult, } from './retype.js';
17
18
  export { setScopeToolDefinition, handleSetScope, handleSetScopeWithDeps, executeSetScope, validateSetScopeArgs, } from './set-scope.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACnI,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,WAAW,EACX,m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M,cAAc,CAAC;AACrD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AACnI,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EACL,kBAAkB,EAClB,UAAU,EACV,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,WAAW,GACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EAClB,KAAK,cAAc,EACnB,KAAK,gBAAgB,GACtB,MAAM,aAAa,CAAC;AACrB,OAAO,EACL,sBAAsB,EACtB,cAAc,EACd,sBAAsB,EACtB,eAAe,EACf,oBAAoB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,sBAAsB,EACtB,yBAAyB,EACzB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC"}
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.checkBillingTier = exports.fetchBlindIndicesForFacts = exports.fetchMainnetContentFps = exports.fetchAllFactsFromSubgraph = exports.validateSetScopeArgs = exports.executeSetScope = exports.handleSetScopeWithDeps = exports.handleSetScope = exports.setScopeToolDefinition = exports.validateRetypeArgs = exports.extractV1Fields = exports.executeMetadataOp = exports.executeRetype = exports.handleRetypeWithDeps = exports.handleRetype = exports.retypeToolDefinition = exports.executePinOperation = exports.handleUnpin = exports.handlePin = exports.unpinToolDefinition = exports.pinToolDefinition = exports.handleAccount = exports.accountToolDefinition = exports.handleSupport = exports.supportToolDefinition = exports.DEBRIEF_SYSTEM_PROMPT = exports.parseDebriefResponse = exports.handleDebrief = exports.debriefToolDefinition = exports.migrateToolDefinition = exports.handleUpgrade = exports.upgradeToolDefinition = exports.handleStatus = exports.statusToolDefinition = exports.handleConsolidate = exports.consolidateToolDefinition = exports.handleImportBatch = exports.importBatchToolDefinition = exports.handleImportFrom = exports.importFromToolDefinition = exports.handleImport = exports.importToolDefinition = exports.handleExport = exports.exportToolDefinition = exports.handleForget = exports.forgetToolDefinition = exports.handleRecall = exports.recallToolDefinition = exports.handleRemember = exports.rememberToolDefinition = void 0;
3
+ exports.validateSetScopeArgs = exports.executeSetScope = exports.handleSetScopeWithDeps = exports.handleSetScope = exports.setScopeToolDefinition = exports.validateRetypeArgs = exports.extractV1Fields = exports.executeMetadataOp = exports.executeRetype = exports.handleRetypeWithDeps = exports.handleRetype = exports.retypeToolDefinition = exports.executePinOperation = exports.handleUnpin = exports.handlePin = exports.unpinToolDefinition = exports.pinToolDefinition = exports.resolvePairRelayUrl = exports.runPairBackgroundTask = exports.handlePair = exports.pairToolDefinition = exports.handleAccount = exports.accountToolDefinition = exports.handleSupport = exports.supportToolDefinition = exports.DEBRIEF_SYSTEM_PROMPT = exports.parseDebriefResponse = exports.handleDebrief = exports.debriefToolDefinition = exports.migrateToolDefinition = exports.handleUpgrade = exports.upgradeToolDefinition = exports.handleStatus = exports.statusToolDefinition = exports.handleConsolidate = exports.consolidateToolDefinition = exports.handleImportBatch = exports.importBatchToolDefinition = exports.handleImportFrom = exports.importFromToolDefinition = exports.handleImport = exports.importToolDefinition = exports.handleExport = exports.exportToolDefinition = exports.handleForget = exports.forgetToolDefinition = exports.handleRecall = exports.recallToolDefinition = exports.handleRemember = exports.rememberToolDefinition = void 0;
4
+ exports.checkBillingTier = exports.fetchBlindIndicesForFacts = exports.fetchMainnetContentFps = exports.fetchAllFactsFromSubgraph = void 0;
4
5
  var remember_js_1 = require("./remember.js");
5
6
  Object.defineProperty(exports, "rememberToolDefinition", { enumerable: true, get: function () { return remember_js_1.rememberToolDefinition; } });
6
7
  Object.defineProperty(exports, "handleRemember", { enumerable: true, get: function () { return remember_js_1.handleRemember; } });
@@ -44,6 +45,11 @@ Object.defineProperty(exports, "handleSupport", { enumerable: true, get: functio
44
45
  var account_js_1 = require("./account.js");
45
46
  Object.defineProperty(exports, "accountToolDefinition", { enumerable: true, get: function () { return account_js_1.accountToolDefinition; } });
46
47
  Object.defineProperty(exports, "handleAccount", { enumerable: true, get: function () { return account_js_1.handleAccount; } });
48
+ var pair_js_1 = require("./pair.js");
49
+ Object.defineProperty(exports, "pairToolDefinition", { enumerable: true, get: function () { return pair_js_1.pairToolDefinition; } });
50
+ Object.defineProperty(exports, "handlePair", { enumerable: true, get: function () { return pair_js_1.handlePair; } });
51
+ Object.defineProperty(exports, "runPairBackgroundTask", { enumerable: true, get: function () { return pair_js_1.runPairBackgroundTask; } });
52
+ Object.defineProperty(exports, "resolvePairRelayUrl", { enumerable: true, get: function () { return pair_js_1.resolvePairRelayUrl; } });
47
53
  var pin_js_1 = require("./pin.js");
48
54
  Object.defineProperty(exports, "pinToolDefinition", { enumerable: true, get: function () { return pin_js_1.pinToolDefinition; } });
49
55
  Object.defineProperty(exports, "unpinToolDefinition", { enumerable: true, get: function () { return pin_js_1.unpinToolDefinition; } });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":";;;AAAA,6CAAuE;AAA9D,qHAAA,sBAAsB,OAAA;AAAE,6GAAA,cAAc,OAAA;AAC/C,yCAAiE;AAAxD,iHAAA,oBAAoB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC3C,yCAAiE;AAAxD,iHAAA,oBAAoB,OAAA;AAAE,yGAAA,YAAY,OAAA;AAC3C,yCAAiE;AAAxD,iHAAA,oBAAoB,OA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,qCAKmB;AAJjB,6GAAA,kBAAkB,OAAA;AAClB,qGAAA,UAAU,OAAA;AACV,gHAAA,qBAAqB,OAAA;AACrB,8GAAA,mBAAmB,OAAA;AAErB,mCASkB;AARhB,2GAAA,iBAAiB,OAAA;AACjB,6GAAA,mBAAmB,OAAA;AACnB,mGAAA,SAAS,OAAA;AACT,qGAAA,WAAW,OAAA;AACX,6GAAA,mBAAmB,OAAA;AAKrB,yCAUqB;AATnB,iHAAA,oBAAoB,OAAA;AACpB,yGAAA,YAAY,OAAA;AACZ,iHAAA,oBAAoB,OAAA;AACpB,0GAAA,aAAa,OAAA;AACb,8GAAA,iBAAiB,OAAA;AACjB,4GAAA,eAAe,OAAA;AACf,+GAAA,kBAAkB,OAAA;AAIpB,+CAMwB;AALtB,sHAAA,sBAAsB,OAAA;AACtB,8GAAA,cAAc,OAAA;AACd,sHAAA,sBAAsB,OAAA;AACtB,+GAAA,eAAe,OAAA;AACf,oHAAA,oBAAoB,OAAA;AAEtB,2CAOsB;AANpB,uHAAA,yBAAyB,OAAA;AACzB,oHAAA,sBAAsB,OAAA;AACtB,uHAAA,yBAAyB,OAAA;AACzB,8GAAA,gBAAgB,OAAA"}
@@ -0,0 +1,118 @@
1
+ /**
2
+ * TotalReclaw MCP — totalreclaw_pair tool
3
+ *
4
+ * Browser-mediated TotalReclaw account setup. The user opens the returned
5
+ * URL on their phone or another browser, the browser generates (or imports)
6
+ * a 12-word BIP-39 recovery phrase, encrypts it via x25519 ECDH + AES-256-GCM,
7
+ * and uploads the ciphertext to the same relay this MCP server already talks
8
+ * to. The MCP server decrypts the phrase locally and writes
9
+ * `~/.totalreclaw/credentials.json` so a host restart picks the user up in
10
+ * configured mode.
11
+ *
12
+ * Phrase-safety invariants (see project_phrase_safety_rule):
13
+ * - The phrase NEVER appears in the tool's return payload.
14
+ * - The phrase NEVER passes through stdout / stderr / logs.
15
+ * - The phrase is generated in the browser; the MCP server only ever sees
16
+ * the decrypted plaintext in-memory inside `completePairing` and writes
17
+ * it to the 0600-mode credentials.json on disk.
18
+ *
19
+ * Flow:
20
+ * 1. Tool handler resolves the relay URL from
21
+ * `TOTALRECLAW_PAIR_RELAY_URL` (preferred) or `TOTALRECLAW_SERVER_URL`
22
+ * (rewrites http→ws / https→wss). Falls back to `wss://api.totalreclaw.xyz`.
23
+ * 2. Opens a relay pair session (`openRemotePairSession`) and returns
24
+ * `{url, pin, expires_at_ms}` to the agent immediately.
25
+ * 3. Schedules a background `awaitPhraseUpload` task so the WS stays open
26
+ * across the tool's return. When the browser POSTs the encrypted
27
+ * phrase, completePairing decrypts, derives keys, registers with the
28
+ * relay, and writes credentials.json.
29
+ *
30
+ * MCP-process lifecycle note: stdio MCP servers stay alive until the host
31
+ * disconnects, so the background WS-await runs to completion or the relay
32
+ * 5-minute TTL, whichever is first. There is a 60-second hard timeout
33
+ * (matching the plugin) so a slow / abandoned browser flow doesn't hold the
34
+ * process hostage. After completion the user must restart their MCP host
35
+ * (Claude Desktop / Cursor / Claude Code) for the server to re-read
36
+ * credentials.json and switch out of `unconfigured` mode.
37
+ *
38
+ * Reference implementation: `skill/plugin/index.ts` (totalreclaw_pair tool
39
+ * handler) and `skill/plugin/pair-cli-relay.ts` (CLI runner). The crypto +
40
+ * WS-client code in `pair-crypto.ts` and `pair-remote-client.ts` is a
41
+ * verbatim port of the plugin equivalents.
42
+ */
43
+ import { type RemotePairSession } from '../pair-remote-client.js';
44
+ export declare const pairToolDefinition: {
45
+ name: string;
46
+ description: string;
47
+ inputSchema: {
48
+ type: string;
49
+ properties: {
50
+ mode: {
51
+ type: string;
52
+ enum: string[];
53
+ description: string;
54
+ default: string;
55
+ };
56
+ };
57
+ additionalProperties: boolean;
58
+ };
59
+ annotations: {
60
+ readOnlyHint: boolean;
61
+ destructiveHint: boolean;
62
+ idempotentHint: boolean;
63
+ };
64
+ };
65
+ /**
66
+ * Resolve the relay base URL for the pair WS.
67
+ *
68
+ * Order:
69
+ * 1. `TOTALRECLAW_PAIR_RELAY_URL` if set (explicit override).
70
+ * 2. `TOTALRECLAW_SERVER_URL` rewritten http→ws / https→wss (matches
71
+ * plugin's 3.3.12-rc.2 behavior — pair WS lives on the same host as
72
+ * the rest of the API, so RC users on api-staging stay on staging).
73
+ * 3. Default `wss://api.totalreclaw.xyz`.
74
+ */
75
+ export declare function resolvePairRelayUrl(env?: NodeJS.ProcessEnv): string;
76
+ /**
77
+ * Run the full WS-await + decrypt + register + write-credentials pipeline.
78
+ * Exported for testing — the tool handler schedules this as a background
79
+ * task so the agent can return URL/PIN to the user immediately.
80
+ *
81
+ * Phrase NEVER leaves this function. Logs only the relay token prefix +
82
+ * userId prefix.
83
+ */
84
+ export declare function runPairBackgroundTask(opts: {
85
+ session: RemotePairSession;
86
+ relayBaseUrl: string;
87
+ serverUrl: string;
88
+ hardTimeoutMs?: number;
89
+ log?: (level: 'info' | 'warn' | 'error', msg: string) => void;
90
+ }): Promise<void>;
91
+ export interface HandlePairOptions {
92
+ /** Override relay URL — for tests. */
93
+ relayBaseUrl?: string;
94
+ /** Override server URL written into credentials.json — defaults to env. */
95
+ serverUrl?: string;
96
+ /**
97
+ * If true, await the background task before returning. Used by tests so
98
+ * they can assert on the post-completion state. In production this is
99
+ * false — the tool handler returns immediately after URL/PIN emit so the
100
+ * agent can hand the URL to the user.
101
+ */
102
+ awaitBackground?: boolean;
103
+ /** Logger override (tests). Default writes to stderr. */
104
+ log?: (level: 'info' | 'warn' | 'error', msg: string) => void;
105
+ }
106
+ /**
107
+ * Handle a totalreclaw_pair tool call. Returns the URL + PIN + expires_at_ms
108
+ * structured payload immediately and schedules the encrypted-phrase WS-await
109
+ * as a background task.
110
+ */
111
+ export declare function handlePair(args: Record<string, unknown> | undefined, opts?: HandlePairOptions): Promise<{
112
+ content: Array<{
113
+ type: string;
114
+ text: string;
115
+ }>;
116
+ isError?: boolean;
117
+ }>;
118
+ //# sourceMappingURL=pair.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pair.d.ts","sourceRoot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