import fs from 'fs';

const jsonl =
  'C:/Users/한맥/.cursor/projects/d-EENE-Dashboard-0608/agent-transcripts/a31af370-8cc7-4941-8299-96fbb85f1ad8/a31af370-8cc7-4941-8299-96fbb85f1ad8.jsonl';
const cssPath = 'd:/EENE_Dashboard_0608/frontend/src/styles/quarter-board.css';

let content = fs.readFileSync(cssPath, 'utf8');
let applied = 0;
let missed = 0;

for (const line of fs.readFileSync(jsonl, 'utf8').split('\n')) {
  if (!line.trim()) continue;
  try {
    const o = JSON.parse(line);
    for (const p of o.message?.content ?? []) {
      if (p.type !== 'tool_use') continue;
      const inp = p.input ?? {};
      if (!inp.path?.includes('quarter-board.css')) continue;
      if (!inp.old_string || !inp.new_string) continue;
      if (content.includes(inp.old_string)) {
        content = content.replace(inp.old_string, inp.new_string);
        applied++;
      } else {
        missed++;
      }
    }
  } catch {
    /* skip */
  }
}

fs.writeFileSync(cssPath, content, 'utf8');
console.log({ applied, missed, length: content.length });
