Files
jackwener__opencli/clis/codex/read.js
YoungCan-Wang 36d22ef4d3 feat(codex): add projects/history sidebar commands with native click + typed fail-fast (#1307)
- 新增 `clis/codex/sidebar.js` 共享 helper,使用 `data-app-action-sidebar-*` DOM 属性 + native click 触发侧边栏导航
- 新增 `clis/codex/projects.js` 与 `clis/codex/history.js`:列表/详情双契约
- typed fail-fast 收口:
  * projects/history 空列表 → EmptyResultError
  * limit/timeout/index/thread-id 非法 → ArgumentError(拒绝 silent-clamp)
  * 目标项找不到 → EmptyResultError
  * sidebar DOM 缺失 → CommandExecutionError
- 新增 8 条 regression 单测(`clis/codex/sidebar.test.js`)
- B 组 codex-mini1 lead green + First-principles-1 aux green on `bcfd88ae`

Round 13 close-out.
2026-05-05 23:03:47 +08:00

42 lines
1.4 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { conversationSelectionArgs, openCodexConversation } from './sidebar.js';
export const readCommand = cli({
site: 'codex',
name: 'read',
access: 'read',
description: 'Read the contents of the current or selected Codex conversation thread',
domain: 'localhost',
strategy: Strategy.UI,
browser: true,
args: [
...conversationSelectionArgs,
],
columns: ['Project', 'Conversation', 'Content'],
func: async (page, kwargs) => {
const selected = await openCodexConversation(page, kwargs);
const historyText = await page.evaluate(`
(function() {
const turns = Array.from(document.querySelectorAll('[data-content-search-turn-key]'));
if (turns.length > 0) {
return turns.map(t => t.innerText || t.textContent).join('\\n\\n---\\n\\n');
}
const threadContainer = document.querySelector('[role="log"], [data-testid="conversation"], .thread-container, .messages-list, main');
if (threadContainer) {
return threadContainer.innerText || threadContainer.textContent;
}
return document.body.innerText;
})()
`);
return [
{
Project: selected?.project || '',
Conversation: selected?.conversation || '',
Content: historyText,
},
];
},
});