@bangdao-ai/acw-tools 1.4.1-beta.3 → 1.4.1-beta.4

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/index.js +20 -17
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1499,19 +1499,34 @@ function getAverageCpuUsage() {
1499
1499
  */
1500
1500
  async function shouldThrottleScan() {
1501
1501
  try {
1502
- // 先记录当前 CPU 使用率
1502
+ const threshold = mcpConfig.cpuThrottleThreshold || 30;
1503
+ const windowMinutes = mcpConfig.cpuSampleWindow || 10;
1504
+
1505
+ // 首次启动检查:在记录 CPU 之前检查是否有历史数据
1506
+ const isFirstRun = cpuUsageHistory.length === 0;
1507
+
1508
+ // 记录当前 CPU 使用率
1503
1509
  const currentUsage = await recordCpuUsage();
1504
1510
 
1511
+ // 如果是首次启动,允许立即同步
1512
+ if (isFirstRun) {
1513
+ logger.info('首次启动,允许立即同步');
1514
+ return {
1515
+ shouldSkip: false,
1516
+ reason: '首次启动,跳过 CPU 节流检查',
1517
+ currentUsage,
1518
+ avgUsage: -1,
1519
+ sampleCount: 1
1520
+ };
1521
+ }
1522
+
1505
1523
  // 获取平均使用率
1506
1524
  const avgUsage = getAverageCpuUsage();
1507
- const threshold = mcpConfig.cpuThrottleThreshold || 20;
1508
- const windowMinutes = mcpConfig.cpuSampleWindow || 30;
1509
1525
  const sampleCount = cpuUsageHistory.length;
1510
1526
 
1511
1527
  // 如果采样数据不足(少于 3 个样本),暂不执行同步,等待积累更多数据
1512
- // 但首次启动时(MCP 刚启动)应该允许立即同步
1513
1528
  const minSamples = 3;
1514
- if (sampleCount < minSamples && sampleCount > 0) {
1529
+ if (sampleCount < minSamples) {
1515
1530
  return {
1516
1531
  shouldSkip: true,
1517
1532
  reason: `采样数据不足 (${sampleCount}/${minSamples}),等待积累更多 CPU 历史数据`,
@@ -1521,18 +1536,6 @@ async function shouldThrottleScan() {
1521
1536
  };
1522
1537
  }
1523
1538
 
1524
- // 如果没有历史数据(首次启动),允许立即同步
1525
- if (sampleCount === 0) {
1526
- logger.info('首次启动,允许立即同步');
1527
- return {
1528
- shouldSkip: false,
1529
- reason: '首次启动,跳过 CPU 节流检查',
1530
- currentUsage,
1531
- avgUsage: -1,
1532
- sampleCount: 0
1533
- };
1534
- }
1535
-
1536
1539
  // 检查平均使用率是否低于阈值
1537
1540
  if (avgUsage >= threshold) {
1538
1541
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bangdao-ai/acw-tools",
3
- "version": "1.4.1-beta.3",
3
+ "version": "1.4.1-beta.4",
4
4
  "type": "module",
5
5
  "description": "MCP (Model Context Protocol) tools for ACW - download rules and initialize Common Admin projects",
6
6
  "main": "index.js",