const fs = require('fs');
const readline = require('readline');
const path = require('path');

async function extract() {
    const logPath = 'C:\\Users\\BS\\.gemini\\antigravity\\brain\\393257b2-e812-421c-92f7-099f2362049e\\.system_generated\\logs\\transcript.jsonl';
    
    if (!fs.existsSync(logPath)) {
        console.log("transcript not found");
        return;
    }
    
    const fileStream = fs.createReadStream(logPath);
    const rl = readline.createInterface({
        input: fileStream,
        crlfDelay: Infinity
    });
    
    let codes = [];
    
    for await (const line of rl) {
        try {
            const parsed = JSON.parse(line);
            if (parsed.type === 'PLANNER_RESPONSE' && parsed.tool_calls) {
                for (const tool of parsed.tool_calls) {
                    if (tool.name === 'write_to_file' || tool.name === 'replace_file_content' || tool.name === 'multi_replace_file_content') {
                        if (tool.args && tool.args.TargetFile && tool.args.TargetFile.includes('app.js')) {
                            // This might be the old app.js with the correct abstracts!
                            if (tool.args.CodeContent) {
                                codes.push({
                                    step: parsed.step_index,
                                    file: tool.args.TargetFile,
                                    len: tool.args.CodeContent.length
                                });
                            }
                        }
                        if (tool.args && tool.args.TargetFile && tool.args.TargetFile.includes('app_final.js')) {
                            if (tool.args.CodeContent) {
                                codes.push({
                                    step: parsed.step_index,
                                    file: tool.args.TargetFile,
                                    len: tool.args.CodeContent.length
                                });
                            }
                        }
                    }
                }
            }
        } catch(e) {}
    }
    
    console.log("Extracted code writes:");
    console.log(JSON.stringify(codes, null, 2));
}

extract();
