Files
jackwener__opencli/clis/codex/send.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

52 lines
1.9 KiB
JavaScript

import { cli, Strategy } from '@jackwener/opencli/registry';
import { selectorError } from '@jackwener/opencli/errors';
import { conversationSelectionArgs, openCodexConversation } from './sidebar.js';
export const sendCommand = cli({
site: 'codex',
name: 'send',
access: 'write',
description: 'Send text/commands to the current or selected Codex AI composer',
domain: 'localhost',
strategy: Strategy.UI,
browser: true,
args: [
{ name: 'text', required: true, positional: true, help: 'Text, command (e.g. /review), or skill (e.g. $imagegen)' },
...conversationSelectionArgs,
],
columns: ['Status', 'Project', 'Conversation', 'InjectedText'],
func: async (page, kwargs) => {
const textToInsert = kwargs.text;
const selected = await openCodexConversation(page, kwargs);
const injected = await page.evaluate(`
(function(text) {
let composer = document.querySelector('textarea, [contenteditable="true"]');
const editables = Array.from(document.querySelectorAll('[contenteditable="true"]'));
if (editables.length > 0) {
composer = editables[editables.length - 1];
}
if (!composer) return false;
composer.focus();
document.execCommand('insertText', false, text);
return true;
})(${JSON.stringify(textToInsert)})
`);
if (!injected)
throw selectorError('Codex Composer input element');
// Wait for the UI to register the input
await page.wait(0.5);
// Simulate Enter key to submit
await page.pressKey('Enter');
return [
{
Status: 'Success',
Project: selected?.project || '',
Conversation: selected?.conversation || '',
InjectedText: textToInsert,
},
];
},
});