@riconext/hermes-repo 1.2.2 → 1.2.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 17d33f3: 增加 flush 调用 LLM 时的详细 debug 日志,便于检查请求输入、原始响应和标准化后的知识文件结果。
8
+
3
9
  ## 1.2.2
4
10
 
5
11
  ### Patch Changes
package/dist/cli.js CHANGED
@@ -62,6 +62,16 @@ function debugLog(enabled, phase, message) {
62
62
  console.error(line);
63
63
  writeToLogFile(line);
64
64
  }
65
+ function debugLogBlock(enabled, phase, label, content) {
66
+ if (!enabled) {
67
+ return;
68
+ }
69
+ debugLog(true, phase, `${label} BEGIN`);
70
+ for (const line of content.split(/\r?\n/)) {
71
+ debugLog(true, phase, `| ${line}`);
72
+ }
73
+ debugLog(true, phase, `${label} END`);
74
+ }
65
75
  function debugFromContext(ctx, phase, message) {
66
76
  debugLog(ctx?.config.debug === true, phase, message);
67
77
  }
@@ -1423,7 +1433,7 @@ function buildLlmConsolidateInput(repoRoot, sessions) {
1423
1433
  currentMemoryMd
1424
1434
  };
1425
1435
  }
1426
- async function callLlmConsolidate(input2, llmConfig) {
1436
+ async function callLlmConsolidate(input2, llmConfig, debug = false) {
1427
1437
  if (!llmConfig.enabled) {
1428
1438
  throw new Error(
1429
1439
  "LLM \u672A\u542F\u7528\uFF1A\u8BF7\u5728 config.json \u4E2D\u8BBE\u7F6E llm.enabled = true"
@@ -1436,6 +1446,23 @@ async function callLlmConsolidate(input2, llmConfig) {
1436
1446
  }
1437
1447
  const url = `${llmConfig.baseUrl.replace(/\/$/, "")}/chat/completions`;
1438
1448
  const userContent = formatUserMessage(input2);
1449
+ debugLog(
1450
+ debug,
1451
+ "llm",
1452
+ `request: provider=${llmConfig.provider}, model=${llmConfig.model}, baseUrl=${llmConfig.baseUrl}, pendingSessions=${input2.pendingSessions.length}, existingKnowledge=${input2.existingKnowledge.length}, currentMemoryChars=${input2.currentMemoryMd?.length ?? 0}`
1453
+ );
1454
+ debugLogBlock(debug, "llm", "system prompt", CONSOLIDATE_SYSTEM_PROMPT);
1455
+ debugLogBlock(debug, "llm", "user input", userContent);
1456
+ const requestBody = {
1457
+ model: llmConfig.model,
1458
+ response_format: { type: "json_object" },
1459
+ messages: [
1460
+ { role: "system", content: CONSOLIDATE_SYSTEM_PROMPT },
1461
+ { role: "user", content: userContent }
1462
+ ],
1463
+ temperature: 0.2
1464
+ };
1465
+ debugLogBlock(debug, "llm", "request body", JSON.stringify(requestBody, null, 2));
1439
1466
  const controller = new AbortController();
1440
1467
  const timeout = setTimeout(() => controller.abort(), 12e4);
1441
1468
  try {
@@ -1445,35 +1472,58 @@ async function callLlmConsolidate(input2, llmConfig) {
1445
1472
  "Content-Type": "application/json",
1446
1473
  Authorization: `Bearer ${llmConfig.apiKey}`
1447
1474
  },
1448
- body: JSON.stringify({
1449
- model: llmConfig.model,
1450
- response_format: { type: "json_object" },
1451
- messages: [
1452
- { role: "system", content: CONSOLIDATE_SYSTEM_PROMPT },
1453
- { role: "user", content: userContent }
1454
- ],
1455
- temperature: 0.2
1456
- }),
1475
+ body: JSON.stringify(requestBody),
1457
1476
  signal: controller.signal
1458
1477
  });
1478
+ debugLog(debug, "llm", `response status: ${res.status} ${res.statusText}`);
1459
1479
  if (!res.ok) {
1460
1480
  const errBody = await res.text().catch(() => "");
1481
+ debugLogBlock(debug, "llm", "error response body", errBody);
1461
1482
  throw new Error(
1462
1483
  `LLM API \u9519\u8BEF (${res.status}): ${errBody.slice(0, 300)}`
1463
1484
  );
1464
1485
  }
1465
1486
  const data = await res.json();
1487
+ debugLogBlock(debug, "llm", "response json", JSON.stringify(data, null, 2));
1466
1488
  const rawContent = data.choices?.[0]?.message?.content;
1467
1489
  if (!rawContent) {
1468
1490
  throw new Error("LLM \u8FD4\u56DE\u5185\u5BB9\u4E3A\u7A7A");
1469
1491
  }
1492
+ debugLogBlock(debug, "llm", "raw message content", rawContent);
1470
1493
  let parsed;
1471
1494
  try {
1472
1495
  parsed = JSON.parse(rawContent);
1473
1496
  } catch {
1474
1497
  throw new Error("LLM \u8FD4\u56DE\u5185\u5BB9\u4E0D\u662F\u5408\u6CD5 JSON");
1475
1498
  }
1476
- return validateAndNormalizeLlmResult(parsed);
1499
+ debugLogBlock(debug, "llm", "parsed content", JSON.stringify(parsed, null, 2));
1500
+ const normalized = validateAndNormalizeLlmResult(parsed);
1501
+ debugLog(
1502
+ debug,
1503
+ "llm",
1504
+ `normalized: knowledgeFiles=${normalized.knowledgeFiles.length}, memoryChars=${normalized.memoryMd.length}, skippedSessions=${normalized.skippedSessions.length}`
1505
+ );
1506
+ debugLogBlock(
1507
+ debug,
1508
+ "llm",
1509
+ "normalized knowledgeFiles",
1510
+ JSON.stringify(normalized.knowledgeFiles, null, 2)
1511
+ );
1512
+ debugLogBlock(debug, "llm", "normalized memoryMd", normalized.memoryMd);
1513
+ debugLogBlock(
1514
+ debug,
1515
+ "llm",
1516
+ "normalized skippedSessions",
1517
+ JSON.stringify(normalized.skippedSessions, null, 2)
1518
+ );
1519
+ return normalized;
1520
+ } catch (err) {
1521
+ debugLog(
1522
+ debug,
1523
+ "llm",
1524
+ `error: ${err instanceof Error ? err.message : String(err)}`
1525
+ );
1526
+ throw err;
1477
1527
  } finally {
1478
1528
  clearTimeout(timeout);
1479
1529
  }
@@ -1769,7 +1819,7 @@ async function runConsolidate(opts) {
1769
1819
  );
1770
1820
  let llmResult;
1771
1821
  try {
1772
- llmResult = await callLlmConsolidate(llmInput, llmConfig);
1822
+ llmResult = await callLlmConsolidate(llmInput, llmConfig, debug === true);
1773
1823
  } catch (err) {
1774
1824
  console.error(`[consolidate] LLM \u8C03\u7528\u5931\u8D25: ${err.message}`);
1775
1825
  throw err;