cc-viewer 1.4.24 → 1.4.26

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +125 -125
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-viewer",
3
- "version": "1.4.24",
3
+ "version": "1.4.26",
4
4
  "description": "Claude Code Logger visualization management tool",
5
5
  "license": "MIT",
6
6
  "main": "server.js",
package/server.js CHANGED
@@ -1309,138 +1309,138 @@ async function setupTerminalWebSocket(httpServer) {
1309
1309
  };
1310
1310
 
1311
1311
  // 文件监控器:监控工作区目录变更(暂时禁用)
1312
- /*
1313
- let fileWatcher = null;
1314
- let fileWatchDebounceTimer = null;
1315
- let currentWatchPath = null;
1316
-
1312
+ // 以下代码已被注释掉,如需启用请取消注释
1313
+ // let fileWatcher = null;
1314
+ // let fileWatchDebounceTimer = null;
1315
+ // let currentWatchPath = null;
1316
+ //
1317
1317
  // 忽略规则:从统一的 IGNORED_PATTERNS 生成,并忽略所有隐藏目录
1318
- const ignoredPaths = [
1319
- ...Array.from(IGNORED_PATTERNS).map(p => `**/${p}/**`),
1320
- '**/.*/**', // 忽略所有隐藏目录(.git, .Trash, .docker 等)
1321
- ];
1322
-
1318
+ // const ignoredPaths = [
1319
+ // ...Array.from(IGNORED_PATTERNS).map(p => '**/' + p + '/**'),
1320
+ // '**/.*/**', // 忽略所有隐藏目录(.git, .Trash, .docker 等)
1321
+ // ];
1322
+ //
1323
1323
  // 启动文件监控
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
-
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
+ //
1385
1385
  // 停止文件监控
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
-
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
+ //
1398
1398
  // 监听 PTY 退出事件,停止文件监控(只在监控器运行时停止)
1399
- onPtyExit(() => {
1400
- if (fileWatcher && !fileWatcher.closed) {
1401
- stopFileWatcher();
1402
- console.log('[CC Viewer] File watcher stopped (PTY exited)');
1403
- }
1404
- });
1405
-
1399
+ // onPtyExit(() => {
1400
+ // if (fileWatcher && !fileWatcher.closed) {
1401
+ // stopFileWatcher();
1402
+ // console.log('[CC Viewer] File watcher stopped (PTY exited)');
1403
+ // }
1404
+ // });
1405
+ //
1406
1406
  // 初始化时检查是否有活跃的工作区
1407
- const workspace = getCurrentWorkspace();
1408
- if (workspace.running && workspace.cwd) {
1409
- startFileWatcher(workspace.cwd);
1410
- }
1411
-
1407
+ // const workspace = getCurrentWorkspace();
1408
+ // if (workspace.running && workspace.cwd) {
1409
+ // startFileWatcher(workspace.cwd);
1410
+ // }
1411
+ //
1412
1412
  // 定期检查工作区状态,确保监控器在 PTY 启动后自动开始工作
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
-
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
+ //
1436
1436
  // 清理定时器
1437
- const originalClose = wss.close;
1438
- wss.close = function() {
1439
- clearInterval(workspaceCheckInterval);
1440
- stopFileWatcher();
1441
- return originalClose.call(this);
1442
- };
1443
- */
1437
+ // const originalClose = wss.close;
1438
+ // wss.close = function() {
1439
+ // clearInterval(workspaceCheckInterval);
1440
+ // stopFileWatcher();
1441
+ // return originalClose.call(this);
1442
+ // };
1443
+
1444
1444
 
1445
1445
  httpServer.on('upgrade', (req, socket, head) => {
1446
1446
  const pathname = new URL(req.url, `http://${req.headers.host}`).pathname;