cc-viewer 1.4.23 → 1.4.25
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/package.json +1 -1
- package/server.js +127 -125
package/package.json
CHANGED
package/server.js
CHANGED
|
@@ -1285,7 +1285,7 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
1285
1285
|
try {
|
|
1286
1286
|
const { WebSocketServer } = await import('ws');
|
|
1287
1287
|
const { writeToPty, resizePty, onPtyData, onPtyExit, getPtyState, getOutputBuffer, getCurrentWorkspace } = await import('./pty-manager.js');
|
|
1288
|
-
const { default: chokidar } = await import('chokidar');
|
|
1288
|
+
// const { default: chokidar } = await import('chokidar');
|
|
1289
1289
|
|
|
1290
1290
|
const wss = new WebSocketServer({ noServer: true });
|
|
1291
1291
|
|
|
@@ -1308,137 +1308,139 @@ async function setupTerminalWebSocket(httpServer) {
|
|
|
1308
1308
|
return null;
|
|
1309
1309
|
};
|
|
1310
1310
|
|
|
1311
|
-
//
|
|
1312
|
-
|
|
1313
|
-
let
|
|
1314
|
-
let
|
|
1315
|
-
|
|
1311
|
+
// 文件监控器:监控工作区目录变更(暂时禁用)
|
|
1312
|
+
// 以下代码已被注释掉,如需启用请取消注释
|
|
1313
|
+
// let fileWatcher = null;
|
|
1314
|
+
// let fileWatchDebounceTimer = null;
|
|
1315
|
+
// let currentWatchPath = null;
|
|
1316
|
+
//
|
|
1316
1317
|
// 忽略规则:从统一的 IGNORED_PATTERNS 生成,并忽略所有隐藏目录
|
|
1317
|
-
const ignoredPaths = [
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
];
|
|
1321
|
-
|
|
1318
|
+
// const ignoredPaths = [
|
|
1319
|
+
// ...Array.from(IGNORED_PATTERNS).map(p => '**/' + p + '/**'),
|
|
1320
|
+
// '**/.*/**', // 忽略所有隐藏目录(.git, .Trash, .docker 等)
|
|
1321
|
+
// ];
|
|
1322
|
+
//
|
|
1322
1323
|
// 启动文件监控
|
|
1323
|
-
const startFileWatcher = (watchPath) => {
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
};
|
|
1383
|
-
|
|
1324
|
+
// const startFileWatcher = (watchPath) => {
|
|
1325
|
+
// if (fileWatcher) {
|
|
1326
|
+
// fileWatcher.close();
|
|
1327
|
+
// }
|
|
1328
|
+
// currentWatchPath = watchPath;
|
|
1329
|
+
//
|
|
1330
|
+
// try {
|
|
1331
|
+
// fileWatcher = chokidar.watch(watchPath, {
|
|
1332
|
+
// ignored: ignoredPaths,
|
|
1333
|
+
// persistent: true,
|
|
1334
|
+
// ignoreInitial: true, // 忽略初始扫描,只监控变更
|
|
1335
|
+
// awaitWriteFinish: {
|
|
1336
|
+
// stabilityThreshold: 100,
|
|
1337
|
+
// pollInterval: 50
|
|
1338
|
+
// }
|
|
1339
|
+
// });
|
|
1340
|
+
//
|
|
1341
|
+
// 监听 chokidar 错误事件,避免崩溃
|
|
1342
|
+
// fileWatcher.on('error', (error) => {
|
|
1343
|
+
// console.error('[CC Viewer] File watcher error:', error.message);
|
|
1344
|
+
// 不要让错误导致进程崩溃,只记录日志
|
|
1345
|
+
// });
|
|
1346
|
+
//
|
|
1347
|
+
// 使用防抖避免频繁触发
|
|
1348
|
+
// fileWatcher.on('all', (eventType, path) => {
|
|
1349
|
+
// if (fileWatchDebounceTimer) {
|
|
1350
|
+
// clearTimeout(fileWatchDebounceTimer);
|
|
1351
|
+
// }
|
|
1352
|
+
//
|
|
1353
|
+
// fileWatchDebounceTimer = setTimeout(() => {
|
|
1354
|
+
// console.log('[CC Viewer] File change detected: ' + eventType + ' - ' + path);
|
|
1355
|
+
//
|
|
1356
|
+
// 广播文件变更事件给所有连接的客户端
|
|
1357
|
+
// const changeEvent = {
|
|
1358
|
+
// type: 'file-change',
|
|
1359
|
+
// eventType,
|
|
1360
|
+
// path,
|
|
1361
|
+
// watchPath: currentWatchPath
|
|
1362
|
+
// };
|
|
1363
|
+
//
|
|
1364
|
+
// const clientCount = wss.clients.size;
|
|
1365
|
+
// console.log('[CC Viewer] Broadcasting file-change to ' + clientCount + ' client(s)');
|
|
1366
|
+
//
|
|
1367
|
+
// wss.clients.forEach((client) => {
|
|
1368
|
+
// if (client.readyState === 1) { // WebSocket.OPEN
|
|
1369
|
+
// try {
|
|
1370
|
+
// client.send(JSON.stringify(changeEvent));
|
|
1371
|
+
// } catch (err) {
|
|
1372
|
+
// console.error('[CC Viewer] Failed to send file-change event:', err.message);
|
|
1373
|
+
// }
|
|
1374
|
+
// }
|
|
1375
|
+
// });
|
|
1376
|
+
// }, 200); // 200ms 防抖延迟
|
|
1377
|
+
// });
|
|
1378
|
+
//
|
|
1379
|
+
// console.log('[CC Viewer] File watcher started for: ' + watchPath);
|
|
1380
|
+
// } catch (err) {
|
|
1381
|
+
// console.error('[CC Viewer] Failed to start file watcher:', err.message);
|
|
1382
|
+
// }
|
|
1383
|
+
// };
|
|
1384
|
+
//
|
|
1384
1385
|
// 停止文件监控
|
|
1385
|
-
const stopFileWatcher = () => {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
};
|
|
1396
|
-
|
|
1386
|
+
// const stopFileWatcher = () => {
|
|
1387
|
+
// if (fileWatchDebounceTimer) {
|
|
1388
|
+
// clearTimeout(fileWatchDebounceTimer);
|
|
1389
|
+
// fileWatchDebounceTimer = null;
|
|
1390
|
+
// }
|
|
1391
|
+
// if (fileWatcher) {
|
|
1392
|
+
// fileWatcher.close();
|
|
1393
|
+
// fileWatcher = null;
|
|
1394
|
+
// }
|
|
1395
|
+
// currentWatchPath = null;
|
|
1396
|
+
// };
|
|
1397
|
+
//
|
|
1397
1398
|
// 监听 PTY 退出事件,停止文件监控(只在监控器运行时停止)
|
|
1398
|
-
onPtyExit(() => {
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
});
|
|
1404
|
-
|
|
1399
|
+
// onPtyExit(() => {
|
|
1400
|
+
// if (fileWatcher && !fileWatcher.closed) {
|
|
1401
|
+
// stopFileWatcher();
|
|
1402
|
+
// console.log('[CC Viewer] File watcher stopped (PTY exited)');
|
|
1403
|
+
// }
|
|
1404
|
+
// });
|
|
1405
|
+
//
|
|
1405
1406
|
// 初始化时检查是否有活跃的工作区
|
|
1406
|
-
const workspace = getCurrentWorkspace();
|
|
1407
|
-
if (workspace.running && workspace.cwd) {
|
|
1408
|
-
|
|
1409
|
-
}
|
|
1410
|
-
|
|
1407
|
+
// const workspace = getCurrentWorkspace();
|
|
1408
|
+
// if (workspace.running && workspace.cwd) {
|
|
1409
|
+
// startFileWatcher(workspace.cwd);
|
|
1410
|
+
// }
|
|
1411
|
+
//
|
|
1411
1412
|
// 定期检查工作区状态,确保监控器在 PTY 启动后自动开始工作
|
|
1412
|
-
const workspaceCheckInterval = setInterval(() => {
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
}, 1000); // 每秒检查一次
|
|
1434
|
-
|
|
1413
|
+
// const workspaceCheckInterval = setInterval(() => {
|
|
1414
|
+
// const currentWorkspace = getCurrentWorkspace();
|
|
1415
|
+
// const isRunning = currentWorkspace.running && currentWorkspace.cwd;
|
|
1416
|
+
//
|
|
1417
|
+
// 调试日志
|
|
1418
|
+
// if (process.env.CCV_DEBUG) {
|
|
1419
|
+
// console.log('[CC Viewer] Workspace check:', {
|
|
1420
|
+
// running: currentWorkspace.running,
|
|
1421
|
+
// cwd: currentWorkspace.cwd,
|
|
1422
|
+
// fileWatcher: fileWatcher ? (fileWatcher.closed ? 'closed' : 'active') : 'none',
|
|
1423
|
+
// currentWatchPath
|
|
1424
|
+
// });
|
|
1425
|
+
// }
|
|
1426
|
+
//
|
|
1427
|
+
// 如果 PTY 正在运行但监控器未启动,则启动监控器
|
|
1428
|
+
// if (isRunning && (!fileWatcher || fileWatcher.closed)) {
|
|
1429
|
+
// if (currentWatchPath !== currentWorkspace.cwd) {
|
|
1430
|
+
// console.log('[CC Viewer] Starting file watcher for: ' + currentWorkspace.cwd);
|
|
1431
|
+
// startFileWatcher(currentWorkspace.cwd);
|
|
1432
|
+
// }
|
|
1433
|
+
// }
|
|
1434
|
+
// }, 1000); // 每秒检查一次
|
|
1435
|
+
//
|
|
1435
1436
|
// 清理定时器
|
|
1436
|
-
const originalClose = wss.close;
|
|
1437
|
-
wss.close = function() {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
};
|
|
1437
|
+
// const originalClose = wss.close;
|
|
1438
|
+
// wss.close = function() {
|
|
1439
|
+
// clearInterval(workspaceCheckInterval);
|
|
1440
|
+
// stopFileWatcher();
|
|
1441
|
+
// return originalClose.call(this);
|
|
1442
|
+
// };
|
|
1443
|
+
|
|
1442
1444
|
|
|
1443
1445
|
httpServer.on('upgrade', (req, socket, head) => {
|
|
1444
1446
|
const pathname = new URL(req.url, `http://${req.headers.host}`).pathname;
|