export.js
1 import * as fs from 'node:fs'; 2 import { cli, Strategy } from '@jackwener/opencli/registry'; 3 export const exportCommand = cli({ 4 site: 'codex', 5 name: 'export', 6 description: 'Export the current Codex conversation to a Markdown file', 7 domain: 'localhost', 8 strategy: Strategy.UI, 9 browser: true, 10 args: [ 11 { name: 'output', required: false, help: 'Output file (default: /tmp/codex-export.md)' }, 12 ], 13 columns: ['Status', 'File', 'Messages'], 14 func: async (page, kwargs) => { 15 const outputPath = kwargs.output || '/tmp/codex-export.md'; 16 const md = await page.evaluate(` 17 (function() { 18 const turns = document.querySelectorAll('[data-content-search-turn-key]'); 19 if (turns.length > 0) { 20 return Array.from(turns).map((t, i) => '## Turn ' + (i + 1) + '\\n\\n' + (t.innerText || t.textContent).trim()).join('\\n\\n---\\n\\n'); 21 } 22 23 const main = document.querySelector('main, [role="main"], [role="log"]'); 24 if (main) return main.innerText || main.textContent; 25 return document.body.innerText; 26 })() 27 `); 28 fs.writeFileSync(outputPath, '# Codex Conversation Export\\n\\n' + md); 29 return [ 30 { 31 Status: 'Success', 32 File: outputPath, 33 Messages: md.split('## Turn').length - 1, 34 }, 35 ]; 36 }, 37 });