/ clis / codex / history.js
history.js
 1  import { cli, Strategy } from '@jackwener/opencli/registry';
 2  export const historyCommand = cli({
 3      site: 'codex',
 4      name: 'history',
 5      description: 'List recent conversation threads in Codex',
 6      domain: 'localhost',
 7      strategy: Strategy.UI,
 8      browser: true,
 9      args: [],
10      columns: ['Index', 'Title'],
11      func: async (page) => {
12          const items = await page.evaluate(`
13        (function() {
14          const results = [];
15          // Codex thread list items
16          const entries = document.querySelectorAll('[data-testid*="thread"], [class*="thread-list"] a, [role="listbox"] [role="option"]');
17          
18          entries.forEach((item, i) => {
19            const title = (item.textContent || item.innerText || '').trim().substring(0, 100);
20            if (title) results.push({ Index: i + 1, Title: title });
21          });
22          
23          // Fallback: sidebar/nav links
24          if (results.length === 0) {
25            const nav = document.querySelector('nav, [role="navigation"], aside');
26            if (nav) {
27              const links = nav.querySelectorAll('a, button');
28              links.forEach((link, i) => {
29                const text = (link.textContent || '').trim().substring(0, 100);
30                if (text && text.length > 3) results.push({ Index: i + 1, Title: text });
31              });
32            }
33          }
34          
35          return results;
36        })()
37      `);
38          if (items.length === 0) {
39              return [{ Index: 0, Title: 'No threads found. Try opening the thread list first.' }];
40          }
41          return items;
42      },
43  });