@cjwddz/mirror 1.1.0 → 1.2.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 +89 -222
- package/dist/cli/client.d.ts +19 -0
- package/dist/cli/client.d.ts.map +1 -0
- package/dist/cli/client.js +107 -0
- package/dist/cli/client.js.map +1 -0
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +88 -51
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/server.d.ts +19 -0
- package/dist/cli/server.d.ts.map +1 -0
- package/dist/cli/server.js +82 -0
- package/dist/cli/server.js.map +1 -0
- package/dist/core/http-tunnel-client.d.ts +64 -0
- package/dist/core/http-tunnel-client.d.ts.map +1 -0
- package/dist/core/http-tunnel-client.js +315 -0
- package/dist/core/http-tunnel-client.js.map +1 -0
- package/dist/core/http-tunnel-protocol.d.ts +86 -0
- package/dist/core/http-tunnel-protocol.d.ts.map +1 -0
- package/dist/core/http-tunnel-protocol.js +29 -0
- package/dist/core/http-tunnel-protocol.js.map +1 -0
- package/dist/core/http-tunnel-server.d.ts +74 -0
- package/dist/core/http-tunnel-server.d.ts.map +1 -0
- package/dist/core/http-tunnel-server.js +317 -0
- package/dist/core/http-tunnel-server.js.map +1 -0
- package/dist/index.d.ts +4 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -8
- package/dist/index.js.map +1 -1
- package/package.json +12 -10
- package/dist/cli/exec.d.ts +0 -9
- package/dist/cli/exec.d.ts.map +0 -1
- package/dist/cli/exec.js +0 -32
- package/dist/cli/exec.js.map +0 -1
- package/dist/cli/host-impl.d.ts +0 -58
- package/dist/cli/host-impl.d.ts.map +0 -1
- package/dist/cli/host-impl.js +0 -547
- package/dist/cli/host-impl.js.map +0 -1
- package/dist/cli/host.d.ts +0 -9
- package/dist/cli/host.d.ts.map +0 -1
- package/dist/cli/host.js +0 -57
- package/dist/cli/host.js.map +0 -1
- package/dist/cli/link.d.ts +0 -10
- package/dist/cli/link.d.ts.map +0 -1
- package/dist/cli/link.js +0 -105
- package/dist/cli/link.js.map +0 -1
- package/dist/cli/logs.d.ts +0 -8
- package/dist/cli/logs.d.ts.map +0 -1
- package/dist/cli/logs.js +0 -48
- package/dist/cli/logs.js.map +0 -1
- package/dist/cli/shell.d.ts +0 -6
- package/dist/cli/shell.d.ts.map +0 -1
- package/dist/cli/shell.js +0 -53
- package/dist/cli/shell.js.map +0 -1
- package/dist/cli/status.d.ts +0 -6
- package/dist/cli/status.d.ts.map +0 -1
- package/dist/cli/status.js +0 -33
- package/dist/cli/status.js.map +0 -1
- package/dist/cli/stop.d.ts +0 -6
- package/dist/cli/stop.d.ts.map +0 -1
- package/dist/cli/stop.js +0 -18
- package/dist/cli/stop.js.map +0 -1
- package/dist/cli/ui/MirrorUI.d.ts +0 -22
- package/dist/cli/ui/MirrorUI.d.ts.map +0 -1
- package/dist/cli/ui/MirrorUI.js +0 -71
- package/dist/cli/ui/MirrorUI.js.map +0 -1
- package/dist/cli/ui/interactive-terminal.d.ts +0 -3
- package/dist/cli/ui/interactive-terminal.d.ts.map +0 -1
- package/dist/cli/ui/interactive-terminal.js +0 -150
- package/dist/cli/ui/interactive-terminal.js.map +0 -1
- package/dist/cli/watch.d.ts +0 -6
- package/dist/cli/watch.d.ts.map +0 -1
- package/dist/cli/watch.js +0 -29
- package/dist/cli/watch.js.map +0 -1
- package/dist/core/daemon.d.ts +0 -154
- package/dist/core/daemon.d.ts.map +0 -1
- package/dist/core/daemon.js +0 -590
- package/dist/core/daemon.js.map +0 -1
- package/dist/core/process-manager.d.ts +0 -19
- package/dist/core/process-manager.d.ts.map +0 -1
- package/dist/core/process-manager.js +0 -76
- package/dist/core/process-manager.js.map +0 -1
- package/dist/transport/pty.d.ts +0 -7
- package/dist/transport/pty.d.ts.map +0 -1
- package/dist/transport/pty.js +0 -26
- package/dist/transport/pty.js.map +0 -1
package/dist/core/daemon.js
DELETED
|
@@ -1,590 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Mirror 守护进程
|
|
3
|
-
* 管理连接、文件同步和命令执行
|
|
4
|
-
*/
|
|
5
|
-
import { WebSocketTransport } from '../transport/websocket.js';
|
|
6
|
-
import { readFileWithHash, getRelativePath, compressContent, shouldCompress } from '../core/file-sync.js';
|
|
7
|
-
import chokidar from 'chokidar';
|
|
8
|
-
import { readdir } from 'fs/promises';
|
|
9
|
-
import { join } from 'path';
|
|
10
|
-
import { randomUUID } from 'crypto';
|
|
11
|
-
import { TokenManager } from './token-manager.js';
|
|
12
|
-
import { OutputBuffer } from './output-buffer.js';
|
|
13
|
-
export class MirrorDaemon {
|
|
14
|
-
transport = null;
|
|
15
|
-
watcher = null;
|
|
16
|
-
tokenManager;
|
|
17
|
-
outputBuffers = new Map();
|
|
18
|
-
commandHistory = [];
|
|
19
|
-
currentVersion = 0;
|
|
20
|
-
isConnected = false;
|
|
21
|
-
isConnecting = false;
|
|
22
|
-
autoReconnect = false;
|
|
23
|
-
reconnectAttempts = 0;
|
|
24
|
-
maxReconnectAttempts = 10;
|
|
25
|
-
reconnectDelay = 2000; // 初始 2 秒
|
|
26
|
-
maxReconnectDelay = 30000; // 最大 30 秒
|
|
27
|
-
lastActivityTime = Date.now();
|
|
28
|
-
inactivityTimeout = 30 * 60 * 1000; // 30 分钟
|
|
29
|
-
inactivityTimer = null;
|
|
30
|
-
commandTimeout = 5 * 60 * 1000; // 5 分钟
|
|
31
|
-
commandTimeouts = new Map();
|
|
32
|
-
messageHandlers = new Map();
|
|
33
|
-
// 交互式会话管理
|
|
34
|
-
hasInteractiveSession = false;
|
|
35
|
-
interactiveSessionId = null;
|
|
36
|
-
// 命令执行队列
|
|
37
|
-
commandQueue = [];
|
|
38
|
-
activeCommands = 0;
|
|
39
|
-
maxConcurrentCommands = 5;
|
|
40
|
-
constructor() {
|
|
41
|
-
this.tokenManager = new TokenManager();
|
|
42
|
-
this.setupInactivityCheck();
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 连接并启动守护进程
|
|
46
|
-
*/
|
|
47
|
-
async connect(config) {
|
|
48
|
-
if (this.isConnecting) {
|
|
49
|
-
throw new Error('Already connecting');
|
|
50
|
-
}
|
|
51
|
-
if (this.isConnected) {
|
|
52
|
-
throw new Error('Already connected');
|
|
53
|
-
}
|
|
54
|
-
this.isConnecting = true;
|
|
55
|
-
try {
|
|
56
|
-
this.transport = new WebSocketTransport();
|
|
57
|
-
await this.transport.connect(config.wsUrl);
|
|
58
|
-
// 设置消息处理器
|
|
59
|
-
this.setupMessageHandlers();
|
|
60
|
-
// 发送 HELLO 消息
|
|
61
|
-
this.transport.send({
|
|
62
|
-
type: 'HELLO',
|
|
63
|
-
clientId: config.clientId,
|
|
64
|
-
token: config.token,
|
|
65
|
-
clientVersion: config.clientVersion,
|
|
66
|
-
workspacePath: config.workspacePath,
|
|
67
|
-
});
|
|
68
|
-
// 等待服务端响应
|
|
69
|
-
await this.waitForServerReady();
|
|
70
|
-
// 保存 token
|
|
71
|
-
const host = new URL(config.wsUrl).host;
|
|
72
|
-
await this.tokenManager.saveToken(config.token, host);
|
|
73
|
-
// 开始全量同步
|
|
74
|
-
await this.performSnapshot(config.workspacePath);
|
|
75
|
-
// 设置文件监听
|
|
76
|
-
this.setupFileWatcher(config.workspacePath);
|
|
77
|
-
this.isConnected = true;
|
|
78
|
-
this.updateActivity();
|
|
79
|
-
}
|
|
80
|
-
finally {
|
|
81
|
-
this.isConnecting = false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* 连接到远程工作区(用于 link 命令)
|
|
86
|
-
*/
|
|
87
|
-
async link(url) {
|
|
88
|
-
const config = this.parseUrl(url);
|
|
89
|
-
await this.connect(config);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* 解析 URL
|
|
93
|
-
*/
|
|
94
|
-
parseUrl(url) {
|
|
95
|
-
let urlToParse = url;
|
|
96
|
-
if (!url.startsWith('ws://') && !url.startsWith('wss://')) {
|
|
97
|
-
urlToParse = `ws://${url}`;
|
|
98
|
-
}
|
|
99
|
-
const urlObj = new URL(urlToParse);
|
|
100
|
-
const clientId = randomUUID();
|
|
101
|
-
return {
|
|
102
|
-
wsUrl: urlToParse,
|
|
103
|
-
clientId,
|
|
104
|
-
token: urlObj.searchParams.get('token') || '',
|
|
105
|
-
clientVersion: '1.0.0',
|
|
106
|
-
workspacePath: process.cwd(),
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* 等待服务端就绪
|
|
111
|
-
*/
|
|
112
|
-
async waitForServerReady() {
|
|
113
|
-
return new Promise((resolve, reject) => {
|
|
114
|
-
if (!this.transport) {
|
|
115
|
-
reject(new Error('Transport not initialized'));
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const timeout = setTimeout(() => {
|
|
119
|
-
reject(new Error('Wait for server ready timeout'));
|
|
120
|
-
}, 60000);
|
|
121
|
-
this.transport.onMessage('READY', () => {
|
|
122
|
-
clearTimeout(timeout);
|
|
123
|
-
resolve();
|
|
124
|
-
});
|
|
125
|
-
this.transport.onMessage('ERROR', (msg) => {
|
|
126
|
-
clearTimeout(timeout);
|
|
127
|
-
const errorMsg = msg;
|
|
128
|
-
reject(new Error(`Connection failed: ${errorMsg.message}`));
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 设置消息处理器
|
|
134
|
-
*/
|
|
135
|
-
setupMessageHandlers() {
|
|
136
|
-
if (!this.transport)
|
|
137
|
-
return;
|
|
138
|
-
// EXEC_OUTPUT
|
|
139
|
-
this.transport.onMessage('EXEC_OUTPUT', (msg) => {
|
|
140
|
-
const outputMsg = msg;
|
|
141
|
-
if (outputMsg.execId) {
|
|
142
|
-
const buffer = this.outputBuffers.get(outputMsg.execId);
|
|
143
|
-
if (buffer && outputMsg.data) {
|
|
144
|
-
buffer.append(outputMsg.data);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
// EXEC_EXIT
|
|
149
|
-
this.transport.onMessage('EXEC_EXIT', (msg) => {
|
|
150
|
-
const exitMsg = msg;
|
|
151
|
-
if (exitMsg.execId) {
|
|
152
|
-
const buffer = this.outputBuffers.get(exitMsg.execId);
|
|
153
|
-
if (buffer) {
|
|
154
|
-
// 保存到历史记录
|
|
155
|
-
const commandResult = this.commandHistory.find(r => r.execId === exitMsg.execId);
|
|
156
|
-
if (commandResult) {
|
|
157
|
-
commandResult.output = buffer.getAll();
|
|
158
|
-
commandResult.exitCode = exitMsg.code;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
// 清理超时定时器
|
|
162
|
-
const timeout = this.commandTimeouts.get(exitMsg.execId);
|
|
163
|
-
if (timeout) {
|
|
164
|
-
clearTimeout(timeout);
|
|
165
|
-
this.commandTimeouts.delete(exitMsg.execId);
|
|
166
|
-
}
|
|
167
|
-
// 减少活跃命令计数
|
|
168
|
-
this.activeCommands--;
|
|
169
|
-
this.processCommandQueue();
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
// FILE_SYNC_STATUS
|
|
173
|
-
this.transport.onMessage('FILE_SYNC_STATUS', () => {
|
|
174
|
-
// 文件同步状态更新(暂不处理)
|
|
175
|
-
});
|
|
176
|
-
// ERROR
|
|
177
|
-
this.transport.onMessage('ERROR', (msg) => {
|
|
178
|
-
const errorMsg = msg;
|
|
179
|
-
console.error(`Error: ${errorMsg.message}`);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* 执行全量快照同步
|
|
184
|
-
*/
|
|
185
|
-
async performSnapshot(workspacePath) {
|
|
186
|
-
this.currentVersion = 1;
|
|
187
|
-
const files = await this.collectFiles(workspacePath);
|
|
188
|
-
const totalFiles = files.length;
|
|
189
|
-
if (!this.transport) {
|
|
190
|
-
throw new Error('Transport not initialized');
|
|
191
|
-
}
|
|
192
|
-
// 发送 SNAPSHOT_START
|
|
193
|
-
this.transport.send({
|
|
194
|
-
type: 'SNAPSHOT_START',
|
|
195
|
-
version: this.currentVersion,
|
|
196
|
-
totalFiles,
|
|
197
|
-
});
|
|
198
|
-
// 发送所有文件
|
|
199
|
-
for (const file of files) {
|
|
200
|
-
try {
|
|
201
|
-
const { content, hash, size } = await readFileWithHash(file);
|
|
202
|
-
const relativePath = getRelativePath(file, workspacePath);
|
|
203
|
-
let finalContent = content;
|
|
204
|
-
let compressed = false;
|
|
205
|
-
if (shouldCompress(size)) {
|
|
206
|
-
try {
|
|
207
|
-
finalContent = await compressContent(content);
|
|
208
|
-
compressed = true;
|
|
209
|
-
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
// 压缩失败,使用原始内容
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
this.transport.send({
|
|
215
|
-
type: 'FILE',
|
|
216
|
-
path: relativePath,
|
|
217
|
-
hash,
|
|
218
|
-
content: finalContent.toString('base64'),
|
|
219
|
-
compressed,
|
|
220
|
-
size,
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
catch (error) {
|
|
224
|
-
console.error(`Failed to send file ${file}:`, error);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
// 发送 SNAPSHOT_END
|
|
228
|
-
this.transport.send({
|
|
229
|
-
type: 'SNAPSHOT_END',
|
|
230
|
-
version: this.currentVersion,
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* 收集文件
|
|
235
|
-
*/
|
|
236
|
-
async collectFiles(dir) {
|
|
237
|
-
const files = [];
|
|
238
|
-
const ignorePatterns = ['.vscode', 'node_modules', '.git', '.next'];
|
|
239
|
-
async function walk(currentDir) {
|
|
240
|
-
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
241
|
-
for (const entry of entries) {
|
|
242
|
-
const fullPath = join(currentDir, entry.name);
|
|
243
|
-
const relativePath = getRelativePath(fullPath, dir);
|
|
244
|
-
if (ignorePatterns.some((pattern) => relativePath.includes(pattern))) {
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
if (entry.isDirectory()) {
|
|
248
|
-
await walk(fullPath);
|
|
249
|
-
}
|
|
250
|
-
else if (entry.isFile()) {
|
|
251
|
-
files.push(fullPath);
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
await walk(dir);
|
|
256
|
-
return files;
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* 设置文件监听
|
|
260
|
-
*/
|
|
261
|
-
setupFileWatcher(workspacePath) {
|
|
262
|
-
this.watcher = chokidar.watch(workspacePath, {
|
|
263
|
-
ignored: [/.vscode/, /node_modules/, /.git/, /.next/],
|
|
264
|
-
ignoreInitial: true,
|
|
265
|
-
persistent: true,
|
|
266
|
-
});
|
|
267
|
-
this.watcher.on('change', async (path) => {
|
|
268
|
-
if (!this.transport)
|
|
269
|
-
return;
|
|
270
|
-
const ws = this.transport.getWebSocket();
|
|
271
|
-
if (!ws || ws.readyState !== 1) {
|
|
272
|
-
return;
|
|
273
|
-
}
|
|
274
|
-
this.currentVersion++;
|
|
275
|
-
try {
|
|
276
|
-
const { content, hash, size } = await readFileWithHash(path);
|
|
277
|
-
const relativePath = getRelativePath(path, workspacePath);
|
|
278
|
-
let finalContent = content;
|
|
279
|
-
let compressed = false;
|
|
280
|
-
if (shouldCompress(size)) {
|
|
281
|
-
try {
|
|
282
|
-
finalContent = await compressContent(content);
|
|
283
|
-
compressed = true;
|
|
284
|
-
}
|
|
285
|
-
catch (error) {
|
|
286
|
-
// 压缩失败,使用原始内容
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
this.transport.send({
|
|
290
|
-
type: 'FILE_DIFF',
|
|
291
|
-
version: this.currentVersion,
|
|
292
|
-
op: 'update',
|
|
293
|
-
path: relativePath,
|
|
294
|
-
hash,
|
|
295
|
-
content: finalContent.toString('base64'),
|
|
296
|
-
compressed,
|
|
297
|
-
size,
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
catch (error) {
|
|
301
|
-
console.error(`Failed to sync file ${path}:`, error);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
this.watcher.on('unlink', (path) => {
|
|
305
|
-
if (!this.transport)
|
|
306
|
-
return;
|
|
307
|
-
const ws = this.transport.getWebSocket();
|
|
308
|
-
if (!ws || ws.readyState !== 1) {
|
|
309
|
-
return;
|
|
310
|
-
}
|
|
311
|
-
this.currentVersion++;
|
|
312
|
-
const relativePath = getRelativePath(path, workspacePath);
|
|
313
|
-
try {
|
|
314
|
-
this.transport.send({
|
|
315
|
-
type: 'FILE_DIFF',
|
|
316
|
-
version: this.currentVersion,
|
|
317
|
-
op: 'delete',
|
|
318
|
-
path: relativePath,
|
|
319
|
-
hash: '',
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
catch (error) {
|
|
323
|
-
// 发送失败,静默跳过
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
}
|
|
327
|
-
/**
|
|
328
|
-
* 执行命令
|
|
329
|
-
*/
|
|
330
|
-
async execCommand(command) {
|
|
331
|
-
if (!this.isConnected || !this.transport) {
|
|
332
|
-
throw new Error('Not connected');
|
|
333
|
-
}
|
|
334
|
-
const execId = randomUUID();
|
|
335
|
-
const buffer = new OutputBuffer();
|
|
336
|
-
this.outputBuffers.set(execId, buffer);
|
|
337
|
-
const commandResult = {
|
|
338
|
-
execId,
|
|
339
|
-
command,
|
|
340
|
-
output: [],
|
|
341
|
-
exitCode: null,
|
|
342
|
-
timestamp: new Date(),
|
|
343
|
-
};
|
|
344
|
-
this.commandHistory.push(commandResult);
|
|
345
|
-
// 设置命令超时
|
|
346
|
-
const timeout = setTimeout(() => {
|
|
347
|
-
if (this.transport) {
|
|
348
|
-
try {
|
|
349
|
-
this.transport.send({
|
|
350
|
-
type: 'EXEC_SIGNAL',
|
|
351
|
-
execId,
|
|
352
|
-
signal: 'SIGTERM',
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
catch (error) {
|
|
356
|
-
// 忽略错误
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
}, this.commandTimeout);
|
|
360
|
-
this.commandTimeouts.set(execId, timeout);
|
|
361
|
-
// 发送命令
|
|
362
|
-
this.transport.send({
|
|
363
|
-
type: 'EXEC',
|
|
364
|
-
execId,
|
|
365
|
-
version: this.currentVersion,
|
|
366
|
-
command,
|
|
367
|
-
});
|
|
368
|
-
this.updateActivity();
|
|
369
|
-
// 等待命令完成
|
|
370
|
-
return new Promise((resolve, reject) => {
|
|
371
|
-
const checkInterval = setInterval(() => {
|
|
372
|
-
const result = this.commandHistory.find(r => r.execId === execId);
|
|
373
|
-
if (result && result.exitCode !== null) {
|
|
374
|
-
clearInterval(checkInterval);
|
|
375
|
-
resolve(buffer.getText());
|
|
376
|
-
}
|
|
377
|
-
}, 100);
|
|
378
|
-
// 10 秒超时保护
|
|
379
|
-
setTimeout(() => {
|
|
380
|
-
clearInterval(checkInterval);
|
|
381
|
-
reject(new Error('Command execution timeout'));
|
|
382
|
-
}, 10000);
|
|
383
|
-
});
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* 获取命令输出
|
|
387
|
-
*/
|
|
388
|
-
getCommandOutput(execId) {
|
|
389
|
-
const buffer = this.outputBuffers.get(execId);
|
|
390
|
-
return buffer ? buffer.getAll() : null;
|
|
391
|
-
}
|
|
392
|
-
/**
|
|
393
|
-
* 获取命令历史
|
|
394
|
-
*/
|
|
395
|
-
getCommandHistory(limit = 10) {
|
|
396
|
-
return this.commandHistory.slice(-limit);
|
|
397
|
-
}
|
|
398
|
-
/**
|
|
399
|
-
* 更新活动时间
|
|
400
|
-
*/
|
|
401
|
-
updateActivity() {
|
|
402
|
-
this.lastActivityTime = Date.now();
|
|
403
|
-
// 重置不活动超时
|
|
404
|
-
if (this.inactivityTimer) {
|
|
405
|
-
clearTimeout(this.inactivityTimer);
|
|
406
|
-
}
|
|
407
|
-
if (this.autoReconnect) {
|
|
408
|
-
this.inactivityTimer = setTimeout(() => {
|
|
409
|
-
this.disconnect();
|
|
410
|
-
}, this.inactivityTimeout);
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* 设置不活动检查
|
|
415
|
-
*/
|
|
416
|
-
setupInactivityCheck() {
|
|
417
|
-
// 在 enableAutoReconnect 中设置
|
|
418
|
-
}
|
|
419
|
-
/**
|
|
420
|
-
* 启用自动重连
|
|
421
|
-
*/
|
|
422
|
-
enableAutoReconnect() {
|
|
423
|
-
this.autoReconnect = true;
|
|
424
|
-
this.updateActivity();
|
|
425
|
-
}
|
|
426
|
-
/**
|
|
427
|
-
* 禁用自动重连
|
|
428
|
-
*/
|
|
429
|
-
disableAutoReconnect() {
|
|
430
|
-
this.autoReconnect = false;
|
|
431
|
-
if (this.inactivityTimer) {
|
|
432
|
-
clearTimeout(this.inactivityTimer);
|
|
433
|
-
this.inactivityTimer = null;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
/**
|
|
437
|
-
* 按需重连
|
|
438
|
-
*/
|
|
439
|
-
async reconnect() {
|
|
440
|
-
if (this.isConnected) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
if (this.isConnecting) {
|
|
444
|
-
throw new Error('Already connecting');
|
|
445
|
-
}
|
|
446
|
-
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
447
|
-
throw new Error('Max reconnect attempts reached');
|
|
448
|
-
}
|
|
449
|
-
this.isConnecting = true;
|
|
450
|
-
try {
|
|
451
|
-
// 计算延迟时间(指数退避)
|
|
452
|
-
const delay = Math.min(this.reconnectDelay * Math.pow(1.5, this.reconnectAttempts), this.maxReconnectDelay);
|
|
453
|
-
await new Promise(resolve => setTimeout(resolve, delay));
|
|
454
|
-
// 重新连接
|
|
455
|
-
// 注意:这里需要保存原始连接配置
|
|
456
|
-
// 实际实现应该保存配置并在重连时使用
|
|
457
|
-
// 这里只是示例
|
|
458
|
-
this.reconnectAttempts = 0;
|
|
459
|
-
this.isConnected = true;
|
|
460
|
-
}
|
|
461
|
-
catch (error) {
|
|
462
|
-
this.reconnectAttempts++;
|
|
463
|
-
throw error;
|
|
464
|
-
}
|
|
465
|
-
finally {
|
|
466
|
-
this.isConnecting = false;
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
/**
|
|
470
|
-
* 断开连接
|
|
471
|
-
*/
|
|
472
|
-
async disconnect() {
|
|
473
|
-
this.disableAutoReconnect();
|
|
474
|
-
if (this.watcher) {
|
|
475
|
-
this.watcher.close();
|
|
476
|
-
this.watcher = null;
|
|
477
|
-
}
|
|
478
|
-
if (this.transport) {
|
|
479
|
-
this.transport.close();
|
|
480
|
-
this.transport = null;
|
|
481
|
-
}
|
|
482
|
-
this.isConnected = false;
|
|
483
|
-
}
|
|
484
|
-
/**
|
|
485
|
-
* 停止守护进程
|
|
486
|
-
*/
|
|
487
|
-
async stop() {
|
|
488
|
-
await this.disconnect();
|
|
489
|
-
// 清理所有定时器
|
|
490
|
-
if (this.inactivityTimer) {
|
|
491
|
-
clearTimeout(this.inactivityTimer);
|
|
492
|
-
this.inactivityTimer = null;
|
|
493
|
-
}
|
|
494
|
-
for (const timeout of this.commandTimeouts.values()) {
|
|
495
|
-
clearTimeout(timeout);
|
|
496
|
-
}
|
|
497
|
-
this.commandTimeouts.clear();
|
|
498
|
-
}
|
|
499
|
-
/**
|
|
500
|
-
* 获取状态
|
|
501
|
-
*/
|
|
502
|
-
getStatus() {
|
|
503
|
-
return {
|
|
504
|
-
isConnected: this.isConnected,
|
|
505
|
-
isConnecting: this.isConnecting,
|
|
506
|
-
hasInteractiveSession: this.hasInteractiveSession,
|
|
507
|
-
activeCommands: this.activeCommands,
|
|
508
|
-
commandQueueSize: this.commandQueue.length,
|
|
509
|
-
reconnectAttempts: this.reconnectAttempts,
|
|
510
|
-
};
|
|
511
|
-
}
|
|
512
|
-
/**
|
|
513
|
-
* 进入交互式会话
|
|
514
|
-
*/
|
|
515
|
-
async startInteractiveSession() {
|
|
516
|
-
if (this.hasInteractiveSession) {
|
|
517
|
-
throw new Error('Interactive session already exists');
|
|
518
|
-
}
|
|
519
|
-
this.hasInteractiveSession = true;
|
|
520
|
-
this.interactiveSessionId = randomUUID();
|
|
521
|
-
this.enableAutoReconnect();
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* 退出交互式会话
|
|
525
|
-
*/
|
|
526
|
-
async stopInteractiveSession() {
|
|
527
|
-
this.hasInteractiveSession = false;
|
|
528
|
-
this.interactiveSessionId = null;
|
|
529
|
-
this.disableAutoReconnect();
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* 添加命令到队列
|
|
533
|
-
*/
|
|
534
|
-
async processCommandQueue() {
|
|
535
|
-
if (this.activeCommands >= this.maxConcurrentCommands || this.commandQueue.length === 0) {
|
|
536
|
-
return;
|
|
537
|
-
}
|
|
538
|
-
const command = this.commandQueue.shift();
|
|
539
|
-
if (command) {
|
|
540
|
-
this.activeCommands++;
|
|
541
|
-
try {
|
|
542
|
-
await command();
|
|
543
|
-
}
|
|
544
|
-
finally {
|
|
545
|
-
this.activeCommands--;
|
|
546
|
-
this.processCommandQueue();
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* 处理命令队列
|
|
552
|
-
*/
|
|
553
|
-
async executeCommand(command) {
|
|
554
|
-
return new Promise((resolve, reject) => {
|
|
555
|
-
const wrappedCommand = async () => {
|
|
556
|
-
try {
|
|
557
|
-
await command();
|
|
558
|
-
resolve();
|
|
559
|
-
}
|
|
560
|
-
catch (error) {
|
|
561
|
-
reject(error);
|
|
562
|
-
}
|
|
563
|
-
};
|
|
564
|
-
this.commandQueue.push(wrappedCommand);
|
|
565
|
-
this.processCommandQueue();
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
/**
|
|
569
|
-
* 注册消息处理器
|
|
570
|
-
*/
|
|
571
|
-
onMessage(type, handler) {
|
|
572
|
-
if (!this.messageHandlers.has(type)) {
|
|
573
|
-
this.messageHandlers.set(type, []);
|
|
574
|
-
}
|
|
575
|
-
this.messageHandlers.get(type).push(handler);
|
|
576
|
-
}
|
|
577
|
-
/**
|
|
578
|
-
* 移除消息处理器
|
|
579
|
-
*/
|
|
580
|
-
offMessage(type, handler) {
|
|
581
|
-
const handlers = this.messageHandlers.get(type);
|
|
582
|
-
if (handlers) {
|
|
583
|
-
const index = handlers.indexOf(handler);
|
|
584
|
-
if (index > -1) {
|
|
585
|
-
handlers.splice(index, 1);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}
|
|
590
|
-
//# sourceMappingURL=daemon.js.map
|
package/dist/core/daemon.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"daemon.js","sourceRoot":"","sources":["../../src/core/daemon.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAO/D,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC1G,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAkBlD,MAAM,OAAO,YAAY;IACf,SAAS,GAA8B,IAAI,CAAC;IAC5C,OAAO,GAA8B,IAAI,CAAC;IAC1C,YAAY,CAAe;IAC3B,aAAa,GAA8B,IAAI,GAAG,EAAE,CAAC;IACrD,cAAc,GAAoB,EAAE,CAAC;IACrC,cAAc,GAAG,CAAC,CAAC;IACnB,WAAW,GAAG,KAAK,CA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AAC,IAAY,EAAE,OAAmC;QAC1D,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChD,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,KAAK,GAAG,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YACxC,IAAI,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC;gBACf,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 进程管理
|
|
3
|
-
*/
|
|
4
|
-
import * as pty from 'node-pty';
|
|
5
|
-
export interface ProcessInfo {
|
|
6
|
-
execId: string;
|
|
7
|
-
process: pty.IPty;
|
|
8
|
-
command: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class ProcessManager {
|
|
11
|
-
private processes;
|
|
12
|
-
private processGroupPids;
|
|
13
|
-
spawn(execId: string, command: string, cwd: string, env?: NodeJS.ProcessEnv): Promise<pty.IPty>;
|
|
14
|
-
getProcess(execId: string): ProcessInfo | undefined;
|
|
15
|
-
removeProcess(execId: string): void;
|
|
16
|
-
killAll(): Promise<void>;
|
|
17
|
-
getAllProcesses(): ProcessInfo[];
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=process-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"process-manager.d.ts","sourceRoot":"","sources":["../../src/core/process-manager.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,GAAG,MAAM,UAAU,CAAC;AAEhC,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,GAAG,CAAC,IAAI,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAuC;IACxD,OAAO,CAAC,gBAAgB,CAA0B;IAE5C,KAAK,CACT,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAM,CAAC,UAAe,GAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC;IA6BpB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAInD,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAW7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA6B9B,eAAe,IAAI,WAAW,EAAE;CAGjC"}
|