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

async function extractMissingFeatures() {
    const logPath = 'C:\\Users\\BS\\.gemini\\antigravity\\brain\\393257b2-e812-421c-92f7-099f2362049e\\.system_generated\\logs\\transcript.jsonl';
    
    if (!fs.existsSync(logPath)) {
        console.log("No transcript found.");
        return;
    }
    
    const rl = readline.createInterface({
        input: fs.createReadStream(logPath),
        crlfDelay: Infinity
    });
    
    let codes = [];
    let seen = new Set();
    
    for await (const line of rl) {
        try {
            const parsed = JSON.parse(line);
            if (parsed.type === 'PLANNER_RESPONSE' && parsed.tool_calls) {
                for (const call of parsed.tool_calls) {
                    if (call.name === 'write_to_file' || call.name === 'replace_file_content' || call.name === 'multi_replace_file_content') {
                        let content = '';
                        if (call.args && call.args.CodeContent) content = call.args.CodeContent;
                        if (call.args && call.args.ReplacementContent) content = call.args.ReplacementContent;
                        if (call.args && call.args.ReplacementChunks) {
                             content = call.args.ReplacementChunks.map(c => c.ReplacementContent).join('\\n');
                        }
                        
                        if (content && (content.includes('openSettlementModal') || content.includes('openContactStatement') || content.includes('openAccountStatement'))) {
                            if (!seen.has(content.length)) {
                                seen.add(content.length);
                                codes.push({
                                    target: call.args.TargetFile || 'unknown',
                                    content: content
                                });
                            }
                        }
                    }
                }
            }
        } catch(e) {}
    }
    
    if (codes.length > 0) {
        let out = '';
        codes.forEach((c, i) => {
            out += `\n\n--- BLOCK ${i} (${c.target}) ---\n`;
            out += c.content;
        });
        fs.writeFileSync('missing_features.txt', out);
        console.log(`Found ${codes.length} blocks! Wrote to missing_features.txt`);
    } else {
        console.log("No blocks found.");
    }
}
extractMissingFeatures();
