debug-parse2.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Debug: check where truncation happens - in the response or in saveFailedResponse
  2. const fs = require('fs');
  3. // Check the saved file - does it match what we expect?
  4. const content = fs.readFileSync('temp/rich-outline-fail_57_1779014018760.txt', 'utf-8');
  5. const marker = '========== AI 原始响应 ';
  6. const idx = content.indexOf(marker);
  7. // File says "AI 原始响应 (9867 chars)"
  8. // Let's check what 9867 chars of actual response would be
  9. const start = content.indexOf('\n', idx) + 1;
  10. const end = content.indexOf('\n\n========== 响应结尾');
  11. const savedResponse = content.substring(start, end).trim();
  12. console.log('Saved response length:', savedResponse.length);
  13. console.log('File header says: 9867 chars');
  14. console.log('Match:', savedResponse.length === 9867);
  15. console.log('\n--- Saved response end ---');
  16. console.log(JSON.stringify(savedResponse.substring(savedResponse.length - 100)));
  17. // The file also has a tail
  18. const tailMarker = '========== 响应结尾500字符 ';
  19. const tailIdx = content.indexOf(tailMarker);
  20. const tailStart = content.indexOf('\n', tailIdx) + 1;
  21. const tail = content.substring(tailStart).trim();
  22. console.log('\n--- Tail (last 500 chars of original) ---');
  23. console.log(JSON.stringify(tail.substring(0, 500)));
  24. // Check if saved response ends mid-property
  25. const lastPropMatch = savedResponse.match(/"estimatedWords":\s*(\d+)/);
  26. console.log('\n--- Last complete property "estimatedWords" ---');
  27. const allEstWords = savedResponse.match(/"estimatedWords":\s*\d+/g);
  28. if (allEstWords) {
  29. console.log('All estimatedWords found:', allEstWords.length);
  30. console.log('Last one:', allEstWords[allEstWords.length - 1]);
  31. } else {
  32. console.log('No complete estimatedWords properties');
  33. }
  34. // Is there a partial "estimatedWords" at the end?
  35. const last500 = savedResponse.slice(-200);
  36. console.log('\n--- Last 200 chars ---');
  37. console.log(JSON.stringify(last500));