mobilecoder-mcp 2.1.2 → 2.1.3
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/dist/agent.d.ts +28 -28
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +350 -322
- package/dist/agent.js.map +1 -1
- package/dist/cli.d.ts +2 -2
- package/dist/cli.js +39 -34
- package/dist/cli.js.map +1 -1
- package/package.json +3 -3
- package/dist/adapters/cli-adapter.d.ts +0 -13
- package/dist/adapters/cli-adapter.d.ts.map +0 -1
- package/dist/adapters/cli-adapter.js +0 -58
- package/dist/adapters/cli-adapter.js.map +0 -1
- package/dist/index.d.ts +0 -3
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -152
- package/dist/index.js.map +0 -1
- package/dist/mcp-handler.d.ts +0 -3
- package/dist/mcp-handler.d.ts.map +0 -1
- package/dist/mcp-handler.js +0 -322
- package/dist/mcp-handler.js.map +0 -1
- package/dist/security.d.ts +0 -54
- package/dist/security.d.ts.map +0 -1
- package/dist/security.js +0 -307
- package/dist/security.js.map +0 -1
- package/dist/tool-detector.d.ts +0 -18
- package/dist/tool-detector.d.ts.map +0 -1
- package/dist/tool-detector.js +0 -93
- package/dist/tool-detector.js.map +0 -1
- package/dist/webrtc.d.ts +0 -23
- package/dist/webrtc.d.ts.map +0 -1
- package/dist/webrtc.js +0 -143
- package/dist/webrtc.js.map +0 -1
package/dist/agent.js
CHANGED
|
@@ -1,323 +1,351 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
this.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.
|
|
97
|
-
this.
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
//
|
|
111
|
-
this.
|
|
112
|
-
this.
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
//
|
|
201
|
-
if (cmd.type === '
|
|
202
|
-
this.
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
//
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
if (
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.ZKRelayAgent = void 0;
|
|
30
|
+
const socket_io_client_1 = require("socket.io-client");
|
|
31
|
+
const os = __importStar(require("os"));
|
|
32
|
+
const pty = __importStar(require("node-pty"));
|
|
33
|
+
const crypto = __importStar(require("crypto"));
|
|
34
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
35
|
+
const ora_1 = __importDefault(require("ora"));
|
|
36
|
+
const fs = __importStar(require("fs"));
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
// 🚨 BURAYI KENDİ DOMAIN ADRESİNLE DEĞİŞTİR!
|
|
39
|
+
const RELAY_SERVER_URL = 'https://api.mobilecoder.xyz';
|
|
40
|
+
// Security Constants
|
|
41
|
+
const PBKDF2_ITERATIONS = 100000;
|
|
42
|
+
const KEY_LENGTH = 32; // 256 bits
|
|
43
|
+
const SALT = 'mobilecoder-salt-v2';
|
|
44
|
+
const KEY_ROTATION_INTERVAL = 600000; // 10 minutes
|
|
45
|
+
const MESSAGE_MAX_AGE = 300000; // 5 minutes
|
|
46
|
+
class ZKRelayAgent {
|
|
47
|
+
socket;
|
|
48
|
+
ptyProcess;
|
|
49
|
+
secretCode;
|
|
50
|
+
roomId;
|
|
51
|
+
// 🔐 Güçlendirilmiş Güvenlik Değişkenleri
|
|
52
|
+
masterKey;
|
|
53
|
+
sessionKey;
|
|
54
|
+
sessionCounter = 0;
|
|
55
|
+
seenNonces = new Set();
|
|
56
|
+
nonceCleanupInterval = null;
|
|
57
|
+
keyRotationInterval = null;
|
|
58
|
+
spinner = (0, ora_1.default)('Initializing Secure Tunnel...');
|
|
59
|
+
constructor() {
|
|
60
|
+
this.setupSecurity();
|
|
61
|
+
this.initPTY();
|
|
62
|
+
this.connectToRelay();
|
|
63
|
+
this.startSecurityMaintenance();
|
|
64
|
+
}
|
|
65
|
+
// 1. Güvenlik Katmanı: PBKDF2 ile Güçlendirilmiş Anahtar Türetme
|
|
66
|
+
setupSecurity() {
|
|
67
|
+
// 6 Haneli rastgele kod (Kullanıcının göreceği)
|
|
68
|
+
const randomNum = Math.floor(100000 + Math.random() * 900000);
|
|
69
|
+
this.secretCode = randomNum.toString();
|
|
70
|
+
// Oda ID'si: Kodun Hash'i (Sunucu sadece bunu görür, kodu göremez)
|
|
71
|
+
this.roomId = crypto.createHash('sha256').update(this.secretCode).digest('hex');
|
|
72
|
+
// 🔐 PBKDF2 ile Master Key Türetme (Brute-force'a karşı savunma)
|
|
73
|
+
this.masterKey = crypto.pbkdf2Sync(this.secretCode, SALT, PBKDF2_ITERATIONS, KEY_LENGTH, 'sha256');
|
|
74
|
+
// Session Key (PFS için rotasyonlu)
|
|
75
|
+
this.sessionKey = this.deriveSessionKey(0);
|
|
76
|
+
}
|
|
77
|
+
// 🔐 Session Key Türetme (Perfect Forward Secrecy)
|
|
78
|
+
deriveSessionKey(counter) {
|
|
79
|
+
return crypto.pbkdf2Sync(this.masterKey, `session-${counter}`, 10000, KEY_LENGTH, 'sha256');
|
|
80
|
+
}
|
|
81
|
+
// 🔄 Key Rotation (Her 10 dakikada bir)
|
|
82
|
+
rotateKey() {
|
|
83
|
+
this.sessionCounter++;
|
|
84
|
+
this.sessionKey = this.deriveSessionKey(this.sessionCounter);
|
|
85
|
+
console.log(chalk_1.default.cyan(`🔄 Session key rotated to #${this.sessionCounter}`));
|
|
86
|
+
// Notify peer about key rotation
|
|
87
|
+
this.sendSecurePayload('key_rotation', { counter: this.sessionCounter });
|
|
88
|
+
}
|
|
89
|
+
// 🧹 Güvenlik Bakımı
|
|
90
|
+
startSecurityMaintenance() {
|
|
91
|
+
// Nonce temizliği (5 dakikadan eski nonce'ları sil)
|
|
92
|
+
this.nonceCleanupInterval = setInterval(() => {
|
|
93
|
+
this.seenNonces.clear();
|
|
94
|
+
}, MESSAGE_MAX_AGE);
|
|
95
|
+
// Key rotation
|
|
96
|
+
this.keyRotationInterval = setInterval(() => {
|
|
97
|
+
this.rotateKey();
|
|
98
|
+
}, KEY_ROTATION_INTERVAL);
|
|
99
|
+
}
|
|
100
|
+
// 2. Terminal (PTY) Başlatma
|
|
101
|
+
initPTY() {
|
|
102
|
+
const shell = os.platform() === 'win32' ? 'powershell.exe' : (process.env.SHELL || 'bash');
|
|
103
|
+
this.ptyProcess = pty.spawn(shell, [], {
|
|
104
|
+
name: 'xterm-256color',
|
|
105
|
+
cols: 80,
|
|
106
|
+
rows: 24,
|
|
107
|
+
cwd: process.cwd(),
|
|
108
|
+
env: process.env
|
|
109
|
+
});
|
|
110
|
+
// Terminalden çıkan veriyi şifrele ve yolla
|
|
111
|
+
this.ptyProcess.onData((data) => {
|
|
112
|
+
this.sendSecurePayload('term_data', data);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
// 3. Relay Sunucusuna Bağlanma
|
|
116
|
+
connectToRelay() {
|
|
117
|
+
this.spinner.start('Connecting to MobileCoder Relay Network...');
|
|
118
|
+
this.socket = (0, socket_io_client_1.io)(RELAY_SERVER_URL, {
|
|
119
|
+
transports: ['websocket'],
|
|
120
|
+
reconnection: true,
|
|
121
|
+
reconnectionAttempts: Infinity
|
|
122
|
+
});
|
|
123
|
+
this.socket.on('connect', () => {
|
|
124
|
+
this.spinner.succeed(chalk_1.default.green('Connected to Relay Node!'));
|
|
125
|
+
// Odaya Katıl (Sadece Hash ID gönderilir)
|
|
126
|
+
this.socket.emit('join_room', { code: this.roomId, type: 'agent' });
|
|
127
|
+
this.printBanner();
|
|
128
|
+
});
|
|
129
|
+
this.socket.on('disconnect', () => {
|
|
130
|
+
this.spinner.warn(chalk_1.default.yellow('Connection lost. Reconnecting...'));
|
|
131
|
+
});
|
|
132
|
+
// Mobilden biri bağlandığında
|
|
133
|
+
this.socket.on('peer_joined', () => {
|
|
134
|
+
console.log(chalk_1.default.green('\n📱 Mobile Client Connected via Encrypted Tunnel!'));
|
|
135
|
+
this.sendEnvInfo();
|
|
136
|
+
});
|
|
137
|
+
// Mobilden şifreli veri geldiğinde
|
|
138
|
+
this.socket.on('relay_data', (message) => {
|
|
139
|
+
this.handleIncomingMessage(message);
|
|
140
|
+
});
|
|
141
|
+
// Also listen for connect_error
|
|
142
|
+
this.socket.on('connect_error', (err) => {
|
|
143
|
+
// console.error(err);
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
// 🔐 AES-256-CBC ile Şifreleme (Nonce tabanlı)
|
|
147
|
+
encrypt(data) {
|
|
148
|
+
const nonce = crypto.randomBytes(16);
|
|
149
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', this.sessionKey, nonce);
|
|
150
|
+
const encrypted = Buffer.concat([
|
|
151
|
+
cipher.update(data, 'utf8'),
|
|
152
|
+
cipher.final()
|
|
153
|
+
]);
|
|
154
|
+
return {
|
|
155
|
+
nonce: nonce.toString('base64'),
|
|
156
|
+
data: encrypted.toString('base64'),
|
|
157
|
+
timestamp: Date.now()
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
// 🔐 AES-256-CBC ile Şifre Çözme (Replay Attack Korumalı)
|
|
161
|
+
decrypt(packet) {
|
|
162
|
+
// Timestamp kontrolü (5 dakikadan eski mesajları reddet)
|
|
163
|
+
if (Date.now() - packet.timestamp > MESSAGE_MAX_AGE) {
|
|
164
|
+
throw new Error('Message too old - potential replay attack');
|
|
165
|
+
}
|
|
166
|
+
// Nonce uniqueness kontrolü (Replay attack önleme)
|
|
167
|
+
if (this.seenNonces.has(packet.nonce)) {
|
|
168
|
+
throw new Error('Replay attack detected - duplicate nonce');
|
|
169
|
+
}
|
|
170
|
+
this.seenNonces.add(packet.nonce);
|
|
171
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', this.sessionKey, Buffer.from(packet.nonce, 'base64'));
|
|
172
|
+
return Buffer.concat([
|
|
173
|
+
decipher.update(Buffer.from(packet.data, 'base64')),
|
|
174
|
+
decipher.final()
|
|
175
|
+
]).toString('utf8');
|
|
176
|
+
}
|
|
177
|
+
// Gelen veriyi çöz ve işle
|
|
178
|
+
handleIncomingMessage(encryptedPayload) {
|
|
179
|
+
try {
|
|
180
|
+
let decryptedText;
|
|
181
|
+
// Yeni format: { nonce, data, timestamp }
|
|
182
|
+
if (typeof encryptedPayload === 'object' && encryptedPayload.nonce) {
|
|
183
|
+
decryptedText = this.decrypt(encryptedPayload);
|
|
184
|
+
}
|
|
185
|
+
// Legacy format: { e: ciphertext } (CryptoJS uyumluluğu)
|
|
186
|
+
else if (typeof encryptedPayload === 'object' && encryptedPayload.e) {
|
|
187
|
+
// Legacy CryptoJS decrypt fallback
|
|
188
|
+
const CryptoJS = require('crypto-js');
|
|
189
|
+
const bytes = CryptoJS.AES.decrypt(encryptedPayload.e, this.secretCode);
|
|
190
|
+
decryptedText = bytes.toString(CryptoJS.enc.Utf8);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!decryptedText)
|
|
196
|
+
return;
|
|
197
|
+
// Veri JSON mu? (Resize komutu vs olabilir)
|
|
198
|
+
try {
|
|
199
|
+
const cmd = JSON.parse(decryptedText);
|
|
200
|
+
// Handle key rotation from peer
|
|
201
|
+
if (cmd.type === 'key_rotation') {
|
|
202
|
+
this.sessionCounter = cmd.counter;
|
|
203
|
+
this.sessionKey = this.deriveSessionKey(this.sessionCounter);
|
|
204
|
+
console.log(chalk_1.default.cyan(`🔄 Key synced to session #${this.sessionCounter}`));
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
// 1. Terminal Input (Keystrokes)
|
|
208
|
+
if (cmd.type === 'input') {
|
|
209
|
+
this.ptyProcess.write(cmd.data);
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
// 2. Terminal Resize
|
|
213
|
+
if (cmd.type === 'resize') {
|
|
214
|
+
this.ptyProcess.resize(cmd.cols, cmd.rows);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
// 3. Chat Commands (e.g. "ls -la")
|
|
218
|
+
if (cmd.type === 'command') {
|
|
219
|
+
this.ptyProcess.write(cmd.text + '\r');
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
// 4. CLI Tool/Button Commands (e.g. "git status")
|
|
223
|
+
if (cmd.type === 'cli_command') {
|
|
224
|
+
this.ptyProcess.write(cmd.command + '\r');
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
// 5. Tool Calls (File System Access)
|
|
228
|
+
if (cmd.type === 'tool_call') {
|
|
229
|
+
this.handleToolCall(cmd.tool, cmd.data, cmd.id);
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
// JSON değilse saf terminal girdisidir
|
|
235
|
+
this.ptyProcess.write(decryptedText);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
// Şifre çözülemezse (Yanlış anahtar vb.) sessizce yut
|
|
240
|
+
console.error(chalk_1.default.red('Decryption failed:'), error.message);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
async handleToolCall(tool, args, id) {
|
|
244
|
+
try {
|
|
245
|
+
let result = null;
|
|
246
|
+
if (tool === 'list_directory') {
|
|
247
|
+
const dirPath = args.path ? path.resolve(args.path) : process.cwd();
|
|
248
|
+
const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
|
|
249
|
+
const files = entries.map(entry => ({
|
|
250
|
+
name: entry.name,
|
|
251
|
+
type: entry.isDirectory() ? 'directory' : 'file',
|
|
252
|
+
size: 0 // Simplification for speed
|
|
253
|
+
}));
|
|
254
|
+
result = { files };
|
|
255
|
+
}
|
|
256
|
+
else if (tool === 'read_file') {
|
|
257
|
+
const filePath = path.resolve(args.path);
|
|
258
|
+
const content = await fs.promises.readFile(filePath, 'utf-8');
|
|
259
|
+
result = { content };
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
throw new Error(`Unknown tool: ${tool}`);
|
|
263
|
+
}
|
|
264
|
+
this.sendSecurePayload('tool_result', {
|
|
265
|
+
id,
|
|
266
|
+
result
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
this.sendSecurePayload('tool_result', {
|
|
271
|
+
id,
|
|
272
|
+
error: error.message,
|
|
273
|
+
type: 'error'
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
// Veriyi şifrele ve gönder
|
|
278
|
+
sendSecurePayload(type, data) {
|
|
279
|
+
let payloadStr = '';
|
|
280
|
+
if (type === 'meta' || type === 'tool_result' || type === 'key_rotation') {
|
|
281
|
+
// Standardize format
|
|
282
|
+
if (type === 'tool_result') {
|
|
283
|
+
if (data.type === 'error') {
|
|
284
|
+
payloadStr = JSON.stringify({ ...data });
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
287
|
+
payloadStr = JSON.stringify({ type: 'result', ...data });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else if (type === 'key_rotation') {
|
|
291
|
+
payloadStr = JSON.stringify({ type: 'key_rotation', ...data });
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
payloadStr = JSON.stringify(data);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
else if (type === 'term_data') {
|
|
298
|
+
// Wrap output in { type: 'output', data: ... }
|
|
299
|
+
if (typeof data === 'string') {
|
|
300
|
+
payloadStr = JSON.stringify({ type: 'output', data: data });
|
|
301
|
+
}
|
|
302
|
+
else {
|
|
303
|
+
payloadStr = JSON.stringify(data);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// Fallback if empty (shouldn't happen with above logic)
|
|
307
|
+
if (!payloadStr)
|
|
308
|
+
payloadStr = JSON.stringify(data);
|
|
309
|
+
// 🔐 Yeni şifreleme formatı ile gönder
|
|
310
|
+
const encrypted = this.encrypt(payloadStr);
|
|
311
|
+
this.socket.emit('relay_data', {
|
|
312
|
+
room: this.roomId,
|
|
313
|
+
payload: encrypted
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
sendEnvInfo() {
|
|
317
|
+
const info = {
|
|
318
|
+
type: 'host_info',
|
|
319
|
+
username: os.userInfo().username,
|
|
320
|
+
hostname: os.hostname(),
|
|
321
|
+
platform: os.platform(),
|
|
322
|
+
cwd: process.cwd()
|
|
323
|
+
};
|
|
324
|
+
this.sendSecurePayload('meta', info);
|
|
325
|
+
}
|
|
326
|
+
printBanner() {
|
|
327
|
+
console.log('\n' + chalk_1.default.bgBlue.bold(' MOBILECODER ZK-RELAY v2.1.0 '));
|
|
328
|
+
console.log(chalk_1.default.gray('🔐 PBKDF2-SHA256 + AES-256-CBC + Nonce-Based Replay Protection'));
|
|
329
|
+
console.log(chalk_1.default.gray('🔄 Perfect Forward Secrecy with 10-min Key Rotation\n'));
|
|
330
|
+
console.log(chalk_1.default.yellow('┌──────────────────────────────────────┐'));
|
|
331
|
+
console.log(chalk_1.default.yellow('│ 🔑 CONNECTION CODE (ENTER ON APP) │'));
|
|
332
|
+
console.log(chalk_1.default.yellow('│ │'));
|
|
333
|
+
console.log(chalk_1.default.yellow(`│ ${chalk_1.default.white.bold.bgBlack(` ${this.secretCode.slice(0, 3)} - ${this.secretCode.slice(3)} `)} │`));
|
|
334
|
+
console.log(chalk_1.default.yellow('│ │'));
|
|
335
|
+
console.log(chalk_1.default.yellow('└──────────────────────────────────────┘'));
|
|
336
|
+
console.log(chalk_1.default.cyan('\nWaiting for mobile connection...'));
|
|
337
|
+
}
|
|
338
|
+
// Cleanup
|
|
339
|
+
destroy() {
|
|
340
|
+
if (this.nonceCleanupInterval)
|
|
341
|
+
clearInterval(this.nonceCleanupInterval);
|
|
342
|
+
if (this.keyRotationInterval)
|
|
343
|
+
clearInterval(this.keyRotationInterval);
|
|
344
|
+
if (this.socket)
|
|
345
|
+
this.socket.disconnect();
|
|
346
|
+
if (this.ptyProcess)
|
|
347
|
+
this.ptyProcess.kill();
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
exports.ZKRelayAgent = ZKRelayAgent;
|
|
323
351
|
//# sourceMappingURL=agent.js.map
|