debug-parse7.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const fs = require('fs');
  2. const content = fs.readFileSync('temp/rich-outline-fail_57_1779014691106.txt', 'utf-8');
  3. const marker = '========== AI 原始响应 ';
  4. const markerIdx = content.indexOf(marker);
  5. const headerEndIdx = content.indexOf(' ==========', markerIdx);
  6. const aiStart = content.indexOf('\n', headerEndIdx) + 1;
  7. const aiEnd = content.indexOf('\n\n', aiStart);
  8. const aiResponse = content.substring(aiStart, aiEnd);
  9. console.log('Response length:', aiResponse.length);
  10. // The error is at position 523, char at 523 is "{"
  11. // The snippet shows: ..."呼吸"},{number":2,"title":
  12. // Wait - let me look more carefully at the actual bytes
  13. // At 520 we have " (quote, closing keyTakeaway string)
  14. // At 521 we have } (closing the parent object)
  15. // At 522 we have , (comma)
  16. // At 523 we have { (opening a new object)
  17. // At 524-529 we have number (but it should be "number")
  18. // At 530 we have "
  19. // At 531 we have :
  20. // At 532 we have 2
  21. // So the AI returned: ...呼吸"},{number":2,...
  22. // But properly formatted JSON would be: ...呼吸"},{"number":2,...
  23. // The issue is there's a missing quote BEFORE "number"
  24. // Let's check if this is a truncation or an AI generation error
  25. // by looking at what's around pos 523 more carefully
  26. console.log('\nContext around pos 523 (200 chars before and after):');
  27. console.log(JSON.stringify(aiResponse.substring(323, 623)));
  28. // Check the last 200 chars
  29. console.log('\nLast 200 chars:');
  30. console.log(JSON.stringify(aiResponse.substring(aiResponse.length - 200)));
  31. // Count all occurrences of ",{" to see if there's a pattern
  32. let count = 0;
  33. let idx = aiResponse.indexOf(',{');
  34. while (idx !== -1) { count++; idx = aiResponse.indexOf(',{', idx + 1); }
  35. console.log('\nOccurrences of ",{":', count);
  36. // Count all occurrences of number": without opening quote
  37. const badPattern = /,\{number":/g;
  38. const matches = aiResponse.match(badPattern);
  39. console.log('Bad pattern ",{number":":', matches ? matches.length : 0);
  40. // The issue: there's NO space after the comma, it's ","{number":2"
  41. // That's a JSON error - missing quote before "number"
  42. // This is likely an AI generation error, not truncation