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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +127 -125
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cc-viewer",
3
- "version": "1.4.23",
3
+ "version": "1.4.25",
4
4
  "description": "Claude Code Logger visualization management tool",
5
5
  "license": "MIT",
6
6
  "main": "server.js",
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
- let fileWatcher = null;
1313
- let fileWatchDebounceTimer = null;
1314
- let currentWatchPath = null;
1315
-
1311
+ // 文件监控器:监控工作区目录变更(暂时禁用)
1312
+ // 以下代码已被注释掉,如需启用请取消注释
1313
+ // let fileWatcher = null;
1314
+ // let fileWatchDebounceTimer = null;
1315
+ // let currentWatchPath = null;
1316
+ //
1316
1317
  // 忽略规则:从统一的 IGNORED_PATTERNS 生成,并忽略所有隐藏目录
1317
- const ignoredPaths = [
1318
- ...Array.from(IGNORED_PATTERNS).map(p => `**/${p}/**`),
1319
- '**/.*/**', // 忽略所有隐藏目录(.git, .Trash, .docker 等)
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
- if (fileWatcher) {
1325
- fileWatcher.close();
1326
- }
1327
- currentWatchPath = watchPath;
1328
-
1329
- try {
1330
- fileWatcher = chokidar.watch(watchPath, {
1331
- ignored: ignoredPaths,
1332
- persistent: true,
1333
- ignoreInitial: true, // 忽略初始扫描,只监控变更
1334
- awaitWriteFinish: {
1335
- stabilityThreshold: 100,
1336
- pollInterval: 50
1337
- }
1338
- });
1339
-
1340
- // 监听 chokidar 错误事件,避免崩溃
1341
- fileWatcher.on('error', (error) => {
1342
- console.error('[CC Viewer] File watcher error:', error.message);
1343
- // 不要让错误导致进程崩溃,只记录日志
1344
- });
1345
-
1346
- // 使用防抖避免频繁触发
1347
- fileWatcher.on('all', (eventType, path) => {
1348
- if (fileWatchDebounceTimer) {
1349
- clearTimeout(fileWatchDebounceTimer);
1350
- }
1351
-
1352
- fileWatchDebounceTimer = setTimeout(() => {
1353
- console.log(`[CC Viewer] File change detected: ${eventType} - ${path}`);
1354
-
1355
- // 广播文件变更事件给所有连接的客户端
1356
- const changeEvent = {
1357
- type: 'file-change',
1358
- eventType,
1359
- path,
1360
- watchPath: currentWatchPath
1361
- };
1362
-
1363
- const clientCount = wss.clients.size;
1364
- console.log(`[CC Viewer] Broadcasting file-change to ${clientCount} client(s)`);
1365
-
1366
- wss.clients.forEach((client) => {
1367
- if (client.readyState === 1) { // WebSocket.OPEN
1368
- try {
1369
- client.send(JSON.stringify(changeEvent));
1370
- } catch (err) {
1371
- console.error('[CC Viewer] Failed to send file-change event:', err.message);
1372
- }
1373
- }
1374
- });
1375
- }, 200); // 200ms 防抖延迟
1376
- });
1377
-
1378
- console.log(`[CC Viewer] File watcher started for: ${watchPath}`);
1379
- } catch (err) {
1380
- console.error('[CC Viewer] Failed to start file watcher:', err.message);
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
- if (fileWatchDebounceTimer) {
1387
- clearTimeout(fileWatchDebounceTimer);
1388
- fileWatchDebounceTimer = null;
1389
- }
1390
- if (fileWatcher) {
1391
- fileWatcher.close();
1392
- fileWatcher = null;
1393
- }
1394
- currentWatchPath = null;
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
- if (fileWatcher && !fileWatcher.closed) {
1400
- stopFileWatcher();
1401
- console.log('[CC Viewer] File watcher stopped (PTY exited)');
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
- startFileWatcher(workspace.cwd);
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
- const currentWorkspace = getCurrentWorkspace();
1414
- const isRunning = currentWorkspace.running && currentWorkspace.cwd;
1415
-
1416
- // 调试日志
1417
- if (process.env.CCV_DEBUG) {
1418
- console.log('[CC Viewer] Workspace check:', {
1419
- running: currentWorkspace.running,
1420
- cwd: currentWorkspace.cwd,
1421
- fileWatcher: fileWatcher ? (fileWatcher.closed ? 'closed' : 'active') : 'none',
1422
- currentWatchPath
1423
- });
1424
- }
1425
-
1426
- // 如果 PTY 正在运行但监控器未启动,则启动监控器
1427
- if (isRunning && (!fileWatcher || fileWatcher.closed)) {
1428
- if (currentWatchPath !== currentWorkspace.cwd) {
1429
- console.log(`[CC Viewer] Starting file watcher for: ${currentWorkspace.cwd}`);
1430
- startFileWatcher(currentWorkspace.cwd);
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
- clearInterval(workspaceCheckInterval);
1439
- stopFileWatcher();
1440
- return originalClose.call(this);
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;