/ clis / codex / read.js
read.js
 1  import { cli, Strategy } from '@jackwener/opencli/registry';
 2  export const readCommand = cli({
 3      site: 'codex',
 4      name: 'read',
 5      description: 'Read the contents of the current Codex conversation thread',
 6      domain: 'localhost',
 7      strategy: Strategy.UI,
 8      browser: true,
 9      args: [],
10      columns: ['Content'],
11      func: async (page) => {
12          const historyText = await page.evaluate(`
13        (function() {
14          const turns = Array.from(document.querySelectorAll('[data-content-search-turn-key]'));
15          if (turns.length > 0) {
16              return turns.map(t => t.innerText || t.textContent).join('\\n\\n---\\n\\n');
17          }
18          
19          const threadContainer = document.querySelector('[role="log"], [data-testid="conversation"], .thread-container, .messages-list, main');
20          
21          if (threadContainer) {
22            return threadContainer.innerText || threadContainer.textContent;
23          }
24          
25          return document.body.innerText;
26        })()
27      `);
28          return [
29              {
30                  Content: historyText,
31              },
32          ];
33      },
34  });