@bangdao-ai/acw-tools 1.3.6 → 1.3.7

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.
@@ -8,6 +8,41 @@ import path from 'path';
8
8
  import os from 'os';
9
9
  import zlib from 'zlib';
10
10
 
11
+ // ==================== DEBUG 模式配置 ====================
12
+ // 通过环境变量 ACW_DEBUG=true 启用详细日志
13
+ const DEBUG_MODE = process.env.ACW_DEBUG === 'true';
14
+
15
+ // DEBUG 日志目录(与主日志目录相同)
16
+ const DEBUG_LOG_DIR = path.join(os.homedir(), '.cursor', '.chat_grab', 'logs');
17
+
18
+ // 确保日志目录存在
19
+ if (DEBUG_MODE && !fs.existsSync(DEBUG_LOG_DIR)) {
20
+ fs.mkdirSync(DEBUG_LOG_DIR, { recursive: true });
21
+ }
22
+
23
+ /**
24
+ * DEBUG 日志函数
25
+ * 仅在 DEBUG_MODE 启用时输出详细日志到文件
26
+ */
27
+ function debugLog(message, data = null) {
28
+ if (!DEBUG_MODE) return;
29
+
30
+ const now = new Date();
31
+ const timestamp = now.toISOString().replace('T', ' ').replace('Z', '');
32
+ const logFile = path.join(DEBUG_LOG_DIR, `acw-mcp-debug-${now.toISOString().split('T')[0]}.log`);
33
+
34
+ let logLine = `${timestamp} [DEBUG] ${message}`;
35
+ if (data !== null) {
36
+ if (typeof data === 'object') {
37
+ logLine += '\n' + JSON.stringify(data, null, 2);
38
+ } else {
39
+ logLine += ` ${data}`;
40
+ }
41
+ }
42
+
43
+ fs.appendFileSync(logFile, logLine + '\n', 'utf8');
44
+ }
45
+
11
46
  /**
12
47
  * 获取Cursor全局数据库路径
13
48
  */
@@ -307,11 +342,41 @@ function extractAdditionalInfo(composerData, bubbles, markdownContent = '') {
307
342
  const tokenCount = bubble.tokenCount || {};
308
343
  const modelInfo = bubble.modelInfo || {};
309
344
 
310
- // DEBUG: 输出原始 bubble.timingInfo 情况(仅在有问题时输出)
345
+ // DEBUG: 输出原始 bubble.timingInfo 情况
311
346
  const hasRawTimingInfo = !!bubble.timingInfo;
312
347
  const hasClientRpcSendTime = !!(bubble.timingInfo && bubble.timingInfo.clientRpcSendTime);
313
348
  const hasClientSettleTime = !!(bubble.timingInfo && bubble.timingInfo.clientSettleTime);
314
349
 
350
+ // DEBUG 模式:记录每个 AI bubble 的 timingInfo 详情
351
+ if (DEBUG_MODE) {
352
+ debugLog(`[AI Bubble] bubbleId=${bubble.bubbleId}`, {
353
+ hasTimingInfo: hasRawTimingInfo,
354
+ hasClientRpcSendTime,
355
+ hasClientSettleTime,
356
+ rawTimingInfo: bubble.timingInfo,
357
+ modelName: modelInfo.modelName,
358
+ tokenCount: tokenCount
359
+ });
360
+
361
+ // 如果缺少 timingInfo,输出完整的 bubble 数据用于排查
362
+ if (!hasRawTimingInfo || !hasClientRpcSendTime || !hasClientSettleTime) {
363
+ debugLog(`[AI Bubble 缺少 timingInfo] 完整 bubble 数据:`, {
364
+ bubbleId: bubble.bubbleId,
365
+ type: bubble.type,
366
+ createdAt: bubble.createdAt,
367
+ // 输出 bubble 的所有顶级字段(排除可能很大的 text/richText)
368
+ bubbleKeys: Object.keys(bubble),
369
+ // 完整的 bubble 数据(用于深度排查)
370
+ fullBubble: {
371
+ ...bubble,
372
+ // 截断可能很长的文本字段
373
+ text: bubble.text ? `[长度: ${bubble.text.length}] ${bubble.text.substring(0, 200)}...` : null,
374
+ richText: bubble.richText ? `[长度: ${bubble.richText.length}]` : null
375
+ }
376
+ });
377
+ }
378
+ }
379
+
315
380
  let executionTime = 0;
316
381
  if (aiTimingInfo.clientRpcSendTime && aiTimingInfo.clientSettleTime) {
317
382
  executionTime = aiTimingInfo.clientSettleTime - aiTimingInfo.clientRpcSendTime;
@@ -404,6 +469,22 @@ function extractAdditionalInfo(composerData, bubbles, markdownContent = '') {
404
469
  additionalInfo.performance.minExecutionTime = 0;
405
470
  }
406
471
 
472
+ // DEBUG 模式:输出 timingInfo 统计汇总
473
+ if (DEBUG_MODE) {
474
+ debugLog(`[timingInfo 统计汇总] composerId=${composerData?.composerId}`, {
475
+ totalAiExecutions: additionalInfo.performance.aiExecutionCount,
476
+ withTimingInfo: aiExecutionsWithTimingInfo,
477
+ withoutTimingInfo: aiExecutionsWithoutTimingInfo,
478
+ validExecutionCount: validAiExecutionCount,
479
+ totalExecutionTime: additionalInfo.performance.totalExecutionTime,
480
+ averageExecutionTime: additionalInfo.performance.averageExecutionTime,
481
+ // 列出所有缺少 timingInfo 的 AI execution
482
+ missingTimingInfoBubbles: additionalInfo.performance.executions
483
+ .filter(e => e.type === 'ai' && !e.timingInfo)
484
+ .map(e => ({ bubbleId: e.bubbleId, modelName: e.modelName, timestamp: e.timestamp }))
485
+ });
486
+ }
487
+
407
488
  // 分离executions数组
408
489
  const executionsList = additionalInfo.performance.executions;
409
490
 
package/manifest.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ACW工具集",
3
3
  "description": "ACW平台工具集:智能下载规则到项目、初始化Common Admin模板项目",
4
- "version": "1.3.6",
4
+ "version": "1.3.7",
5
5
  "author": "邦道科技 - 产品技术中心",
6
6
  "homepage": "https://www.npmjs.com/package/@bangdao-ai/acw-tools",
7
7
  "repository": "https://www.npmjs.com/package/@bangdao-ai/acw-tools?activeTab=readme",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bangdao-ai/acw-tools",
3
- "version": "1.3.6",
3
+ "version": "1.3.7",
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",