const fs = require('fs');
const content = fs.readFileSync('temp/rich-outline-fail_57_1779014691106.txt', 'utf-8');
const marker = '========== AI 原始响应 ';
const markerIdx = content.indexOf(marker);
const headerEndIdx = content.indexOf(' ==========', markerIdx);
const aiStart = content.indexOf('\n', headerEndIdx) + 1;
const aiEnd = content.indexOf('\n\n', aiStart);
const aiResponse = content.substring(aiStart, aiEnd);

const pos = 523;
// Check around position 500-550
console.log('500-550 chars:');
console.log(JSON.stringify(aiResponse.substring(500, 550)));
console.log('\nActual bytes:');
for (let i = 500; i < 550; i++) {
  const code = aiResponse.charCodeAt(i);
  process.stdout.write(i + ':' + code + '[' + aiResponse[i] + '] ');
}
console.log();

// The context shows: ...呼吸"},{number":2,"title"
// So at position 523 we have {number":2
// This means "number" property name is missing opening quote!
// Let's verify
const snippet = aiResponse.substring(pos - 5, pos + 30);
console.log('\nSnippet around error:', JSON.stringify(snippet));

// The exact characters at positions 523-530
console.log('\nChars 523-532:');
for (let i = 523; i < 532; i++) {
  const code = aiResponse.charCodeAt(i);
  console.log('  pos', i, '=', code, JSON.stringify(aiResponse[i]));
}

// Check if maybe there's a stray quote or something
// Look at what's between last " and the { at pos 523
let lastFewChars = '';
for (let i = 518; i < 523; i++) {
  lastFewChars += JSON.stringify(aiResponse[i]) + ' ';
}
console.log('\n518-522 chars:', lastFewChars);