extract-diff.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 export const extractDiffCommand = cli({ 3 site: 'codex', 4 name: 'extract-diff', 5 description: 'Extract visual code review diff patches from Codex', 6 domain: 'localhost', 7 strategy: Strategy.UI, 8 browser: true, 9 columns: ['File', 'Diff'], 10 func: async (page) => { 11 const diffs = await page.evaluate(` 12 (function() { 13 const results = []; 14 // Assuming diffs are rendered with standard diff classes or monaco difference editors 15 const diffBlocks = document.querySelectorAll('.diff-editor, .monaco-diff-editor, [data-testid="diff-view"]'); 16 17 diffBlocks.forEach((block, index) => { 18 // Very roughly scrape text representing additions/deletions mapped from the inner wrapper 19 results.push({ 20 File: block.getAttribute('data-filename') || \`DiffBlock_\${index+1}\`, 21 Diff: block.innerText || block.textContent 22 }); 23 }); 24 25 // If no structured diffs found, try to find any code blocks labeled as patches 26 if (results.length === 0) { 27 const codeBlocks = document.querySelectorAll('pre code.language-diff, pre code.language-patch'); 28 codeBlocks.forEach((code, index) => { 29 results.push({ 30 File: \`Patch_\${index+1}\`, 31 Diff: code.innerText || code.textContent 32 }); 33 }); 34 } 35 36 return results; 37 })() 38 `); 39 if (diffs.length === 0) { 40 return [{ File: 'No diffs found', Diff: 'Try running opencli codex send "/review" first' }]; 41 } 42 return diffs; 43 }, 44 });