@totalreclaw/mcp-server 1.0.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 +113 -0
- package/dist/cli/setup.d.ts +43 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +276 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +700 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts.d.ts +27 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +219 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources/index.d.ts +2 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +8 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/memory-context.d.ts +16 -0
- package/dist/resources/memory-context.d.ts.map +1 -0
- package/dist/resources/memory-context.js +111 -0
- package/dist/resources/memory-context.js.map +1 -0
- package/dist/server.d.ts +4 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +25 -0
- package/dist/server.js.map +1 -0
- package/dist/subgraph/crypto.d.ts +106 -0
- package/dist/subgraph/crypto.d.ts.map +1 -0
- package/dist/subgraph/crypto.js +287 -0
- package/dist/subgraph/crypto.js.map +1 -0
- package/dist/subgraph/embedding.d.ts +47 -0
- package/dist/subgraph/embedding.d.ts.map +1 -0
- package/dist/subgraph/embedding.js +77 -0
- package/dist/subgraph/embedding.js.map +1 -0
- package/dist/subgraph/index.d.ts +7 -0
- package/dist/subgraph/index.d.ts.map +1 -0
- package/dist/subgraph/index.js +23 -0
- package/dist/subgraph/index.js.map +1 -0
- package/dist/subgraph/lsh.d.ts +95 -0
- package/dist/subgraph/lsh.d.ts.map +1 -0
- package/dist/subgraph/lsh.js +211 -0
- package/dist/subgraph/lsh.js.map +1 -0
- package/dist/subgraph/reranker.d.ts +157 -0
- package/dist/subgraph/reranker.d.ts.map +1 -0
- package/dist/subgraph/reranker.js +427 -0
- package/dist/subgraph/reranker.js.map +1 -0
- package/dist/subgraph/search.d.ts +62 -0
- package/dist/subgraph/search.d.ts.map +1 -0
- package/dist/subgraph/search.js +208 -0
- package/dist/subgraph/search.js.map +1 -0
- package/dist/subgraph/store.d.ts +97 -0
- package/dist/subgraph/store.d.ts.map +1 -0
- package/dist/subgraph/store.js +270 -0
- package/dist/subgraph/store.js.map +1 -0
- package/dist/tools/export.d.ts +48 -0
- package/dist/tools/export.d.ts.map +1 -0
- package/dist/tools/export.js +126 -0
- package/dist/tools/export.js.map +1 -0
- package/dist/tools/forget.d.ts +43 -0
- package/dist/tools/forget.d.ts.map +1 -0
- package/dist/tools/forget.js +96 -0
- package/dist/tools/forget.js.map +1 -0
- package/dist/tools/import.d.ts +73 -0
- package/dist/tools/import.d.ts.map +1 -0
- package/dist/tools/import.js +248 -0
- package/dist/tools/import.js.map +1 -0
- package/dist/tools/index.d.ts +8 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +25 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/recall.d.ts +65 -0
- package/dist/tools/recall.d.ts.map +1 -0
- package/dist/tools/recall.js +113 -0
- package/dist/tools/recall.js.map +1 -0
- package/dist/tools/remember.d.ts +109 -0
- package/dist/tools/remember.d.ts.map +1 -0
- package/dist/tools/remember.js +227 -0
- package/dist/tools/remember.js.map +1 -0
- package/dist/tools/status.d.ts +43 -0
- package/dist/tools/status.d.ts.map +1 -0
- package/dist/tools/status.js +110 -0
- package/dist/tools/status.js.map +1 -0
- package/dist/tools/upgrade.d.ts +48 -0
- package/dist/tools/upgrade.d.ts.map +1 -0
- package/dist/tools/upgrade.js +122 -0
- package/dist/tools/upgrade.js.map +1 -0
- package/package.json +61 -0
package/README.md
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# @totalreclaw/mcp-server
|
|
2
|
+
|
|
3
|
+
MCP (Model Context Protocol) server for TotalReclaw - zero-knowledge encrypted memory.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @totalreclaw/mcp-server
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### With Claude Desktop
|
|
14
|
+
|
|
15
|
+
Add to your `claude_desktop_config.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"mcpServers": {
|
|
20
|
+
"totalreclaw": {
|
|
21
|
+
"command": "npx",
|
|
22
|
+
"args": ["-y", "@totalreclaw/mcp-server"],
|
|
23
|
+
"env": {
|
|
24
|
+
"TOTALRECLAW_SERVER_URL": "http://localhost:8080",
|
|
25
|
+
"TOTALRECLAW_MASTER_PASSWORD": "your-secure-password"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### With NanoClaw
|
|
33
|
+
|
|
34
|
+
See the `@totalreclaw/skill-nanoclaw` package for NanoClaw integration.
|
|
35
|
+
|
|
36
|
+
### Environment Variables
|
|
37
|
+
|
|
38
|
+
| Variable | Description | Default |
|
|
39
|
+
|----------|-------------|---------|
|
|
40
|
+
| `TOTALRECLAW_SERVER_URL` | TotalReclaw server URL | `http://127.0.0.1:8080` |
|
|
41
|
+
| `TOTALRECLAW_MASTER_PASSWORD` | Master password for encryption | Required |
|
|
42
|
+
| `TOTALRECLAW_NAMESPACE` | Default namespace | `default` |
|
|
43
|
+
| `TOTALRECLAW_CREDENTIALS_PATH` | Path to store credentials | `/workspace/.totalreclaw/credentials.json` |
|
|
44
|
+
|
|
45
|
+
## Available Tools
|
|
46
|
+
|
|
47
|
+
### totalreclaw_remember
|
|
48
|
+
|
|
49
|
+
Store a fact in encrypted memory.
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"fact": "User prefers dark mode",
|
|
54
|
+
"importance": 7,
|
|
55
|
+
"namespace": "work"
|
|
56
|
+
}
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### totalreclaw_recall
|
|
60
|
+
|
|
61
|
+
Search memories semantically.
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
{
|
|
65
|
+
"query": "user preferences",
|
|
66
|
+
"k": 8,
|
|
67
|
+
"min_importance": 5
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### totalreclaw_forget
|
|
72
|
+
|
|
73
|
+
Delete a memory.
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"fact_id": "uuid-of-fact"
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### totalreclaw_export
|
|
82
|
+
|
|
83
|
+
Export all memories for portability.
|
|
84
|
+
|
|
85
|
+
```json
|
|
86
|
+
{
|
|
87
|
+
"format": "markdown"
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### totalreclaw_import
|
|
92
|
+
|
|
93
|
+
Import memories from backup.
|
|
94
|
+
|
|
95
|
+
```json
|
|
96
|
+
{
|
|
97
|
+
"content": "...",
|
|
98
|
+
"format": "json",
|
|
99
|
+
"merge_strategy": "skip_existing"
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm run build # Build the package
|
|
107
|
+
npm test # Run tests
|
|
108
|
+
npm run lint # Lint code
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
## License
|
|
112
|
+
|
|
113
|
+
MIT
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TotalReclaw MCP Setup CLI
|
|
3
|
+
*
|
|
4
|
+
* Interactive setup wizard for new users. Guides through:
|
|
5
|
+
* 1. Mnemonic creation or import (BIP-39 12-word)
|
|
6
|
+
* 2. Key derivation (HKDF-SHA256 -- identical to plugin/crypto.ts)
|
|
7
|
+
* 3. Server registration
|
|
8
|
+
* 4. Credential persistence (~/.totalreclaw/credentials.json)
|
|
9
|
+
* 5. MCP config snippet for Claude Desktop / Cursor / VS Code
|
|
10
|
+
*
|
|
11
|
+
* Key derivation chain (BIP-39 path, must match plugin/crypto.ts exactly):
|
|
12
|
+
* mnemonic -> mnemonicToSeedSync() -> 512-bit seed
|
|
13
|
+
* salt = seed[0..32]
|
|
14
|
+
* authKey = HKDF-SHA256(seed, salt, "totalreclaw-auth-key-v1", 32)
|
|
15
|
+
* authKeyHash = SHA-256(authKey).hex()
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Derive the auth key and salt from a BIP-39 mnemonic.
|
|
19
|
+
*
|
|
20
|
+
* This is the exact same derivation as `deriveKeysFromMnemonic` in
|
|
21
|
+
* `skill/plugin/crypto.ts`:
|
|
22
|
+
* - BIP-39 seed via mnemonicToSeedSync (512 bits)
|
|
23
|
+
* - salt = first 32 bytes of seed
|
|
24
|
+
* - authKey = HKDF-SHA256(seed, salt, "totalreclaw-auth-key-v1", 32)
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveAuthKey(mnemonic: string): {
|
|
27
|
+
authKey: Uint8Array;
|
|
28
|
+
salt: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Compute SHA-256(authKey) as a hex string.
|
|
32
|
+
* Matches `computeAuthKeyHash` in plugin/crypto.ts.
|
|
33
|
+
*/
|
|
34
|
+
export declare function computeAuthKeyHash(authKey: Uint8Array): string;
|
|
35
|
+
export interface SavedCredentials {
|
|
36
|
+
userId: string;
|
|
37
|
+
salt: string;
|
|
38
|
+
serverUrl: string;
|
|
39
|
+
}
|
|
40
|
+
export declare function saveCredentials(credentials: SavedCredentials, filePath?: string): void;
|
|
41
|
+
export declare function loadCredentials(filePath?: string): SavedCredentials;
|
|
42
|
+
export declare function runSetup(): Promise<void>;
|
|
43
|
+
//# sourceMappingURL=setup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.d.ts","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA0BH;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAWzF;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAG9D;AAgED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,eAAe,CAAC,WAAW,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAYtF;AAED,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAInE;AAiCD,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAuG9C"}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* TotalReclaw MCP Setup CLI
|
|
4
|
+
*
|
|
5
|
+
* Interactive setup wizard for new users. Guides through:
|
|
6
|
+
* 1. Mnemonic creation or import (BIP-39 12-word)
|
|
7
|
+
* 2. Key derivation (HKDF-SHA256 -- identical to plugin/crypto.ts)
|
|
8
|
+
* 3. Server registration
|
|
9
|
+
* 4. Credential persistence (~/.totalreclaw/credentials.json)
|
|
10
|
+
* 5. MCP config snippet for Claude Desktop / Cursor / VS Code
|
|
11
|
+
*
|
|
12
|
+
* Key derivation chain (BIP-39 path, must match plugin/crypto.ts exactly):
|
|
13
|
+
* mnemonic -> mnemonicToSeedSync() -> 512-bit seed
|
|
14
|
+
* salt = seed[0..32]
|
|
15
|
+
* authKey = HKDF-SHA256(seed, salt, "totalreclaw-auth-key-v1", 32)
|
|
16
|
+
* authKeyHash = SHA-256(authKey).hex()
|
|
17
|
+
*/
|
|
18
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
19
|
+
if (k2 === undefined) k2 = k;
|
|
20
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
21
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
22
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
23
|
+
}
|
|
24
|
+
Object.defineProperty(o, k2, desc);
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
35
|
+
var ownKeys = function(o) {
|
|
36
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
37
|
+
var ar = [];
|
|
38
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
39
|
+
return ar;
|
|
40
|
+
};
|
|
41
|
+
return ownKeys(o);
|
|
42
|
+
};
|
|
43
|
+
return function (mod) {
|
|
44
|
+
if (mod && mod.__esModule) return mod;
|
|
45
|
+
var result = {};
|
|
46
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
47
|
+
__setModuleDefault(result, mod);
|
|
48
|
+
return result;
|
|
49
|
+
};
|
|
50
|
+
})();
|
|
51
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
52
|
+
exports.deriveAuthKey = deriveAuthKey;
|
|
53
|
+
exports.computeAuthKeyHash = computeAuthKeyHash;
|
|
54
|
+
exports.saveCredentials = saveCredentials;
|
|
55
|
+
exports.loadCredentials = loadCredentials;
|
|
56
|
+
exports.runSetup = runSetup;
|
|
57
|
+
const readline = __importStar(require("node:readline"));
|
|
58
|
+
const fs = __importStar(require("node:fs"));
|
|
59
|
+
const path = __importStar(require("node:path"));
|
|
60
|
+
const os = __importStar(require("node:os"));
|
|
61
|
+
const bip39_1 = require("@scure/bip39");
|
|
62
|
+
const english_js_1 = require("@scure/bip39/wordlists/english.js");
|
|
63
|
+
const hkdf_js_1 = require("@noble/hashes/hkdf.js");
|
|
64
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// Constants -- must match plugin/crypto.ts
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
const AUTH_KEY_INFO = 'totalreclaw-auth-key-v1';
|
|
69
|
+
const DEFAULT_SERVER_URL = 'https://api.totalreclaw.xyz';
|
|
70
|
+
const CREDENTIALS_DIR = path.join(os.homedir(), '.totalreclaw');
|
|
71
|
+
const CREDENTIALS_PATH = path.join(CREDENTIALS_DIR, 'credentials.json');
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
// Key Derivation (BIP-39 path only -- matches plugin/crypto.ts)
|
|
74
|
+
// ---------------------------------------------------------------------------
|
|
75
|
+
/**
|
|
76
|
+
* Derive the auth key and salt from a BIP-39 mnemonic.
|
|
77
|
+
*
|
|
78
|
+
* This is the exact same derivation as `deriveKeysFromMnemonic` in
|
|
79
|
+
* `skill/plugin/crypto.ts`:
|
|
80
|
+
* - BIP-39 seed via mnemonicToSeedSync (512 bits)
|
|
81
|
+
* - salt = first 32 bytes of seed
|
|
82
|
+
* - authKey = HKDF-SHA256(seed, salt, "totalreclaw-auth-key-v1", 32)
|
|
83
|
+
*/
|
|
84
|
+
function deriveAuthKey(mnemonic) {
|
|
85
|
+
const seed = (0, bip39_1.mnemonicToSeedSync)(mnemonic.trim());
|
|
86
|
+
// Deterministic salt: first 32 bytes of BIP-39 seed
|
|
87
|
+
const salt = seed.slice(0, 32);
|
|
88
|
+
// HKDF-SHA256 with the full 512-bit seed as IKM
|
|
89
|
+
const infoBytes = new TextEncoder().encode(AUTH_KEY_INFO);
|
|
90
|
+
const authKey = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, seed, salt, infoBytes, 32);
|
|
91
|
+
return { authKey, salt };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compute SHA-256(authKey) as a hex string.
|
|
95
|
+
* Matches `computeAuthKeyHash` in plugin/crypto.ts.
|
|
96
|
+
*/
|
|
97
|
+
function computeAuthKeyHash(authKey) {
|
|
98
|
+
const hash = (0, sha2_js_1.sha256)(authKey);
|
|
99
|
+
return Buffer.from(hash).toString('hex');
|
|
100
|
+
}
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// Readline helpers
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
function createInterface() {
|
|
105
|
+
return readline.createInterface({
|
|
106
|
+
input: process.stdin,
|
|
107
|
+
output: process.stdout,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function ask(rl, question) {
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
rl.question(question, (answer) => {
|
|
113
|
+
resolve(answer.trim());
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
async function registerWithServer(serverUrl, authKeyHash, saltHex) {
|
|
118
|
+
const url = `${serverUrl.replace(/\/+$/, '')}/v1/register`;
|
|
119
|
+
const response = await fetch(url, {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: { 'Content-Type': 'application/json' },
|
|
122
|
+
body: JSON.stringify({
|
|
123
|
+
auth_key_hash: authKeyHash,
|
|
124
|
+
salt: saltHex,
|
|
125
|
+
}),
|
|
126
|
+
});
|
|
127
|
+
if (!response.ok) {
|
|
128
|
+
const body = await response.text().catch(() => '');
|
|
129
|
+
throw new Error(`Registration failed (HTTP ${response.status}): ${body || response.statusText}`);
|
|
130
|
+
}
|
|
131
|
+
const data = (await response.json());
|
|
132
|
+
if (!data.user_id) {
|
|
133
|
+
throw new Error('Registration response missing user_id');
|
|
134
|
+
}
|
|
135
|
+
return data.user_id;
|
|
136
|
+
}
|
|
137
|
+
function saveCredentials(credentials, filePath) {
|
|
138
|
+
const targetPath = filePath || CREDENTIALS_PATH;
|
|
139
|
+
const dir = path.dirname(targetPath);
|
|
140
|
+
if (!fs.existsSync(dir)) {
|
|
141
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
142
|
+
}
|
|
143
|
+
fs.writeFileSync(targetPath, JSON.stringify(credentials, null, 2) + '\n', {
|
|
144
|
+
encoding: 'utf-8',
|
|
145
|
+
mode: 0o600, // Owner read/write only
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
function loadCredentials(filePath) {
|
|
149
|
+
const targetPath = filePath || CREDENTIALS_PATH;
|
|
150
|
+
const data = fs.readFileSync(targetPath, 'utf-8');
|
|
151
|
+
return JSON.parse(data);
|
|
152
|
+
}
|
|
153
|
+
// ---------------------------------------------------------------------------
|
|
154
|
+
// Config Snippet
|
|
155
|
+
// ---------------------------------------------------------------------------
|
|
156
|
+
function printConfigSnippet(serverUrl) {
|
|
157
|
+
const snippet = {
|
|
158
|
+
mcpServers: {
|
|
159
|
+
totalreclaw: {
|
|
160
|
+
command: 'npx',
|
|
161
|
+
args: ['@totalreclaw/mcp-server'],
|
|
162
|
+
env: {
|
|
163
|
+
TOTALRECLAW_MASTER_PASSWORD: '<your-12-word-seed-phrase>',
|
|
164
|
+
TOTALRECLAW_SERVER_URL: serverUrl,
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
console.log('\n========================================');
|
|
170
|
+
console.log('Add this to your MCP config');
|
|
171
|
+
console.log('(Claude Desktop / Cursor / VS Code):');
|
|
172
|
+
console.log('========================================\n');
|
|
173
|
+
console.log(JSON.stringify(snippet, null, 2));
|
|
174
|
+
console.log('\nReplace <your-12-word-seed-phrase> with your actual seed phrase.');
|
|
175
|
+
console.log('');
|
|
176
|
+
}
|
|
177
|
+
// ---------------------------------------------------------------------------
|
|
178
|
+
// Main Setup Flow
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
async function runSetup() {
|
|
181
|
+
const rl = createInterface();
|
|
182
|
+
console.log('');
|
|
183
|
+
console.log('=== TotalReclaw Setup ===');
|
|
184
|
+
console.log('Zero-knowledge encrypted memory for AI agents.');
|
|
185
|
+
console.log('');
|
|
186
|
+
try {
|
|
187
|
+
// ── Step 1: Mnemonic ──────────────────────────────────────────────────
|
|
188
|
+
let mnemonic;
|
|
189
|
+
const hasExisting = await ask(rl, 'Do you have an existing seed phrase? (y/n): ');
|
|
190
|
+
if (hasExisting.toLowerCase() === 'y' || hasExisting.toLowerCase() === 'yes') {
|
|
191
|
+
// Import existing mnemonic
|
|
192
|
+
console.log('');
|
|
193
|
+
console.log('Enter your 12-word seed phrase (space-separated):');
|
|
194
|
+
mnemonic = await ask(rl, '> ');
|
|
195
|
+
if (!(0, bip39_1.validateMnemonic)(mnemonic, english_js_1.wordlist)) {
|
|
196
|
+
console.error('\nError: Invalid mnemonic. Please check your words and try again.');
|
|
197
|
+
rl.close();
|
|
198
|
+
process.exit(1);
|
|
199
|
+
}
|
|
200
|
+
console.log('\nSeed phrase validated successfully.');
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
// Generate new mnemonic
|
|
204
|
+
mnemonic = (0, bip39_1.generateMnemonic)(english_js_1.wordlist, 128); // 128 bits = 12 words
|
|
205
|
+
console.log('');
|
|
206
|
+
console.log('Your new seed phrase (WRITE THIS DOWN AND KEEP IT SAFE):');
|
|
207
|
+
console.log('');
|
|
208
|
+
console.log(` ${mnemonic}`);
|
|
209
|
+
console.log('');
|
|
210
|
+
console.log('WARNING: This is the ONLY way to recover your encrypted memories.');
|
|
211
|
+
console.log(' Anyone with this phrase can access your data.');
|
|
212
|
+
console.log(' Store it in a password manager or write it down securely.');
|
|
213
|
+
console.log('');
|
|
214
|
+
const confirmed = await ask(rl, 'Have you saved your seed phrase? (yes to continue): ');
|
|
215
|
+
if (confirmed.toLowerCase() !== 'yes' && confirmed.toLowerCase() !== 'y') {
|
|
216
|
+
console.log('\nSetup cancelled. Please save your seed phrase and try again.');
|
|
217
|
+
rl.close();
|
|
218
|
+
process.exit(1);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// ── Step 2: Key Derivation ────────────────────────────────────────────
|
|
222
|
+
const { authKey, salt } = deriveAuthKey(mnemonic);
|
|
223
|
+
const authKeyHash = computeAuthKeyHash(authKey);
|
|
224
|
+
const saltHex = Buffer.from(salt).toString('hex');
|
|
225
|
+
console.log('\nKeys derived successfully.');
|
|
226
|
+
// ── Step 3: Server URL ────────────────────────────────────────────────
|
|
227
|
+
const serverUrlInput = await ask(rl, `Server URL (press Enter for ${DEFAULT_SERVER_URL}): `);
|
|
228
|
+
const serverUrl = serverUrlInput || DEFAULT_SERVER_URL;
|
|
229
|
+
// ── Step 4: Server Registration ───────────────────────────────────────
|
|
230
|
+
console.log(`\nRegistering with ${serverUrl}...`);
|
|
231
|
+
let userId;
|
|
232
|
+
try {
|
|
233
|
+
userId = await registerWithServer(serverUrl, authKeyHash, saltHex);
|
|
234
|
+
console.log(`Registered successfully. User ID: ${userId}`);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
238
|
+
console.error(`\nRegistration failed: ${message}`);
|
|
239
|
+
console.error('You can retry setup later or register manually.');
|
|
240
|
+
rl.close();
|
|
241
|
+
process.exit(1);
|
|
242
|
+
}
|
|
243
|
+
// ── Step 5: Save Credentials ──────────────────────────────────────────
|
|
244
|
+
const credentials = {
|
|
245
|
+
userId,
|
|
246
|
+
salt: saltHex,
|
|
247
|
+
serverUrl,
|
|
248
|
+
};
|
|
249
|
+
saveCredentials(credentials);
|
|
250
|
+
console.log(`\nCredentials saved to ${CREDENTIALS_PATH}`);
|
|
251
|
+
console.log('(Mnemonic and keys are NOT stored -- only userId, salt, and serverUrl.)');
|
|
252
|
+
// ── Step 6: Print Config Snippet ──────────────────────────────────────
|
|
253
|
+
printConfigSnippet(serverUrl);
|
|
254
|
+
console.log('Setup complete! You can now use TotalReclaw with any MCP-compatible AI agent.');
|
|
255
|
+
console.log('');
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
rl.close();
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// ---------------------------------------------------------------------------
|
|
262
|
+
// CLI Entry Point
|
|
263
|
+
// ---------------------------------------------------------------------------
|
|
264
|
+
// When run directly (not imported), execute the setup wizard
|
|
265
|
+
const isDirectRun = typeof process !== 'undefined' &&
|
|
266
|
+
process.argv[1] &&
|
|
267
|
+
(process.argv[1].endsWith('/setup.js') ||
|
|
268
|
+
process.argv[1].endsWith('/setup.ts') ||
|
|
269
|
+
process.argv[1].endsWith('cli/setup'));
|
|
270
|
+
if (isDirectRun) {
|
|
271
|
+
runSetup().catch((error) => {
|
|
272
|
+
console.error('Setup failed:', error);
|
|
273
|
+
process.exit(1);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
//# sourceMappingURL=setup.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/cli/setup.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCH,sCAWC;AAMD,gDAGC;AAsED,0CAYC;AAED,0CAIC;AAiCD,4BAuGC;AArRD,wDAA0C;AAC1C,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAE9B,wCAAsF;AACtF,kEAA6D;AAC7D,mDAA6C;AAC7C,mDAA+C;AAE/C,8EAA8E;AAC9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